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
db0611de
Commit
db0611de
authored
May 30, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复rtsp注册前未设置sdp的bug
rtsp鉴权放置在查找流之前,防止无谓的按需拉流
parent
6d08e2a2
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
56 行增加
和
50 行删除
+56
-50
3rdpart/ZLToolKit
+1
-1
src/Rtmp/RtmpSession.cpp
+3
-2
src/Rtsp/RtspMediaSource.h
+6
-1
src/Rtsp/RtspSession.cpp
+46
-46
没有找到文件。
ZLToolKit
@
e0399743
Subproject commit e
b3e28a6188fc8a7e5007215cc10a2b8c35c2cdd
Subproject commit e
03997435ad388a7c169de7a4b17b76d773ab69b
src/Rtmp/RtmpSession.cpp
查看文件 @
db0611de
...
@@ -46,7 +46,7 @@ RtmpSession::~RtmpSession() {
...
@@ -46,7 +46,7 @@ RtmpSession::~RtmpSession() {
}
}
void
RtmpSession
::
onError
(
const
SockException
&
err
)
{
void
RtmpSession
::
onError
(
const
SockException
&
err
)
{
Debug
P
(
this
)
<<
err
.
what
();
Warn
P
(
this
)
<<
err
.
what
();
//流量统计事件广播
//流量统计事件广播
GET_CONFIG
(
uint32_t
,
iFlowThreshold
,
General
::
kFlowThreshold
);
GET_CONFIG
(
uint32_t
,
iFlowThreshold
,
General
::
kFlowThreshold
);
...
@@ -143,6 +143,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
...
@@ -143,6 +143,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
}));
}));
dec
.
load
<
AMFValue
>
();
/* NULL */
dec
.
load
<
AMFValue
>
();
/* NULL */
_mediaInfo
.
parse
(
_strTcUrl
+
"/"
+
dec
.
load
<
std
::
string
>
());
_mediaInfo
.
parse
(
_strTcUrl
+
"/"
+
dec
.
load
<
std
::
string
>
());
_mediaInfo
.
_schema
=
RTMP_SCHEMA
;
auto
onRes
=
[
this
,
pToken
](
const
string
&
err
){
auto
onRes
=
[
this
,
pToken
](
const
string
&
err
){
auto
src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
MediaSource
::
find
(
RTMP_SCHEMA
,
auto
src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
MediaSource
::
find
(
RTMP_SCHEMA
,
...
@@ -305,7 +306,6 @@ void RtmpSession::doPlayResponse(const string &err,const std::function<void(bool
...
@@ -305,7 +306,6 @@ void RtmpSession::doPlayResponse(const string &err,const std::function<void(bool
}
}
//鉴权成功,查找媒体源并回复
//鉴权成功,查找媒体源并回复
_mediaInfo
.
_schema
=
RTMP_SCHEMA
;
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
MediaSource
::
findAsync
(
_mediaInfo
,
weakSelf
.
lock
(),
true
,[
weakSelf
,
cb
](
const
MediaSource
::
Ptr
&
src
){
MediaSource
::
findAsync
(
_mediaInfo
,
weakSelf
.
lock
(),
true
,[
weakSelf
,
cb
](
const
MediaSource
::
Ptr
&
src
){
auto
rtmp_src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
src
);
auto
rtmp_src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
src
);
...
@@ -351,6 +351,7 @@ void RtmpSession::onCmd_play2(AMFDecoder &dec) {
...
@@ -351,6 +351,7 @@ void RtmpSession::onCmd_play2(AMFDecoder &dec) {
void
RtmpSession
::
onCmd_play
(
AMFDecoder
&
dec
)
{
void
RtmpSession
::
onCmd_play
(
AMFDecoder
&
dec
)
{
dec
.
load
<
AMFValue
>
();
/* NULL */
dec
.
load
<
AMFValue
>
();
/* NULL */
_mediaInfo
.
parse
(
_strTcUrl
+
"/"
+
dec
.
load
<
std
::
string
>
());
_mediaInfo
.
parse
(
_strTcUrl
+
"/"
+
dec
.
load
<
std
::
string
>
());
_mediaInfo
.
_schema
=
RTMP_SCHEMA
;
doPlay
(
dec
);
doPlay
(
dec
);
}
}
...
...
src/Rtsp/RtspMediaSource.h
查看文件 @
db0611de
...
@@ -117,6 +117,9 @@ public:
...
@@ -117,6 +117,9 @@ public:
//派生类设置该媒体源媒体描述信息
//派生类设置该媒体源媒体描述信息
_strSdp
=
sdp
;
_strSdp
=
sdp
;
_sdpAttr
.
load
(
sdp
);
_sdpAttr
.
load
(
sdp
);
if
(
_pRing
){
regist
();
}
}
}
void
onWrite
(
const
RtpPacket
::
Ptr
&
rtppt
,
bool
keyPos
)
override
{
void
onWrite
(
const
RtpPacket
::
Ptr
&
rtppt
,
bool
keyPos
)
override
{
...
@@ -136,7 +139,9 @@ public:
...
@@ -136,7 +139,9 @@ public:
strongSelf
->
onReaderChanged
(
size
);
strongSelf
->
onReaderChanged
(
size
);
});
});
onReaderChanged
(
0
);
onReaderChanged
(
0
);
regist
();
if
(
!
_strSdp
.
empty
()){
regist
();
}
}
}
_pRing
->
write
(
rtppt
,
keyPos
);
_pRing
->
write
(
rtppt
,
keyPos
);
checkNoneReader
();
checkNoneReader
();
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
db0611de
...
@@ -147,7 +147,8 @@ void RtspSession::onWholeRtspPacket(Parser &parser) {
...
@@ -147,7 +147,8 @@ void RtspSession::onWholeRtspPacket(Parser &parser) {
if
(
_strContentBase
.
empty
()
&&
strCmd
!=
"GET"
){
if
(
_strContentBase
.
empty
()
&&
strCmd
!=
"GET"
){
_strContentBase
=
parser
.
Url
();
_strContentBase
=
parser
.
Url
();
_mediaInfo
.
parse
(
parser
.
FullUrl
());
_mediaInfo
.
parse
(
parser
.
FullUrl
());
}
_mediaInfo
.
_schema
=
RTSP_SCHEMA
;
}
typedef
void
(
RtspSession
::*
rtsp_request_handler
)(
const
Parser
&
parser
);
typedef
void
(
RtspSession
::*
rtsp_request_handler
)(
const
Parser
&
parser
);
static
unordered_map
<
string
,
rtsp_request_handler
>
s_handler_map
;
static
unordered_map
<
string
,
rtsp_request_handler
>
s_handler_map
;
...
@@ -257,7 +258,6 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
...
@@ -257,7 +258,6 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
auto
onRes
=
[
this
](
const
string
&
err
){
auto
onRes
=
[
this
](
const
string
&
err
){
bool
authSuccess
=
err
.
empty
();
bool
authSuccess
=
err
.
empty
();
if
(
!
authSuccess
){
if
(
!
authSuccess
){
//第一次play是播放,否则是恢复播放。只对播放鉴权
sendRtspResponse
(
"401 Unauthorized"
,
{
"Content-Type"
,
"text/plain"
},
err
);
sendRtspResponse
(
"401 Unauthorized"
,
{
"Content-Type"
,
"text/plain"
},
err
);
shutdown
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"401 Unauthorized:"
<<
err
));
shutdown
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"401 Unauthorized:"
<<
err
));
return
;
return
;
...
@@ -307,10 +307,46 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
...
@@ -307,10 +307,46 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
}
}
void
RtspSession
::
handleReq_Describe
(
const
Parser
&
parser
)
{
void
RtspSession
::
handleReq_Describe
(
const
Parser
&
parser
)
{
_mediaInfo
.
_schema
=
RTSP_SCHEMA
;
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
//该请求中的认证信息
auto
authorization
=
parser
[
"Authorization"
];
auto
authorization
=
parser
[
"Authorization"
];
onGetRealm
invoker
=
[
weakSelf
,
authorization
](
const
string
&
realm
){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
//本对象已经销毁
return
;
}
//切换到自己的线程然后执行
strongSelf
->
async
([
weakSelf
,
realm
,
authorization
](){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
//本对象已经销毁
return
;
}
if
(
realm
.
empty
()){
//无需认证,回复sdp
strongSelf
->
onAuthSuccess
();
return
;
}
//该流需要认证
strongSelf
->
onAuthUser
(
realm
,
authorization
);
});
};
//广播是否需要认证事件
if
(
!
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastOnGetRtspRealm
,
_mediaInfo
,
invoker
,
*
this
)){
//无人监听此事件,说明无需认证
invoker
(
""
);
}
}
void
RtspSession
::
onAuthSuccess
()
{
TraceP
(
this
);
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
MediaSource
::
findAsync
(
_mediaInfo
,
weakSelf
.
lock
(),
true
,[
weakSelf
,
authorization
](
const
MediaSource
::
Ptr
&
src
){
MediaSource
::
findAsync
(
_mediaInfo
,
weakSelf
.
lock
(),
true
,[
weakSelf
](
const
MediaSource
::
Ptr
&
src
){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
if
(
!
strongSelf
){
return
;
return
;
...
@@ -330,7 +366,7 @@ void RtspSession::handleReq_Describe(const Parser &parser) {
...
@@ -330,7 +366,7 @@ void RtspSession::handleReq_Describe(const Parser &parser) {
if
(
strongSelf
->
_aTrackInfo
.
empty
())
{
if
(
strongSelf
->
_aTrackInfo
.
empty
())
{
//该流无效
//该流无效
strongSelf
->
send_StreamNotFound
();
strongSelf
->
send_StreamNotFound
();
strongSelf
->
shutdown
(
SockException
(
Err_shutdown
,
"can not find any availabe track in sdp
"
));
strongSelf
->
shutdown
(
SockException
(
Err_shutdown
,
"can not find any availabe track in sdp
:"
<<
strongSelf
->
_strSdp
));
return
;
return
;
}
}
strongSelf
->
_strSession
=
makeRandStr
(
12
);
strongSelf
->
_strSession
=
makeRandStr
(
12
);
...
@@ -341,49 +377,13 @@ void RtspSession::handleReq_Describe(const Parser &parser) {
...
@@ -341,49 +377,13 @@ void RtspSession::handleReq_Describe(const Parser &parser) {
track
->
_time_stamp
=
rtsp_src
->
getTimeStamp
(
track
->
_type
);
track
->
_time_stamp
=
rtsp_src
->
getTimeStamp
(
track
->
_type
);
}
}
//该请求中的认证信息
strongSelf
->
sendRtspResponse
(
"200 OK"
,
onGetRealm
invoker
=
[
weakSelf
,
authorization
](
const
string
&
realm
){
{
"Content-Base"
,
strongSelf
->
_strContentBase
+
"/"
,
auto
strongSelf
=
weakSelf
.
lock
();
"x-Accept-Retransmit"
,
"our-retransmit"
,
if
(
!
strongSelf
){
"x-Accept-Dynamic-Rate"
,
"1"
//本对象已经销毁
},
strongSelf
->
_strSdp
);
return
;
}
//切换到自己的线程然后执行
strongSelf
->
async
([
weakSelf
,
realm
,
authorization
](){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
//本对象已经销毁
return
;
}
if
(
realm
.
empty
()){
//无需认证,回复sdp
strongSelf
->
onAuthSuccess
();
return
;
}
//该流需要认证
strongSelf
->
onAuthUser
(
realm
,
authorization
);
});
};
//广播是否需要认证事件
if
(
!
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastOnGetRtspRealm
,
strongSelf
->
_mediaInfo
,
invoker
,
*
strongSelf
)){
//无人监听此事件,说明无需认证
invoker
(
""
);
}
});
});
}
}
void
RtspSession
::
onAuthSuccess
()
{
TraceP
(
this
);
sendRtspResponse
(
"200 OK"
,
{
"Content-Base"
,
_strContentBase
+
"/"
,
"x-Accept-Retransmit"
,
"our-retransmit"
,
"x-Accept-Dynamic-Rate"
,
"1"
},
_strSdp
);
}
void
RtspSession
::
onAuthFailed
(
const
string
&
realm
,
const
string
&
why
,
bool
close
)
{
void
RtspSession
::
onAuthFailed
(
const
string
&
realm
,
const
string
&
why
,
bool
close
)
{
GET_CONFIG
(
bool
,
authBasic
,
Rtsp
::
kAuthBasic
);
GET_CONFIG
(
bool
,
authBasic
,
Rtsp
::
kAuthBasic
);
if
(
!
authBasic
)
{
if
(
!
authBasic
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论