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
15affeff
Commit
15affeff
authored
Sep 18, 2022
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化关闭媒体源相关逻辑: #1963
parent
daafe62f
隐藏空白字符变更
内嵌
并排
正在显示
21 个修改的文件
包含
44 行增加
和
69 行删除
+44
-69
api/source/mk_media.cpp
+3
-7
server/FFmpegSource.cpp
+3
-3
server/FFmpegSource.h
+1
-1
src/Common/MediaSource.cpp
+8
-4
src/Common/MediaSource.h
+2
-2
src/Player/PlayerProxy.cpp
+2
-6
src/Player/PlayerProxy.h
+1
-1
src/Record/MP4Reader.cpp
+3
-6
src/Record/MP4Reader.h
+1
-1
src/Rtmp/RtmpSession.cpp
+3
-6
src/Rtmp/RtmpSession.h
+1
-1
src/Rtp/RtpSelector.cpp
+2
-5
src/Rtp/RtpSelector.h
+1
-1
src/Rtp/RtpSession.cpp
+3
-6
src/Rtp/RtpSession.h
+1
-1
src/Rtsp/RtspSession.cpp
+2
-5
src/Rtsp/RtspSession.h
+1
-1
srt/SrtTransportImp.cpp
+2
-5
srt/SrtTransportImp.hpp
+1
-1
webrtc/WebRtcPusher.cpp
+2
-5
webrtc/WebRtcPusher.h
+1
-1
没有找到文件。
api/source/mk_media.cpp
查看文件 @
15affeff
...
...
@@ -60,19 +60,15 @@ public:
protected
:
// 通知其停止推流
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
{
if
(
!
force
&&
_channel
->
totalReaderCount
()){
//非强制关闭且正有人在观看该视频
return
false
;
}
if
(
!
_on_close
){
bool
close
(
MediaSource
&
sender
)
override
{
if
(
!
_on_close
)
{
//未设置回调,没法关闭
WarnL
<<
"请使用mk_media_set_on_close函数设置回调函数!"
;
return
false
;
}
//请在回调中调用mk_media_release函数释放资源,否则MediaSource::close()操作不会生效
_on_close
(
_on_close_data
);
WarnL
<<
"close media:
"
<<
sender
.
getUrl
()
<<
" "
<<
force
;
WarnL
<<
"close media:
"
<<
sender
.
getUrl
()
;
return
true
;
}
...
...
server/FFmpegSource.cpp
查看文件 @
15affeff
...
...
@@ -273,14 +273,14 @@ void FFmpegSource::setOnClose(const function<void()> &cb){
_onClose
=
cb
;
}
bool
FFmpegSource
::
close
(
MediaSource
&
sender
,
bool
force
)
{
bool
FFmpegSource
::
close
(
MediaSource
&
sender
)
{
auto
listener
=
getDelegate
();
if
(
listener
&&
!
listener
->
close
(
sender
,
force
))
{
if
(
listener
&&
!
listener
->
close
(
sender
))
{
//关闭失败
return
false
;
}
//该流无人观看,我们停止吧
if
(
_onClose
)
{
if
(
_onClose
)
{
_onClose
();
}
return
true
;
...
...
server/FFmpegSource.h
查看文件 @
15affeff
...
...
@@ -75,7 +75,7 @@ private:
///////MediaSourceEvent override///////
// 关闭
bool
close
(
mediakit
::
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
mediakit
::
MediaSource
&
sender
)
override
;
// 获取媒体源类型
mediakit
::
MediaOriginType
getOriginType
(
mediakit
::
MediaSource
&
sender
)
const
override
;
//获取媒体源url或者文件路径
...
...
src/Common/MediaSource.cpp
查看文件 @
15affeff
...
...
@@ -211,10 +211,14 @@ bool MediaSource::speed(float speed) {
bool
MediaSource
::
close
(
bool
force
)
{
auto
listener
=
_listener
.
lock
();
if
(
!
listener
){
if
(
!
listener
)
{
return
false
;
}
if
(
!
force
&&
totalReaderCount
())
{
//有人观看,不强制关闭
return
false
;
}
return
listener
->
close
(
*
this
,
force
);
return
listener
->
close
(
*
this
);
}
float
MediaSource
::
getLossRate
(
mediakit
::
TrackType
type
)
{
...
...
@@ -680,12 +684,12 @@ bool MediaSourceEventInterceptor::speed(MediaSource &sender, float speed) {
return
listener
->
speed
(
sender
,
speed
);
}
bool
MediaSourceEventInterceptor
::
close
(
MediaSource
&
sender
,
bool
force
)
{
bool
MediaSourceEventInterceptor
::
close
(
MediaSource
&
sender
)
{
auto
listener
=
_listener
.
lock
();
if
(
!
listener
)
{
return
false
;
}
return
listener
->
close
(
sender
,
force
);
return
listener
->
close
(
sender
);
}
int
MediaSourceEventInterceptor
::
totalReaderCount
(
MediaSource
&
sender
)
{
...
...
src/Common/MediaSource.h
查看文件 @
15affeff
...
...
@@ -74,7 +74,7 @@ public:
// 通知倍数
virtual
bool
speed
(
MediaSource
&
sender
,
float
speed
)
{
return
false
;
}
// 通知其停止产生流
virtual
bool
close
(
MediaSource
&
sender
,
bool
force
)
{
return
false
;
}
virtual
bool
close
(
MediaSource
&
sender
)
{
return
false
;
}
// 获取观看总人数,此函数一般强制重载
virtual
int
totalReaderCount
(
MediaSource
&
sender
)
{
throw
NotImplemented
(
toolkit
::
demangle
(
typeid
(
*
this
).
name
())
+
"::totalReaderCount not implemented"
);
}
// 通知观看人数变化
...
...
@@ -150,7 +150,7 @@ public:
bool
seekTo
(
MediaSource
&
sender
,
uint32_t
stamp
)
override
;
bool
pause
(
MediaSource
&
sender
,
bool
pause
)
override
;
bool
speed
(
MediaSource
&
sender
,
float
speed
)
override
;
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
)
override
;
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
void
onReaderChanged
(
MediaSource
&
sender
,
int
size
)
override
;
void
onRegist
(
MediaSource
&
sender
,
bool
regist
)
override
;
...
...
src/Player/PlayerProxy.cpp
查看文件 @
15affeff
...
...
@@ -143,11 +143,7 @@ void PlayerProxy::rePlay(const string &strUrl, int iFailedCnt) {
},
getPoller
());
}
bool
PlayerProxy
::
close
(
MediaSource
&
sender
,
bool
force
)
{
if
(
!
force
&&
totalReaderCount
())
{
return
false
;
}
bool
PlayerProxy
::
close
(
MediaSource
&
sender
)
{
//通知其停止推流
weak_ptr
<
PlayerProxy
>
weakSelf
=
dynamic_pointer_cast
<
PlayerProxy
>
(
shared_from_this
());
getPoller
()
->
async_first
([
weakSelf
]()
{
...
...
@@ -160,7 +156,7 @@ bool PlayerProxy::close(MediaSource &sender, bool force) {
strongSelf
->
teardown
();
});
_on_close
(
SockException
(
Err_shutdown
,
"closed by user"
));
WarnL
<<
sender
.
getUrl
()
<<
" "
<<
force
;
WarnL
<<
"close media: "
<<
sender
.
getUrl
()
;
return
true
;
}
...
...
src/Player/PlayerProxy.h
查看文件 @
15affeff
...
...
@@ -54,7 +54,7 @@ public:
private
:
//MediaSourceEvent override
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
)
override
;
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
MediaOriginType
getOriginType
(
MediaSource
&
sender
)
const
override
;
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
...
...
src/Record/MP4Reader.cpp
查看文件 @
15affeff
...
...
@@ -230,12 +230,9 @@ bool MP4Reader::seekTo(uint32_t stamp_seek) {
return
false
;
}
bool
MP4Reader
::
close
(
MediaSource
&
sender
,
bool
force
)
{
if
(
!
_muxer
||
(
!
force
&&
_muxer
->
totalReaderCount
()))
{
return
false
;
}
_timer
.
reset
();
WarnL
<<
sender
.
getUrl
()
<<
" "
<<
force
;
bool
MP4Reader
::
close
(
MediaSource
&
sender
)
{
_timer
=
nullptr
;
WarnL
<<
"close media: "
<<
sender
.
getUrl
();
return
true
;
}
...
...
src/Record/MP4Reader.h
查看文件 @
15affeff
...
...
@@ -55,7 +55,7 @@ private:
bool
pause
(
MediaSource
&
sender
,
bool
pause
)
override
;
bool
speed
(
MediaSource
&
sender
,
float
speed
)
override
;
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
)
override
;
MediaOriginType
getOriginType
(
MediaSource
&
sender
)
const
override
;
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
...
...
src/Rtmp/RtmpSession.cpp
查看文件 @
15affeff
...
...
@@ -569,13 +569,10 @@ void RtmpSession::onSendMedia(const RtmpPacket::Ptr &pkt) {
sendRtmp
(
pkt
->
type_id
,
pkt
->
stream_index
,
pkt
,
pkt
->
time_stamp
,
pkt
->
chunk_id
);
}
bool
RtmpSession
::
close
(
MediaSource
&
sender
,
bool
force
)
{
bool
RtmpSession
::
close
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
if
(
!
_push_src
||
(
!
force
&&
_push_src
->
totalReaderCount
())){
return
false
;
}
string
err
=
StrPrinter
<<
"close media:"
<<
sender
.
getUrl
()
<<
" "
<<
force
;
safeShutdown
(
SockException
(
Err_shutdown
,
err
));
string
err
=
StrPrinter
<<
"close media: "
<<
sender
.
getUrl
();
safeShutdown
(
SockException
(
Err_shutdown
,
err
));
return
true
;
}
...
...
src/Rtmp/RtmpSession.h
查看文件 @
15affeff
...
...
@@ -71,7 +71,7 @@ private:
///////MediaSourceEvent override///////
// 关闭
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
)
override
;
// 播放总人数
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
// 获取媒体源类型
...
...
src/Rtp/RtpSelector.cpp
查看文件 @
15affeff
...
...
@@ -134,17 +134,14 @@ void RtpProcessHelper::attachEvent() {
_process
->
setDelegate
(
shared_from_this
());
}
bool
RtpProcessHelper
::
close
(
MediaSource
&
sender
,
bool
force
)
{
bool
RtpProcessHelper
::
close
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
if
(
!
_process
||
(
!
force
&&
_process
->
totalReaderCount
(
sender
)))
{
return
false
;
}
auto
parent
=
_parent
.
lock
();
if
(
!
parent
)
{
return
false
;
}
parent
->
delProcess
(
_stream_id
,
_process
.
get
());
WarnL
<<
"close media:
"
<<
sender
.
getUrl
()
<<
" "
<<
force
;
WarnL
<<
"close media:
"
<<
sender
.
getUrl
()
;
return
true
;
}
...
...
src/Rtp/RtpSelector.h
查看文件 @
15affeff
...
...
@@ -31,7 +31,7 @@ public:
protected
:
// 通知其停止推流
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
)
override
;
private
:
std
::
string
_stream_id
;
...
...
src/Rtp/RtpSession.cpp
查看文件 @
15affeff
...
...
@@ -124,13 +124,10 @@ void RtpSession::onRtpPacket(const char *data, size_t len) {
_ticker
.
resetTime
();
}
bool
RtpSession
::
close
(
MediaSource
&
sender
,
bool
force
)
{
bool
RtpSession
::
close
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
if
(
!
_process
||
(
!
force
&&
static_pointer_cast
<
MediaSourceEvent
>
(
_process
)
->
totalReaderCount
(
sender
))){
return
false
;
}
string
err
=
StrPrinter
<<
"close media:"
<<
sender
.
getUrl
()
<<
" "
<<
force
;
safeShutdown
(
SockException
(
Err_shutdown
,
err
));
string
err
=
StrPrinter
<<
"close media: "
<<
sender
.
getUrl
();
safeShutdown
(
SockException
(
Err_shutdown
,
err
));
return
true
;
}
...
...
src/Rtp/RtpSession.h
查看文件 @
15affeff
...
...
@@ -35,7 +35,7 @@ public:
protected
:
// 通知其停止推流
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
)
override
;
// 收到rtp回调
void
onRtpPacket
(
const
char
*
data
,
size_t
len
)
override
;
// RtpSplitter override
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
15affeff
...
...
@@ -1136,12 +1136,9 @@ int RtspSession::getTrackIndexByInterleaved(int interleaved) {
throw
SockException
(
Err_shutdown
,
StrPrinter
<<
"no such track with interleaved:"
<<
interleaved
);
}
bool
RtspSession
::
close
(
MediaSource
&
sender
,
bool
force
)
{
bool
RtspSession
::
close
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
if
(
!
_push_src
||
(
!
force
&&
_push_src
->
totalReaderCount
())){
return
false
;
}
string
err
=
StrPrinter
<<
"close media:"
<<
sender
.
getUrl
()
<<
" "
<<
force
;
string
err
=
StrPrinter
<<
"close media: "
<<
sender
.
getUrl
();
safeShutdown
(
SockException
(
Err_shutdown
,
err
));
return
true
;
}
...
...
src/Rtsp/RtspSession.h
查看文件 @
15affeff
...
...
@@ -82,7 +82,7 @@ protected:
///////MediaSourceEvent override///////
// 关闭
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
)
override
;
// 播放总人数
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
// 获取媒体源类型
...
...
srt/SrtTransportImp.cpp
查看文件 @
15affeff
...
...
@@ -109,11 +109,8 @@ void SrtTransportImp::onShutdown(const SockException &ex) {
SrtTransport
::
onShutdown
(
ex
);
}
bool
SrtTransportImp
::
close
(
mediakit
::
MediaSource
&
sender
,
bool
force
)
{
if
(
!
force
&&
totalReaderCount
(
sender
))
{
return
false
;
}
std
::
string
err
=
StrPrinter
<<
"close media:"
<<
sender
.
getUrl
()
<<
" "
<<
force
;
bool
SrtTransportImp
::
close
(
mediakit
::
MediaSource
&
sender
)
{
std
::
string
err
=
StrPrinter
<<
"close media: "
<<
sender
.
getUrl
();
weak_ptr
<
SrtTransportImp
>
weak_self
=
static_pointer_cast
<
SrtTransportImp
>
(
shared_from_this
());
getPoller
()
->
async
([
weak_self
,
err
]()
{
auto
strong_self
=
weak_self
.
lock
();
...
...
srt/SrtTransportImp.hpp
查看文件 @
15affeff
...
...
@@ -50,7 +50,7 @@ protected:
///////MediaSourceEvent override///////
// 关闭
bool
close
(
mediakit
::
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
mediakit
::
MediaSource
&
sender
)
override
;
// 获取媒体源类型
mediakit
::
MediaOriginType
getOriginType
(
mediakit
::
MediaSource
&
sender
)
const
override
;
// 获取媒体源url或者文件路径
...
...
webrtc/WebRtcPusher.cpp
查看文件 @
15affeff
...
...
@@ -38,12 +38,9 @@ WebRtcPusher::WebRtcPusher(const EventPoller::Ptr &poller,
CHECK
(
_push_src
);
}
bool
WebRtcPusher
::
close
(
MediaSource
&
sender
,
bool
force
)
{
bool
WebRtcPusher
::
close
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
if
(
!
force
&&
totalReaderCount
(
sender
))
{
return
false
;
}
string
err
=
StrPrinter
<<
"close media:"
<<
sender
.
getUrl
()
<<
" "
<<
force
;
string
err
=
StrPrinter
<<
"close media: "
<<
sender
.
getUrl
();
weak_ptr
<
WebRtcPusher
>
weak_self
=
static_pointer_cast
<
WebRtcPusher
>
(
shared_from_this
());
getPoller
()
->
async
([
weak_self
,
err
]()
{
auto
strong_self
=
weak_self
.
lock
();
...
...
webrtc/WebRtcPusher.h
查看文件 @
15affeff
...
...
@@ -33,7 +33,7 @@ protected:
protected
:
///////MediaSourceEvent override///////
// 关闭
bool
close
(
mediakit
::
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
mediakit
::
MediaSource
&
sender
)
override
;
// 播放总人数
int
totalReaderCount
(
mediakit
::
MediaSource
&
sender
)
override
;
// 获取媒体源类型
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论