From 8390d72b784e03d87e85567e9f382ef8a3c26dc5 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 28 Jun 2024 22:38:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96on=5Fpublish=20hook=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E5=A4=AA=E6=85=A2=E5=AF=BC=E8=87=B4rtp=E6=8E=A8?= =?UTF-8?q?=E6=B5=81=E6=97=A0=E6=B3=95=E7=A7=92=E5=BC=80=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由限制缓存个数改成限制缓存时间长度(10秒) --- src/Rtp/RtpProcess.cpp | 9 +++++---- src/Rtp/RtpProcess.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index d5632c51..24c343ee 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -18,8 +18,8 @@ using namespace std; using namespace toolkit; //在创建_muxer对象前(也就是推流鉴权成功前),需要先缓存frame,这样可以防止丢包,提高体验 -//但是同时需要控制缓冲长度,防止内存溢出。200帧数据,大概有10秒数据,应该足矣等待鉴权hook返回 -static constexpr size_t kMaxCachedFrame = 200; +//但是同时需要控制缓冲长度,防止内存溢出。最多缓存10秒数据,应该足矣等待鉴权hook返回 +static constexpr size_t kMaxCachedFrameMS = 10 * 1000; namespace mediakit { @@ -112,6 +112,7 @@ bool RtpProcess::inputRtp(bool is_udp, const Socket::Ptr &sock, const char *data _addr.reset(new sockaddr_storage(*((sockaddr_storage *)addr))); if (first) { emitOnPublish(); + _cache_ticker.resetTime(); } } @@ -152,8 +153,8 @@ bool RtpProcess::inputFrame(const Frame::Ptr &frame) { _last_frame_time.resetTime(); return _muxer->inputFrame(frame); } - if (_cached_func.size() > kMaxCachedFrame) { - WarnL << "cached frame of track(" << frame->getCodecName() << ") is too much, now dropped, please check your on_publish hook url in config.ini file"; + if (_cache_ticker.elapsedTime() > kMaxCachedFrameMS) { + WarnL << "Cached frame of stream(" << _media_info.stream << ") is too much, your on_publish hook responded too late!"; return false; } auto frame_cached = Frame::getCacheAbleFrame(frame); diff --git a/src/Rtp/RtpProcess.h b/src/Rtp/RtpProcess.h index 4c264c7a..3f1509d0 100644 --- a/src/Rtp/RtpProcess.h +++ b/src/Rtp/RtpProcess.h @@ -117,6 +117,7 @@ private: toolkit::Timer::Ptr _timer; toolkit::Ticker _last_check_alive; std::recursive_mutex _func_mtx; + toolkit::Ticker _cache_ticker; std::deque > _cached_func; };