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