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
ace20071
Commit
ace20071
authored
Mar 23, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复无人播放事件触发延时不准确的bug
parent
1168174c
隐藏空白字符变更
内嵌
并排
正在显示
21 个修改的文件
包含
43 行增加
和
140 行删除
+43
-140
.gitignore
+1
-0
api/source/mk_media.cpp
+0
-9
server/FFmpegSource.cpp
+1
-10
server/FFmpegSource.h
+0
-1
src/Common/MediaSource.cpp
+27
-10
src/Common/MediaSource.h
+8
-11
src/Player/PlayerProxy.cpp
+0
-7
src/Player/PlayerProxy.h
+0
-1
src/Record/HlsMediaSource.h
+1
-1
src/Record/MP4Reader.cpp
+0
-7
src/Record/MP4Reader.h
+0
-1
src/Rtmp/RtmpMediaSource.h
+3
-22
src/Rtmp/RtmpSession.cpp
+0
-8
src/Rtmp/RtmpSession.h
+0
-1
src/Rtp/RtpSelector.cpp
+0
-7
src/Rtp/RtpSelector.h
+0
-2
src/Rtp/RtpSession.cpp
+0
-8
src/Rtp/RtpSession.h
+0
-2
src/Rtsp/RtspMediaSource.h
+2
-22
src/Rtsp/RtspSession.cpp
+0
-9
src/Rtsp/RtspSession.h
+0
-1
没有找到文件。
.gitignore
查看文件 @
ace20071
...
...
@@ -44,3 +44,4 @@
/3rdpart/media-server/.idea/
/build/
/3rdpart/media-server/.idea/
/ios/
api/source/mk_media.cpp
查看文件 @
ace20071
...
...
@@ -71,15 +71,6 @@ protected:
return
true
;
}
// 通知无人观看
void
onNoneReader
(
MediaSource
&
sender
)
override
{
if
(
_channel
->
totalReaderCount
()){
//统计有误,还有人在看
return
;
}
MediaSourceEvent
::
onNoneReader
(
sender
);
}
// 观看总人数
int
totalReaderCount
(
MediaSource
&
sender
)
override
{
return
_channel
->
totalReaderCount
();
...
...
server/FFmpegSource.cpp
查看文件 @
ace20071
...
...
@@ -236,21 +236,12 @@ bool FFmpegSource::close(MediaSource &sender, bool force) {
return
true
;
}
void
FFmpegSource
::
onNoneReader
(
MediaSource
&
sender
)
{
auto
listener
=
_listener
.
lock
();
if
(
listener
){
listener
->
onNoneReader
(
sender
);
}
else
{
MediaSourceEvent
::
onNoneReader
(
sender
);
}
}
int
FFmpegSource
::
totalReaderCount
(
MediaSource
&
sender
)
{
auto
listener
=
_listener
.
lock
();
if
(
listener
){
return
listener
->
totalReaderCount
(
sender
);
}
return
0
;
return
sender
.
readerCount
()
;
}
void
FFmpegSource
::
onGetMediaSource
(
const
MediaSource
::
Ptr
&
src
)
{
...
...
server/FFmpegSource.h
查看文件 @
ace20071
...
...
@@ -59,7 +59,6 @@ private:
//MediaSourceEvent override
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
void
onNoneReader
(
MediaSource
&
sender
)
override
;
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
private
:
Process
_process
;
...
...
src/Common/MediaSource.cpp
查看文件 @
ace20071
...
...
@@ -117,7 +117,9 @@ void MediaSource::onNoneReader(){
if
(
!
listener
){
return
;
}
listener
->
onNoneReader
(
*
this
);
if
(
listener
->
totalReaderCount
(
*
this
)
==
0
)
{
listener
->
onNoneReader
(
*
this
);
}
}
void
MediaSource
::
for_each_media
(
const
function
<
void
(
const
MediaSource
::
Ptr
&
src
)
>
&
cb
)
{
...
...
@@ -382,16 +384,31 @@ void MediaInfo::parse(const string &url){
void
MediaSourceEvent
::
onNoneReader
(
MediaSource
&
sender
){
//没有任何读取器消费该源,表明该源可以关闭了
WarnL
<<
sender
.
getSchema
()
<<
"/"
<<
sender
.
getVhost
()
<<
"/"
<<
sender
.
getApp
()
<<
"/"
<<
sender
.
getId
();
weak_ptr
<
MediaSource
>
weakPtr
=
sender
.
shared_from_this
();
//异步广播该事件,防止同步调用sender.close()导致在接收rtp或rtmp包时清空包缓存等操作
EventPollerPool
::
Instance
().
getPoller
()
->
async
([
weakPtr
](){
auto
strongPtr
=
weakPtr
.
lock
();
if
(
strongPtr
){
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastStreamNoneReader
,
*
strongPtr
);
GET_CONFIG
(
int
,
stream_none_reader_delay
,
General
::
kStreamNoneReaderDelayMS
);
weak_ptr
<
MediaSource
>
weakSender
=
sender
.
shared_from_this
();
_async_close_timer
=
std
::
make_shared
<
Timer
>
(
stream_none_reader_delay
/
1000.0
,
[
weakSender
]()
{
auto
strongSender
=
weakSender
.
lock
();
if
(
!
strongSender
)
{
//对象已经销毁
return
false
;
}
if
(
strongSender
->
totalReaderCount
()
!=
0
)
{
//还有人消费
return
false
;
}
},
false
);
WarnL
<<
"onNoneReader:"
<<
strongSender
->
getSchema
()
<<
"/"
<<
strongSender
->
getVhost
()
<<
"/"
<<
strongSender
->
getApp
()
<<
"/"
<<
strongSender
->
getId
();
//触发消息广播
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastStreamNoneReader
,
*
strongSender
);
return
false
;
},
nullptr
);
}
...
...
src/Common/MediaSource.h
查看文件 @
ace20071
...
...
@@ -52,24 +52,21 @@ namespace mediakit {
class
MediaSource
;
class
MediaSourceEvent
{
public
:
friend
class
MediaSource
;
MediaSourceEvent
(){};
virtual
~
MediaSourceEvent
(){};
// 通知拖动进度条
virtual
bool
seekTo
(
MediaSource
&
sender
,
uint32_t
ui32Stamp
){
return
false
;
}
virtual
bool
seekTo
(
MediaSource
&
sender
,
uint32_t
ui32Stamp
){
return
false
;
}
// 通知其停止推流
virtual
bool
close
(
MediaSource
&
sender
,
bool
force
)
{
return
false
;
}
// 通知无人观看
virtual
void
onNoneReader
(
MediaSource
&
sender
);
virtual
bool
close
(
MediaSource
&
sender
,
bool
force
)
{
return
false
;}
// 观看总人数
virtual
int
totalReaderCount
(
MediaSource
&
sender
)
=
0
;
private
:
// 通知无人观看
void
onNoneReader
(
MediaSource
&
sender
);
private
:
Timer
::
Ptr
_async_close_timer
;
};
/**
...
...
src/Player/PlayerProxy.cpp
查看文件 @
ace20071
...
...
@@ -196,13 +196,6 @@ bool PlayerProxy::close(MediaSource &sender,bool force) {
return
true
;
}
void
PlayerProxy
::
onNoneReader
(
MediaSource
&
sender
)
{
if
(
!
_mediaMuxer
||
totalReaderCount
()){
return
;
}
MediaSourceEvent
::
onNoneReader
(
sender
);
}
int
PlayerProxy
::
totalReaderCount
(){
return
(
_mediaMuxer
?
_mediaMuxer
->
totalReaderCount
()
:
0
)
+
(
_pMediaSrc
?
_pMediaSrc
->
readerCount
()
:
0
);
}
...
...
src/Player/PlayerProxy.h
查看文件 @
ace20071
...
...
@@ -83,7 +83,6 @@ public:
private
:
//MediaSourceEvent override
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
void
onNoneReader
(
MediaSource
&
sender
)
override
;
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
void
rePlay
(
const
string
&
strUrl
,
int
iFailedCnt
);
void
onPlaySuccess
();
...
...
src/Record/HlsMediaSource.h
查看文件 @
ace20071
...
...
@@ -79,7 +79,7 @@ private:
return
;
}
if
(
--
_readerCount
==
0
&&
totalReaderCount
()
==
0
)
{
if
(
--
_readerCount
==
0
)
{
onNoneReader
();
}
}
...
...
src/Record/MP4Reader.cpp
查看文件 @
ace20071
...
...
@@ -190,13 +190,6 @@ bool MP4Reader::close(MediaSource &sender,bool force){
return
true
;
}
void
MP4Reader
::
onNoneReader
(
MediaSource
&
sender
)
{
if
(
!
_mediaMuxer
||
_mediaMuxer
->
totalReaderCount
()){
return
;
}
MediaSourceEvent
::
onNoneReader
(
sender
);
}
int
MP4Reader
::
totalReaderCount
(
MediaSource
&
sender
)
{
return
_mediaMuxer
?
_mediaMuxer
->
totalReaderCount
()
:
sender
.
readerCount
();
}
...
...
src/Record/MP4Reader.h
查看文件 @
ace20071
...
...
@@ -77,7 +77,6 @@ private:
//MediaSourceEvent override
bool
seekTo
(
MediaSource
&
sender
,
uint32_t
ui32Stamp
)
override
;
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
void
onNoneReader
(
MediaSource
&
sender
)
override
;
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
#ifdef ENABLE_MP4V2
void
seek
(
uint32_t
iSeekTime
,
bool
bReStart
=
true
);
...
...
src/Rtmp/RtmpMediaSource.h
查看文件 @
ace20071
...
...
@@ -161,7 +161,6 @@ public:
_track_stamps_map
[
pkt
->
typeId
]
=
pkt
->
timeStamp
;
//不存在视频,为了减少缓存延时,那么关闭GOP缓存
_ring
->
write
(
pkt
,
_have_video
?
pkt
->
isVideoKeyFrame
()
:
true
);
checkNoneReader
();
}
/**
...
...
@@ -184,33 +183,15 @@ private:
* 每次增减消费者都会触发该函数
*/
void
onReaderChanged
(
int
size
)
{
//我们记录最后一次活动时间
_reader_changed_ticker
.
resetTime
();
if
(
size
!=
0
||
totalReaderCount
()
!=
0
)
{
//还有消费者正在观看该流
_async_emit_none_reader
=
false
;
return
;
}
_async_emit_none_reader
=
true
;
}
/**
* 检查是否无人消费该流,
* 如果无人消费且超过一定时间会触发onNoneReader事件
*/
void
checkNoneReader
()
{
GET_CONFIG
(
int
,
stream_none_reader_delay
,
General
::
kStreamNoneReaderDelayMS
);
if
(
_async_emit_none_reader
&&
_reader_changed_ticker
.
elapsedTime
()
>
stream_none_reader_delay
)
{
_async_emit_none_reader
=
false
;
if
(
size
==
0
)
{
onNoneReader
();
}
}
protected
:
private
:
int
_ring_size
;
bool
_async_emit_none_reader
=
false
;
bool
_have_video
=
false
;
mutable
recursive_mutex
_mtx
;
Ticker
_reader_changed_ticker
;
AMFValue
_metadata
;
RingBuffer
<
RtmpPacket
::
Ptr
>::
Ptr
_ring
;
unordered_map
<
int
,
uint32_t
>
_track_stamps_map
;
...
...
src/Rtmp/RtmpSession.cpp
查看文件 @
ace20071
...
...
@@ -544,14 +544,6 @@ bool RtmpSession::close(MediaSource &sender,bool force) {
return
true
;
}
void
RtmpSession
::
onNoneReader
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
if
(
!
_pPublisherSrc
||
_pPublisherSrc
->
totalReaderCount
()){
return
;
}
MediaSourceEvent
::
onNoneReader
(
sender
);
}
int
RtmpSession
::
totalReaderCount
(
MediaSource
&
sender
)
{
return
_pPublisherSrc
?
_pPublisherSrc
->
totalReaderCount
()
:
sender
.
readerCount
();
}
...
...
src/Rtmp/RtmpSession.h
查看文件 @
ace20071
...
...
@@ -85,7 +85,6 @@ private:
//MediaSourceEvent override
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
void
onNoneReader
(
MediaSource
&
sender
)
override
;
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
void
setSocketFlags
();
...
...
src/Rtp/RtpSelector.cpp
查看文件 @
ace20071
...
...
@@ -142,13 +142,6 @@ bool RtpProcessHelper::close(MediaSource &sender, bool force) {
return
true
;
}
void
RtpProcessHelper
::
onNoneReader
(
MediaSource
&
sender
)
{
if
(
!
_process
||
_process
->
totalReaderCount
()){
return
;
}
MediaSourceEvent
::
onNoneReader
(
sender
);
}
int
RtpProcessHelper
::
totalReaderCount
(
MediaSource
&
sender
)
{
return
_process
?
_process
->
totalReaderCount
()
:
sender
.
totalReaderCount
();
}
...
...
src/Rtp/RtpSelector.h
查看文件 @
ace20071
...
...
@@ -47,8 +47,6 @@ public:
protected
:
// 通知其停止推流
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
// 通知无人观看
void
onNoneReader
(
MediaSource
&
sender
)
override
;
// 观看总人数
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
private
:
...
...
src/Rtp/RtpSession.cpp
查看文件 @
ace20071
...
...
@@ -87,14 +87,6 @@ bool RtpSession::close(MediaSource &sender, bool force) {
return
true
;
}
void
RtpSession
::
onNoneReader
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
if
(
!
_process
||
_process
->
totalReaderCount
()){
return
;
}
MediaSourceEvent
::
onNoneReader
(
sender
);
}
int
RtpSession
::
totalReaderCount
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
return
_process
?
_process
->
totalReaderCount
()
:
sender
.
totalReaderCount
();
...
...
src/Rtp/RtpSession.h
查看文件 @
ace20071
...
...
@@ -46,8 +46,6 @@ public:
protected
:
// 通知其停止推流
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
// 通知无人观看
void
onNoneReader
(
MediaSource
&
sender
)
override
;
// 观看总人数
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
void
onRtpPacket
(
const
char
*
data
,
uint64_t
len
)
override
;
...
...
src/Rtsp/RtspMediaSource.h
查看文件 @
ace20071
...
...
@@ -191,39 +191,19 @@ public:
}
//不存在视频,为了减少缓存延时,那么关闭GOP缓存
_ring
->
write
(
rtp
,
_have_video
?
keyPos
:
true
);
checkNoneReader
();
}
private
:
/**
* 每次增减消费者都会触发该函数
*/
void
onReaderChanged
(
int
size
)
{
//我们记录最后一次活动时间
_reader_changed_ticker
.
resetTime
();
if
(
size
!=
0
||
totalReaderCount
()
!=
0
)
{
//还有消费者正在观看该流
_async_emit_none_reader
=
false
;
return
;
}
_async_emit_none_reader
=
true
;
}
/**
* 检查是否无人消费该流,
* 如果无人消费且超过一定时间会触发onNoneReader事件
*/
void
checkNoneReader
()
{
GET_CONFIG
(
int
,
stream_none_reader_delay
,
General
::
kStreamNoneReaderDelayMS
);
if
(
_async_emit_none_reader
&&
_reader_changed_ticker
.
elapsedTime
()
>
stream_none_reader_delay
)
{
_async_emit_none_reader
=
false
;
if
(
size
==
0
)
{
onNoneReader
();
}
}
pr
otected
:
pr
ivate
:
int
_ring_size
;
bool
_async_emit_none_reader
=
false
;
bool
_have_video
=
false
;
Ticker
_reader_changed_ticker
;
SdpParser
_sdp_parser
;
string
_sdp
;
RingType
::
Ptr
_ring
;
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
ace20071
...
...
@@ -1135,15 +1135,6 @@ bool RtspSession::close(MediaSource &sender,bool force) {
return
true
;
}
void
RtspSession
::
onNoneReader
(
MediaSource
&
sender
){
//此回调在其他线程触发
if
(
!
_pushSrc
||
_pushSrc
->
totalReaderCount
()){
return
;
}
MediaSourceEvent
::
onNoneReader
(
sender
);
}
int
RtspSession
::
totalReaderCount
(
MediaSource
&
sender
)
{
return
_pushSrc
?
_pushSrc
->
totalReaderCount
()
:
sender
.
readerCount
();
}
...
...
src/Rtsp/RtspSession.h
查看文件 @
ace20071
...
...
@@ -107,7 +107,6 @@ protected:
void
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtppt
,
int
trackidx
)
override
;
//MediaSourceEvent override
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
void
onNoneReader
(
MediaSource
&
sender
)
override
;
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
//TcpSession override
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论