Skip to content

Commit fcebd6d

Browse files
Merge pull request #1152 from sbarrac/master
Added playout delay extension support
2 parents 1f4d08a + c281c46 commit fcebd6d

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-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

+20
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 += 4;
38+
3439
if (rtpConfig->mid.has_value())
3540
rtpExtHeaderSize += (1 + rtpConfig->mid->length());
3641

@@ -85,6 +90,21 @@ 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+
uint16_t min = rtpConfig->playoutDelayMin & 0xFFF;
96+
uint16_t max = rtpConfig->playoutDelayMax & 0xFFF;
97+
98+
// 12 bits for min + 12 bits for max
99+
byte data[] = {
100+
byte((min >> 4) & 0xFF),
101+
byte(((min & 0xF) << 4) | ((max >> 8) & 0xF)),
102+
byte(max & 0xFF)
103+
};
104+
105+
extHeader->writeOneByteHeader(offset, rtpConfig->playoutDelayId, data, 3);
106+
offset += 4;
107+
}
88108
}
89109

90110
rtp->preparePacket();

0 commit comments

Comments
 (0)