mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-31 00:37:39 +08:00
统一使用MultiMediaSourceMuxer转协议
This commit is contained in:
parent
46f5a853ac
commit
cf4482983b
@ -38,8 +38,8 @@
|
||||
#include "Rtmp.h"
|
||||
#include "RtmpMediaSource.h"
|
||||
#include "RtmpDemuxer.h"
|
||||
#include "MediaFile/MediaRecorder.h"
|
||||
#include "Rtsp/RtspMediaSourceMuxer.h"
|
||||
#include "Common/MultiMediaSourceMuxer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
@ -54,8 +54,9 @@ public:
|
||||
const string &id,
|
||||
bool bEnableHls = true,
|
||||
bool bEnableMp4 = false,
|
||||
int ringSize = 0):RtmpMediaSource(vhost, app, id,ringSize){
|
||||
_recorder = std::make_shared<MediaRecorder>(vhost, app, id, bEnableHls, bEnableMp4);
|
||||
int ringSize = 0) : RtmpMediaSource(vhost, app, id,ringSize){
|
||||
_bEnableHls = bEnableHls;
|
||||
_bEnableMp4 = bEnableMp4;
|
||||
_rtmpDemuxer = std::make_shared<RtmpDemuxer>();
|
||||
}
|
||||
virtual ~RtmpToRtspMediaSource(){}
|
||||
@ -67,36 +68,39 @@ public:
|
||||
|
||||
void onWrite(const RtmpPacket::Ptr &pkt,bool key_pos) override {
|
||||
_rtmpDemuxer->inputRtmp(pkt);
|
||||
if(!_rtspMuxer && _rtmpDemuxer->isInited(2000)){
|
||||
_rtspMuxer = std::make_shared<RtspMediaSourceMuxer>(getVhost(),
|
||||
getApp(),
|
||||
getId(),
|
||||
std::make_shared<TitleSdp>(_rtmpDemuxer->getDuration()));
|
||||
if(!_muxer && _rtmpDemuxer->isInited(2000)){
|
||||
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(),
|
||||
getApp(),
|
||||
getId(),
|
||||
_rtmpDemuxer->getDuration(),
|
||||
true,//转rtsp
|
||||
false,//不重复生成rtmp
|
||||
_bEnableHls,
|
||||
_bEnableMp4);
|
||||
for (auto &track : _rtmpDemuxer->getTracks(false)){
|
||||
_rtspMuxer->addTrack(track);
|
||||
_recorder->addTrack(track);
|
||||
track->addDelegate(_rtspMuxer);
|
||||
track->addDelegate(_recorder);
|
||||
_muxer->addTrack(track);
|
||||
track->addDelegate(_muxer);
|
||||
}
|
||||
_rtspMuxer->setListener(_listener);
|
||||
_muxer->setListener(_listener);
|
||||
}
|
||||
RtmpMediaSource::onWrite(pkt,key_pos);
|
||||
}
|
||||
|
||||
void setListener(const std::weak_ptr<MediaSourceEvent> &listener) override {
|
||||
RtmpMediaSource::setListener(listener);
|
||||
if(_rtspMuxer){
|
||||
_rtspMuxer->setListener(listener);
|
||||
if(_muxer){
|
||||
_muxer->setListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
int readerCount() override {
|
||||
return RtmpMediaSource::readerCount() + (_rtspMuxer ? _rtspMuxer->readerCount() : 0);
|
||||
return RtmpMediaSource::readerCount() + (_muxer ? _muxer->readerCount() : 0);
|
||||
}
|
||||
private:
|
||||
RtmpDemuxer::Ptr _rtmpDemuxer;
|
||||
RtspMediaSourceMuxer::Ptr _rtspMuxer;
|
||||
MediaRecorder::Ptr _recorder;
|
||||
MultiMediaSourceMuxer::Ptr _muxer;
|
||||
bool _bEnableHls;
|
||||
bool _bEnableMp4;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
@ -29,10 +29,8 @@
|
||||
|
||||
#include "Rtmp/amf.h"
|
||||
#include "RtspMediaSource.h"
|
||||
#include "MediaFile/MediaRecorder.h"
|
||||
#include "Rtmp/RtmpMediaSource.h"
|
||||
#include "RtspDemuxer.h"
|
||||
#include "Rtmp/RtmpMediaSourceMuxer.h"
|
||||
#include "Common/MultiMediaSourceMuxer.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
@ -48,7 +46,8 @@ public:
|
||||
bool bEnableHls = true,
|
||||
bool bEnableMp4 = false,
|
||||
int ringSize = 0) : RtspMediaSource(vhost, app, id,ringSize) {
|
||||
_recorder = std::make_shared<MediaRecorder>(vhost, app, id, bEnableHls, bEnableMp4);
|
||||
_bEnableHls = bEnableHls;
|
||||
_bEnableMp4 = bEnableMp4;
|
||||
}
|
||||
|
||||
virtual ~RtspToRtmpMediaSource() {}
|
||||
@ -61,18 +60,20 @@ public:
|
||||
virtual void onWrite(const RtpPacket::Ptr &rtp, bool bKeyPos) override {
|
||||
if (_rtspDemuxer) {
|
||||
bKeyPos = _rtspDemuxer->inputRtp(rtp);
|
||||
if (!_rtmpMuxer && _rtspDemuxer->isInited(2000)) {
|
||||
_rtmpMuxer = std::make_shared<RtmpMediaSourceMuxer>(getVhost(),
|
||||
getApp(),
|
||||
getId(),
|
||||
std::make_shared<TitleMete>(_rtspDemuxer->getDuration()));
|
||||
if (!_muxer && _rtspDemuxer->isInited(2000)) {
|
||||
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(),
|
||||
getApp(),
|
||||
getId(),
|
||||
_rtspDemuxer->getDuration(),
|
||||
false,//不重复生成rtsp
|
||||
true,//转rtmp
|
||||
_bEnableHls,
|
||||
_bEnableMp4);
|
||||
for (auto &track : _rtspDemuxer->getTracks(false)) {
|
||||
_rtmpMuxer->addTrack(track);
|
||||
_recorder->addTrack(track);
|
||||
track->addDelegate(_rtmpMuxer);
|
||||
track->addDelegate(_recorder);
|
||||
_muxer->addTrack(track);
|
||||
track->addDelegate(_muxer);
|
||||
}
|
||||
_rtmpMuxer->setListener(_listener);
|
||||
_muxer->setListener(_listener);
|
||||
}
|
||||
}
|
||||
RtspMediaSource::onWrite(rtp, bKeyPos);
|
||||
@ -80,17 +81,18 @@ public:
|
||||
|
||||
void setListener(const std::weak_ptr<MediaSourceEvent> &listener) override {
|
||||
RtspMediaSource::setListener(listener);
|
||||
if(_rtmpMuxer){
|
||||
_rtmpMuxer->setListener(listener);
|
||||
if(_muxer){
|
||||
_muxer->setListener(listener);
|
||||
}
|
||||
}
|
||||
int readerCount() override {
|
||||
return RtspMediaSource::readerCount() + (_rtmpMuxer ? _rtmpMuxer->readerCount() : 0);
|
||||
return RtspMediaSource::readerCount() + (_muxer ? _muxer->readerCount() : 0);
|
||||
}
|
||||
private:
|
||||
RtspDemuxer::Ptr _rtspDemuxer;
|
||||
RtmpMediaSourceMuxer::Ptr _rtmpMuxer;
|
||||
MediaRecorder::Ptr _recorder;
|
||||
MultiMediaSourceMuxer::Ptr _muxer;
|
||||
bool _bEnableHls;
|
||||
bool _bEnableMp4;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
Loading…
Reference in New Issue
Block a user