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
ac705972
Commit
ac705972
authored
Sep 06, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化getTrack接口相关代码
parent
28262b15
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
34 行增加
和
45 行删除
+34
-45
src/Common/MediaSource.cpp
+12
-8
src/Common/MediaSource.h
+15
-9
src/Common/MultiMediaSourceMuxer.cpp
+1
-9
src/Common/MultiMediaSourceMuxer.h
+3
-5
src/Player/PlayerProxy.cpp
+1
-2
src/Rtmp/RtmpMediaSourceImp.h
+1
-2
src/Rtmp/RtmpMediaSourceMuxer.h
+0
-5
src/Rtsp/RtspMediaSourceImp.h
+1
-1
src/Rtsp/RtspMediaSourceMuxer.h
+0
-4
没有找到文件。
src/Common/MediaSource.cpp
查看文件 @
ac705972
...
@@ -54,15 +54,11 @@ const string& MediaSource::getId() const {
...
@@ -54,15 +54,11 @@ const string& MediaSource::getId() const {
}
}
vector
<
Track
::
Ptr
>
MediaSource
::
getTracks
(
bool
ready
)
const
{
vector
<
Track
::
Ptr
>
MediaSource
::
getTracks
(
bool
ready
)
const
{
auto
strongPtr
=
_track_source
.
lock
();
auto
listener
=
_listener
.
lock
();
if
(
strongPt
r
){
if
(
!
listene
r
){
return
strongPtr
->
getTracks
(
ready
);
return
vector
<
Track
::
Ptr
>
(
);
}
}
return
vector
<
Track
::
Ptr
>
();
return
listener
->
getTracks
(
const_cast
<
MediaSource
&>
(
*
this
),
ready
);
}
void
MediaSource
::
setTrackSource
(
const
std
::
weak_ptr
<
TrackSource
>
&
track_src
)
{
_track_source
=
track_src
;
}
}
void
MediaSource
::
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
){
void
MediaSource
::
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
){
...
@@ -549,6 +545,14 @@ bool MediaSourceEventInterceptor::isRecording(MediaSource &sender, Recorder::typ
...
@@ -549,6 +545,14 @@ bool MediaSourceEventInterceptor::isRecording(MediaSource &sender, Recorder::typ
return
listener
->
isRecording
(
sender
,
type
);
return
listener
->
isRecording
(
sender
,
type
);
}
}
vector
<
Track
::
Ptr
>
MediaSourceEventInterceptor
::
getTracks
(
MediaSource
&
sender
,
bool
trackReady
)
const
{
auto
listener
=
_listener
.
lock
();
if
(
!
listener
)
{
return
vector
<
Track
::
Ptr
>
();
}
return
listener
->
getTracks
(
sender
,
trackReady
);
}
/////////////////////////////////////FlushPolicy//////////////////////////////////////
/////////////////////////////////////FlushPolicy//////////////////////////////////////
static
bool
isFlushAble_default
(
bool
is_video
,
uint32_t
last_stamp
,
uint32_t
new_stamp
,
int
cache_size
)
{
static
bool
isFlushAble_default
(
bool
is_video
,
uint32_t
last_stamp
,
uint32_t
new_stamp
,
int
cache_size
)
{
...
...
src/Common/MediaSource.h
查看文件 @
ac705972
...
@@ -59,6 +59,8 @@ public:
...
@@ -59,6 +59,8 @@ public:
virtual
bool
setupRecord
(
MediaSource
&
sender
,
Recorder
::
type
type
,
bool
start
,
const
string
&
custom_path
)
{
return
false
;
};
virtual
bool
setupRecord
(
MediaSource
&
sender
,
Recorder
::
type
type
,
bool
start
,
const
string
&
custom_path
)
{
return
false
;
};
// 获取录制状态
// 获取录制状态
virtual
bool
isRecording
(
MediaSource
&
sender
,
Recorder
::
type
type
)
{
return
false
;
};
virtual
bool
isRecording
(
MediaSource
&
sender
,
Recorder
::
type
type
)
{
return
false
;
};
// 获取所有track相关信息
virtual
vector
<
Track
::
Ptr
>
getTracks
(
MediaSource
&
sender
,
bool
trackReady
=
true
)
const
{
return
vector
<
Track
::
Ptr
>
();
};
private
:
private
:
Timer
::
Ptr
_async_close_timer
;
Timer
::
Ptr
_async_close_timer
;
...
@@ -74,9 +76,10 @@ public:
...
@@ -74,9 +76,10 @@ public:
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
void
onNoneReader
(
MediaSource
&
sender
)
override
;
void
onNoneReader
(
MediaSource
&
sender
)
override
;
void
onRegist
(
MediaSource
&
sender
,
bool
regist
)
override
;
;
void
onRegist
(
MediaSource
&
sender
,
bool
regist
)
override
;
bool
setupRecord
(
MediaSource
&
sender
,
Recorder
::
type
type
,
bool
start
,
const
string
&
custom_path
)
override
;
bool
setupRecord
(
MediaSource
&
sender
,
Recorder
::
type
type
,
bool
start
,
const
string
&
custom_path
)
override
;
bool
isRecording
(
MediaSource
&
sender
,
Recorder
::
type
type
)
override
;
bool
isRecording
(
MediaSource
&
sender
,
Recorder
::
type
type
)
override
;
vector
<
Track
::
Ptr
>
getTracks
(
MediaSource
&
sender
,
bool
trackReady
=
true
)
const
override
;
protected
:
protected
:
std
::
weak_ptr
<
MediaSourceEvent
>
_listener
;
std
::
weak_ptr
<
MediaSourceEvent
>
_listener
;
...
@@ -116,6 +119,8 @@ public:
...
@@ -116,6 +119,8 @@ public:
MediaSource
(
const
string
&
schema
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
)
;
MediaSource
(
const
string
&
schema
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
)
;
virtual
~
MediaSource
()
;
virtual
~
MediaSource
()
;
////////////////获取MediaSource相关信息////////////////
// 获取协议类型
// 获取协议类型
const
string
&
getSchema
()
const
;
const
string
&
getSchema
()
const
;
// 虚拟主机
// 虚拟主机
...
@@ -125,11 +130,16 @@ public:
...
@@ -125,11 +130,16 @@ public:
// 流id
// 流id
const
string
&
getId
()
const
;
const
string
&
getId
()
const
;
// 设置TrackSource
void
setTrackSource
(
const
std
::
weak_ptr
<
TrackSource
>
&
track_src
);
// 获取所有Track
// 获取所有Track
vector
<
Track
::
Ptr
>
getTracks
(
bool
ready
=
true
)
const
override
;
vector
<
Track
::
Ptr
>
getTracks
(
bool
ready
=
true
)
const
override
;
// 获取流当前时间戳
virtual
uint32_t
getTimeStamp
(
TrackType
type
)
{
return
0
;
};
// 设置时间戳
virtual
void
setTimeStamp
(
uint32_t
stamp
)
{};
////////////////MediaSourceEvent相关接口实现////////////////
// 设置监听者
// 设置监听者
void
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
);
void
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
);
// 获取监听者
// 获取监听者
...
@@ -140,11 +150,6 @@ public:
...
@@ -140,11 +150,6 @@ public:
// 观看者个数,包括(hls/rtsp/rtmp)
// 观看者个数,包括(hls/rtsp/rtmp)
virtual
int
totalReaderCount
();
virtual
int
totalReaderCount
();
// 获取流当前时间戳
virtual
uint32_t
getTimeStamp
(
TrackType
type
)
{
return
0
;
};
// 设置时间戳
virtual
void
setTimeStamp
(
uint32_t
stamp
)
{};
// 拖动进度条
// 拖动进度条
bool
seekTo
(
uint32_t
stamp
);
bool
seekTo
(
uint32_t
stamp
);
// 关闭该流
// 关闭该流
...
@@ -156,6 +161,8 @@ public:
...
@@ -156,6 +161,8 @@ public:
// 获取录制状态
// 获取录制状态
bool
isRecording
(
Recorder
::
type
type
);
bool
isRecording
(
Recorder
::
type
type
);
////////////////static方法,查找或生成MediaSource////////////////
// 同步查找流
// 同步查找流
static
Ptr
find
(
const
string
&
schema
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
id
);
static
Ptr
find
(
const
string
&
schema
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
id
);
// 异步查找流
// 异步查找流
...
@@ -180,7 +187,6 @@ private:
...
@@ -180,7 +187,6 @@ private:
string
_vhost
;
string
_vhost
;
string
_app
;
string
_app
;
string
_stream_id
;
string
_stream_id
;
weak_ptr
<
TrackSource
>
_track_source
;
std
::
weak_ptr
<
MediaSourceEvent
>
_listener
;
std
::
weak_ptr
<
MediaSourceEvent
>
_listener
;
};
};
...
...
src/Common/MultiMediaSourceMuxer.cpp
查看文件 @
ac705972
...
@@ -96,7 +96,6 @@ bool MultiMuxerPrivate::setupRecord(MediaSource &sender, Recorder::type type, bo
...
@@ -96,7 +96,6 @@ bool MultiMuxerPrivate::setupRecord(MediaSource &sender, Recorder::type type, bo
if
(
hls_src
)
{
if
(
hls_src
)
{
//设置HlsMediaSource的事件监听器
//设置HlsMediaSource的事件监听器
hls_src
->
setListener
(
_listener
);
hls_src
->
setListener
(
_listener
);
hls_src
->
setTrackSource
(
shared_from_this
());
}
}
}
else
if
(
!
start
&&
_hls
)
{
}
else
if
(
!
start
&&
_hls
)
{
//停止录制
//停止录制
...
@@ -189,19 +188,12 @@ void MultiMuxerPrivate::onTrackFrame(const Frame::Ptr &frame) {
...
@@ -189,19 +188,12 @@ void MultiMuxerPrivate::onTrackFrame(const Frame::Ptr &frame) {
void
MultiMuxerPrivate
::
onAllTrackReady
()
{
void
MultiMuxerPrivate
::
onAllTrackReady
()
{
if
(
_rtmp
)
{
if
(
_rtmp
)
{
_rtmp
->
setTrackSource
(
shared_from_this
());
_rtmp
->
onAllTrackReady
();
_rtmp
->
onAllTrackReady
();
}
}
if
(
_rtsp
)
{
if
(
_rtsp
)
{
_rtsp
->
setTrackSource
(
shared_from_this
());
_rtsp
->
onAllTrackReady
();
_rtsp
->
onAllTrackReady
();
}
}
auto
hls_src
=
getHlsMediaSource
();
if
(
hls_src
)
{
hls_src
->
setTrackSource
(
shared_from_this
());
}
if
(
_track_listener
)
{
if
(
_track_listener
)
{
_track_listener
->
onAllTrackReady
();
_track_listener
->
onAllTrackReady
();
}
}
...
@@ -243,7 +235,7 @@ void MultiMediaSourceMuxer::setTimeStamp(uint32_t stamp) {
...
@@ -243,7 +235,7 @@ void MultiMediaSourceMuxer::setTimeStamp(uint32_t stamp) {
_muxer
->
setTimeStamp
(
stamp
);
_muxer
->
setTimeStamp
(
stamp
);
}
}
vector
<
Track
::
Ptr
>
MultiMediaSourceMuxer
::
getTracks
(
bool
trackReady
)
const
{
vector
<
Track
::
Ptr
>
MultiMediaSourceMuxer
::
getTracks
(
MediaSource
&
sender
,
bool
trackReady
)
const
{
return
_muxer
->
getTracks
(
trackReady
);
return
_muxer
->
getTracks
(
trackReady
);
}
}
...
...
src/Common/MultiMediaSourceMuxer.h
查看文件 @
ac705972
...
@@ -57,7 +57,7 @@ private:
...
@@ -57,7 +57,7 @@ private:
std
::
weak_ptr
<
MediaSourceEvent
>
_listener
;
std
::
weak_ptr
<
MediaSourceEvent
>
_listener
;
};
};
class
MultiMediaSourceMuxer
:
public
MediaSourceEventInterceptor
,
public
MediaSinkInterface
,
public
TrackSource
,
public
MultiMuxerPrivate
::
Listener
,
public
std
::
enable_shared_from_this
<
MultiMediaSourceMuxer
>
{
class
MultiMediaSourceMuxer
:
public
MediaSourceEventInterceptor
,
public
MediaSinkInterface
,
public
MultiMuxerPrivate
::
Listener
,
public
std
::
enable_shared_from_this
<
MultiMediaSourceMuxer
>
{
public
:
public
:
typedef
MultiMuxerPrivate
::
Listener
Listener
;
typedef
MultiMuxerPrivate
::
Listener
Listener
;
typedef
std
::
shared_ptr
<
MultiMediaSourceMuxer
>
Ptr
;
typedef
std
::
shared_ptr
<
MultiMediaSourceMuxer
>
Ptr
;
...
@@ -94,16 +94,14 @@ public:
...
@@ -94,16 +94,14 @@ public:
*/
*/
void
setTimeStamp
(
uint32_t
stamp
);
void
setTimeStamp
(
uint32_t
stamp
);
/////////////////////////////////
TrackSource
override/////////////////////////////////
/////////////////////////////////
MediaSourceEvent
override/////////////////////////////////
/**
/**
* 获取所有Track
* 获取所有Track
* @param trackReady 是否筛选过滤未就绪的track
* @param trackReady 是否筛选过滤未就绪的track
* @return 所有Track
* @return 所有Track
*/
*/
vector
<
Track
::
Ptr
>
getTracks
(
bool
trackReady
=
true
)
const
override
;
vector
<
Track
::
Ptr
>
getTracks
(
MediaSource
&
sender
,
bool
trackReady
=
true
)
const
override
;
/////////////////////////////////MediaSourceEvent override/////////////////////////////////
/**
/**
* 观看总人数
* 观看总人数
...
...
src/Player/PlayerProxy.cpp
查看文件 @
ac705972
...
@@ -96,7 +96,7 @@ void PlayerProxy::play(const string &strUrlTmp) {
...
@@ -96,7 +96,7 @@ void PlayerProxy::play(const string &strUrlTmp) {
return
;
return
;
}
}
if
(
strongSelf
->
_muxer
)
{
if
(
strongSelf
->
_muxer
)
{
auto
tracks
=
strongSelf
->
getTracks
(
false
);
auto
tracks
=
strongSelf
->
MediaPlayer
::
getTracks
(
false
);
for
(
auto
&
track
:
tracks
){
for
(
auto
&
track
:
tracks
){
track
->
delDelegate
(
strongSelf
->
_muxer
.
get
());
track
->
delDelegate
(
strongSelf
->
_muxer
.
get
());
}
}
...
@@ -271,7 +271,6 @@ void PlayerProxy::onPlaySuccess() {
...
@@ -271,7 +271,6 @@ void PlayerProxy::onPlaySuccess() {
_muxer
->
addTrackCompleted
();
_muxer
->
addTrackCompleted
();
if
(
_pMediaSrc
)
{
if
(
_pMediaSrc
)
{
_pMediaSrc
->
setTrackSource
(
_muxer
);
//让_muxer对象拦截一部分事件(比如说录像相关事件)
//让_muxer对象拦截一部分事件(比如说录像相关事件)
_pMediaSrc
->
setListener
(
_muxer
);
_pMediaSrc
->
setListener
(
_muxer
);
}
}
...
...
src/Rtmp/RtmpMediaSourceImp.h
查看文件 @
ac705972
...
@@ -112,12 +112,11 @@ public:
...
@@ -112,12 +112,11 @@ public:
* _muxer触发的所有Track就绪的事件
* _muxer触发的所有Track就绪的事件
*/
*/
void
onAllTrackReady
()
override
{
void
onAllTrackReady
()
override
{
setTrackSource
(
_muxer
);
_all_track_ready
=
true
;
_all_track_ready
=
true
;
if
(
_recreate_metadata
)
{
if
(
_recreate_metadata
)
{
//更新metadata
//更新metadata
for
(
auto
&
track
:
_muxer
->
getTracks
())
{
for
(
auto
&
track
:
_muxer
->
getTracks
(
*
this
))
{
Metadata
::
addTrack
(
_metadata
,
track
);
Metadata
::
addTrack
(
_metadata
,
track
);
}
}
RtmpMediaSource
::
updateMetaData
(
_metadata
);
RtmpMediaSource
::
updateMetaData
(
_metadata
);
...
...
src/Rtmp/RtmpMediaSourceMuxer.h
查看文件 @
ac705972
...
@@ -46,11 +46,6 @@ public:
...
@@ -46,11 +46,6 @@ public:
_media_src
->
setMetaData
(
getMetadata
());
_media_src
->
setMetaData
(
getMetadata
());
}
}
// 设置TrackSource
void
setTrackSource
(
const
std
::
weak_ptr
<
TrackSource
>
&
track_src
){
_media_src
->
setTrackSource
(
track_src
);
}
private
:
private
:
RtmpMediaSource
::
Ptr
_media_src
;
RtmpMediaSource
::
Ptr
_media_src
;
};
};
...
...
src/Rtsp/RtspMediaSourceImp.h
查看文件 @
ac705972
...
@@ -100,9 +100,9 @@ public:
...
@@ -100,9 +100,9 @@ public:
* _muxer触发的所有Track就绪的事件
* _muxer触发的所有Track就绪的事件
*/
*/
void
onAllTrackReady
()
override
{
void
onAllTrackReady
()
override
{
setTrackSource
(
_muxer
);
_all_track_ready
=
true
;
_all_track_ready
=
true
;
}
}
private
:
private
:
RtspDemuxer
::
Ptr
_demuxer
;
RtspDemuxer
::
Ptr
_demuxer
;
MultiMediaSourceMuxer
::
Ptr
_muxer
;
MultiMediaSourceMuxer
::
Ptr
_muxer
;
...
...
src/Rtsp/RtspMediaSourceMuxer.h
查看文件 @
ac705972
...
@@ -45,10 +45,6 @@ public:
...
@@ -45,10 +45,6 @@ public:
_mediaSouce
->
setSdp
(
getSdp
());
_mediaSouce
->
setSdp
(
getSdp
());
}
}
// 设置TrackSource
void
setTrackSource
(
const
std
::
weak_ptr
<
TrackSource
>
&
track_src
){
_mediaSouce
->
setTrackSource
(
track_src
);
}
private
:
private
:
RtspMediaSource
::
Ptr
_mediaSouce
;
RtspMediaSource
::
Ptr
_mediaSouce
;
};
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论