diff --git a/src/Common/config.cpp b/src/Common/config.cpp index dab61670..1659a451 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -306,6 +306,7 @@ const string kTimeoutMS = "protocol_timeout_ms"; const string kMediaTimeoutMS = "media_timeout_ms"; const string kBeatIntervalMS = "beat_interval_ms"; const string kBenchmarkMode = "benchmark_mode"; +const string kWaitTrackReady = "wait_track_ready"; } } // namespace mediakit diff --git a/src/Common/config.h b/src/Common/config.h index dbf193c4..e4c5d76f 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -331,6 +331,8 @@ extern const string kMediaTimeoutMS; extern const string kBeatIntervalMS; //是否为性能测试模式,性能测试模式开启后不会解析rtp或rtmp包 extern const string kBenchmarkMode; +//播放器在触发播放成功事件时,是否等待所有track ready时再回调 +extern const string kWaitTrackReady; } } // namespace mediakit diff --git a/src/Player/PlayerBase.cpp b/src/Player/PlayerBase.cpp index ffca3fc8..ae02d365 100644 --- a/src/Player/PlayerBase.cpp +++ b/src/Player/PlayerBase.cpp @@ -60,6 +60,7 @@ PlayerBase::PlayerBase() { this->mINI::operator[](kTimeoutMS) = 10000; this->mINI::operator[](kMediaTimeoutMS) = 5000; this->mINI::operator[](kBeatIntervalMS) = 5000; + this->mINI::operator[](kWaitTrackReady) = true; } ///////////////////////////DemuxerSink////////////////////////////// diff --git a/src/Rtmp/RtmpPlayerImp.h b/src/Rtmp/RtmpPlayerImp.h index b0056aa8..f976707c 100644 --- a/src/Rtmp/RtmpPlayerImp.h +++ b/src/Rtmp/RtmpPlayerImp.h @@ -79,7 +79,7 @@ private: } void onPlayResult(const SockException &ex) override { - if (ex) { + if (!(*this)[Client::kWaitTrackReady].as() || ex) { Super::onPlayResult(ex); return; } @@ -88,7 +88,9 @@ private: bool addTrack(const Track::Ptr &track) override { return true; } void addTrackCompleted() override { - Super::onPlayResult(SockException(Err_success, "play success")); + if ((*this)[Client::kWaitTrackReady].as()) { + Super::onPlayResult(SockException(Err_success, "play success")); + } } private: @@ -98,7 +100,7 @@ private: _rtmp_src->setMetaData(val); } _demuxer = std::make_shared(); - _demuxer->setTrackListener(this, true); + _demuxer->setTrackListener(this, (*this)[Client::kWaitTrackReady].as()); _demuxer->loadMetaData(val); } diff --git a/src/Rtsp/RtspPlayerImp.h b/src/Rtsp/RtspPlayerImp.h index 51aea0a9..cad54de8 100644 --- a/src/Rtsp/RtspPlayerImp.h +++ b/src/Rtsp/RtspPlayerImp.h @@ -76,7 +76,7 @@ private: _rtsp_media_src->setSdp(sdp); } _demuxer = std::make_shared(); - _demuxer->setTrackListener(this, true); + _demuxer->setTrackListener(this, (*this)[Client::kWaitTrackReady].as()); _demuxer->loadSdp(sdp); return true; } @@ -91,7 +91,7 @@ private: } void onPlayResult(const SockException &ex) override { - if (ex) { + if (!(*this)[Client::kWaitTrackReady].as() || ex) { Super::onPlayResult(ex); return; } @@ -100,7 +100,9 @@ private: bool addTrack(const Track::Ptr &track) override { return true; } void addTrackCompleted() override { - Super::onPlayResult(SockException(Err_success, "play success")); + if ((*this)[Client::kWaitTrackReady].as()) { + Super::onPlayResult(SockException(Err_success, "play success")); + } } private: