From dc3701e6ccbca7845cee40e7802c05a9c18b395c Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Sun, 6 Dec 2020 21:08:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drtp=E5=AD=98=E5=9C=A8ext?= =?UTF-8?q?=E6=97=B6=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90=E7=9A=84bug:#585?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/RtpReceiver.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Rtsp/RtpReceiver.cpp b/src/Rtsp/RtpReceiver.cpp index 3ae03e01..75d5b45e 100644 --- a/src/Rtsp/RtpReceiver.cpp +++ b/src/Rtsp/RtpReceiver.cpp @@ -101,16 +101,18 @@ bool RtpReceiver::handleOneRtp(int track_index, TrackType type, int samplerate, //ssrc匹配正确,不匹配计数清零 _ssrc_err_count[track_index] = 0; - //获取rtp中媒体数据偏移量 - rtp.offset = 12 + 4; + //rtp 12个固定字节头 + rtp.offset = 12; + //rtp有csrc rtp.offset += 4 * csrc; - if (ext && rtp_raw_len >= rtp.offset) { - /* calculate the header extension length (stored as number of 32-bit words) */ - ext = (AV_RB16(rtp_raw_ptr + rtp.offset - 2) + 1) << 2; - rtp.offset += ext; + if (ext) { + //rtp有ext + uint16_t reserved = AV_RB16(rtp_raw_ptr + rtp.offset); + uint16_t extlen = AV_RB16(rtp_raw_ptr + rtp.offset + 2) << 2; + rtp.offset += extlen + 4; } - if (rtp_raw_len + 4 <= rtp.offset) { + if (rtp_raw_len <= rtp.offset) { WarnL << "无有效负载的rtp包:" << rtp_raw_len << " <= " << (int) rtp.offset; return false; } @@ -128,9 +130,10 @@ bool RtpReceiver::handleOneRtp(int track_index, TrackType type, int samplerate, payload_ptr[1] = rtp.interleaved; payload_ptr[2] = rtp_raw_len >> 8; payload_ptr[3] = (rtp_raw_len & 0x00FF); + //添加rtp over tcp前4个字节的偏移量 + rtp.offset += 4; //拷贝rtp负载 memcpy(payload_ptr + 4, rtp_raw_ptr, rtp_raw_len); - //排序rtp auto seq = rtp_ptr->sequence; _rtp_sortor[track_index].sortPacket(seq, std::move(rtp_ptr));