From adfc084d4a3cd18c4ab08de0de4c28e2a4c5b93d Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 23 Sep 2019 17:08:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E9=AB=98=E6=97=A0Metadata=E7=9A=84rtm?= =?UTF-8?q?p=E6=8E=A8=E6=B5=81=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/RtmpDemuxer.cpp | 3 --- src/Rtmp/RtmpDemuxer.h | 8 -------- src/Rtmp/RtmpToRtspMediaSource.h | 10 ++++++++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Rtmp/RtmpDemuxer.cpp b/src/Rtmp/RtmpDemuxer.cpp index 81ae4e2a..818b0af5 100644 --- a/src/Rtmp/RtmpDemuxer.cpp +++ b/src/Rtmp/RtmpDemuxer.cpp @@ -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) { switch (pkt->typeId) { diff --git a/src/Rtmp/RtmpDemuxer.h b/src/Rtmp/RtmpDemuxer.h index 8d828bb1..64ef1cf5 100644 --- a/src/Rtmp/RtmpDemuxer.h +++ b/src/Rtmp/RtmpDemuxer.h @@ -55,14 +55,6 @@ public: RtmpDemuxer(const AMFValue &val); virtual ~RtmpDemuxer(){}; - /** - * - * 获取rtmp track 数 - * @param metadata rtmp的metadata - * @return - */ - static int getTrackCount(const AMFValue &metadata); - /** * 开始解复用 * @param pkt rtmp包 diff --git a/src/Rtmp/RtmpToRtspMediaSource.h b/src/Rtmp/RtmpToRtspMediaSource.h index 153fc5c6..4d7c864b 100644 --- a/src/Rtmp/RtmpToRtspMediaSource.h +++ b/src/Rtmp/RtmpToRtspMediaSource.h @@ -53,16 +53,22 @@ public: const string &app, const string &id, int ringSize = 0) : RtmpMediaSource(vhost, app, id,ringSize){ - _demuxer = std::make_shared(); } virtual ~RtmpToRtspMediaSource(){} void onGetMetaData(const AMFValue &metadata) override { - _demuxer = std::make_shared(metadata); + if(!_demuxer){ + //在未调用onWrite前,设置Metadata能触发生成RtmpDemuxer + _demuxer = std::make_shared(metadata); + } RtmpMediaSource::onGetMetaData(metadata); } void onWrite(const RtmpPacket::Ptr &pkt,bool key_pos = true) override { + if(!_demuxer){ + //尚未获取Metadata,那么不管有没有Metadata,都生成RtmpDemuxer + _demuxer = std::make_shared(); + } _demuxer->inputRtmp(pkt); if(!_muxer && _demuxer->isInited(2000)){ _muxer = std::make_shared(getVhost(),