diff --git a/src/Common/MediaSink.h b/src/Common/MediaSink.h index 2714cafe..1d29b038 100644 --- a/src/Common/MediaSink.h +++ b/src/Common/MediaSink.h @@ -107,7 +107,14 @@ public: * @param trackReady 是否获取已经准备好的Track */ vector getTracks(bool trackReady = true) const override; - + + /** + * 返回是否所有track已经准备完成 + */ + bool isAllTrackReady() const { + return _all_track_ready; + } + /** * 添加aac静音轨道 */ diff --git a/src/Http/HlsPlayer.cpp b/src/Http/HlsPlayer.cpp index 25046951..77668bab 100644 --- a/src/Http/HlsPlayer.cpp +++ b/src/Http/HlsPlayer.cpp @@ -316,6 +316,12 @@ void HlsDemuxer::start(const EventPoller::Ptr &poller, TrackListener *listener) } bool HlsDemuxer::inputFrame(const Frame::Ptr &frame) { + //为了避免track准备时间过长, 因此在没准备好之前, 直接消费掉所有的帧 + if (!_delegate.isAllTrackReady()) { + _delegate.inputFrame(frame); + return true; + } + //计算相对时间戳 int64_t dts, pts; _stamp[frame->getTrackType()].revise(frame->dts(), frame->pts(), dts, pts);