From a15d59cf23bd5613ea375ba13517ac0ecfabfec4 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Tue, 22 Feb 2022 11:44:37 +0800 Subject: [PATCH] =?UTF-8?q?hls/ts=E6=92=AD=E6=94=BE=E5=99=A8=E6=94=B9?= =?UTF-8?q?=E6=88=90=E7=BB=9D=E5=AF=B9=E6=97=B6=E9=97=B4=E6=88=B3:#1389?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HlsPlayer.cpp | 14 +++++--------- src/Http/HlsPlayer.h | 6 +----- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Http/HlsPlayer.cpp b/src/Http/HlsPlayer.cpp index e20607f4..305b5f43 100644 --- a/src/Http/HlsPlayer.cpp +++ b/src/Http/HlsPlayer.cpp @@ -241,11 +241,6 @@ void HlsPlayer::playDelay() { void HlsDemuxer::start(const EventPoller::Ptr &poller, TrackListener *listener) { _frame_cache.clear(); - _stamp[TrackAudio].setRelativeStamp(0); - _stamp[TrackVideo].setRelativeStamp(0); - _stamp[TrackAudio].syncTo(_stamp[TrackVideo]); - setPlayPosition(0); - _delegate.setTrackListener(listener); //每50毫秒执行一次 @@ -267,11 +262,12 @@ bool HlsDemuxer::inputFrame(const Frame::Ptr &frame) { return true; } - //计算相对时间戳 - int64_t dts, pts; - _stamp[frame->getTrackType()].revise(frame->dts(), frame->pts(), dts, pts); + if (_frame_cache.empty()) { + //设置当前播放位置时间戳 + setPlayPosition(frame->dts()); + } //根据时间戳缓存frame - _frame_cache.emplace(dts, Frame::getCacheAbleFrame(frame)); + _frame_cache.emplace(frame->dts(), Frame::getCacheAbleFrame(frame)); if (getBufferMS() > 30 * 1000) { //缓存超过30秒,强制消费至15秒(减少延时或内存占用) diff --git a/src/Http/HlsPlayer.h b/src/Http/HlsPlayer.h index a520137f..dd69e3bc 100644 --- a/src/Http/HlsPlayer.h +++ b/src/Http/HlsPlayer.h @@ -19,10 +19,7 @@ namespace mediakit { -class HlsDemuxer - : public MediaSinkInterface - , public TrackSource - , public std::enable_shared_from_this { +class HlsDemuxer : public MediaSinkInterface , public TrackSource, public std::enable_shared_from_this { public: HlsDemuxer() = default; ~HlsDemuxer() override { _timer = nullptr; } @@ -43,7 +40,6 @@ private: private: int64_t _ticker_offset = 0; toolkit::Ticker _ticker; - Stamp _stamp[2]; toolkit::Timer::Ptr _timer; MediaSinkDelegate _delegate; std::multimap _frame_cache;