浏览代码

Added color space extension support

TaekLimLee 1 月之前
父节点
当前提交
e90f746d5c
共有 4 个文件被更改,包括 38 次插入0 次删除
  1. 8 0
      include/rtc/rtc.h
  2. 9 0
      include/rtc/rtppacketizationconfig.hpp
  3. 7 0
      src/capi.cpp
  4. 14 0
      src/rtppacketizer.cpp

+ 8 - 0
include/rtc/rtc.h

@@ -352,6 +352,14 @@ typedef struct {
 	uint8_t playoutDelayId;
 	uint8_t playoutDelayId;
 	uint16_t playoutDelayMin;
 	uint16_t playoutDelayMin;
 	uint16_t playoutDelayMax;
 	uint16_t playoutDelayMax;
+
+	uint8_t colorSpaceId;
+	uint8_t colorChromaSitingHorz;
+	uint8_t colorChromaSitingVert;
+	uint8_t colorRange;
+	uint8_t colorPrimaries;
+	uint8_t colorTransfer;
+	uint8_t colorMatrix;
 } rtcPacketizerInit;
 } rtcPacketizerInit;
 
 
 // Deprecated, do not use
 // Deprecated, do not use

+ 9 - 0
include/rtc/rtppacketizationconfig.hpp

@@ -74,6 +74,15 @@ public:
 	uint16_t playoutDelayMin = 0;
 	uint16_t playoutDelayMin = 0;
 	uint16_t playoutDelayMax = 0;
 	uint16_t playoutDelayMax = 0;
 
 
+	// https://webrtc.googlesource.com/src/+/refs/heads/main/docs/native-code/rtp-hdrext/color-space/
+	uint8_t colorSpaceId = 0;               // the negotiated ID of color space header extension
+	uint8_t colorChromaSitingHorz = 0;      // unspecified
+	uint8_t colorChromaSitingVert = 0;      // unspecified
+	uint8_t colorRange = 2;                 // full range
+	uint8_t colorPrimaries = 1;             // BT.709-6
+	uint8_t colorTransfer = 1;              // BT.709-6
+	uint8_t colorMatrix = 1;                // BT.709-6
+
 	/// Construct RTP configuration used in packetization process
 	/// Construct RTP configuration used in packetization process
 	/// @param ssrc SSRC of source
 	/// @param ssrc SSRC of source
 	/// @param cname CNAME of source
 	/// @param cname CNAME of source

+ 7 - 0
src/capi.cpp

@@ -278,6 +278,13 @@ createRtpPacketizationConfig(const rtcPacketizationHandlerInit *init) {
 	config->playoutDelayId = init->playoutDelayId;
 	config->playoutDelayId = init->playoutDelayId;
 	config->playoutDelayMin = init->playoutDelayMin;
 	config->playoutDelayMin = init->playoutDelayMin;
 	config->playoutDelayMax = init->playoutDelayMax;
 	config->playoutDelayMax = init->playoutDelayMax;
+	config->colorSpaceId = init->colorSpaceId;
+	config->colorChromaSitingHorz = init->colorChromaSitingHorz;
+	config->colorChromaSitingVert = init->colorChromaSitingVert;
+	config->colorRange = init->colorRange;
+	config->colorPrimaries = init->colorPrimaries;
+	config->colorTransfer = init->colorTransfer;
+	config->colorMatrix = init->colorMatrix;
 	return config;
 	return config;
 }
 }
 
 

+ 14 - 0
src/rtppacketizer.cpp

@@ -57,10 +57,14 @@ message_ptr RtpPacketizer::packetize(const binary &payload, bool mark) {
 		rtpExtHeaderSize += headerSize + 1;
 		rtpExtHeaderSize += headerSize + 1;
 
 
 	const bool setPlayoutDelay = rtpConfig->playoutDelayId > 0;
 	const bool setPlayoutDelay = rtpConfig->playoutDelayId > 0;
+	const bool setColorSpace = rtpConfig->colorSpaceId > 0;
 
 
 	if (setPlayoutDelay)
 	if (setPlayoutDelay)
 		rtpExtHeaderSize += headerSize + 3;
 		rtpExtHeaderSize += headerSize + 3;
 
 
+	if (setColorSpace)
+		rtpExtHeaderSize += headerSize + 4;
+	
 	if (rtpConfig->mid.has_value())
 	if (rtpConfig->mid.has_value())
 		rtpExtHeaderSize += headerSize + rtpConfig->mid->length();
 		rtpExtHeaderSize += headerSize + rtpConfig->mid->length();
 
 
@@ -139,6 +143,16 @@ message_ptr RtpPacketizer::packetize(const binary &payload, bool mark) {
 			offset += extHeader->writeHeader(
 			offset += extHeader->writeHeader(
 			    twoByteHeader, offset, rtpConfig->playoutDelayId, data, 3);
 			    twoByteHeader, offset, rtpConfig->playoutDelayId, data, 3);
 		}
 		}
+
+		if (setColorSpace) {
+			uint8_t range_chr = (rtpConfig->colorRange << 4) + (rtpConfig->colorChromaSitingHorz << 2) + rtpConfig->colorChromaSitingVert;
+
+			byte data[] = {byte(rtpConfig->colorPrimaries), byte(rtpConfig->colorTransfer),
+			               byte(rtpConfig->colorMatrix), byte(range_chr)};
+
+			offset += extHeader->writeHeader(
+			    twoByteHeader, offset, rtpConfig->playoutDelayId, data, 4);
+		}
 	}
 	}
 
 
 	rtp->preparePacket();
 	rtp->preparePacket();