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
dfe213ab
Commit
dfe213ab
authored
Oct 29, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rtsp服务器实现延时获取RtspMediaSouce
parent
f84038fa
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
93 行增加
和
8 行删除
+93
-8
src/Rtsp/RtspSession.cpp
+88
-8
src/Rtsp/RtspSession.h
+5
-0
没有找到文件。
src/Rtsp/RtspSession.cpp
查看文件 @
dfe213ab
...
...
@@ -141,6 +141,13 @@ void RtspSession::onManager() {
shutdown
();
return
;
}
if
(
_delayTask
){
if
(
time
(
NULL
)
>
_iTaskTimeLine
){
_delayTask
();
_delayTask
=
nullptr
;
}
}
}
...
...
@@ -226,15 +233,23 @@ bool RtspSession::handleReq_Describe() {
_mediaInfo
.
parse
(
_parser
.
FullUrl
());
}
if
(
!
findStream
())
{
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
\
auto
parserCopy
=
_parser
;
findStream
([
weakSelf
,
parserCopy
](
bool
success
){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
return
;
}
//恢复现场
strongSelf
->
_parser
=
parserCopy
;
if
(
!
success
){
//未找到相应的MediaSource
send_StreamNotFound
();
return
false
;
strongSelf
->
send_StreamNotFound
();
strongSelf
->
shutdown
();
return
;
}
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
//该请求中的认证信息
auto
authorization
=
_parser
[
"Authorization"
];
auto
authorization
=
strongSelf
->
_parser
[
"Authorization"
];
onGetRealm
invoker
=
[
weakSelf
,
authorization
](
const
string
&
realm
){
if
(
realm
.
empty
()){
//无需认证,回复sdp
...
...
@@ -247,12 +262,13 @@ bool RtspSession::handleReq_Describe() {
//广播是否需要认证事件
if
(
!
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastOnGetRtspRealm
,
_mediaInfo
,
strongSelf
->
_mediaInfo
,
invoker
,
*
this
)){
*
strongSelf
)){
//无人监听此事件,说明无需认证
invoker
(
""
);
}
});
return
true
;
}
void
RtspSession
::
onAuthSuccess
(
const
weak_ptr
<
RtspSession
>
&
weakSelf
)
{
...
...
@@ -901,6 +917,70 @@ inline void RtspSession::send_NotAcceptable() {
}
void
RtspSession
::
doDelay
(
int
delaySec
,
const
std
::
function
<
void
()
>
&
fun
)
{
if
(
_delayTask
){
_delayTask
();
}
_delayTask
=
fun
;
_iTaskTimeLine
=
time
(
NULL
)
+
delaySec
;
}
void
RtspSession
::
cancelDelyaTask
(){
_delayTask
=
nullptr
;
}
void
RtspSession
::
findStream
(
const
function
<
void
(
bool
)
>
&
cb
)
{
bool
success
=
findStream
();
if
(
success
)
{
cb
(
true
);
return
;
}
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
auto
task_id
=
this
;
auto
media_info
=
_mediaInfo
;
auto
onRegist
=
[
task_id
,
weakSelf
,
media_info
,
cb
](
BroadcastMediaChangedArgs
)
{
if
(
bRegist
&&
schema
==
media_info
.
_schema
&&
vhost
==
media_info
.
_vhost
&&
app
==
media_info
.
_app
&&
stream
==
media_info
.
_streamid
)
{
//播发器请求的rtmp流终于注册上了
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
return
;
}
//切换到自己的线程再回复
//如果触发 kBroadcastMediaChanged 事件的线程与本RtspSession绑定的线程相同,
//那么strongSelf->async操作可能是同步操作,
//通过指定参数may_sync为false确保 NoticeCenter::delListener操作延后执行,
//以便防止遍历事件监听对象map时做删除操作
strongSelf
->
async
([
task_id
,
weakSelf
,
media_info
,
cb
]()
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
return
;
}
DebugL
<<
"收到rtsp注册事件,回复播放器:"
<<
media_info
.
_schema
<<
"/"
<<
media_info
.
_vhost
<<
"/"
<<
media_info
.
_app
<<
"/"
<<
media_info
.
_streamid
;
cb
(
strongSelf
->
findStream
());
//取消延时任务,防止多次回复
strongSelf
->
cancelDelyaTask
();
//取消事件监听
//在事件触发时不能在当前线程移除事件监听,否则会导致遍历map时做删除操作导致程序崩溃
NoticeCenter
::
Instance
().
delListener
(
task_id
,
Broadcast
::
kBroadcastMediaChanged
);
},
false
);
}
};
NoticeCenter
::
Instance
().
addListener
(
task_id
,
Broadcast
::
kBroadcastMediaChanged
,
onRegist
);
//5秒后执行失败回调
doDelay
(
5
,
[
cb
]()
{
cb
(
false
);
});
}
inline
bool
RtspSession
::
findStream
()
{
RtspMediaSource
::
Ptr
pMediaSrc
=
dynamic_pointer_cast
<
RtspMediaSource
>
(
MediaSource
::
find
(
RTSP_SCHEMA
,
_mediaInfo
.
_vhost
,
_mediaInfo
.
_app
,
_mediaInfo
.
_streamid
)
);
...
...
src/Rtsp/RtspSession.h
查看文件 @
dfe213ab
...
...
@@ -104,6 +104,7 @@ private:
void
inline
send_SessionNotFound
();
//会话id错误
void
inline
send_NotAcceptable
();
//rtsp同时播放数限制
inline
bool
findStream
();
//根据rtsp url查找 MediaSource实例
inline
void
findStream
(
const
function
<
void
(
bool
)
>
&
cb
);
//根据rtsp url查找 MediaSource实例
inline
void
initSender
(
const
std
::
shared_ptr
<
RtspSession
>
&
pSession
);
//处理rtsp over http,quicktime使用的
inline
void
sendRtpPacket
(
const
RtpPacket
::
Ptr
&
pkt
);
...
...
@@ -143,6 +144,8 @@ private:
static
void
onAuthBasic
(
const
weak_ptr
<
RtspSession
>
&
weakSelf
,
const
string
&
realm
,
const
string
&
strBase64
);
static
void
onAuthDigest
(
const
weak_ptr
<
RtspSession
>
&
weakSelf
,
const
string
&
realm
,
const
string
&
strMd5
);
void
doDelay
(
int
delaySec
,
const
std
::
function
<
void
()
>
&
fun
);
void
cancelDelyaTask
();
private
:
char
*
_pcBuf
=
nullptr
;
Ticker
_ticker
;
...
...
@@ -199,6 +202,8 @@ private:
static
unordered_map
<
string
,
weak_ptr
<
RtspSession
>
>
g_mapGetter
;
static
unordered_map
<
void
*
,
std
::
shared_ptr
<
RtspSession
>
>
g_mapPostter
;
std
::
function
<
void
()
>
_delayTask
;
uint32_t
_iTaskTimeLine
=
0
;
};
}
/* namespace mediakit */
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论