Skip to content

Commit

Permalink
Ensure rtpExtHeaderSize is a multiple of 4
Browse files Browse the repository at this point in the history
As defined in RFC3550, headerLength counts the number of 32-bit words.
Therefore, rtpExtHeaderSize must always be a multiple of 4.
  • Loading branch information
melpon committed Nov 28, 2023
1 parent 499398a commit 9d6b94c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/rtppacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ message_ptr RtpPacketizer::packetize(shared_ptr<binary> 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);
Expand All @@ -57,8 +59,7 @@ message_ptr RtpPacketizer::packetize(shared_ptr<binary> payload, bool mark) {
auto extHeader = rtp->getExtensionHeader();
extHeader->setProfileSpecificId(0xbede);

auto headerLength = static_cast<uint16_t>(rtpExtHeaderSize - 4);
headerLength = static_cast<uint16_t>((headerLength + 3) / 4);
headerLength = static_cast<uint16_t>(headerLength / 4) - 1;

extHeader->setHeaderLength(headerLength);
extHeader->clearBody();
Expand Down

0 comments on commit 9d6b94c

Please sign in to comment.