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
6a649174
Commit
6a649174
authored
May 08, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加播放恢复事件
parent
3e0e0ce2
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
96 行增加
和
52 行删除
+96
-52
src/Player/MediaPlayer.cpp
+1
-0
src/Player/PlayerBase.h
+27
-2
src/Rtmp/RtmpPlayer.cpp
+31
-21
src/Rtsp/RtspPlayer.cpp
+37
-29
没有找到文件。
src/Player/MediaPlayer.cpp
查看文件 @
6a649174
...
...
@@ -45,6 +45,7 @@ void MediaPlayer::play(const string &strUrl) {
_parser
=
PlayerBase
::
createPlayer
(
_poller
,
strUrl
);
_parser
->
setOnShutdown
(
_shutdownCB
);
_parser
->
setOnPlayResult
(
_playResultCB
);
_parser
->
setOnResume
(
_resumeCB
);
_parser
->
setMediaSouce
(
_pMediaSrc
);
_parser
->
mINI
::
operator
=
(
*
this
);
_parser
->
play
(
strUrl
);
...
...
src/Player/PlayerBase.h
查看文件 @
6a649174
...
...
@@ -120,6 +120,12 @@ public:
*/
virtual
void
setOnPlayResult
(
const
function
<
void
(
const
SockException
&
ex
)
>
&
cb
)
{}
/**
* 设置播放恢复回调
* @param cb
*/
virtual
void
setOnResume
(
const
function
<
void
()
>
&
cb
)
{}
/**
* 获取播放进度,取值 0.0 ~ 1.0
* @return
...
...
@@ -147,6 +153,10 @@ public:
protected
:
virtual
void
onShutdown
(
const
SockException
&
ex
)
{}
virtual
void
onPlayResult
(
const
SockException
&
ex
)
{}
/**
* 暂停后恢复播放时间
*/
virtual
void
onResume
(){};
};
template
<
typename
Parent
,
typename
Parser
>
...
...
@@ -172,6 +182,13 @@ public:
_playResultCB
=
cb
;
}
void
setOnResume
(
const
function
<
void
()
>
&
cb
)
override
{
if
(
_parser
)
{
_parser
->
setOnResume
(
cb
);
}
_resumeCB
=
cb
;
}
bool
isInited
(
int
analysisMs
)
override
{
if
(
_parser
)
{
return
_parser
->
isInited
(
analysisMs
);
...
...
@@ -237,7 +254,14 @@ protected:
}
//播放成功却未初始化完毕,这个时候不回调汇报播放成功
}
void
checkInited
(
int
analysisMs
){
void
onResume
()
override
{
if
(
_resumeCB
){
_resumeCB
();
}
}
void
checkInited
(
int
analysisMs
){
if
(
!
_playResultCB
){
return
;
}
...
...
@@ -249,7 +273,8 @@ protected:
protected
:
function
<
void
(
const
SockException
&
ex
)
>
_shutdownCB
;
function
<
void
(
const
SockException
&
ex
)
>
_playResultCB
;
std
::
shared_ptr
<
Parser
>
_parser
;
function
<
void
()
>
_resumeCB
;
std
::
shared_ptr
<
Parser
>
_parser
;
MediaSource
::
Ptr
_pMediaSrc
;
};
...
...
src/Rtmp/RtmpPlayer.cpp
查看文件 @
6a649174
...
...
@@ -117,30 +117,40 @@ void RtmpPlayer::onErr(const SockException &ex){
void
RtmpPlayer
::
onPlayResult_l
(
const
SockException
&
ex
)
{
WarnL
<<
ex
.
getErrCode
()
<<
" "
<<
ex
.
what
();
if
(
!
ex
){
//恢复rtmp接收超时定时器
_mediaTicker
.
resetTime
();
weak_ptr
<
RtmpPlayer
>
weakSelf
=
dynamic_pointer_cast
<
RtmpPlayer
>
(
shared_from_this
());
int
timeoutMS
=
(
*
this
)[
kMediaTimeoutMS
].
as
<
int
>
();
_pMediaTimer
.
reset
(
new
Timer
(
timeoutMS
/
2000.0
,
[
weakSelf
,
timeoutMS
]()
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
return
false
;
}
if
(
strongSelf
->
_mediaTicker
.
elapsedTime
()
>
timeoutMS
)
{
//recv media timeout!
strongSelf
->
onPlayResult_l
(
SockException
(
Err_timeout
,
"recv rtmp timeout"
));
return
false
;
}
return
true
;
},
getPoller
()));
}
if
(
_pPlayTimer
)
{
//开始播放阶段
_pPlayTimer
.
reset
();
onPlayResult
(
ex
);
if
(
!
ex
){
_mediaTicker
.
resetTime
();
weak_ptr
<
RtmpPlayer
>
weakSelf
=
dynamic_pointer_cast
<
RtmpPlayer
>
(
shared_from_this
());
int
timeoutMS
=
(
*
this
)[
kMediaTimeoutMS
].
as
<
int
>
();
_pMediaTimer
.
reset
(
new
Timer
(
timeoutMS
/
2000.0
,
[
weakSelf
,
timeoutMS
]()
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
return
false
;
}
if
(
strongSelf
->
_mediaTicker
.
elapsedTime
()
>
timeoutMS
)
{
//recv media timeout!
strongSelf
->
onPlayResult_l
(
SockException
(
Err_timeout
,
"recv rtmp timeout"
));
return
false
;
}
return
true
;
},
getPoller
()));
}
}
else
if
(
ex
){
//播放成功后异常断开回调
onShutdown
(
ex
);
}
}
else
{
//播放中途阶段
if
(
ex
)
{
//播放成功后异常断开回调
onShutdown
(
ex
);
}
else
{
//恢复播放
onResume
();
}
}
if
(
ex
){
teardown
();
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
6a649174
...
...
@@ -614,36 +614,44 @@ void RtspPlayer::onRecvRTP_l(const RtpPacket::Ptr &pRtppt, const SdpTrack::Ptr &
}
void
RtspPlayer
::
onPlayResult_l
(
const
SockException
&
ex
)
{
WarnL
<<
ex
.
getErrCode
()
<<
" "
<<
ex
.
what
();
if
(
_pPlayTimer
){
//播放结果回调
_pPlayTimer
.
reset
();
onPlayResult
(
ex
);
if
(
!
ex
){
//播放成功
_rtpTicker
.
resetTime
();
weak_ptr
<
RtspPlayer
>
weakSelf
=
dynamic_pointer_cast
<
RtspPlayer
>
(
shared_from_this
());
int
timeoutMS
=
(
*
this
)[
kMediaTimeoutMS
].
as
<
int
>
();
_pRtpTimer
.
reset
(
new
Timer
(
timeoutMS
/
2000.0
,
[
weakSelf
,
timeoutMS
]()
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
return
false
;
}
if
(
strongSelf
->
_rtpTicker
.
elapsedTime
()
>
timeoutMS
)
{
//recv rtp timeout!
strongSelf
->
onPlayResult_l
(
SockException
(
Err_timeout
,
"recv rtp timeout"
));
return
false
;
}
return
true
;
},
getPoller
()));
}
}
else
if
(
ex
){
//播放成功后异常断开回调
onShutdown
(
ex
);
}
if
(
ex
){
teardown
();
}
if
(
!
ex
){
//播放成功,恢复rtp接收超时定时器
_rtpTicker
.
resetTime
();
weak_ptr
<
RtspPlayer
>
weakSelf
=
dynamic_pointer_cast
<
RtspPlayer
>
(
shared_from_this
());
int
timeoutMS
=
(
*
this
)[
kMediaTimeoutMS
].
as
<
int
>
();
_pRtpTimer
.
reset
(
new
Timer
(
timeoutMS
/
2000.0
,
[
weakSelf
,
timeoutMS
]()
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
return
false
;
}
if
(
strongSelf
->
_rtpTicker
.
elapsedTime
()
>
timeoutMS
)
{
//recv rtp timeout!
strongSelf
->
onPlayResult_l
(
SockException
(
Err_timeout
,
"recv rtp timeout"
));
return
false
;
}
return
true
;
},
getPoller
()));
}
if
(
_pPlayTimer
)
{
//开始播放阶段
_pPlayTimer
.
reset
();
onPlayResult
(
ex
);
}
else
{
//播放中途阶段
if
(
ex
)
{
//播放成功后异常断开回调
onShutdown
(
ex
);
}
else
{
//恢复播放
onResume
();
}
}
if
(
ex
){
teardown
();
}
}
int
RtspPlayer
::
getTrackIndexByControlSuffix
(
const
string
&
controlSuffix
)
const
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论