基本完成hls相关的主要事件

This commit is contained in:
xiongziliang
2019-12-29 10:49:04 +08:00
parent 1afacdcff8
commit 54736859d4
13 changed files with 142 additions and 74 deletions

View File

@@ -31,6 +31,7 @@
#include "Rtmp/RtmpMediaSourceMuxer.h"
#include "Record/Recorder.h"
#include "Record/HlsMediaSource.h"
#include "Record/HlsRecorder.h"
class MultiMediaSourceMuxer : public MediaSink , public std::enable_shared_from_this<MultiMediaSourceMuxer>{
public:
@@ -42,32 +43,29 @@ public:
};
typedef std::shared_ptr<MultiMediaSourceMuxer> Ptr;
MultiMediaSourceMuxer(const string &vhost,
const string &strApp,
const string &strId,
float dur_sec = 0.0,
bool bEanbleRtsp = true,
bool bEanbleRtmp = true,
bool bEanbleHls = true,
bool bEnableMp4 = false){
if (bEanbleRtmp) {
_rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost, strApp, strId, std::make_shared<TitleMeta>(dur_sec));
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){
if (enable_rtmp) {
_rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleMeta>(dur_sec));
}
if (bEanbleRtsp) {
_rtsp = std::make_shared<RtspMediaSourceMuxer>(vhost, strApp, strId, std::make_shared<TitleSdp>(dur_sec));
if (enable_rtsp) {
_rtsp = std::make_shared<RtspMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleSdp>(dur_sec));
}
if(bEanbleHls){
Recorder::startRecord(Recorder::type_hls,vhost, strApp, strId, true, false);
if(enable_hls){
Recorder::startRecord(Recorder::type_hls,vhost, app, stream, true, false);
}
if(bEnableMp4){
Recorder::startRecord(Recorder::type_mp4,vhost, strApp, strId, true, false);
if(enable_mp4){
Recorder::startRecord(Recorder::type_mp4,vhost, app, stream, true, false);
}
_get_hls_player = [vhost,strApp,strId](){
auto src = MediaSource::find(HLS_SCHEMA,vhost,strApp,strId);
return src ? src->readerCount() : 0;
_get_hls_media_source = [vhost,app,stream](){
auto recorder = dynamic_pointer_cast<HlsRecorder>(Recorder::getRecorder(Recorder::type_hls,vhost,app,stream));
if(recorder){
return recorder->getMediaSource();
}
return MediaSource::Ptr();
};
}
virtual ~MultiMediaSourceMuxer(){}
@@ -92,9 +90,15 @@ public:
if(_rtmp) {
_rtmp->setListener(listener);
}
if(_rtsp) {
_rtsp->setListener(listener);
}
auto hls_src = _get_hls_media_source();
if(hls_src){
hls_src->setListener(listener);
}
}
/**
@@ -102,10 +106,15 @@ public:
* @return
*/
int totalReaderCount() const{
return (_rtsp ? _rtsp->readerCount() : 0) + (_rtmp ? _rtmp->readerCount() : 0) + _get_hls_player();
auto hls_src = _get_hls_media_source();
return (_rtsp ? _rtsp->readerCount() : 0) + (_rtmp ? _rtmp->readerCount() : 0) + (hls_src ? hls_src->readerCount() : 0);
}
void setTimeStamp(uint32_t stamp){
if(_rtmp){
_rtmp->setTimeStamp(stamp);
}
if(_rtsp){
_rtsp->setTimeStamp(stamp);
}
@@ -154,6 +163,11 @@ protected:
_rtsp->onAllTrackReady();
}
auto hls_src = _get_hls_media_source();
if(hls_src){
hls_src->setTrackSource(shared_from_this());
}
if(_listener){
_listener->onAllTrackReady();
}
@@ -162,7 +176,7 @@ private:
RtmpMediaSourceMuxer::Ptr _rtmp;
RtspMediaSourceMuxer::Ptr _rtsp;
Listener *_listener = nullptr;
function<int()> _get_hls_player;
function<MediaSource::Ptr ()> _get_hls_media_source;
};