From 1cc3add97f98761d116d3035e17ec45c40f05926 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 15 Nov 2020 00:59:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8D=87=E6=8C=89=E9=9C=80=E8=BD=AC?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E6=80=A7=E8=83=BD=E4=B8=8E=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MultiMediaSourceMuxer.cpp | 15 +++++++++++++-- src/Common/MultiMediaSourceMuxer.h | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index 5774f45c..f3d44352 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -9,6 +9,7 @@ */ #include +#include "Common/config.h" #include "MultiMediaSourceMuxer.h" namespace mediakit { @@ -450,11 +451,21 @@ void MultiMediaSourceMuxer::inputFrame(const Frame::Ptr &frame_in) { } bool MultiMediaSourceMuxer::isEnabled(){ + GET_CONFIG(uint32_t, stream_none_reader_delay_ms, General::kStreamNoneReaderDelayMS); + if (!_is_enable || _last_check.elapsedTime() > stream_none_reader_delay_ms) { + //无人观看时,每次检查是否真的无人观看 + //有人观看时,则延迟一定时间检查一遍是否无人观看了(节省性能) #if defined(ENABLE_RTPPROXY) - return (_muxer->isEnabled() || _rtp_sender); + _is_enable = (_muxer->isEnabled() || _rtp_sender); #else - return _muxer->isEnabled(); + _is_enable = _muxer->isEnabled(); #endif //ENABLE_RTPPROXY + if (_is_enable) { + //无人观看时,不刷新计时器,因为无人观看时每次都会检查一遍,所以刷新计数器无意义且浪费cpu + _last_check.resetTime(); + } + } + return _is_enable; } diff --git a/src/Common/MultiMediaSourceMuxer.h b/src/Common/MultiMediaSourceMuxer.h index 11ef0e81..36729447 100644 --- a/src/Common/MultiMediaSourceMuxer.h +++ b/src/Common/MultiMediaSourceMuxer.h @@ -183,6 +183,8 @@ public: void onAllTrackReady() override; private: + bool _is_enable = false; + Ticker _last_check; Stamp _stamp[2]; MultiMuxerPrivate::Ptr _muxer; std::weak_ptr _track_listener;