Bladeren bron

Added playout delay extension support

sbarrac 1 jaar geleden
bovenliggende
commit
41320cc08e
4 gewijzigde bestanden met toevoegingen van 30 en 0 verwijderingen
  1. 3 0
      include/rtc/rtc.h
  2. 8 0
      include/rtc/rtppacketizationconfig.hpp
  3. 3 0
      src/capi.cpp
  4. 16 0
      src/rtppacketizer.cpp

+ 3 - 0
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

+ 8 - 0
include/rtc/rtppacketizationconfig.hpp

@@ -61,6 +61,14 @@ public:
 	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

+ 3 - 0
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;
 }
 

+ 16 - 0
src/rtppacketizer.cpp

@@ -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 += 1;
+
 	if (rtpConfig->mid.has_value())
 		rtpExtHeaderSize += (1 + rtpConfig->mid->length());
 
@@ -85,6 +90,17 @@ message_ptr RtpPacketizer::packetize(shared_ptr<binary> payload, bool mark) {
 			    reinterpret_cast<const std::byte *>(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();