提高无Metadata的rtmp推流的兼容性

This commit is contained in:
xiongziliang 2019-09-23 17:08:00 +08:00
parent 1fda56ab6e
commit adfc084d4a
3 changed files with 8 additions and 13 deletions

View File

@ -45,9 +45,6 @@ RtmpDemuxer::RtmpDemuxer(const AMFValue &val) {
} }
} }
int RtmpDemuxer::getTrackCount(const AMFValue &metadata) {
return (int)(metadata["videocodecid"].type() != AMF_NULL) + (int)(metadata["audiocodecid"].type() != AMF_NULL);
}
bool RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) { bool RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
switch (pkt->typeId) { switch (pkt->typeId) {

View File

@ -55,14 +55,6 @@ public:
RtmpDemuxer(const AMFValue &val); RtmpDemuxer(const AMFValue &val);
virtual ~RtmpDemuxer(){}; virtual ~RtmpDemuxer(){};
/**
*
* rtmp track
* @param metadata rtmp的metadata
* @return
*/
static int getTrackCount(const AMFValue &metadata);
/** /**
* *
* @param pkt rtmp包 * @param pkt rtmp包

View File

@ -53,16 +53,22 @@ public:
const string &app, const string &app,
const string &id, const string &id,
int ringSize = 0) : RtmpMediaSource(vhost, app, id,ringSize){ int ringSize = 0) : RtmpMediaSource(vhost, app, id,ringSize){
_demuxer = std::make_shared<RtmpDemuxer>();
} }
virtual ~RtmpToRtspMediaSource(){} virtual ~RtmpToRtspMediaSource(){}
void onGetMetaData(const AMFValue &metadata) override { void onGetMetaData(const AMFValue &metadata) override {
_demuxer = std::make_shared<RtmpDemuxer>(metadata); if(!_demuxer){
//在未调用onWrite前设置Metadata能触发生成RtmpDemuxer
_demuxer = std::make_shared<RtmpDemuxer>(metadata);
}
RtmpMediaSource::onGetMetaData(metadata); RtmpMediaSource::onGetMetaData(metadata);
} }
void onWrite(const RtmpPacket::Ptr &pkt,bool key_pos = true) override { void onWrite(const RtmpPacket::Ptr &pkt,bool key_pos = true) override {
if(!_demuxer){
//尚未获取Metadata那么不管有没有Metadata都生成RtmpDemuxer
_demuxer = std::make_shared<RtmpDemuxer>();
}
_demuxer->inputRtmp(pkt); _demuxer->inputRtmp(pkt);
if(!_muxer && _demuxer->isInited(2000)){ if(!_muxer && _demuxer->isInited(2000)){
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), _muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(),