From 3f6625e75a2a589c61ebe1a13bc788175f6a0a08 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 25 Nov 2023 10:32:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=BA=E5=88=B6flush=E5=90=8E=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=B6=E9=97=B4=E6=88=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MultiMediaSourceMuxer.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index 384a5829..88944f0d 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -58,7 +58,7 @@ public: bool inputFrame(const Frame::Ptr &frame) override { if (!_timer) { resetTimer(EventPoller::getCurrentPoller()); - _ticker.resetTime(); + setCurrentStamp(0); } int64_t dts; @@ -71,7 +71,7 @@ private: void onTick() { while (!_cache.empty()) { auto &front = _cache.front(); - if (_ticker.elapsedTime() < front.first) { + if (getCurrentStamp() < front.first) { // 还没到消费时间 break; } @@ -81,6 +81,7 @@ private: _cache.pop_front(); } if (_cache.size() > 25 * 5) { + auto dts = _cache.back().first; // 强制flush数据 WarnL << "Flush frame paced sender cache: " << _cache.size(); while (!_cache.empty()) { @@ -88,11 +89,22 @@ private: _cb(front.second); _cache.pop_front(); } + setCurrentStamp(dts); } } + uint64_t getCurrentStamp () { + return _ticker.elapsedTime() + _stamp_offset; + } + + uint64_t setCurrentStamp(uint64_t stamp ) { + _stamp_offset = stamp; + _ticker.resetTime(); + } + private: uint32_t _paced_sender_ms; + uint64_t _stamp_offset = 0; OnFrame _cb; Stamp _stamp[2]; Ticker _ticker;