From 8717cd2f3d35cb5495557171d8d3aa552fe966f2 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Wed, 23 Jun 2021 11:09:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/RtpProcess.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index a3e1aaf5..6a18437a 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -13,14 +13,17 @@ #include "RtpProcess.h" #include "Http/HttpTSPlayer.h" -#define RTP_APP_NAME "rtp" +static constexpr char kRtpAppName[] = "rtp"; +//在创建_muxer对象前(也就是推流鉴权成功前),需要先缓存frame,这样可以防止丢包,提高体验 +//但是同时需要控制缓冲长度,防止内存溢出。200帧数据,大概有10秒数据,应该足矣等待鉴权hook返回 +static constexpr size_t kMaxCachedFrame = 200; namespace mediakit { RtpProcess::RtpProcess(const string &stream_id) { - _media_info._schema = RTP_APP_NAME; + _media_info._schema = kRtpAppName; _media_info._vhost = DEFAULT_VHOST; - _media_info._app = RTP_APP_NAME; + _media_info._app = kRtpAppName; _media_info._streamid = stream_id; GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir); @@ -112,8 +115,8 @@ void RtpProcess::inputFrame(const Frame::Ptr &frame) { _last_frame_time.resetTime(); _muxer->inputFrame(frame); } else { - if (_cached_func.size() > 100) { - WarnL << "cached frame of track(" << frame->getCodecName() << ") is too much, now droped"; + if (_cached_func.size() > kMaxCachedFrame) { + WarnL << "cached frame of track(" << frame->getCodecName() << ") is too much, now dropped"; return; } auto frame_cached = Frame::getCacheAbleFrame(frame);