From 9d6b94c3510c5f5391de0d642d394ffad269b926 Mon Sep 17 00:00:00 2001 From: melpon Date: Wed, 29 Nov 2023 02:37:03 +0900 Subject: [PATCH] Ensure rtpExtHeaderSize is a multiple of 4 As defined in RFC3550, headerLength counts the number of 32-bit words. Therefore, rtpExtHeaderSize must always be a multiple of 4. --- src/rtppacketizer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rtppacketizer.cpp b/src/rtppacketizer.cpp index 73f580bc2..c707647e0 100644 --- a/src/rtppacketizer.cpp +++ b/src/rtppacketizer.cpp @@ -40,6 +40,8 @@ message_ptr RtpPacketizer::packetize(shared_ptr payload, bool mark) { if (rtpExtHeaderSize != 0) rtpExtHeaderSize += 4; + rtpExtHeaderSize = (rtpExtHeaderSize + 3) & ~3; + auto message = make_message(RtpHeaderSize + rtpExtHeaderSize + payload->size()); auto *rtp = (RtpHeader *)message->data(); rtp->setPayloadType(rtpConfig->payloadType); @@ -57,8 +59,7 @@ message_ptr RtpPacketizer::packetize(shared_ptr payload, bool mark) { auto extHeader = rtp->getExtensionHeader(); extHeader->setProfileSpecificId(0xbede); - auto headerLength = static_cast(rtpExtHeaderSize - 4); - headerLength = static_cast((headerLength + 3) / 4); + headerLength = static_cast(headerLength / 4) - 1; extHeader->setHeaderLength(headerLength); extHeader->clearBody();