From 8a1f9793759898b958a6d5390af74dbd7a0578c7 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 27 Nov 2021 22:20:22 +0800 Subject: [PATCH] =?UTF-8?q?RTC:=20=E4=BF=AE=E5=A4=8Dtwcc=20rtp=20ext=20seq?= =?UTF-8?q?=E5=9B=9E=E9=80=80=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/TwccContext.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/webrtc/TwccContext.cpp b/webrtc/TwccContext.cpp index 6a3bfbd6..ed565186 100644 --- a/webrtc/TwccContext.cpp +++ b/webrtc/TwccContext.cpp @@ -21,7 +21,7 @@ enum class ExtSeqStatus : int { void TwccContext::onRtp(uint32_t ssrc, uint16_t twcc_ext_seq, uint64_t stamp_ms) { switch ((ExtSeqStatus) checkSeqStatus(twcc_ext_seq)) { - case ExtSeqStatus::jumped: /*回环后,收到回环前的大ext seq包,过滤掉*/ return; + case ExtSeqStatus::jumped: /*seq异常,过滤掉*/ return; case ExtSeqStatus::looped: /*回环,触发发送twcc rtcp*/ onSendTwcc(ssrc); break; case ExtSeqStatus::normal: break; default: /*不可达*/assert(0); break; @@ -56,16 +56,29 @@ int TwccContext::checkSeqStatus(uint16_t twcc_ext_seq) const { return (int) ExtSeqStatus::normal; } auto max = _rtp_recv_status.rbegin()->first; - if (max > 0xFF00 && twcc_ext_seq < 0xFF) { - //发生回环了 + auto delta = (int32_t) twcc_ext_seq - (int32_t) max; + if (delta > 0 && delta < 0xFFFF / 2) { + //正常增长 + return (int) ExtSeqStatus::normal; + } + if (delta < -0xFF00) { + //回环 TraceL << "rtp twcc ext seq looped:" << max << " -> " << twcc_ext_seq; return (int) ExtSeqStatus::looped; } - if (twcc_ext_seq - max > 0xFFFF / 2) { - TraceL << "rtp twcc ext seq jumped:" << max << " -> " << twcc_ext_seq; + if (delta > 0xFF00) { + //回环后收到前面大的乱序的包,无法处理,丢弃 + TraceL << "rtp twcc ext seq jumped after looped:" << max << " -> " << twcc_ext_seq; return (int) ExtSeqStatus::jumped; } - return (int) ExtSeqStatus::normal; + auto min = _rtp_recv_status.begin()->first; + if (min <= twcc_ext_seq || twcc_ext_seq <= max) { + //正常回退 + return (int) ExtSeqStatus::normal; + } + //seq莫名的大幅增加或减少,无法处理,丢弃 + TraceL << "rtp twcc ext seq jumped:" << max << " -> " << twcc_ext_seq; + return (int) ExtSeqStatus::jumped; } void TwccContext::onSendTwcc(uint32_t ssrc) {