Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playout delay extension support #1152

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/rtc/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions include/rtc/rtppacketizationconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class RTC_CPP_EXPORT RtpPacketizationConfig {
uint8_t ridId = 0;
optional<std::string> 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
Expand Down
3 changes: 3 additions & 0 deletions src/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
20 changes: 20 additions & 0 deletions src/rtppacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ message_ptr RtpPacketizer::packetize(shared_ptr<binary> payload, bool mark) {
if (setVideoRotation)
rtpExtHeaderSize += 2;

const bool setPlayoutDelay = (rtpConfig->playoutDelayId > 0 && rtpConfig->playoutDelayId < 15);

if (setPlayoutDelay)
rtpExtHeaderSize += 4;

if (rtpConfig->mid.has_value())
rtpExtHeaderSize += (1 + rtpConfig->mid->length());

Expand Down Expand Up @@ -85,6 +90,21 @@ message_ptr RtpPacketizer::packetize(shared_ptr<binary> payload, bool mark) {
reinterpret_cast<const std::byte *>(rtpConfig->rid->c_str()),
rtpConfig->rid->length());
}

if (setPlayoutDelay) {
uint16_t min = rtpConfig->playoutDelayMin & 0xFFF;
uint16_t max = rtpConfig->playoutDelayMax & 0xFFF;

// 12 bits for min + 12 bits for max
byte data[] = {
byte((min >> 4) & 0xFF),
byte(((min & 0xF) << 4) | ((max >> 8) & 0xF)),
byte(max & 0xFF)
};

extHeader->writeOneByteHeader(offset, rtpConfig->playoutDelayId, data, 3);
offset += 4;
}
}

rtp->preparePacket();
Expand Down
Loading