mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 12:37:09 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
259247132a
@ -13,8 +13,8 @@
|
|||||||
//最多等待未初始化的Track 10秒,超时之后会忽略未初始化的Track
|
//最多等待未初始化的Track 10秒,超时之后会忽略未初始化的Track
|
||||||
#define MAX_WAIT_MS_READY 10000
|
#define MAX_WAIT_MS_READY 10000
|
||||||
|
|
||||||
//如果添加Track,最多等待5秒
|
//如果直播流只有单Track,最多等待3秒,超时后未收到其他Track的数据,则认为是单Track
|
||||||
#define MAX_WAIT_MS_ADD_TRACK 5000
|
#define MAX_WAIT_MS_ADD_TRACK 3000
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
|
@ -22,12 +22,10 @@ using namespace toolkit;
|
|||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
class MediaSinkInterface : public FrameWriterInterface {
|
class TrackListener {
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<MediaSinkInterface> Ptr;
|
TrackListener() = default;
|
||||||
|
virtual ~TrackListener() = default;
|
||||||
MediaSinkInterface(){};
|
|
||||||
virtual ~MediaSinkInterface(){};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加track,内部会调用Track的clone方法
|
* 添加track,内部会调用Track的clone方法
|
||||||
@ -37,14 +35,22 @@ public:
|
|||||||
virtual void addTrack(const Track::Ptr & track) = 0;
|
virtual void addTrack(const Track::Ptr & track) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加所有Track完毕
|
* 添加track完毕
|
||||||
*/
|
*/
|
||||||
virtual void addTrackCompleted() {}
|
virtual void addTrackCompleted() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置track
|
* 重置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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,8 +60,8 @@ public:
|
|||||||
class MediaSink : public MediaSinkInterface, public TrackSource{
|
class MediaSink : public MediaSinkInterface, public TrackSource{
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<MediaSink> Ptr;
|
typedef std::shared_ptr<MediaSink> Ptr;
|
||||||
MediaSink(){}
|
MediaSink() = default;
|
||||||
virtual ~MediaSink(){}
|
~MediaSink() override = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入frame
|
* 输入frame
|
||||||
@ -87,6 +93,7 @@ public:
|
|||||||
* @param trackReady 是否获取已经准备好的Track
|
* @param trackReady 是否获取已经准备好的Track
|
||||||
*/
|
*/
|
||||||
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* 某track已经准备好,其ready()状态返回true,
|
* 某track已经准备好,其ready()状态返回true,
|
||||||
@ -105,6 +112,7 @@ protected:
|
|||||||
* @param frame
|
* @param frame
|
||||||
*/
|
*/
|
||||||
virtual void onTrackFrame(const Frame::Ptr &frame) {};
|
virtual void onTrackFrame(const Frame::Ptr &frame) {};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* 触发onAllTrackReady事件
|
* 触发onAllTrackReady事件
|
||||||
@ -116,6 +124,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
void checkTrackIfReady(const Track::Ptr &track);
|
void checkTrackIfReady(const Track::Ptr &track);
|
||||||
void checkTrackIfReady_l(const Track::Ptr &track);
|
void checkTrackIfReady_l(const Track::Ptr &track);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _all_track_ready = false;
|
bool _all_track_ready = false;
|
||||||
size_t _max_track_size = 2;
|
size_t _max_track_size = 2;
|
||||||
|
@ -308,7 +308,7 @@ void MultiMediaSourceMuxer::setTrackListener(const std::weak_ptr<MultiMuxerPriva
|
|||||||
|
|
||||||
int MultiMediaSourceMuxer::totalReaderCount() const {
|
int MultiMediaSourceMuxer::totalReaderCount() const {
|
||||||
#if defined(ENABLE_RTPPROXY)
|
#if defined(ENABLE_RTPPROXY)
|
||||||
return _muxer->totalReaderCount() + _rtp_sender.size();
|
return _muxer->totalReaderCount() + (int)_rtp_sender.size();
|
||||||
#else
|
#else
|
||||||
return _muxer->totalReaderCount();
|
return _muxer->totalReaderCount();
|
||||||
#endif
|
#endif
|
||||||
|
@ -106,13 +106,25 @@ float Demuxer::getDuration() const {
|
|||||||
return _fDuration;
|
return _fDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Demuxer::onAddTrack(const Track::Ptr &track){
|
void Demuxer::addTrack(const Track::Ptr &track){
|
||||||
if(_listener){
|
if(_listener){
|
||||||
_listener->onAddTrack(track);
|
_listener->addTrack(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;
|
_listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "Util/mini.h"
|
#include "Util/mini.h"
|
||||||
#include "Util/RingBuffer.h"
|
#include "Util/RingBuffer.h"
|
||||||
#include "Common/MediaSource.h"
|
#include "Common/MediaSource.h"
|
||||||
|
#include "Common/MediaSink.h"
|
||||||
#include "Extension/Frame.h"
|
#include "Extension/Frame.h"
|
||||||
#include "Extension/Track.h"
|
#include "Extension/Track.h"
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
@ -227,18 +228,10 @@ protected:
|
|||||||
MediaSource::Ptr _pMediaSrc;
|
MediaSource::Ptr _pMediaSrc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Demuxer : public PlayerBase, public TrackListener{
|
||||||
class Demuxer : public PlayerBase{
|
|
||||||
public:
|
public:
|
||||||
class Listener{
|
Demuxer() = default;
|
||||||
public:
|
~Demuxer() override = default;
|
||||||
Listener() = default;
|
|
||||||
virtual ~Listener() = default;
|
|
||||||
virtual void onAddTrack(const Track::Ptr &track) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
Demuxer(){};
|
|
||||||
virtual ~Demuxer(){};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回是否完成初始化完毕
|
* 返回是否完成初始化完毕
|
||||||
@ -267,15 +260,19 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 设置track监听器
|
* 设置track监听器
|
||||||
*/
|
*/
|
||||||
void setTrackListener(Listener *listener);
|
void setTrackListener(TrackListener *listener);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onAddTrack(const Track::Ptr &track);
|
void addTrack(const Track::Ptr &track) override;
|
||||||
|
void addTrackCompleted() override;
|
||||||
|
void resetTracks() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Listener *_listener = nullptr;
|
float _fDuration = 0;
|
||||||
|
Ticker _ticker;
|
||||||
AudioTrack::Ptr _audioTrack;
|
AudioTrack::Ptr _audioTrack;
|
||||||
VideoTrack::Ptr _videoTrack;
|
VideoTrack::Ptr _videoTrack;
|
||||||
Ticker _ticker;
|
TrackListener *_listener = nullptr;
|
||||||
float _fDuration = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace mediakit */
|
} /* namespace mediakit */
|
||||||
|
@ -72,6 +72,11 @@ bool RtmpDemuxer::loadMetaData(const AMFValue &val){
|
|||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
WarnL << ex.what();
|
WarnL << ex.what();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
//metadata中存在track相关的描述,那么我们根据metadata判断有多少个track
|
||||||
|
addTrackCompleted();
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +119,7 @@ void RtmpDemuxer::makeVideoTrack(const AMFValue &videoCodec, int bit_rate) {
|
|||||||
if (_video_rtmp_decoder) {
|
if (_video_rtmp_decoder) {
|
||||||
//设置rtmp解码器代理,生成的frame写入该Track
|
//设置rtmp解码器代理,生成的frame写入该Track
|
||||||
_video_rtmp_decoder->addDelegate(_videoTrack);
|
_video_rtmp_decoder->addDelegate(_videoTrack);
|
||||||
onAddTrack(_videoTrack);
|
addTrack(_videoTrack);
|
||||||
_try_get_video_track = true;
|
_try_get_video_track = true;
|
||||||
} else {
|
} else {
|
||||||
//找不到相应的rtmp解码器,该track无效
|
//找不到相应的rtmp解码器,该track无效
|
||||||
@ -133,7 +138,7 @@ void RtmpDemuxer::makeAudioTrack(const AMFValue &audioCodec,int sample_rate, int
|
|||||||
if (_audio_rtmp_decoder) {
|
if (_audio_rtmp_decoder) {
|
||||||
//设置rtmp解码器代理,生成的frame写入该Track
|
//设置rtmp解码器代理,生成的frame写入该Track
|
||||||
_audio_rtmp_decoder->addDelegate(_audioTrack);
|
_audio_rtmp_decoder->addDelegate(_audioTrack);
|
||||||
onAddTrack(_audioTrack);
|
addTrack(_audioTrack);
|
||||||
_try_get_audio_track = true;
|
_try_get_audio_track = true;
|
||||||
} else {
|
} else {
|
||||||
//找不到相应的rtmp解码器,该track无效
|
//找不到相应的rtmp解码器,该track无效
|
||||||
|
@ -27,7 +27,7 @@ using namespace std;
|
|||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
class RtmpMediaSourceImp: public RtmpMediaSource, public Demuxer::Listener , public MultiMediaSourceMuxer::Listener {
|
class RtmpMediaSourceImp: public RtmpMediaSource, public TrackListener , public MultiMediaSourceMuxer::Listener {
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<RtmpMediaSourceImp> Ptr;
|
typedef std::shared_ptr<RtmpMediaSourceImp> Ptr;
|
||||||
|
|
||||||
@ -97,13 +97,28 @@ public:
|
|||||||
/**
|
/**
|
||||||
* _demuxer触发的添加Track事件
|
* _demuxer触发的添加Track事件
|
||||||
*/
|
*/
|
||||||
void onAddTrack(const Track::Ptr &track) override {
|
void addTrack(const Track::Ptr &track) override {
|
||||||
if(_muxer){
|
if(_muxer){
|
||||||
_muxer->addTrack(track);
|
_muxer->addTrack(track);
|
||||||
track->addDelegate(_muxer);
|
track->addDelegate(_muxer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _demuxer触发的Track添加完毕事件
|
||||||
|
*/
|
||||||
|
void addTrackCompleted() override {
|
||||||
|
if (_muxer) {
|
||||||
|
_muxer->addTrackCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetTracks() override {
|
||||||
|
if (_muxer) {
|
||||||
|
_muxer->resetTracks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _muxer触发的所有Track就绪的事件
|
* _muxer触发的所有Track就绪的事件
|
||||||
*/
|
*/
|
||||||
|
@ -38,6 +38,9 @@ void RtspDemuxer::loadSdp(const SdpParser &attr) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//rtsp能通过sdp立即知道有多少个track
|
||||||
|
addTrackCompleted();
|
||||||
|
|
||||||
auto titleTrack = attr.getTrack(TrackTitle);
|
auto titleTrack = attr.getTrack(TrackTitle);
|
||||||
if(titleTrack){
|
if(titleTrack){
|
||||||
_fDuration = titleTrack->_duration;
|
_fDuration = titleTrack->_duration;
|
||||||
@ -83,7 +86,7 @@ void RtspDemuxer::makeAudioTrack(const SdpTrack::Ptr &audio) {
|
|||||||
if(_audioRtpDecoder){
|
if(_audioRtpDecoder){
|
||||||
//设置rtp解码器代理,生成的frame写入该Track
|
//设置rtp解码器代理,生成的frame写入该Track
|
||||||
_audioRtpDecoder->addDelegate(_audioTrack);
|
_audioRtpDecoder->addDelegate(_audioTrack);
|
||||||
onAddTrack(_audioTrack);
|
addTrack(_audioTrack);
|
||||||
} else{
|
} else{
|
||||||
//找不到相应的rtp解码器,该track无效
|
//找不到相应的rtp解码器,该track无效
|
||||||
_audioTrack.reset();
|
_audioTrack.reset();
|
||||||
@ -101,7 +104,7 @@ void RtspDemuxer::makeVideoTrack(const SdpTrack::Ptr &video) {
|
|||||||
if(_videoRtpDecoder){
|
if(_videoRtpDecoder){
|
||||||
//设置rtp解码器代理,生成的frame写入该Track
|
//设置rtp解码器代理,生成的frame写入该Track
|
||||||
_videoRtpDecoder->addDelegate(_videoTrack);
|
_videoRtpDecoder->addDelegate(_videoTrack);
|
||||||
onAddTrack(_videoTrack);
|
addTrack(_videoTrack);
|
||||||
}else{
|
}else{
|
||||||
//找不到相应的rtp解码器,该track无效
|
//找不到相应的rtp解码器,该track无效
|
||||||
_videoTrack.reset();
|
_videoTrack.reset();
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
class RtspMediaSourceImp : public RtspMediaSource, public Demuxer::Listener , public MultiMediaSourceMuxer::Listener {
|
class RtspMediaSourceImp : public RtspMediaSource, public TrackListener, public MultiMediaSourceMuxer::Listener {
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<RtspMediaSourceImp> Ptr;
|
typedef std::shared_ptr<RtspMediaSourceImp> Ptr;
|
||||||
|
|
||||||
@ -88,13 +88,28 @@ public:
|
|||||||
/**
|
/**
|
||||||
* _demuxer触发的添加Track事件
|
* _demuxer触发的添加Track事件
|
||||||
*/
|
*/
|
||||||
void onAddTrack(const Track::Ptr &track) override {
|
void addTrack(const Track::Ptr &track) override {
|
||||||
if(_muxer){
|
if(_muxer){
|
||||||
_muxer->addTrack(track);
|
_muxer->addTrack(track);
|
||||||
track->addDelegate(_muxer);
|
track->addDelegate(_muxer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _demuxer触发的Track添加完毕事件
|
||||||
|
*/
|
||||||
|
void addTrackCompleted() override {
|
||||||
|
if (_muxer) {
|
||||||
|
_muxer->addTrackCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetTracks() override {
|
||||||
|
if (_muxer) {
|
||||||
|
_muxer->resetTracks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _muxer触发的所有Track就绪的事件
|
* _muxer触发的所有Track就绪的事件
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user