Skip to content

Commit 41320cc

Browse files
committed
Added playout delay extension support
1 parent fbd8f23 commit 41320cc

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

include/rtc/rtc.h

+3
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ typedef struct {
341341
// AV1 only
342342
rtcObuPacketization obuPacketization; // OBU paketization for AV1 samples
343343

344+
uint8_t playoutDelayId;
345+
uint16_t playoutDelayMin;
346+
uint16_t playoutDelayMax;
344347
} rtcPacketizerInit;
345348

346349
// Deprecated, do not use

include/rtc/rtppacketizationconfig.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ class RTC_CPP_EXPORT RtpPacketizationConfig {
6161
uint8_t ridId = 0;
6262
optional<std::string> rid;
6363

64+
// the negotiated ID of the playout delay header extension
65+
// https://webrtc.googlesource.com/src/+/main/docs/native-code/rtp-hdrext/playout-delay/README.md
66+
uint8_t playoutDelayId;
67+
68+
// Minimum/maxiumum playout delay, in 10ms intervals. A value of 10 would equal a 100ms delay
69+
uint16_t playoutDelayMin;
70+
uint16_t playoutDelayMax;
71+
6472
/// Construct RTP configuration used in packetization process
6573
/// @param ssrc SSRC of source
6674
/// @param cname CNAME of source

src/capi.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ createRtpPacketizationConfig(const rtcPacketizationHandlerInit *init) {
275275
init->payloadType, init->clockRate);
276276
config->sequenceNumber = init->sequenceNumber;
277277
config->timestamp = init->timestamp;
278+
config->playoutDelayId = init->playoutDelayId;
279+
config->playoutDelayMin = init->playoutDelayMin;
280+
config->playoutDelayMax = init->playoutDelayMax;
278281
return config;
279282
}
280283

src/rtppacketizer.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ message_ptr RtpPacketizer::packetize(shared_ptr<binary> payload, bool mark) {
3131
if (setVideoRotation)
3232
rtpExtHeaderSize += 2;
3333

34+
const bool setPlayoutDelay = (rtpConfig->playoutDelayId > 0 && rtpConfig->playoutDelayId < 15);
35+
36+
if (setPlayoutDelay)
37+
rtpExtHeaderSize += 1;
38+
3439
if (rtpConfig->mid.has_value())
3540
rtpExtHeaderSize += (1 + rtpConfig->mid->length());
3641

@@ -85,6 +90,17 @@ message_ptr RtpPacketizer::packetize(shared_ptr<binary> payload, bool mark) {
8590
reinterpret_cast<const std::byte *>(rtpConfig->rid->c_str()),
8691
rtpConfig->rid->length());
8792
}
93+
94+
if (setPlayoutDelay) {
95+
// 12 bits for min + 12 bits for max
96+
char data[] = {rtpConfig->playoutDelayMin >> 4,
97+
(char)(rtpConfig->playoutDelayMin << 4) |
98+
(char)(rtpConfig->playoutDelayMax >> 8),
99+
rtpConfig->playoutDelayMax};
100+
101+
extHeader->writeOneByteHeader(offset, rtpConfig->playoutDelayId, (byte *)data, 3);
102+
offset += 4;
103+
}
88104
}
89105

90106
rtp->preparePacket();

0 commit comments

Comments
 (0)