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
679c7980
Commit
679c7980
authored
Aug 28, 2022
by
xiongzilaing
Committed by
ziyue
Aug 28, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
整理媒体事件相关代码,删除无须重载时的多余代码逻辑
parent
67ad2a49
隐藏空白字符变更
内嵌
并排
正在显示
23 个修改的文件
包含
48 行增加
和
104 行删除
+48
-104
api/source/mk_media.cpp
+0
-12
src/Common/MediaSource.cpp
+1
-2
src/Common/MediaSource.h
+12
-4
src/Common/MultiMediaSourceMuxer.cpp
+20
-1
src/Common/MultiMediaSourceMuxer.h
+6
-0
src/Player/PlayerProxy.cpp
+0
-4
src/Player/PlayerProxy.h
+0
-1
src/Record/MP4Reader.cpp
+0
-4
src/Record/MP4Reader.h
+0
-1
src/Rtmp/RtmpSession.cpp
+0
-4
src/Rtmp/RtmpSession.h
+0
-1
src/Rtp/RtpProcess.cpp
+0
-8
src/Rtp/RtpProcess.h
+2
-4
src/Rtp/RtpSelector.cpp
+2
-10
src/Rtp/RtpSelector.h
+2
-6
src/Rtp/RtpSession.cpp
+2
-11
src/Rtp/RtpSession.h
+1
-5
src/Rtsp/RtspSession.cpp
+0
-4
src/Rtsp/RtspSession.h
+0
-1
srt/SrtTransportImp.cpp
+0
-10
srt/SrtTransportImp.hpp
+0
-4
webrtc/WebRtcPusher.cpp
+0
-5
webrtc/WebRtcPusher.h
+0
-2
没有找到文件。
api/source/mk_media.cpp
查看文件 @
679c7980
...
@@ -22,7 +22,6 @@ public:
...
@@ -22,7 +22,6 @@ public:
template
<
typename
...
ArgsType
>
template
<
typename
...
ArgsType
>
MediaHelper
(
ArgsType
&&
...
args
){
MediaHelper
(
ArgsType
&&
...
args
){
_channel
=
std
::
make_shared
<
DevChannel
>
(
std
::
forward
<
ArgsType
>
(
args
)...);
_channel
=
std
::
make_shared
<
DevChannel
>
(
std
::
forward
<
ArgsType
>
(
args
)...);
_poller
=
EventPollerPool
::
Instance
().
getPoller
();
}
}
~
MediaHelper
(){}
~
MediaHelper
(){}
...
@@ -59,11 +58,6 @@ public:
...
@@ -59,11 +58,6 @@ public:
_on_regist_data
=
user_data
;
_on_regist_data
=
user_data
;
}
}
// 获取所属线程
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
{
return
_poller
;
}
protected
:
protected
:
// 通知其停止推流
// 通知其停止推流
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
{
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
{
...
@@ -105,11 +99,6 @@ protected:
...
@@ -105,11 +99,6 @@ protected:
return
_on_speed
(
_on_speed_data
,
speed
);
return
_on_speed
(
_on_speed_data
,
speed
);
}
}
// 观看总人数
int
totalReaderCount
(
MediaSource
&
sender
)
override
{
return
_channel
->
totalReaderCount
();
}
void
onRegist
(
MediaSource
&
sender
,
bool
regist
)
override
{
void
onRegist
(
MediaSource
&
sender
,
bool
regist
)
override
{
if
(
_on_regist
)
{
if
(
_on_regist
)
{
_on_regist
(
_on_regist_data
,
&
sender
,
regist
);
_on_regist
(
_on_regist_data
,
&
sender
,
regist
);
...
@@ -117,7 +106,6 @@ protected:
...
@@ -117,7 +106,6 @@ protected:
}
}
private
:
private
:
EventPoller
::
Ptr
_poller
;
DevChannel
::
Ptr
_channel
;
DevChannel
::
Ptr
_channel
;
on_mk_media_close
_on_close
=
nullptr
;
on_mk_media_close
_on_close
=
nullptr
;
on_mk_media_seek
_on_seek
=
nullptr
;
on_mk_media_seek
_on_seek
=
nullptr
;
...
...
src/Common/MediaSource.cpp
查看文件 @
679c7980
...
@@ -592,7 +592,7 @@ MediaSource::Ptr MediaSource::createFromMP4(const string &schema, const string &
...
@@ -592,7 +592,7 @@ MediaSource::Ptr MediaSource::createFromMP4(const string &schema, const string &
/////////////////////////////////////MediaSourceEvent//////////////////////////////////////
/////////////////////////////////////MediaSourceEvent//////////////////////////////////////
void
MediaSourceEvent
::
onReaderChanged
(
MediaSource
&
sender
,
int
size
){
void
MediaSourceEvent
::
onReaderChanged
(
MediaSource
&
sender
,
int
size
){
if
(
size
||
totalReaderCount
(
sender
))
{
if
(
size
||
sender
.
totalReaderCount
(
))
{
//还有人观看该视频,不触发关闭事件
//还有人观看该视频,不触发关闭事件
_async_close_timer
=
nullptr
;
_async_close_timer
=
nullptr
;
return
;
return
;
...
@@ -736,7 +736,6 @@ toolkit::EventPoller::Ptr MediaSourceEventInterceptor::getOwnerPoller(MediaSourc
...
@@ -736,7 +736,6 @@ toolkit::EventPoller::Ptr MediaSourceEventInterceptor::getOwnerPoller(MediaSourc
return
EventPollerPool
::
Instance
().
getPoller
();
return
EventPollerPool
::
Instance
().
getPoller
();
}
}
bool
MediaSourceEventInterceptor
::
setupRecord
(
MediaSource
&
sender
,
Recorder
::
type
type
,
bool
start
,
const
string
&
custom_path
,
size_t
max_second
)
{
bool
MediaSourceEventInterceptor
::
setupRecord
(
MediaSource
&
sender
,
Recorder
::
type
type
,
bool
start
,
const
string
&
custom_path
,
size_t
max_second
)
{
auto
listener
=
_listener
.
lock
();
auto
listener
=
_listener
.
lock
();
if
(
!
listener
)
{
if
(
!
listener
)
{
...
...
src/Common/MediaSource.h
查看文件 @
679c7980
...
@@ -54,6 +54,14 @@ class MediaSource;
...
@@ -54,6 +54,14 @@ class MediaSource;
class
MediaSourceEvent
{
class
MediaSourceEvent
{
public
:
public
:
friend
class
MediaSource
;
friend
class
MediaSource
;
class
NotImplemented
:
public
std
::
runtime_error
{
public
:
template
<
typename
...
T
>
NotImplemented
(
T
&&
...
args
)
:
std
::
runtime_error
(
std
::
forward
<
T
>
(
args
)...)
{}
~
NotImplemented
()
override
=
default
;
};
MediaSourceEvent
(){};
MediaSourceEvent
(){};
virtual
~
MediaSourceEvent
(){};
virtual
~
MediaSourceEvent
(){};
...
@@ -72,16 +80,16 @@ public:
...
@@ -72,16 +80,16 @@ public:
virtual
bool
speed
(
MediaSource
&
sender
,
float
speed
)
{
return
false
;
}
virtual
bool
speed
(
MediaSource
&
sender
,
float
speed
)
{
return
false
;
}
// 通知其停止产生流
// 通知其停止产生流
virtual
bool
close
(
MediaSource
&
sender
,
bool
force
)
{
return
false
;
}
virtual
bool
close
(
MediaSource
&
sender
,
bool
force
)
{
return
false
;
}
// 获取观看总人数
// 获取观看总人数
,此函数一般强制重载
virtual
int
totalReaderCount
(
MediaSource
&
sender
)
=
0
;
virtual
int
totalReaderCount
(
MediaSource
&
sender
)
{
throw
NotImplemented
(
toolkit
::
demangle
(
typeid
(
*
this
).
name
())
+
"::totalReaderCount not implemented"
);
}
// 通知观看人数变化
// 通知观看人数变化
virtual
void
onReaderChanged
(
MediaSource
&
sender
,
int
size
);
virtual
void
onReaderChanged
(
MediaSource
&
sender
,
int
size
);
//流注册或注销事件
//流注册或注销事件
virtual
void
onRegist
(
MediaSource
&
sender
,
bool
regist
)
{};
virtual
void
onRegist
(
MediaSource
&
sender
,
bool
regist
)
{};
// 获取丢包率
// 获取丢包率
virtual
int
getLossRate
(
MediaSource
&
sender
,
TrackType
type
)
{
return
-
1
;
}
virtual
int
getLossRate
(
MediaSource
&
sender
,
TrackType
type
)
{
return
-
1
;
}
// 获取所在线程
// 获取所在线程
, 此函数一般强制重载
virtual
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
=
0
;
virtual
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
{
throw
NotImplemented
(
toolkit
::
demangle
(
typeid
(
*
this
).
name
())
+
"::getOwnerPoller not implemented"
);
}
////////////////////////仅供MultiMediaSourceMuxer对象继承////////////////////////
////////////////////////仅供MultiMediaSourceMuxer对象继承////////////////////////
// 开启或关闭录制
// 开启或关闭录制
...
...
src/Common/MultiMediaSourceMuxer.cpp
查看文件 @
679c7980
...
@@ -88,6 +88,7 @@ const std::string &MultiMediaSourceMuxer::getStreamId() const {
...
@@ -88,6 +88,7 @@ const std::string &MultiMediaSourceMuxer::getStreamId() const {
}
}
MultiMediaSourceMuxer
::
MultiMediaSourceMuxer
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
float
dur_sec
,
const
ProtocolOption
&
option
)
{
MultiMediaSourceMuxer
::
MultiMediaSourceMuxer
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
float
dur_sec
,
const
ProtocolOption
&
option
)
{
_poller
=
EventPollerPool
::
Instance
().
getPoller
();
_vhost
=
vhost
;
_vhost
=
vhost
;
_app
=
app
;
_app
=
app
;
_stream_id
=
stream
;
_stream_id
=
stream
;
...
@@ -187,7 +188,12 @@ int MultiMediaSourceMuxer::totalReaderCount(MediaSource &sender) {
...
@@ -187,7 +188,12 @@ int MultiMediaSourceMuxer::totalReaderCount(MediaSource &sender) {
if
(
!
listener
)
{
if
(
!
listener
)
{
return
totalReaderCount
();
return
totalReaderCount
();
}
}
return
listener
->
totalReaderCount
(
sender
);
try
{
return
listener
->
totalReaderCount
(
sender
);
}
catch
(
MediaSourceEvent
::
NotImplemented
&
)
{
//listener未重载totalReaderCount
return
totalReaderCount
();
}
}
}
//此函数可能跨线程调用
//此函数可能跨线程调用
...
@@ -290,6 +296,19 @@ vector<Track::Ptr> MultiMediaSourceMuxer::getMediaTracks(MediaSource &sender, bo
...
@@ -290,6 +296,19 @@ vector<Track::Ptr> MultiMediaSourceMuxer::getMediaTracks(MediaSource &sender, bo
return
getTracks
(
trackReady
);
return
getTracks
(
trackReady
);
}
}
EventPoller
::
Ptr
MultiMediaSourceMuxer
::
getOwnerPoller
(
MediaSource
&
sender
)
{
auto
listener
=
getDelegate
();
if
(
!
listener
)
{
return
_poller
;
}
try
{
return
listener
->
getOwnerPoller
(
sender
);
}
catch
(
MediaSourceEvent
::
NotImplemented
&
)
{
// listener未重载getOwnerPoller
return
_poller
;
}
}
bool
MultiMediaSourceMuxer
::
onTrackReady
(
const
Track
::
Ptr
&
track
)
{
bool
MultiMediaSourceMuxer
::
onTrackReady
(
const
Track
::
Ptr
&
track
)
{
if
(
CodecL16
==
track
->
getCodecId
())
{
if
(
CodecL16
==
track
->
getCodecId
())
{
WarnL
<<
"L16音频格式目前只支持RTSP协议推流拉流!!!"
;
WarnL
<<
"L16音频格式目前只支持RTSP协议推流拉流!!!"
;
...
...
src/Common/MultiMediaSourceMuxer.h
查看文件 @
679c7980
...
@@ -154,6 +154,11 @@ public:
...
@@ -154,6 +154,11 @@ public:
*/
*/
std
::
vector
<
Track
::
Ptr
>
getMediaTracks
(
MediaSource
&
sender
,
bool
trackReady
=
true
)
const
override
;
std
::
vector
<
Track
::
Ptr
>
getMediaTracks
(
MediaSource
&
sender
,
bool
trackReady
=
true
)
const
override
;
/**
* 获取所属线程
*/
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
const
std
::
string
&
getVhost
()
const
;
const
std
::
string
&
getVhost
()
const
;
const
std
::
string
&
getApp
()
const
;
const
std
::
string
&
getApp
()
const
;
const
std
::
string
&
getStreamId
()
const
;
const
std
::
string
&
getStreamId
()
const
;
...
@@ -201,6 +206,7 @@ private:
...
@@ -201,6 +206,7 @@ private:
TSMediaSourceMuxer
::
Ptr
_ts
;
TSMediaSourceMuxer
::
Ptr
_ts
;
MediaSinkInterface
::
Ptr
_mp4
;
MediaSinkInterface
::
Ptr
_mp4
;
HlsRecorder
::
Ptr
_hls
;
HlsRecorder
::
Ptr
_hls
;
toolkit
::
EventPoller
::
Ptr
_poller
;
//对象个数统计
//对象个数统计
toolkit
::
ObjectStatistic
<
MultiMediaSourceMuxer
>
_statistic
;
toolkit
::
ObjectStatistic
<
MultiMediaSourceMuxer
>
_statistic
;
...
...
src/Player/PlayerProxy.cpp
查看文件 @
679c7980
...
@@ -185,10 +185,6 @@ std::shared_ptr<SockInfo> PlayerProxy::getOriginSock(MediaSource &sender) const
...
@@ -185,10 +185,6 @@ std::shared_ptr<SockInfo> PlayerProxy::getOriginSock(MediaSource &sender) const
return
getSockInfo
();
return
getSockInfo
();
}
}
toolkit
::
EventPoller
::
Ptr
PlayerProxy
::
getOwnerPoller
(
MediaSource
&
sender
)
{
return
getPoller
();
}
void
PlayerProxy
::
onPlaySuccess
()
{
void
PlayerProxy
::
onPlaySuccess
()
{
GET_CONFIG
(
bool
,
reset_when_replay
,
General
::
kResetWhenRePlay
);
GET_CONFIG
(
bool
,
reset_when_replay
,
General
::
kResetWhenRePlay
);
if
(
dynamic_pointer_cast
<
RtspMediaSource
>
(
_media_src
))
{
if
(
dynamic_pointer_cast
<
RtspMediaSource
>
(
_media_src
))
{
...
...
src/Player/PlayerProxy.h
查看文件 @
679c7980
...
@@ -59,7 +59,6 @@ private:
...
@@ -59,7 +59,6 @@ private:
MediaOriginType
getOriginType
(
MediaSource
&
sender
)
const
override
;
MediaOriginType
getOriginType
(
MediaSource
&
sender
)
const
override
;
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
std
::
shared_ptr
<
toolkit
::
SockInfo
>
getOriginSock
(
MediaSource
&
sender
)
const
override
;
std
::
shared_ptr
<
toolkit
::
SockInfo
>
getOriginSock
(
MediaSource
&
sender
)
const
override
;
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
void
rePlay
(
const
std
::
string
&
strUrl
,
int
iFailedCnt
);
void
rePlay
(
const
std
::
string
&
strUrl
,
int
iFailedCnt
);
void
onPlaySuccess
();
void
onPlaySuccess
();
...
...
src/Record/MP4Reader.cpp
查看文件 @
679c7980
...
@@ -239,10 +239,6 @@ bool MP4Reader::close(MediaSource &sender, bool force) {
...
@@ -239,10 +239,6 @@ bool MP4Reader::close(MediaSource &sender, bool force) {
return
true
;
return
true
;
}
}
int
MP4Reader
::
totalReaderCount
(
MediaSource
&
sender
)
{
return
_muxer
?
_muxer
->
totalReaderCount
()
:
sender
.
readerCount
();
}
MediaOriginType
MP4Reader
::
getOriginType
(
MediaSource
&
sender
)
const
{
MediaOriginType
MP4Reader
::
getOriginType
(
MediaSource
&
sender
)
const
{
return
MediaOriginType
::
mp4_vod
;
return
MediaOriginType
::
mp4_vod
;
}
}
...
...
src/Record/MP4Reader.h
查看文件 @
679c7980
...
@@ -56,7 +56,6 @@ private:
...
@@ -56,7 +56,6 @@ private:
bool
speed
(
MediaSource
&
sender
,
float
speed
)
override
;
bool
speed
(
MediaSource
&
sender
,
float
speed
)
override
;
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
MediaOriginType
getOriginType
(
MediaSource
&
sender
)
const
override
;
MediaOriginType
getOriginType
(
MediaSource
&
sender
)
const
override
;
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
...
...
src/Rtmp/RtmpSession.cpp
查看文件 @
679c7980
...
@@ -599,10 +599,6 @@ std::shared_ptr<SockInfo> RtmpSession::getOriginSock(MediaSource &sender) const
...
@@ -599,10 +599,6 @@ std::shared_ptr<SockInfo> RtmpSession::getOriginSock(MediaSource &sender) const
return
const_cast
<
RtmpSession
*>
(
this
)
->
shared_from_this
();
return
const_cast
<
RtmpSession
*>
(
this
)
->
shared_from_this
();
}
}
toolkit
::
EventPoller
::
Ptr
RtmpSession
::
getOwnerPoller
(
MediaSource
&
sender
)
{
return
getPoller
();
}
void
RtmpSession
::
setSocketFlags
(){
void
RtmpSession
::
setSocketFlags
(){
GET_CONFIG
(
int
,
merge_write_ms
,
General
::
kMergeWriteMS
);
GET_CONFIG
(
int
,
merge_write_ms
,
General
::
kMergeWriteMS
);
if
(
merge_write_ms
>
0
)
{
if
(
merge_write_ms
>
0
)
{
...
...
src/Rtmp/RtmpSession.h
查看文件 @
679c7980
...
@@ -80,7 +80,6 @@ private:
...
@@ -80,7 +80,6 @@ private:
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
// 获取媒体源客户端相关信息
// 获取媒体源客户端相关信息
std
::
shared_ptr
<
SockInfo
>
getOriginSock
(
MediaSource
&
sender
)
const
override
;
std
::
shared_ptr
<
SockInfo
>
getOriginSock
(
MediaSource
&
sender
)
const
override
;
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
void
setSocketFlags
();
void
setSocketFlags
();
std
::
string
getStreamId
(
const
std
::
string
&
str
);
std
::
string
getStreamId
(
const
std
::
string
&
str
);
...
...
src/Rtp/RtpProcess.cpp
查看文件 @
679c7980
...
@@ -229,14 +229,6 @@ string RtpProcess::getIdentifier() const {
...
@@ -229,14 +229,6 @@ string RtpProcess::getIdentifier() const {
return
_media_info
.
_streamid
;
return
_media_info
.
_streamid
;
}
}
int
RtpProcess
::
getTotalReaderCount
()
{
return
_muxer
?
_muxer
->
totalReaderCount
()
:
0
;
}
void
RtpProcess
::
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
)
{
setDelegate
(
listener
);
}
void
RtpProcess
::
emitOnPublish
()
{
void
RtpProcess
::
emitOnPublish
()
{
weak_ptr
<
RtpProcess
>
weak_self
=
shared_from_this
();
weak_ptr
<
RtpProcess
>
weak_self
=
shared_from_this
();
Broadcast
::
PublishAuthInvoker
invoker
=
[
weak_self
](
const
string
&
err
,
const
ProtocolOption
&
option
)
{
Broadcast
::
PublishAuthInvoker
invoker
=
[
weak_self
](
const
string
&
err
,
const
ProtocolOption
&
option
)
{
...
...
src/Rtp/RtpProcess.h
查看文件 @
679c7980
...
@@ -64,11 +64,8 @@ public:
...
@@ -64,11 +64,8 @@ public:
uint16_t
get_peer_port
()
override
;
uint16_t
get_peer_port
()
override
;
std
::
string
getIdentifier
()
const
override
;
std
::
string
getIdentifier
()
const
override
;
int
getTotalReaderCount
();
void
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
);
void
setHelper
(
const
std
::
weak_ptr
<
RtcpContext
>
help
);
void
setHelper
(
const
std
::
weak_ptr
<
RtcpContext
>
help
);
int
getLossRate
(
MediaSource
&
sender
,
TrackType
type
)
override
;
protected
:
protected
:
bool
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
;
bool
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
;
bool
addTrack
(
const
Track
::
Ptr
&
track
)
override
;
bool
addTrack
(
const
Track
::
Ptr
&
track
)
override
;
...
@@ -80,6 +77,7 @@ protected:
...
@@ -80,6 +77,7 @@ protected:
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
std
::
shared_ptr
<
SockInfo
>
getOriginSock
(
MediaSource
&
sender
)
const
override
;
std
::
shared_ptr
<
SockInfo
>
getOriginSock
(
MediaSource
&
sender
)
const
override
;
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
int
getLossRate
(
MediaSource
&
sender
,
TrackType
type
)
override
;
private
:
private
:
void
emitOnPublish
();
void
emitOnPublish
();
...
...
src/Rtp/RtpSelector.cpp
查看文件 @
679c7980
...
@@ -131,12 +131,12 @@ RtpProcessHelper::~RtpProcessHelper() {
...
@@ -131,12 +131,12 @@ RtpProcessHelper::~RtpProcessHelper() {
void
RtpProcessHelper
::
attachEvent
()
{
void
RtpProcessHelper
::
attachEvent
()
{
//主要目的是close回调触发时能把对象从RtpSelector中删除
//主要目的是close回调触发时能把对象从RtpSelector中删除
_process
->
set
Listener
(
shared_from_this
());
_process
->
set
Delegate
(
shared_from_this
());
}
}
bool
RtpProcessHelper
::
close
(
MediaSource
&
sender
,
bool
force
)
{
bool
RtpProcessHelper
::
close
(
MediaSource
&
sender
,
bool
force
)
{
//此回调在其他线程触发
//此回调在其他线程触发
if
(
!
_process
||
(
!
force
&&
_process
->
getTotalReaderCount
(
)))
{
if
(
!
_process
||
(
!
force
&&
_process
->
totalReaderCount
(
sender
)))
{
return
false
;
return
false
;
}
}
auto
parent
=
_parent
.
lock
();
auto
parent
=
_parent
.
lock
();
...
@@ -148,14 +148,6 @@ bool RtpProcessHelper::close(MediaSource &sender, bool force) {
...
@@ -148,14 +148,6 @@ bool RtpProcessHelper::close(MediaSource &sender, bool force) {
return
true
;
return
true
;
}
}
int
RtpProcessHelper
::
totalReaderCount
(
MediaSource
&
sender
)
{
return
_process
?
_process
->
getTotalReaderCount
()
:
sender
.
totalReaderCount
();
}
toolkit
::
EventPoller
::
Ptr
RtpProcessHelper
::
getOwnerPoller
(
MediaSource
&
sender
)
{
return
toolkit
::
EventPollerPool
::
Instance
().
getPoller
();
}
RtpProcess
::
Ptr
&
RtpProcessHelper
::
getProcess
()
{
RtpProcess
::
Ptr
&
RtpProcessHelper
::
getProcess
()
{
return
_process
;
return
_process
;
}
}
...
...
src/Rtp/RtpSelector.h
查看文件 @
679c7980
...
@@ -32,15 +32,11 @@ public:
...
@@ -32,15 +32,11 @@ public:
protected
:
protected
:
// 通知其停止推流
// 通知其停止推流
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
// 观看总人数
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
// 获取所属线程
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
private
:
private
:
std
::
weak_ptr
<
RtpSelector
>
_parent
;
RtpProcess
::
Ptr
_process
;
std
::
string
_stream_id
;
std
::
string
_stream_id
;
RtpProcess
::
Ptr
_process
;
std
::
weak_ptr
<
RtpSelector
>
_parent
;
};
};
class
RtpSelector
:
public
std
::
enable_shared_from_this
<
RtpSelector
>
{
class
RtpSelector
:
public
std
::
enable_shared_from_this
<
RtpSelector
>
{
...
...
src/Rtp/RtpSession.cpp
查看文件 @
679c7980
...
@@ -101,7 +101,7 @@ void RtpSession::onRtpPacket(const char *data, size_t len) {
...
@@ -101,7 +101,7 @@ void RtpSession::onRtpPacket(const char *data, size_t len) {
}
}
//tcp情况下,一个tcp链接只可能是一路流,不需要通过多个ssrc来区分,所以不需要频繁getProcess
//tcp情况下,一个tcp链接只可能是一路流,不需要通过多个ssrc来区分,所以不需要频繁getProcess
_process
=
RtpSelector
::
Instance
().
getProcess
(
_stream_id
,
true
);
_process
=
RtpSelector
::
Instance
().
getProcess
(
_stream_id
,
true
);
_process
->
set
Listener
(
dynamic_pointer_cast
<
RtpSession
>
(
shared_from_this
()));
_process
->
set
Delegate
(
dynamic_pointer_cast
<
RtpSession
>
(
shared_from_this
()));
}
}
try
{
try
{
uint32_t
rtp_ssrc
=
0
;
uint32_t
rtp_ssrc
=
0
;
...
@@ -126,7 +126,7 @@ void RtpSession::onRtpPacket(const char *data, size_t len) {
...
@@ -126,7 +126,7 @@ void RtpSession::onRtpPacket(const char *data, size_t len) {
bool
RtpSession
::
close
(
MediaSource
&
sender
,
bool
force
)
{
bool
RtpSession
::
close
(
MediaSource
&
sender
,
bool
force
)
{
//此回调在其他线程触发
//此回调在其他线程触发
if
(
!
_process
||
(
!
force
&&
_process
->
getTotalReaderCount
(
))){
if
(
!
_process
||
(
!
force
&&
static_pointer_cast
<
MediaSourceEvent
>
(
_process
)
->
totalReaderCount
(
sender
))){
return
false
;
return
false
;
}
}
string
err
=
StrPrinter
<<
"close media:"
<<
sender
.
getSchema
()
<<
"/"
<<
sender
.
getVhost
()
<<
"/"
<<
sender
.
getApp
()
<<
"/"
<<
sender
.
getId
()
<<
" "
<<
force
;
string
err
=
StrPrinter
<<
"close media:"
<<
sender
.
getSchema
()
<<
"/"
<<
sender
.
getVhost
()
<<
"/"
<<
sender
.
getApp
()
<<
"/"
<<
sender
.
getId
()
<<
" "
<<
force
;
...
@@ -134,15 +134,6 @@ bool RtpSession::close(MediaSource &sender, bool force) {
...
@@ -134,15 +134,6 @@ bool RtpSession::close(MediaSource &sender, bool force) {
return
true
;
return
true
;
}
}
int
RtpSession
::
totalReaderCount
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
return
_process
?
_process
->
getTotalReaderCount
()
:
sender
.
totalReaderCount
();
}
toolkit
::
EventPoller
::
Ptr
RtpSession
::
getOwnerPoller
(
MediaSource
&
sender
)
{
return
getPoller
();
}
static
const
char
*
findSSRC
(
const
char
*
data
,
ssize_t
len
,
uint32_t
ssrc
)
{
static
const
char
*
findSSRC
(
const
char
*
data
,
ssize_t
len
,
uint32_t
ssrc
)
{
//rtp前面必须预留两个字节的长度字段
//rtp前面必须预留两个字节的长度字段
for
(
ssize_t
i
=
2
;
i
<=
len
-
4
;
++
i
)
{
for
(
ssize_t
i
=
2
;
i
<=
len
-
4
;
++
i
)
{
...
...
src/Rtp/RtpSession.h
查看文件 @
679c7980
...
@@ -36,13 +36,9 @@ public:
...
@@ -36,13 +36,9 @@ public:
protected
:
protected
:
// 通知其停止推流
// 通知其停止推流
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
// 观看总人数
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
// 获取所属线程
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
// 收到rtp回调
// 收到rtp回调
void
onRtpPacket
(
const
char
*
data
,
size_t
len
)
override
;
void
onRtpPacket
(
const
char
*
data
,
size_t
len
)
override
;
// RtpSplitter override
const
char
*
onSearchPacketTail
(
const
char
*
data
,
size_t
len
)
override
;
const
char
*
onSearchPacketTail
(
const
char
*
data
,
size_t
len
)
override
;
private
:
private
:
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
679c7980
...
@@ -1154,10 +1154,6 @@ std::shared_ptr<SockInfo> RtspSession::getOriginSock(MediaSource &sender) const
...
@@ -1154,10 +1154,6 @@ std::shared_ptr<SockInfo> RtspSession::getOriginSock(MediaSource &sender) const
return
const_cast
<
RtspSession
*>
(
this
)
->
shared_from_this
();
return
const_cast
<
RtspSession
*>
(
this
)
->
shared_from_this
();
}
}
toolkit
::
EventPoller
::
Ptr
RtspSession
::
getOwnerPoller
(
MediaSource
&
sender
)
{
return
getPoller
();
}
void
RtspSession
::
onBeforeRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
track_index
){
void
RtspSession
::
onBeforeRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
track_index
){
updateRtcpContext
(
rtp
);
updateRtcpContext
(
rtp
);
}
}
...
...
src/Rtsp/RtspSession.h
查看文件 @
679c7980
...
@@ -91,7 +91,6 @@ protected:
...
@@ -91,7 +91,6 @@ protected:
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
std
::
string
getOriginUrl
(
MediaSource
&
sender
)
const
override
;
// 获取媒体源客户端相关信息
// 获取媒体源客户端相关信息
std
::
shared_ptr
<
SockInfo
>
getOriginSock
(
MediaSource
&
sender
)
const
override
;
std
::
shared_ptr
<
SockInfo
>
getOriginSock
(
MediaSource
&
sender
)
const
override
;
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
/////TcpSession override////
/////TcpSession override////
ssize_t
send
(
toolkit
::
Buffer
::
Ptr
pkt
)
override
;
ssize_t
send
(
toolkit
::
Buffer
::
Ptr
pkt
)
override
;
...
...
srt/SrtTransportImp.cpp
查看文件 @
679c7980
...
@@ -129,11 +129,6 @@ bool SrtTransportImp::close(mediakit::MediaSource &sender, bool force) {
...
@@ -129,11 +129,6 @@ bool SrtTransportImp::close(mediakit::MediaSource &sender, bool force) {
return
true
;
return
true
;
}
}
// 播放总人数
int
SrtTransportImp
::
totalReaderCount
(
mediakit
::
MediaSource
&
sender
)
{
return
_muxer
?
_muxer
->
totalReaderCount
()
:
sender
.
readerCount
();
}
// 获取媒体源类型
// 获取媒体源类型
mediakit
::
MediaOriginType
SrtTransportImp
::
getOriginType
(
mediakit
::
MediaSource
&
sender
)
const
{
mediakit
::
MediaOriginType
SrtTransportImp
::
getOriginType
(
mediakit
::
MediaSource
&
sender
)
const
{
return
MediaOriginType
::
srt_push
;
return
MediaOriginType
::
srt_push
;
...
@@ -149,11 +144,6 @@ std::shared_ptr<SockInfo> SrtTransportImp::getOriginSock(mediakit::MediaSource &
...
@@ -149,11 +144,6 @@ std::shared_ptr<SockInfo> SrtTransportImp::getOriginSock(mediakit::MediaSource &
return
static_pointer_cast
<
SockInfo
>
(
getSession
());
return
static_pointer_cast
<
SockInfo
>
(
getSession
());
}
}
toolkit
::
EventPoller
::
Ptr
SrtTransportImp
::
getOwnerPoller
(
MediaSource
&
sender
){
auto
session
=
getSession
();
return
session
?
session
->
getPoller
()
:
EventPollerPool
::
Instance
().
getPoller
();
}
void
SrtTransportImp
::
emitOnPublish
()
{
void
SrtTransportImp
::
emitOnPublish
()
{
std
::
weak_ptr
<
SrtTransportImp
>
weak_self
=
static_pointer_cast
<
SrtTransportImp
>
(
shared_from_this
());
std
::
weak_ptr
<
SrtTransportImp
>
weak_self
=
static_pointer_cast
<
SrtTransportImp
>
(
shared_from_this
());
Broadcast
::
PublishAuthInvoker
invoker
=
[
weak_self
](
const
std
::
string
&
err
,
const
ProtocolOption
&
option
)
{
Broadcast
::
PublishAuthInvoker
invoker
=
[
weak_self
](
const
std
::
string
&
err
,
const
ProtocolOption
&
option
)
{
...
...
srt/SrtTransportImp.hpp
查看文件 @
679c7980
...
@@ -51,16 +51,12 @@ protected:
...
@@ -51,16 +51,12 @@ protected:
///////MediaSourceEvent override///////
///////MediaSourceEvent override///////
// 关闭
// 关闭
bool
close
(
mediakit
::
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
mediakit
::
MediaSource
&
sender
,
bool
force
)
override
;
// 播放总人数
int
totalReaderCount
(
mediakit
::
MediaSource
&
sender
)
override
;
// 获取媒体源类型
// 获取媒体源类型
mediakit
::
MediaOriginType
getOriginType
(
mediakit
::
MediaSource
&
sender
)
const
override
;
mediakit
::
MediaOriginType
getOriginType
(
mediakit
::
MediaSource
&
sender
)
const
override
;
// 获取媒体源url或者文件路径
// 获取媒体源url或者文件路径
std
::
string
getOriginUrl
(
mediakit
::
MediaSource
&
sender
)
const
override
;
std
::
string
getOriginUrl
(
mediakit
::
MediaSource
&
sender
)
const
override
;
// 获取媒体源客户端相关信息
// 获取媒体源客户端相关信息
std
::
shared_ptr
<
SockInfo
>
getOriginSock
(
mediakit
::
MediaSource
&
sender
)
const
override
;
std
::
shared_ptr
<
SockInfo
>
getOriginSock
(
mediakit
::
MediaSource
&
sender
)
const
override
;
// get poller
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
MediaSource
&
sender
)
override
;
///////MediaSinkInterface override///////
///////MediaSinkInterface override///////
void
resetTracks
()
override
{};
void
resetTracks
()
override
{};
...
...
webrtc/WebRtcPusher.cpp
查看文件 @
679c7980
...
@@ -150,8 +150,4 @@ void WebRtcPusher::onRtcConfigure(RtcConfigure &configure) const {
...
@@ -150,8 +150,4 @@ void WebRtcPusher::onRtcConfigure(RtcConfigure &configure) const {
int
WebRtcPusher
::
getLossRate
(
MediaSource
&
sender
,
mediakit
::
TrackType
type
){
int
WebRtcPusher
::
getLossRate
(
MediaSource
&
sender
,
mediakit
::
TrackType
type
){
return
WebRtcTransportImp
::
getLossRate
(
type
);
return
WebRtcTransportImp
::
getLossRate
(
type
);
}
toolkit
::
EventPoller
::
Ptr
WebRtcPusher
::
getOwnerPoller
(
mediakit
::
MediaSource
&
sender
)
{
return
getPoller
();
}
}
\ No newline at end of file
webrtc/WebRtcPusher.h
查看文件 @
679c7980
...
@@ -41,8 +41,6 @@ protected:
...
@@ -41,8 +41,6 @@ protected:
std
::
shared_ptr
<
SockInfo
>
getOriginSock
(
mediakit
::
MediaSource
&
sender
)
const
override
;
std
::
shared_ptr
<
SockInfo
>
getOriginSock
(
mediakit
::
MediaSource
&
sender
)
const
override
;
// 获取丢包率
// 获取丢包率
int
getLossRate
(
mediakit
::
MediaSource
&
sender
,
mediakit
::
TrackType
type
)
override
;
int
getLossRate
(
mediakit
::
MediaSource
&
sender
,
mediakit
::
TrackType
type
)
override
;
// 获取MediaSource归属线程
toolkit
::
EventPoller
::
Ptr
getOwnerPoller
(
mediakit
::
MediaSource
&
sender
)
override
;
private
:
private
:
WebRtcPusher
(
const
EventPoller
::
Ptr
&
poller
,
const
mediakit
::
RtspMediaSourceImp
::
Ptr
&
src
,
WebRtcPusher
(
const
EventPoller
::
Ptr
&
poller
,
const
mediakit
::
RtspMediaSourceImp
::
Ptr
&
src
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论