From 0b2e55429d3977c0d5a625626150fff979c1b538 Mon Sep 17 00:00:00 2001 From: alexliyu7352 Date: Fri, 17 Dec 2021 14:47:17 +0800 Subject: [PATCH] =?UTF-8?q?HLS:=20=E5=8A=A0=E9=80=9Ftrack=E5=B0=B1?= =?UTF-8?q?=E7=BB=AA=E9=80=9F=E5=BA=A6=20(#1286)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 加速track的准备速度 * 重命名为isAllTrackReady * 无须缓冲帧时,暂不用转换为可缓存帧 Co-authored-by: 夏楚 <771730766@qq.com> --- src/Common/MediaSink.h | 9 ++++++++- src/Http/HlsPlayer.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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);