From 2e74d5c9578c4ac586cb4785973094ee3a963be4 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 24 Apr 2020 13:51:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=88=E5=B9=B6=E5=86=99?= =?UTF-8?q?=E7=9B=B8=E5=85=B3bug:=20#282?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MediaSource.cpp | 20 ++++++++++++++------ src/Common/MediaSource.h | 13 ++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index a350704f..e2b4aee1 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -486,14 +486,22 @@ static bool isFlushAble_merge(bool is_audio, uint32_t last_stamp, uint32_t new_s return cache_size > 20; } -bool FlushPolicy::isFlushAble(uint32_t last_stamp, uint32_t new_stamp, int cache_size) { - GET_CONFIG(bool,ultraLowDelay, General::kUltraLowDelay); - GET_CONFIG(int,mergeWriteMS, General::kMergeWriteMS); - if(ultraLowDelay || mergeWriteMS <= 0){ +bool FlushPolicy::isFlushAble(uint32_t new_stamp, int cache_size) { + bool ret = false; + GET_CONFIG(bool, ultraLowDelay, General::kUltraLowDelay); + GET_CONFIG(int, mergeWriteMS, General::kMergeWriteMS); + if (ultraLowDelay || mergeWriteMS <= 0) { //关闭了合并写或者合并写阈值小于等于0 - return isFlushAble_default(_is_audio, last_stamp, new_stamp, cache_size); + ret = isFlushAble_default(_is_audio, _last_stamp, new_stamp, cache_size); + } else { + ret = isFlushAble_merge(_is_audio, _last_stamp, new_stamp, cache_size, mergeWriteMS); } - return isFlushAble_merge(_is_audio, last_stamp, new_stamp, cache_size,mergeWriteMS); + + if (ret) { +// DebugL << _is_audio << " " << _last_stamp << " " << new_stamp; + _last_stamp = new_stamp; + } + return ret; } } /* namespace mediakit */ \ No newline at end of file diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index cddfb272..ab0a0cfa 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -173,9 +173,10 @@ public: return packet->timeStamp; } - bool isFlushAble(uint32_t last_stamp, uint32_t new_stamp, int cache_size); + bool isFlushAble(uint32_t new_stamp, int cache_size); private: bool _is_audio; + uint32_t _last_stamp= 0; }; /// 视频合并写缓存模板 @@ -192,14 +193,12 @@ public: virtual ~VideoPacketCache() = default; void inputVideo(const std::shared_ptr &rtp, bool key_pos) { - auto new_stamp = _policy.getStamp(rtp); - if (_policy.isFlushAble(_last_stamp, new_stamp, _cache->size())) { + if (_policy.isFlushAble(_policy.getStamp(rtp), _cache->size())) { flushAll(); } //追加数据到最后 _cache->emplace_back(rtp); - _last_stamp = new_stamp; if (key_pos) { _key_pos = key_pos; } @@ -220,7 +219,6 @@ private: private: policy _policy; std::shared_ptr _cache; - uint32_t _last_stamp = 0; bool _key_pos = false; }; @@ -238,13 +236,11 @@ public: virtual ~AudioPacketCache() = default; void inputAudio(const std::shared_ptr &rtp) { - auto new_stamp = _policy.getStamp(rtp); - if (_policy.isFlushAble(_last_stamp, new_stamp, _cache->size())) { + if (_policy.isFlushAble(_policy.getStamp(rtp), _cache->size())) { flushAll(); } //追加数据到最后 _cache->emplace_back(rtp); - _last_stamp = new_stamp; } virtual void onFlushAudio(std::shared_ptr &) = 0; @@ -261,7 +257,6 @@ private: private: policy _policy; std::shared_ptr _cache; - uint32_t _last_stamp = 0; }; } /* namespace mediakit */