From 1ef3642ed45966a2b4f27c8dd34e9ae396a7fcae Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 21 Jun 2024 20:21:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96webrtc=20jitter=20buffer?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Nack.h | 22 ++++++++++++++++++++++ webrtc/WebRtcTransport.cpp | 9 +++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/webrtc/Nack.h b/webrtc/Nack.h index 8ed98be9..276f51e8 100644 --- a/webrtc/Nack.h +++ b/webrtc/Nack.h @@ -20,6 +20,28 @@ namespace mediakit { +// RTC配置项目 +namespace Rtc { + +//~ nack接收端(rtp发送端) +// Nack缓存包最早时间间隔 +extern const std::string kMaxNackMS; +// Nack包检查间隔(包数量) +extern const std::string kRtpCacheCheckInterval; + +//~ nack发送端(rtp接收端) +// 最大保留的rtp丢包状态个数 +extern const std::string kNackMaxSize; +// rtp丢包状态最长保留时间 +extern const std::string kNackMaxMS; +// nack最多请求重传次数 +extern const std::string kNackMaxCount; +// nack重传频率,rtt的倍数 +extern const std::string kNackIntervalRatio; +// nack包中rtp个数,减小此值可以让nack包响应更灵敏 +extern const std::string kNackRtpSize; +} // namespace Rtc + class NackList { public: void pushBack(RtpPacket::Ptr rtp); diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 3d2aaa68..ea3e8e85 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -13,6 +13,7 @@ #include "Util/base64.h" #include "Network/sockutil.h" #include "Common/config.h" +#include "Nack.h" #include "RtpExt.h" #include "Rtcp/Rtcp.h" #include "Rtcp/RtcpFCI.h" @@ -57,9 +58,6 @@ const string kMinBitrate = RTC_FIELD "min_bitrate"; // 数据通道设置 const string kDataChannelEcho = RTC_FIELD "datachannel_echo"; -// rtp丢包状态最长保留时间 -const string kNackMaxMS = RTC_FIELD "nackMaxMS"; - static onceToken token([]() { mINI::Instance()[kTimeOutSec] = 15; mINI::Instance()[kExternIP] = ""; @@ -72,8 +70,6 @@ static onceToken token([]() { mINI::Instance()[kMinBitrate] = 0; mINI::Instance()[kDataChannelEcho] = true; - - mINI::Instance()[kNackMaxMS] = 3 * 1000; }); } // namespace RTC @@ -806,7 +802,8 @@ public: setOnSorted(std::move(cb)); //设置jitter buffer参数 GET_CONFIG(uint32_t, nack_maxms, Rtc::kNackMaxMS); - RtpTrackImp::setParams(1024, nack_maxms, 512); + GET_CONFIG(uint32_t, nack_max_rtp, Rtc::kNackMaxSize); + RtpTrackImp::setParams(nack_max_rtp, nack_maxms, nack_max_rtp / 2); _nack_ctx.setOnNack([this](const FCI_NACK &nack) { onNack(nack); }); }