From 41320cc08ed788be6ddbbedde458241e8291a399 Mon Sep 17 00:00:00 2001 From: sbarrac Date: Mon, 1 Apr 2024 22:23:09 +0100 Subject: [PATCH 1/5] Added playout delay extension support --- include/rtc/rtc.h | 3 +++ include/rtc/rtppacketizationconfig.hpp | 8 ++++++++ src/capi.cpp | 3 +++ src/rtppacketizer.cpp | 16 ++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/include/rtc/rtc.h b/include/rtc/rtc.h index e37ccec86..1476b6a9a 100644 --- a/include/rtc/rtc.h +++ b/include/rtc/rtc.h @@ -341,6 +341,9 @@ typedef struct { // AV1 only rtcObuPacketization obuPacketization; // OBU paketization for AV1 samples + uint8_t playoutDelayId; + uint16_t playoutDelayMin; + uint16_t playoutDelayMax; } rtcPacketizerInit; // Deprecated, do not use diff --git a/include/rtc/rtppacketizationconfig.hpp b/include/rtc/rtppacketizationconfig.hpp index 0e6dcada2..ace13063e 100644 --- a/include/rtc/rtppacketizationconfig.hpp +++ b/include/rtc/rtppacketizationconfig.hpp @@ -61,6 +61,14 @@ class RTC_CPP_EXPORT RtpPacketizationConfig { uint8_t ridId = 0; optional rid; + // the negotiated ID of the playout delay header extension + // https://webrtc.googlesource.com/src/+/main/docs/native-code/rtp-hdrext/playout-delay/README.md + uint8_t playoutDelayId; + + // Minimum/maxiumum playout delay, in 10ms intervals. A value of 10 would equal a 100ms delay + uint16_t playoutDelayMin; + uint16_t playoutDelayMax; + /// Construct RTP configuration used in packetization process /// @param ssrc SSRC of source /// @param cname CNAME of source diff --git a/src/capi.cpp b/src/capi.cpp index b6942214a..6f8c790d2 100644 --- a/src/capi.cpp +++ b/src/capi.cpp @@ -275,6 +275,9 @@ createRtpPacketizationConfig(const rtcPacketizationHandlerInit *init) { init->payloadType, init->clockRate); config->sequenceNumber = init->sequenceNumber; config->timestamp = init->timestamp; + config->playoutDelayId = init->playoutDelayId; + config->playoutDelayMin = init->playoutDelayMin; + config->playoutDelayMax = init->playoutDelayMax; return config; } diff --git a/src/rtppacketizer.cpp b/src/rtppacketizer.cpp index ba7048ac5..fa9d65ee6 100644 --- a/src/rtppacketizer.cpp +++ b/src/rtppacketizer.cpp @@ -31,6 +31,11 @@ message_ptr RtpPacketizer::packetize(shared_ptr payload, bool mark) { if (setVideoRotation) rtpExtHeaderSize += 2; + const bool setPlayoutDelay = (rtpConfig->playoutDelayId > 0 && rtpConfig->playoutDelayId < 15); + + if (setPlayoutDelay) + rtpExtHeaderSize += 1; + if (rtpConfig->mid.has_value()) rtpExtHeaderSize += (1 + rtpConfig->mid->length()); @@ -85,6 +90,17 @@ message_ptr RtpPacketizer::packetize(shared_ptr payload, bool mark) { reinterpret_cast(rtpConfig->rid->c_str()), rtpConfig->rid->length()); } + + if (setPlayoutDelay) { + // 12 bits for min + 12 bits for max + char data[] = {rtpConfig->playoutDelayMin >> 4, + (char)(rtpConfig->playoutDelayMin << 4) | + (char)(rtpConfig->playoutDelayMax >> 8), + rtpConfig->playoutDelayMax}; + + extHeader->writeOneByteHeader(offset, rtpConfig->playoutDelayId, (byte *)data, 3); + offset += 4; + } } rtp->preparePacket(); From 2f13f9e294dbfcdba7fc1ac38c9374d52cf84b68 Mon Sep 17 00:00:00 2001 From: sbarrac Date: Mon, 1 Apr 2024 23:02:38 +0100 Subject: [PATCH 2/5] Fixed data conversion --- src/rtppacketizer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/rtppacketizer.cpp b/src/rtppacketizer.cpp index fa9d65ee6..3ca6677ca 100644 --- a/src/rtppacketizer.cpp +++ b/src/rtppacketizer.cpp @@ -92,11 +92,15 @@ message_ptr RtpPacketizer::packetize(shared_ptr payload, bool mark) { } if (setPlayoutDelay) { + uint16_t min = rtpConfig->playoutDelayMin & 0xFFF; + uint16_t max = rtpConfig->playoutDelayMax & 0xFFF; + // 12 bits for min + 12 bits for max - char data[] = {rtpConfig->playoutDelayMin >> 4, - (char)(rtpConfig->playoutDelayMin << 4) | - (char)(rtpConfig->playoutDelayMax >> 8), - rtpConfig->playoutDelayMax}; + char data[] = { + (min >> 4) & 0xFF, + ((min & 0xF) << 4) | ((max >> 8) & 0xF), + max & 0xFF + }; extHeader->writeOneByteHeader(offset, rtpConfig->playoutDelayId, (byte *)data, 3); offset += 4; From a17ef4ec2905815138c53639f86bba1abadf1767 Mon Sep 17 00:00:00 2001 From: sbarrac Date: Mon, 1 Apr 2024 23:22:09 +0100 Subject: [PATCH 3/5] Add casts --- src/rtppacketizer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rtppacketizer.cpp b/src/rtppacketizer.cpp index 3ca6677ca..e39c8bb3e 100644 --- a/src/rtppacketizer.cpp +++ b/src/rtppacketizer.cpp @@ -97,9 +97,9 @@ message_ptr RtpPacketizer::packetize(shared_ptr payload, bool mark) { // 12 bits for min + 12 bits for max char data[] = { - (min >> 4) & 0xFF, - ((min & 0xF) << 4) | ((max >> 8) & 0xF), - max & 0xFF + static_cast((min >> 4) & 0xFF), + static_cast(((min & 0xF) << 4) | ((max >> 8) & 0xF)), + static_cast(max & 0xFF) }; extHeader->writeOneByteHeader(offset, rtpConfig->playoutDelayId, (byte *)data, 3); From d6e352f1d2150ae5f6ddb5494e2242211bc479cd Mon Sep 17 00:00:00 2001 From: sbarrac <46637437+sbarrac@users.noreply.github.com> Date: Fri, 19 Apr 2024 20:47:35 +0100 Subject: [PATCH 4/5] Update src/rtppacketizer.cpp Co-authored-by: Paul-Louis Ageneau --- src/rtppacketizer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rtppacketizer.cpp b/src/rtppacketizer.cpp index e39c8bb3e..27205184b 100644 --- a/src/rtppacketizer.cpp +++ b/src/rtppacketizer.cpp @@ -96,13 +96,13 @@ message_ptr RtpPacketizer::packetize(shared_ptr payload, bool mark) { uint16_t max = rtpConfig->playoutDelayMax & 0xFFF; // 12 bits for min + 12 bits for max - char data[] = { - static_cast((min >> 4) & 0xFF), - static_cast(((min & 0xF) << 4) | ((max >> 8) & 0xF)), - static_cast(max & 0xFF) + byte data[] = { + byte((min >> 4) & 0xFF), + byte(((min & 0xF) << 4) | ((max >> 8) & 0xF)), + byte(max & 0xFF) }; - extHeader->writeOneByteHeader(offset, rtpConfig->playoutDelayId, (byte *)data, 3); + extHeader->writeOneByteHeader(offset, rtpConfig->playoutDelayId, data, 3); offset += 4; } } From c281c46295101fa7e2f30c4d0c07133b90902c82 Mon Sep 17 00:00:00 2001 From: sbarrac <46637437+sbarrac@users.noreply.github.com> Date: Fri, 19 Apr 2024 20:51:58 +0100 Subject: [PATCH 5/5] Changed header size --- src/rtppacketizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rtppacketizer.cpp b/src/rtppacketizer.cpp index 27205184b..9cb7332ae 100644 --- a/src/rtppacketizer.cpp +++ b/src/rtppacketizer.cpp @@ -34,7 +34,7 @@ message_ptr RtpPacketizer::packetize(shared_ptr payload, bool mark) { const bool setPlayoutDelay = (rtpConfig->playoutDelayId > 0 && rtpConfig->playoutDelayId < 15); if (setPlayoutDelay) - rtpExtHeaderSize += 1; + rtpExtHeaderSize += 4; if (rtpConfig->mid.has_value()) rtpExtHeaderSize += (1 + rtpConfig->mid->length());