From 3bf1a9fddbe0c9afa41d851a06db03c3a92dad55 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 29 Oct 2018 10:53:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DRtmp=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E5=99=A8=E5=BE=AA=E7=8E=AF=E5=BC=95=E7=94=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/RtmpMediaSource.h | 3 +-- src/RtmpMuxer/RtmpDemuxer.cpp | 4 ++++ src/RtmpMuxer/RtmpDemuxer.h | 8 ++++++++ src/RtmpMuxer/RtmpMuxer.cpp | 3 ++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Rtmp/RtmpMediaSource.h b/src/Rtmp/RtmpMediaSource.h index 99ff7d8e..71960c46 100644 --- a/src/Rtmp/RtmpMediaSource.h +++ b/src/Rtmp/RtmpMediaSource.h @@ -80,8 +80,7 @@ public: virtual void onGetMetaData(const AMFValue &metadata) { lock_guard lock(_mtxMap); _metadata = metadata; - RtmpDemuxer parser(metadata); - _iCfgFrameSize = parser.getTracks().size(); + _iCfgFrameSize = RtmpDemuxer::getTrackCount(metadata); if(ready()){ MediaSource::regist(); _bRegisted = true; diff --git a/src/RtmpMuxer/RtmpDemuxer.cpp b/src/RtmpMuxer/RtmpDemuxer.cpp index bfc005b3..412b9256 100644 --- a/src/RtmpMuxer/RtmpDemuxer.cpp +++ b/src/RtmpMuxer/RtmpDemuxer.cpp @@ -45,6 +45,10 @@ RtmpDemuxer::RtmpDemuxer(const AMFValue &val) { } } +int RtmpDemuxer::getTrackCount(const AMFValue &metedata) { + return (int)(metedata["videocodecid"].type() != AMF_NULL) + (int)(metedata["audiocodecid"].type() != AMF_NULL); +} + bool RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) { switch (pkt->typeId) { case MSG_VIDEO: { diff --git a/src/RtmpMuxer/RtmpDemuxer.h b/src/RtmpMuxer/RtmpDemuxer.h index 2c610222..e3a12912 100644 --- a/src/RtmpMuxer/RtmpDemuxer.h +++ b/src/RtmpMuxer/RtmpDemuxer.h @@ -55,6 +55,14 @@ public: */ RtmpDemuxer(const AMFValue &val); + /** + * + * 获取rtmp track 数 + * @param metedata rtmp的metedata + * @return + */ + static int getTrackCount(const AMFValue &metedata); + virtual ~RtmpDemuxer(){}; /** diff --git a/src/RtmpMuxer/RtmpMuxer.cpp b/src/RtmpMuxer/RtmpMuxer.cpp index ed7e28af..ff97eb6d 100644 --- a/src/RtmpMuxer/RtmpMuxer.cpp +++ b/src/RtmpMuxer/RtmpMuxer.cpp @@ -39,7 +39,8 @@ RtmpMuxer::RtmpMuxer(const TitleMete::Ptr &title) { void RtmpMuxer::onTrackReady(const Track::Ptr &track) { //生成rtmp编码器 - auto encoder = Factory::getRtmpCodecByTrack(track); + //克隆该Track,防止循环引用 + auto encoder = Factory::getRtmpCodecByTrack(track->clone()); if (!encoder) { return; }