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 kBeatIntervalMS = "beat_interval_ms";
const string kBenchmarkMode = "benchmark_mode";
const string kWaitTrackReady = "wait_track_ready";
}
} // namespace mediakit

View File

@ -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

View File

@ -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//////////////////////////////

View File

@ -79,7 +79,7 @@ private:
}
void onPlayResult(const SockException &ex) override {
if (ex) {
if (!(*this)[Client::kWaitTrackReady].as<bool>() || 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<bool>()) {
Super::onPlayResult(SockException(Err_success, "play success"));
}
}
private:
@ -98,7 +100,7 @@ private:
_rtmp_src->setMetaData(val);
}
_demuxer = std::make_shared<RtmpDemuxer>();
_demuxer->setTrackListener(this, true);
_demuxer->setTrackListener(this, (*this)[Client::kWaitTrackReady].as<bool>());
_demuxer->loadMetaData(val);
}

View File

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