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
25924713
Commit
25924713
authored
Apr 22, 2021
by
xiongziliang
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
f70bfb5f
0bb87858
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
98 行增加
和
42 行删除
+98
-42
src/Common/MediaSink.cpp
+2
-2
src/Common/MediaSink.h
+21
-12
src/Common/MultiMediaSourceMuxer.cpp
+1
-1
src/Player/PlayerBase.cpp
+15
-3
src/Player/PlayerBase.h
+13
-16
src/Rtmp/RtmpDemuxer.cpp
+7
-2
src/Rtmp/RtmpMediaSourceImp.h
+17
-2
src/Rtsp/RtspDemuxer.cpp
+5
-2
src/Rtsp/RtspMediaSourceImp.h
+17
-2
没有找到文件。
src/Common/MediaSink.cpp
查看文件 @
25924713
...
...
@@ -13,8 +13,8 @@
//最多等待未初始化的Track 10秒,超时之后会忽略未初始化的Track
#define MAX_WAIT_MS_READY 10000
//如果
添加Track,最多等待5秒
#define MAX_WAIT_MS_ADD_TRACK
5
000
//如果
直播流只有单Track,最多等待3秒,超时后未收到其他Track的数据,则认为是单Track
#define MAX_WAIT_MS_ADD_TRACK
3
000
namespace
mediakit
{
...
...
src/Common/MediaSink.h
查看文件 @
25924713
...
...
@@ -22,12 +22,10 @@ using namespace toolkit;
namespace
mediakit
{
class
MediaSinkInterface
:
public
FrameWriterInterface
{
class
TrackListener
{
public
:
typedef
std
::
shared_ptr
<
MediaSinkInterface
>
Ptr
;
MediaSinkInterface
(){};
virtual
~
MediaSinkInterface
(){};
TrackListener
()
=
default
;
virtual
~
TrackListener
()
=
default
;
/**
* 添加track,内部会调用Track的clone方法
...
...
@@ -37,25 +35,33 @@ public:
virtual
void
addTrack
(
const
Track
::
Ptr
&
track
)
=
0
;
/**
* 添加
所有T
rack完毕
* 添加
t
rack完毕
*/
virtual
void
addTrackCompleted
()
{}
virtual
void
addTrackCompleted
()
{}
;
/**
* 重置track
*/
virtual
void
resetTracks
()
=
0
;
virtual
void
resetTracks
()
{};
};
class
MediaSinkInterface
:
public
FrameWriterInterface
,
public
TrackListener
{
public
:
typedef
std
::
shared_ptr
<
MediaSinkInterface
>
Ptr
;
MediaSinkInterface
()
=
default
;
~
MediaSinkInterface
()
override
=
default
;
};
/**
* 该类的作用是等待Track ready()返回true也就是就绪后再通知派生类进行下一步的操作
* 目的是输入Frame前由Track截取处理下,以便获取有效的信息(譬如sps pps aa_cfg)
*/
class
MediaSink
:
public
MediaSinkInterface
,
public
TrackSource
{
class
MediaSink
:
public
MediaSinkInterface
,
public
TrackSource
{
public
:
typedef
std
::
shared_ptr
<
MediaSink
>
Ptr
;
MediaSink
()
{}
virtual
~
MediaSink
(){}
MediaSink
()
=
default
;
~
MediaSink
()
override
=
default
;
/**
* 输入frame
...
...
@@ -86,7 +92,8 @@ public:
* 获取所有Track
* @param trackReady 是否获取已经准备好的Track
*/
vector
<
Track
::
Ptr
>
getTracks
(
bool
trackReady
=
true
)
const
override
;
vector
<
Track
::
Ptr
>
getTracks
(
bool
trackReady
=
true
)
const
override
;
protected
:
/**
* 某track已经准备好,其ready()状态返回true,
...
...
@@ -105,6 +112,7 @@ protected:
* @param frame
*/
virtual
void
onTrackFrame
(
const
Frame
::
Ptr
&
frame
)
{};
private
:
/**
* 触发onAllTrackReady事件
...
...
@@ -116,6 +124,7 @@ private:
*/
void
checkTrackIfReady
(
const
Track
::
Ptr
&
track
);
void
checkTrackIfReady_l
(
const
Track
::
Ptr
&
track
);
private
:
bool
_all_track_ready
=
false
;
size_t
_max_track_size
=
2
;
...
...
src/Common/MultiMediaSourceMuxer.cpp
查看文件 @
25924713
...
...
@@ -308,7 +308,7 @@ void MultiMediaSourceMuxer::setTrackListener(const std::weak_ptr<MultiMuxerPriva
int
MultiMediaSourceMuxer
::
totalReaderCount
()
const
{
#if defined(ENABLE_RTPPROXY)
return
_muxer
->
totalReaderCount
()
+
_rtp_sender
.
size
();
return
_muxer
->
totalReaderCount
()
+
(
int
)
_rtp_sender
.
size
();
#else
return
_muxer
->
totalReaderCount
();
#endif
...
...
src/Player/PlayerBase.cpp
查看文件 @
25924713
...
...
@@ -106,13 +106,25 @@ float Demuxer::getDuration() const {
return
_fDuration
;
}
void
Demuxer
::
onA
ddTrack
(
const
Track
::
Ptr
&
track
){
void
Demuxer
::
a
ddTrack
(
const
Track
::
Ptr
&
track
){
if
(
_listener
){
_listener
->
onA
ddTrack
(
track
);
_listener
->
a
ddTrack
(
track
);
}
}
void
Demuxer
::
setTrackListener
(
Demuxer
::
Listener
*
listener
)
{
void
Demuxer
::
addTrackCompleted
(){
if
(
_listener
){
_listener
->
addTrackCompleted
();
}
}
void
Demuxer
::
resetTracks
()
{
if
(
_listener
)
{
_listener
->
resetTracks
();
}
}
void
Demuxer
::
setTrackListener
(
TrackListener
*
listener
)
{
_listener
=
listener
;
}
...
...
src/Player/PlayerBase.h
查看文件 @
25924713
...
...
@@ -19,6 +19,7 @@
#include "Util/mini.h"
#include "Util/RingBuffer.h"
#include "Common/MediaSource.h"
#include "Common/MediaSink.h"
#include "Extension/Frame.h"
#include "Extension/Track.h"
using
namespace
toolkit
;
...
...
@@ -227,18 +228,10 @@ protected:
MediaSource
::
Ptr
_pMediaSrc
;
};
class
Demuxer
:
public
PlayerBase
{
class
Demuxer
:
public
PlayerBase
,
public
TrackListener
{
public
:
class
Listener
{
public
:
Listener
()
=
default
;
virtual
~
Listener
()
=
default
;
virtual
void
onAddTrack
(
const
Track
::
Ptr
&
track
)
=
0
;
};
Demuxer
(){};
virtual
~
Demuxer
(){};
Demuxer
()
=
default
;
~
Demuxer
()
override
=
default
;
/**
* 返回是否完成初始化完毕
...
...
@@ -267,15 +260,19 @@ public:
/**
* 设置track监听器
*/
void
setTrackListener
(
Listener
*
listener
);
void
setTrackListener
(
TrackListener
*
listener
);
protected
:
void
onAddTrack
(
const
Track
::
Ptr
&
track
);
void
addTrack
(
const
Track
::
Ptr
&
track
)
override
;
void
addTrackCompleted
()
override
;
void
resetTracks
()
override
;
protected
:
Listener
*
_listener
=
nullptr
;
float
_fDuration
=
0
;
Ticker
_ticker
;
AudioTrack
::
Ptr
_audioTrack
;
VideoTrack
::
Ptr
_videoTrack
;
Ticker
_ticker
;
float
_fDuration
=
0
;
TrackListener
*
_listener
=
nullptr
;
};
}
/* namespace mediakit */
...
...
src/Rtmp/RtmpDemuxer.cpp
查看文件 @
25924713
...
...
@@ -72,6 +72,11 @@ bool RtmpDemuxer::loadMetaData(const AMFValue &val){
}
catch
(
std
::
exception
&
ex
)
{
WarnL
<<
ex
.
what
();
}
if
(
ret
)
{
//metadata中存在track相关的描述,那么我们根据metadata判断有多少个track
addTrackCompleted
();
}
return
ret
;
}
...
...
@@ -114,7 +119,7 @@ void RtmpDemuxer::makeVideoTrack(const AMFValue &videoCodec, int bit_rate) {
if
(
_video_rtmp_decoder
)
{
//设置rtmp解码器代理,生成的frame写入该Track
_video_rtmp_decoder
->
addDelegate
(
_videoTrack
);
onA
ddTrack
(
_videoTrack
);
a
ddTrack
(
_videoTrack
);
_try_get_video_track
=
true
;
}
else
{
//找不到相应的rtmp解码器,该track无效
...
...
@@ -133,7 +138,7 @@ void RtmpDemuxer::makeAudioTrack(const AMFValue &audioCodec,int sample_rate, int
if
(
_audio_rtmp_decoder
)
{
//设置rtmp解码器代理,生成的frame写入该Track
_audio_rtmp_decoder
->
addDelegate
(
_audioTrack
);
onA
ddTrack
(
_audioTrack
);
a
ddTrack
(
_audioTrack
);
_try_get_audio_track
=
true
;
}
else
{
//找不到相应的rtmp解码器,该track无效
...
...
src/Rtmp/RtmpMediaSourceImp.h
查看文件 @
25924713
...
...
@@ -27,7 +27,7 @@ using namespace std;
using
namespace
toolkit
;
namespace
mediakit
{
class
RtmpMediaSourceImp
:
public
RtmpMediaSource
,
public
Demuxer
::
Listener
,
public
MultiMediaSourceMuxer
::
Listener
{
class
RtmpMediaSourceImp
:
public
RtmpMediaSource
,
public
Track
Listener
,
public
MultiMediaSourceMuxer
::
Listener
{
public
:
typedef
std
::
shared_ptr
<
RtmpMediaSourceImp
>
Ptr
;
...
...
@@ -97,7 +97,7 @@ public:
/**
* _demuxer触发的添加Track事件
*/
void
onA
ddTrack
(
const
Track
::
Ptr
&
track
)
override
{
void
a
ddTrack
(
const
Track
::
Ptr
&
track
)
override
{
if
(
_muxer
){
_muxer
->
addTrack
(
track
);
track
->
addDelegate
(
_muxer
);
...
...
@@ -105,6 +105,21 @@ public:
}
/**
* _demuxer触发的Track添加完毕事件
*/
void
addTrackCompleted
()
override
{
if
(
_muxer
)
{
_muxer
->
addTrackCompleted
();
}
}
void
resetTracks
()
override
{
if
(
_muxer
)
{
_muxer
->
resetTracks
();
}
}
/**
* _muxer触发的所有Track就绪的事件
*/
void
onAllTrackReady
()
override
{
...
...
src/Rtsp/RtspDemuxer.cpp
查看文件 @
25924713
...
...
@@ -38,6 +38,9 @@ void RtspDemuxer::loadSdp(const SdpParser &attr) {
break
;
}
}
//rtsp能通过sdp立即知道有多少个track
addTrackCompleted
();
auto
titleTrack
=
attr
.
getTrack
(
TrackTitle
);
if
(
titleTrack
){
_fDuration
=
titleTrack
->
_duration
;
...
...
@@ -83,7 +86,7 @@ void RtspDemuxer::makeAudioTrack(const SdpTrack::Ptr &audio) {
if
(
_audioRtpDecoder
){
//设置rtp解码器代理,生成的frame写入该Track
_audioRtpDecoder
->
addDelegate
(
_audioTrack
);
onA
ddTrack
(
_audioTrack
);
a
ddTrack
(
_audioTrack
);
}
else
{
//找不到相应的rtp解码器,该track无效
_audioTrack
.
reset
();
...
...
@@ -101,7 +104,7 @@ void RtspDemuxer::makeVideoTrack(const SdpTrack::Ptr &video) {
if
(
_videoRtpDecoder
){
//设置rtp解码器代理,生成的frame写入该Track
_videoRtpDecoder
->
addDelegate
(
_videoTrack
);
onA
ddTrack
(
_videoTrack
);
a
ddTrack
(
_videoTrack
);
}
else
{
//找不到相应的rtp解码器,该track无效
_videoTrack
.
reset
();
...
...
src/Rtsp/RtspMediaSourceImp.h
查看文件 @
25924713
...
...
@@ -18,7 +18,7 @@
using
namespace
toolkit
;
namespace
mediakit
{
class
RtspMediaSourceImp
:
public
RtspMediaSource
,
public
Demuxer
::
Listener
,
public
MultiMediaSourceMuxer
::
Listener
{
class
RtspMediaSourceImp
:
public
RtspMediaSource
,
public
TrackListener
,
public
MultiMediaSourceMuxer
::
Listener
{
public
:
typedef
std
::
shared_ptr
<
RtspMediaSourceImp
>
Ptr
;
...
...
@@ -88,7 +88,7 @@ public:
/**
* _demuxer触发的添加Track事件
*/
void
onA
ddTrack
(
const
Track
::
Ptr
&
track
)
override
{
void
a
ddTrack
(
const
Track
::
Ptr
&
track
)
override
{
if
(
_muxer
){
_muxer
->
addTrack
(
track
);
track
->
addDelegate
(
_muxer
);
...
...
@@ -96,6 +96,21 @@ public:
}
/**
* _demuxer触发的Track添加完毕事件
*/
void
addTrackCompleted
()
override
{
if
(
_muxer
)
{
_muxer
->
addTrackCompleted
();
}
}
void
resetTracks
()
override
{
if
(
_muxer
)
{
_muxer
->
resetTracks
();
}
}
/**
* _muxer触发的所有Track就绪的事件
*/
void
onAllTrackReady
()
override
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论