diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 71cc6999..eea274c1 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -112,6 +112,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) { if (!ok) { throw std::runtime_error( StrPrinter << "Already publishing:" << m_strApp << "/" << m_strId << endl); } + m_bPublisherSrcRegisted = false; m_pPublisherSrc.reset(new RtmpToRtspMediaSource(m_strApp,m_strId)); } @@ -244,7 +245,6 @@ void RtmpSession::setMetaData(AMFDecoder &dec) { throw std::runtime_error("can only set metadata"); } m_pPublisherSrc->onGetMetaData(dec.load()); - m_pPublisherSrc->regist(); } void RtmpSession::onProcessCmd(AMFDecoder &dec) { @@ -284,6 +284,10 @@ void RtmpSession::onRtmpChunk(RtmpPacket &chunkData) { throw std::runtime_error("Not a rtmp publisher!"); } m_pPublisherSrc->onGetMedia(chunkData); + if(!m_bPublisherSrcRegisted && m_pPublisherSrc->ready()){ + m_bPublisherSrcRegisted = true; + m_pPublisherSrc->regist(); + } } break; default: diff --git a/src/Rtmp/RtmpSession.h b/src/Rtmp/RtmpSession.h index f41c7e27..1ee4fd18 100644 --- a/src/Rtmp/RtmpSession.h +++ b/src/Rtmp/RtmpSession.h @@ -44,6 +44,7 @@ private: RingBuffer::RingReader::Ptr m_pRingReader; std::shared_ptr m_pPublisherSrc; + bool m_bPublisherSrcRegisted = false; std::weak_ptr m_pPlayerSrc; void onProcessCmd(AMFDecoder &dec);