Player: 添加kWaitTrackReady选项决定播放器是否等待所有track ready再回调

This commit is contained in:
ziyue 2021-11-10 13:56:04 +08:00
parent e38f2253ff
commit b7e187d7af
5 changed files with 14 additions and 6 deletions

View File

@ -306,6 +306,7 @@ const string kTimeoutMS = "protocol_timeout_ms";
const string kMediaTimeoutMS = "media_timeout_ms"; const string kMediaTimeoutMS = "media_timeout_ms";
const string kBeatIntervalMS = "beat_interval_ms"; const string kBeatIntervalMS = "beat_interval_ms";
const string kBenchmarkMode = "benchmark_mode"; const string kBenchmarkMode = "benchmark_mode";
const string kWaitTrackReady = "wait_track_ready";
} }
} // namespace mediakit } // namespace mediakit

View File

@ -331,6 +331,8 @@ extern const string kMediaTimeoutMS;
extern const string kBeatIntervalMS; extern const string kBeatIntervalMS;
//是否为性能测试模式性能测试模式开启后不会解析rtp或rtmp包 //是否为性能测试模式性能测试模式开启后不会解析rtp或rtmp包
extern const string kBenchmarkMode; extern const string kBenchmarkMode;
//播放器在触发播放成功事件时是否等待所有track ready时再回调
extern const string kWaitTrackReady;
} }
} // namespace mediakit } // namespace mediakit

View File

@ -60,6 +60,7 @@ PlayerBase::PlayerBase() {
this->mINI::operator[](kTimeoutMS) = 10000; this->mINI::operator[](kTimeoutMS) = 10000;
this->mINI::operator[](kMediaTimeoutMS) = 5000; this->mINI::operator[](kMediaTimeoutMS) = 5000;
this->mINI::operator[](kBeatIntervalMS) = 5000; this->mINI::operator[](kBeatIntervalMS) = 5000;
this->mINI::operator[](kWaitTrackReady) = true;
} }
///////////////////////////DemuxerSink////////////////////////////// ///////////////////////////DemuxerSink//////////////////////////////

View File

@ -79,7 +79,7 @@ private:
} }
void onPlayResult(const SockException &ex) override { void onPlayResult(const SockException &ex) override {
if (ex) { if (!(*this)[Client::kWaitTrackReady].as<bool>() || ex) {
Super::onPlayResult(ex); Super::onPlayResult(ex);
return; return;
} }
@ -88,8 +88,10 @@ private:
bool addTrack(const Track::Ptr &track) override { return true; } bool addTrack(const Track::Ptr &track) override { return true; }
void addTrackCompleted() override { void addTrackCompleted() override {
if ((*this)[Client::kWaitTrackReady].as<bool>()) {
Super::onPlayResult(SockException(Err_success, "play success")); Super::onPlayResult(SockException(Err_success, "play success"));
} }
}
private: private:
void onCheckMeta_l(const AMFValue &val) { void onCheckMeta_l(const AMFValue &val) {
@ -98,7 +100,7 @@ private:
_rtmp_src->setMetaData(val); _rtmp_src->setMetaData(val);
} }
_demuxer = std::make_shared<RtmpDemuxer>(); _demuxer = std::make_shared<RtmpDemuxer>();
_demuxer->setTrackListener(this, true); _demuxer->setTrackListener(this, (*this)[Client::kWaitTrackReady].as<bool>());
_demuxer->loadMetaData(val); _demuxer->loadMetaData(val);
} }

View File

@ -76,7 +76,7 @@ private:
_rtsp_media_src->setSdp(sdp); _rtsp_media_src->setSdp(sdp);
} }
_demuxer = std::make_shared<RtspDemuxer>(); _demuxer = std::make_shared<RtspDemuxer>();
_demuxer->setTrackListener(this, true); _demuxer->setTrackListener(this, (*this)[Client::kWaitTrackReady].as<bool>());
_demuxer->loadSdp(sdp); _demuxer->loadSdp(sdp);
return true; return true;
} }
@ -91,7 +91,7 @@ private:
} }
void onPlayResult(const SockException &ex) override { void onPlayResult(const SockException &ex) override {
if (ex) { if (!(*this)[Client::kWaitTrackReady].as<bool>() || ex) {
Super::onPlayResult(ex); Super::onPlayResult(ex);
return; return;
} }
@ -100,8 +100,10 @@ private:
bool addTrack(const Track::Ptr &track) override { return true; } bool addTrack(const Track::Ptr &track) override { return true; }
void addTrackCompleted() override { void addTrackCompleted() override {
if ((*this)[Client::kWaitTrackReady].as<bool>()) {
Super::onPlayResult(SockException(Err_success, "play success")); Super::onPlayResult(SockException(Err_success, "play success"));
} }
}
private: private:
RtspDemuxer::Ptr _demuxer; RtspDemuxer::Ptr _demuxer;