From 032a2ac91d1b04fdfa8c7033c320fedeb7c6a3f0 Mon Sep 17 00:00:00 2001 From: dengjfzh <76604422+dengjfzh@users.noreply.github.com> Date: Fri, 26 May 2023 17:34:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DTCP=20RTP=202=E5=AD=97?= =?UTF-8?q?=E8=8A=82=E5=A4=B4=E8=A2=AB=E8=AF=AF=E5=88=A4=E4=B8=BA4?= =?UTF-8?q?=E5=AD=97=E8=8A=82=E5=A4=B4=E7=9A=84=E9=97=AE=E9=A2=98=20(#2499?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当RFC4571封装的RTP包大小在0x2400到0x24ff之间时,会被误认为是RTSP Interleaved 封装的数据。因为0x24正好是'$'的ASCII码,而RtpSplitter::onSearchPacketTail通过'$'来识别RTSP Interleaved数据。暂时没有想到什么好的办法能够百分之百的正确区分RFC4571数据和RTSP Interleaved数据。增加一个状态变量记录之前的状态,一旦检测到数据不是RTSP Interleaved格式,则后续不再进行尝试,以减小误判的可能性。 --- src/Rtp/RtpSplitter.cpp | 12 ++++++++---- src/Rtp/RtpSplitter.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Rtp/RtpSplitter.cpp b/src/Rtp/RtpSplitter.cpp index f7175b30..78c5223c 100644 --- a/src/Rtp/RtpSplitter.cpp +++ b/src/Rtp/RtpSplitter.cpp @@ -59,11 +59,15 @@ const char *RtpSplitter::onSearchPacketTail(const char *data, size_t len) { return onSearchPacketTail_l(data + kEHOME_OFFSET + 2, len - kEHOME_OFFSET - 2); } - if (data[0] == '$') { - //可能是4个字节的rtp头 - _offset = 4; - return onSearchPacketTail_l(data + 2, len - 2); + if ( _is_rtsp_interleaved ) { + if (data[0] == '$') { + //可能是4个字节的rtp头 + _offset = 4; + return onSearchPacketTail_l(data + 2, len - 2); + } + _is_rtsp_interleaved = false; } + //两个字节的rtp头 _offset = 2; return onSearchPacketTail_l(data, len); diff --git a/src/Rtp/RtpSplitter.h b/src/Rtp/RtpSplitter.h index 9401691e..50e3af43 100644 --- a/src/Rtp/RtpSplitter.h +++ b/src/Rtp/RtpSplitter.h @@ -36,6 +36,7 @@ protected: private: bool _is_ehome = false; + bool _is_rtsp_interleaved = true; size_t _offset = 0; };