From 653667baf5a8085e994ab03204686dbf5cb46644 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 24 Sep 2019 11:42:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E9=AB=98=E5=AF=B9=E6=97=A0Metadata?= =?UTF-8?q?=E7=9A=84rtmp=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/RtmpPlayer.cpp | 10 +++++++++- src/Rtmp/RtmpPlayer.h | 3 ++- src/Rtmp/RtmpPlayerImp.h | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Rtmp/RtmpPlayer.cpp b/src/Rtmp/RtmpPlayer.cpp index 75ce6593..b840a416 100644 --- a/src/Rtmp/RtmpPlayer.cpp +++ b/src/Rtmp/RtmpPlayer.cpp @@ -108,6 +108,7 @@ void RtmpPlayer::play(const string &strUrl) { return false; },getPoller())); + _metadata_got = false; startConnect(strHost, iPort , playTimeOutSec); } void RtmpPlayer::onErr(const SockException &ex){ @@ -319,8 +320,9 @@ void RtmpPlayer::onCmd_onMetaData(AMFDecoder &dec) { //TraceL; auto val = dec.load(); if(!onCheckMeta(val)){ - throw std::runtime_error("onCheckMeta faied"); + throw std::runtime_error("onCheckMeta failed"); } + _metadata_got = true; } void RtmpPlayer::onStreamDry(uint32_t ui32StreamId) { @@ -372,6 +374,12 @@ void RtmpPlayer::onRtmpChunk(RtmpPacket &chunkData) { //计算播放进度时间轴用 _aiNowStamp[idx] = chunkData.timeStamp; } + if(!_metadata_got){ + _metadata_got = true; + if(!onCheckMeta(TitleMeta().getMetadata())){ + throw std::runtime_error("onCheckMeta failed"); + } + } onMediaData_l(std::make_shared(std::move(chunkData))); } break; diff --git a/src/Rtmp/RtmpPlayer.h b/src/Rtmp/RtmpPlayer.h index 7d479d1e..e63ee668 100644 --- a/src/Rtmp/RtmpPlayer.h +++ b/src/Rtmp/RtmpPlayer.h @@ -55,7 +55,7 @@ public: void pause(bool bPause) override; void teardown() override; protected: - virtual bool onCheckMeta(AMFValue &val) =0; + virtual bool onCheckMeta(const AMFValue &val) =0; virtual void onMediaData(const RtmpPacket::Ptr &chunkData) =0; uint32_t getProgressMilliSecond() const; void seekToMilliSecond(uint32_t ms); @@ -119,6 +119,7 @@ private: uint32_t _aiFistStamp[2] = { 0, 0 }; uint32_t _aiNowStamp[2] = { 0, 0 }; Ticker _aNowStampTicker[2]; + bool _metadata_got = false; }; } /* namespace mediakit */ diff --git a/src/Rtmp/RtmpPlayerImp.h b/src/Rtmp/RtmpPlayerImp.h index 8a14eeff..49e8da6a 100644 --- a/src/Rtmp/RtmpPlayerImp.h +++ b/src/Rtmp/RtmpPlayerImp.h @@ -62,7 +62,7 @@ public: } private: //派生类回调函数 - bool onCheckMeta(AMFValue &val) override { + bool onCheckMeta(const AMFValue &val) override { _pRtmpMediaSrc = dynamic_pointer_cast(_pMediaSrc); if(_pRtmpMediaSrc){ _pRtmpMediaSrc->onGetMetaData(val);