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

This commit is contained in:
xiongziliang 2019-09-24 11:42:27 +08:00
parent 928f642a27
commit 653667baf5
3 changed files with 12 additions and 3 deletions

View File

@ -108,6 +108,7 @@ void RtmpPlayer::play(const string &strUrl) {
return false; return false;
},getPoller())); },getPoller()));
_metadata_got = false;
startConnect(strHost, iPort , playTimeOutSec); startConnect(strHost, iPort , playTimeOutSec);
} }
void RtmpPlayer::onErr(const SockException &ex){ void RtmpPlayer::onErr(const SockException &ex){
@ -319,8 +320,9 @@ void RtmpPlayer::onCmd_onMetaData(AMFDecoder &dec) {
//TraceL; //TraceL;
auto val = dec.load<AMFValue>(); auto val = dec.load<AMFValue>();
if(!onCheckMeta(val)){ if(!onCheckMeta(val)){
throw std::runtime_error("onCheckMeta faied"); throw std::runtime_error("onCheckMeta failed");
} }
_metadata_got = true;
} }
void RtmpPlayer::onStreamDry(uint32_t ui32StreamId) { void RtmpPlayer::onStreamDry(uint32_t ui32StreamId) {
@ -371,6 +373,12 @@ void RtmpPlayer::onRtmpChunk(RtmpPacket &chunkData) {
if (_aNowStampTicker[idx].elapsedTime() > 500) { if (_aNowStampTicker[idx].elapsedTime() > 500) {
//计算播放进度时间轴用 //计算播放进度时间轴用
_aiNowStamp[idx] = chunkData.timeStamp; _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<RtmpPacket>(std::move(chunkData))); onMediaData_l(std::make_shared<RtmpPacket>(std::move(chunkData)));
} }

View File

@ -55,7 +55,7 @@ public:
void pause(bool bPause) override; void pause(bool bPause) override;
void teardown() override; void teardown() override;
protected: protected:
virtual bool onCheckMeta(AMFValue &val) =0; virtual bool onCheckMeta(const AMFValue &val) =0;
virtual void onMediaData(const RtmpPacket::Ptr &chunkData) =0; virtual void onMediaData(const RtmpPacket::Ptr &chunkData) =0;
uint32_t getProgressMilliSecond() const; uint32_t getProgressMilliSecond() const;
void seekToMilliSecond(uint32_t ms); void seekToMilliSecond(uint32_t ms);
@ -119,6 +119,7 @@ private:
uint32_t _aiFistStamp[2] = { 0, 0 }; uint32_t _aiFistStamp[2] = { 0, 0 };
uint32_t _aiNowStamp[2] = { 0, 0 }; uint32_t _aiNowStamp[2] = { 0, 0 };
Ticker _aNowStampTicker[2]; Ticker _aNowStampTicker[2];
bool _metadata_got = false;
}; };
} /* namespace mediakit */ } /* namespace mediakit */

View File

@ -62,7 +62,7 @@ public:
} }
private: private:
//派生类回调函数 //派生类回调函数
bool onCheckMeta(AMFValue &val) override { bool onCheckMeta(const AMFValue &val) override {
_pRtmpMediaSrc = dynamic_pointer_cast<RtmpMediaSource>(_pMediaSrc); _pRtmpMediaSrc = dynamic_pointer_cast<RtmpMediaSource>(_pMediaSrc);
if(_pRtmpMediaSrc){ if(_pRtmpMediaSrc){
_pRtmpMediaSrc->onGetMetaData(val); _pRtmpMediaSrc->onGetMetaData(val);