From b7e187d7af3d5f238e17f8fdec185045a91e53a0 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Wed, 10 Nov 2021 13:56:04 +0800 Subject: [PATCH] =?UTF-8?q?Player:=20=E6=B7=BB=E5=8A=A0kWaitTrackReady?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E5=86=B3=E5=AE=9A=E6=92=AD=E6=94=BE=E5=99=A8?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E7=AD=89=E5=BE=85=E6=89=80=E6=9C=89track=20r?= =?UTF-8?q?eady=E5=86=8D=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/config.cpp | 1 + src/Common/config.h | 2 ++ src/Player/PlayerBase.cpp | 1 + src/Rtmp/RtmpPlayerImp.h | 8 +++++--- src/Rtsp/RtspPlayerImp.h | 8 +++++--- 5 files changed, 14 insertions(+), 6 deletions(-) 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: