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;