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
f23e1177
Commit
f23e1177
authored
Aug 08, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MultiMediaSourceMuxer默认能处理大部分事件
parent
b3f048f1
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
43 行增加
和
38 行删除
+43
-38
src/Common/MediaSource.cpp
+1
-0
src/Common/MultiMediaSourceMuxer.cpp
+13
-4
src/Common/MultiMediaSourceMuxer.h
+24
-30
src/Record/Recorder.cpp
+3
-2
src/Rtmp/RtmpMediaSourceImp.h
+1
-1
src/Rtsp/RtspMediaSourceImp.h
+1
-1
没有找到文件。
src/Common/MediaSource.cpp
查看文件 @
f23e1177
...
...
@@ -106,6 +106,7 @@ void MediaSource::onNoneReader(){
bool
MediaSource
::
setupRecord
(
Recorder
::
type
type
,
bool
start
,
const
string
&
custom_path
){
auto
listener
=
_listener
.
lock
();
if
(
!
listener
)
{
WarnL
<<
"未设置MediaSource的事件监听者,setupRecord失败:"
<<
getSchema
()
<<
"/"
<<
getVhost
()
<<
"/"
<<
getApp
()
<<
"/"
<<
getId
();
return
false
;
}
return
listener
->
setupRecord
(
*
this
,
type
,
start
,
custom_path
);
...
...
src/Common/MultiMediaSourceMuxer.cpp
查看文件 @
f23e1177
...
...
@@ -231,6 +231,7 @@ MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost,
bool
enable_hls
,
bool
enable_mp4
)
{
_muxer
.
reset
(
new
MultiMuxerPrivate
(
vhost
,
app
,
stream
,
dur_sec
,
enable_rtsp
,
enable_rtmp
,
enable_hls
,
enable_mp4
));
_muxer
->
setTrackListener
(
this
);
}
void
MultiMediaSourceMuxer
::
setMediaListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
)
{
...
...
@@ -238,6 +239,10 @@ void MultiMediaSourceMuxer::setMediaListener(const std::weak_ptr<MediaSourceEven
_listener
=
listener
;
}
void
MultiMediaSourceMuxer
::
setTrackListener
(
const
std
::
weak_ptr
<
MultiMuxerPrivate
::
Listener
>
&
listener
)
{
_track_listener
=
listener
;
}
int
MultiMediaSourceMuxer
::
totalReaderCount
()
const
{
return
_muxer
->
totalReaderCount
();
}
...
...
@@ -246,10 +251,6 @@ void MultiMediaSourceMuxer::setTimeStamp(uint32_t stamp) {
_muxer
->
setTimeStamp
(
stamp
);
}
void
MultiMediaSourceMuxer
::
setTrackListener
(
Listener
*
listener
)
{
_muxer
->
setTrackListener
(
listener
);
}
vector
<
Track
::
Ptr
>
MultiMediaSourceMuxer
::
getTracks
(
bool
trackReady
)
const
{
return
_muxer
->
getTracks
(
trackReady
);
}
...
...
@@ -310,6 +311,14 @@ void MultiMediaSourceMuxer::addTrackCompleted() {
_muxer
->
addTrackCompleted
();
}
void
MultiMediaSourceMuxer
::
onAllTrackReady
(){
_muxer
->
setMediaListener
(
shared_from_this
());
auto
track_listener
=
_track_listener
.
lock
();
if
(
track_listener
){
track_listener
->
onAllTrackReady
();
}
}
void
MultiMediaSourceMuxer
::
resetTracks
()
{
_muxer
->
resetTracks
();
}
...
...
src/Common/MultiMediaSourceMuxer.h
查看文件 @
f23e1177
...
...
@@ -27,17 +27,12 @@ public:
virtual
~
Listener
()
=
default
;
virtual
void
onAllTrackReady
()
=
0
;
};
~
MultiMuxerPrivate
()
override
;
private
:
MultiMuxerPrivate
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
float
dur_sec
,
bool
enable_rtsp
,
bool
enable_rtmp
,
bool
enable_hls
,
bool
enable_mp4
);
~
MultiMuxerPrivate
()
override
;
private
:
MultiMuxerPrivate
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
float
dur_sec
,
bool
enable_rtsp
,
bool
enable_rtmp
,
bool
enable_hls
,
bool
enable_mp4
);
void
resetTracks
()
override
;
void
setMediaListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
);
int
totalReaderCount
()
const
;
...
...
@@ -46,11 +41,11 @@ private:
bool
setupRecord
(
MediaSource
&
sender
,
Recorder
::
type
type
,
bool
start
,
const
string
&
custom_path
);
bool
isRecording
(
MediaSource
&
sender
,
Recorder
::
type
type
);
bool
isEnabled
();
private
:
void
onTrackReady
(
const
Track
::
Ptr
&
track
)
override
;
void
onTrackFrame
(
const
Frame
::
Ptr
&
frame
)
override
;
void
onAllTrackReady
()
override
;
MediaSource
::
Ptr
getHlsMediaSource
()
const
;
private
:
RtmpMediaSourceMuxer
::
Ptr
_rtmp
;
RtspMediaSourceMuxer
::
Ptr
_rtsp
;
...
...
@@ -62,30 +57,29 @@ private:
bool
_enable_record
=
false
;
};
class
MultiMediaSourceMuxer
:
public
MediaSourceEvent
,
public
MediaSinkInterface
,
public
TrackSource
,
public
std
::
enable_shared_from_this
<
MultiMediaSourceMuxer
>
{
class
MultiMediaSourceMuxer
:
public
MediaSourceEvent
,
public
MediaSinkInterface
,
public
TrackSource
,
public
MultiMuxerPrivate
::
Listener
,
public
std
::
enable_shared_from_this
<
MultiMediaSourceMuxer
>
{
public
:
typedef
MultiMuxerPrivate
::
Listener
Listener
;
typedef
std
::
shared_ptr
<
MultiMediaSourceMuxer
>
Ptr
;
~
MultiMediaSourceMuxer
()
override
;
MultiMediaSourceMuxer
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
float
dur_sec
=
0
.
0
,
bool
enable_rtsp
=
true
,
bool
enable_rtmp
=
true
,
bool
enable_hls
=
true
,
bool
enable_mp4
=
false
);
MultiMediaSourceMuxer
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
float
dur_sec
=
0
.
0
,
bool
enable_rtsp
=
true
,
bool
enable_rtmp
=
true
,
bool
enable_hls
=
true
,
bool
enable_mp4
=
false
);
/**
* 设置事件监听器
* @param listener
* @param listener
监听器
*/
void
setMediaListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
);
/**
* 随着Track就绪事件监听器
* @param listener 事件监听器
*/
void
setTrackListener
(
const
std
::
weak_ptr
<
MultiMuxerPrivate
::
Listener
>
&
listener
);
/**
* 返回总的消费者个数
* @return
*/
int
totalReaderCount
()
const
;
...
...
@@ -96,12 +90,6 @@ public:
void
setTimeStamp
(
uint32_t
stamp
);
/**
* 随着Track就绪事件监听器
* @param listener 事件监听器
*/
void
setTrackListener
(
Listener
*
listener
);
/**
* 获取所有Track
* @param trackReady 是否筛选过滤未就绪的track
* @return 所有Track
...
...
@@ -163,17 +151,21 @@ public:
/**
* 添加track,内部会调用Track的clone方法
* 只会克隆sps pps这些信息 ,而不会克隆Delegate相关关系
* @param track
* @param track
添加音频或视频轨道
*/
void
addTrack
(
const
Track
::
Ptr
&
track
)
override
;
/**
* 添加track完毕
* @param track
*/
void
addTrackCompleted
();
/**
* 所有track全部就绪
*/
void
onAllTrackReady
()
override
;
/**
* 重置track
*/
void
resetTracks
()
override
;
...
...
@@ -188,9 +180,11 @@ public:
* 判断是否生效(是否正在转其他协议)
*/
bool
isEnabled
();
private
:
MultiMuxerPrivate
::
Ptr
_muxer
;
std
::
weak_ptr
<
MediaSourceEvent
>
_listener
;
std
::
weak_ptr
<
MultiMuxerPrivate
::
Listener
>
_track_listener
;
Stamp
_stamp
[
2
];
};
...
...
src/Record/Recorder.cpp
查看文件 @
f23e1177
...
...
@@ -97,10 +97,11 @@ bool Recorder::isRecording(type type, const string &vhost, const string &app, co
bool
Recorder
::
startRecord
(
type
type
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
,
const
string
&
customized_path
){
auto
src
=
getMediaSource
(
vhost
,
app
,
stream_id
);
if
(
!
src
){
if
(
!
src
)
{
WarnL
<<
"未找到相关的MediaSource,startRecord失败:"
<<
vhost
<<
"/"
<<
app
<<
"/"
<<
stream_id
;
return
false
;
}
return
src
->
setupRecord
(
type
,
true
,
customized_path
);
return
src
->
setupRecord
(
type
,
true
,
customized_path
);
}
bool
Recorder
::
stopRecord
(
type
type
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
){
...
...
src/Rtmp/RtmpMediaSourceImp.h
查看文件 @
f23e1177
...
...
@@ -127,7 +127,7 @@ public:
//不重复生成rtmp
_muxer
=
std
::
make_shared
<
MultiMediaSourceMuxer
>
(
getVhost
(),
getApp
(),
getId
(),
_demuxer
->
getDuration
(),
enableRtsp
,
false
,
enableHls
,
enableMP4
);
_muxer
->
setMediaListener
(
getListener
());
_muxer
->
setTrackListener
(
this
);
_muxer
->
setTrackListener
(
static_pointer_cast
<
RtmpMediaSourceImp
>
(
shared_from_this
())
);
for
(
auto
&
track
:
_demuxer
->
getTracks
(
false
)){
_muxer
->
addTrack
(
track
);
track
->
addDelegate
(
_muxer
);
...
...
src/Rtsp/RtspMediaSourceImp.h
查看文件 @
f23e1177
...
...
@@ -114,7 +114,7 @@ public:
//不重复生成rtsp
_muxer
=
std
::
make_shared
<
MultiMediaSourceMuxer
>
(
getVhost
(),
getApp
(),
getId
(),
_demuxer
->
getDuration
(),
false
,
enableRtmp
,
enableHls
,
enableMP4
);
_muxer
->
setMediaListener
(
getListener
());
_muxer
->
setTrackListener
(
this
);
_muxer
->
setTrackListener
(
static_pointer_cast
<
RtspMediaSourceImp
>
(
shared_from_this
())
);
for
(
auto
&
track
:
_demuxer
->
getTracks
(
false
)){
_muxer
->
addTrack
(
track
);
track
->
addDelegate
(
_muxer
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论