Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
d375116e
Commit
d375116e
authored
Feb 06, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化鉴权invoker定义
parent
991715fc
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
26 行增加
和
21 行删除
+26
-21
src/Common/config.h
+2
-1
src/Http/HttpSession.cpp
+6
-5
src/Rtmp/RtmpSession.cpp
+12
-10
src/Rtsp/RtspSession.cpp
+6
-5
没有找到文件。
src/Common/config.h
查看文件 @
d375116e
...
@@ -85,7 +85,8 @@ extern const char kBroadcastOnRtspAuth[];
...
@@ -85,7 +85,8 @@ extern const char kBroadcastOnRtspAuth[];
#define BroadcastOnRtspAuthArgs const string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker
#define BroadcastOnRtspAuthArgs const string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker
//鉴权结果回调对象
//鉴权结果回调对象
typedef
std
::
function
<
void
(
bool
success
,
const
string
&
errMessage
)
>
AuthInvoker
;
//如果errMessage为空则代表鉴权成功
typedef
std
::
function
<
void
(
const
string
&
errMessage
)
>
AuthInvoker
;
//收到rtmp推流事件广播,通过该事件控制推流鉴权
//收到rtmp推流事件广播,通过该事件控制推流鉴权
extern
const
char
kBroadcastRtmpPublish
[];
extern
const
char
kBroadcastRtmpPublish
[];
...
...
src/Http/HttpSession.cpp
查看文件 @
d375116e
...
@@ -206,7 +206,8 @@ inline bool HttpSession::checkLiveFlvStream(){
...
@@ -206,7 +206,8 @@ inline bool HttpSession::checkLiveFlvStream(){
return
true
;
return
true
;
}
}
auto
onRes
=
[
this
,
mediaSrc
](
bool
authSuccess
,
const
string
&
err
){
auto
onRes
=
[
this
,
mediaSrc
](
const
string
&
err
){
bool
authSuccess
=
err
.
empty
();
if
(
!
authSuccess
){
if
(
!
authSuccess
){
sendResponse
(
"401 Unauthorized"
,
makeHttpHeader
(
true
,
err
.
size
()),
err
);
sendResponse
(
"401 Unauthorized"
,
makeHttpHeader
(
true
,
err
.
size
()),
err
);
shutdown
();
shutdown
();
...
@@ -279,23 +280,23 @@ inline bool HttpSession::checkLiveFlvStream(){
...
@@ -279,23 +280,23 @@ inline bool HttpSession::checkLiveFlvStream(){
};
};
weak_ptr
<
HttpSession
>
weakSelf
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
weak_ptr
<
HttpSession
>
weakSelf
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
authSuccess
,
const
string
&
err
){
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
const
string
&
err
){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
if
(
!
strongSelf
){
return
;
return
;
}
}
strongSelf
->
async
([
weakSelf
,
onRes
,
authSuccess
,
err
](){
strongSelf
->
async
([
weakSelf
,
onRes
,
err
](){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
if
(
!
strongSelf
){
return
;
return
;
}
}
onRes
(
authSuccess
,
err
);
onRes
(
err
);
});
});
};
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
m_mediaInfo
,
invoker
);
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
m_mediaInfo
,
invoker
);
if
(
!
flag
){
if
(
!
flag
){
//该事件无人监听,默认不鉴权
//该事件无人监听,默认不鉴权
onRes
(
true
,
""
);
onRes
(
""
);
}
}
return
true
;
return
true
;
}
}
...
...
src/Rtmp/RtmpSession.cpp
查看文件 @
d375116e
...
@@ -134,12 +134,13 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
...
@@ -134,12 +134,13 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
dec
.
load
<
AMFValue
>
();
/* NULL */
dec
.
load
<
AMFValue
>
();
/* NULL */
m_mediaInfo
.
parse
(
m_strTcUrl
+
"/"
+
dec
.
load
<
std
::
string
>
());
m_mediaInfo
.
parse
(
m_strTcUrl
+
"/"
+
dec
.
load
<
std
::
string
>
());
auto
onRes
=
[
this
](
bool
authSuccess
,
const
string
&
err
){
auto
onRes
=
[
this
](
const
string
&
err
){
auto
src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
MediaSource
::
find
(
RTMP_SCHEMA
,
auto
src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
MediaSource
::
find
(
RTMP_SCHEMA
,
m_mediaInfo
.
m_vhost
,
m_mediaInfo
.
m_vhost
,
m_mediaInfo
.
m_app
,
m_mediaInfo
.
m_app
,
m_mediaInfo
.
m_streamid
,
m_mediaInfo
.
m_streamid
,
false
));
false
));
bool
authSuccess
=
err
.
empty
();
bool
ok
=
(
!
src
&&
!
m_pPublisherSrc
&&
authSuccess
);
bool
ok
=
(
!
src
&&
!
m_pPublisherSrc
&&
authSuccess
);
AMFValue
status
(
AMF_OBJECT
);
AMFValue
status
(
AMF_OBJECT
);
status
.
set
(
"level"
,
ok
?
"status"
:
"error"
);
status
.
set
(
"level"
,
ok
?
"status"
:
"error"
);
...
@@ -162,17 +163,17 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
...
@@ -162,17 +163,17 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
};
};
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
success
,
const
string
&
err
){
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
const
string
&
err
){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
if
(
!
strongSelf
){
return
;
return
;
}
}
strongSelf
->
async
([
weakSelf
,
onRes
,
success
,
err
](){
strongSelf
->
async
([
weakSelf
,
onRes
,
err
](){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
if
(
!
strongSelf
){
return
;
return
;
}
}
onRes
(
success
,
err
);
onRes
(
err
);
});
});
};
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Config
::
Broadcast
::
kBroadcastRtmpPublish
,
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Config
::
Broadcast
::
kBroadcastRtmpPublish
,
...
@@ -180,7 +181,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
...
@@ -180,7 +181,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
invoker
);
invoker
);
if
(
!
flag
){
if
(
!
flag
){
//该事件无人监听,默认鉴权成功
//该事件无人监听,默认鉴权成功
onRes
(
true
,
""
);
onRes
(
""
);
}
}
}
}
...
@@ -194,12 +195,13 @@ void RtmpSession::onCmd_deleteStream(AMFDecoder &dec) {
...
@@ -194,12 +195,13 @@ void RtmpSession::onCmd_deleteStream(AMFDecoder &dec) {
}
}
void
RtmpSession
::
doPlay
(
AMFDecoder
&
dec
){
void
RtmpSession
::
doPlay
(
AMFDecoder
&
dec
){
auto
onRes
=
[
this
](
bool
authSuccess
,
const
string
&
err
)
{
auto
onRes
=
[
this
](
const
string
&
err
)
{
auto
src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
MediaSource
::
find
(
RTMP_SCHEMA
,
auto
src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
MediaSource
::
find
(
RTMP_SCHEMA
,
m_mediaInfo
.
m_vhost
,
m_mediaInfo
.
m_vhost
,
m_mediaInfo
.
m_app
,
m_mediaInfo
.
m_app
,
m_mediaInfo
.
m_streamid
,
m_mediaInfo
.
m_streamid
,
true
));
true
));
bool
authSuccess
=
err
.
empty
();
bool
ok
=
(
src
.
operator
bool
()
&&
authSuccess
);
bool
ok
=
(
src
.
operator
bool
()
&&
authSuccess
);
if
(
ok
){
if
(
ok
){
ok
=
ok
&&
src
->
ready
();
ok
=
ok
&&
src
->
ready
();
...
@@ -297,23 +299,23 @@ void RtmpSession::doPlay(AMFDecoder &dec){
...
@@ -297,23 +299,23 @@ void RtmpSession::doPlay(AMFDecoder &dec){
};
};
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
authSuccess
,
const
string
&
err
){
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
const
string
&
err
){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
if
(
!
strongSelf
){
return
;
return
;
}
}
strongSelf
->
async
([
weakSelf
,
onRes
,
authSuccess
,
err
](){
strongSelf
->
async
([
weakSelf
,
onRes
,
err
](){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
if
(
!
strongSelf
){
return
;
return
;
}
}
onRes
(
authSuccess
,
err
);
onRes
(
err
);
});
});
};
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
m_mediaInfo
,
invoker
);
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
m_mediaInfo
,
invoker
);
if
(
!
flag
){
if
(
!
flag
){
//该事件无人监听,默认不鉴权
//该事件无人监听,默认不鉴权
onRes
(
true
,
""
);
onRes
(
""
);
}
}
}
}
void
RtmpSession
::
onCmd_play2
(
AMFDecoder
&
dec
)
{
void
RtmpSession
::
onCmd_play2
(
AMFDecoder
&
dec
)
{
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
d375116e
...
@@ -649,7 +649,8 @@ bool RtspSession::handleReq_Play() {
...
@@ -649,7 +649,8 @@ bool RtspSession::handleReq_Play() {
send_SessionNotFound
();
send_SessionNotFound
();
return
false
;
return
false
;
}
}
auto
onRes
=
[
this
](
bool
authSuccess
,
const
string
&
err
){
auto
onRes
=
[
this
](
const
string
&
err
){
bool
authSuccess
=
err
.
empty
();
char
response
[
2
*
1024
];
char
response
[
2
*
1024
];
m_pcBuf
=
response
;
m_pcBuf
=
response
;
if
(
!
authSuccess
&&
m_bFirstPlay
){
if
(
!
authSuccess
&&
m_bFirstPlay
){
...
@@ -742,23 +743,23 @@ bool RtspSession::handleReq_Play() {
...
@@ -742,23 +743,23 @@ bool RtspSession::handleReq_Play() {
};
};
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
bool
authSuccess
,
const
string
&
err
){
Broadcast
::
AuthInvoker
invoker
=
[
weakSelf
,
onRes
](
const
string
&
err
){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
if
(
!
strongSelf
){
return
;
return
;
}
}
strongSelf
->
async
([
weakSelf
,
onRes
,
authSuccess
,
err
](){
strongSelf
->
async
([
weakSelf
,
onRes
,
err
](){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
if
(
!
strongSelf
){
return
;
return
;
}
}
onRes
(
authSuccess
,
err
);
onRes
(
err
);
});
});
};
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
m_mediaInfo
,
invoker
);
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
m_mediaInfo
,
invoker
);
if
(
!
flag
){
if
(
!
flag
){
//该事件无人监听,默认不鉴权
//该事件无人监听,默认不鉴权
onRes
(
true
,
""
);
onRes
(
""
);
}
}
return
true
;
return
true
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论