Bladeren bron

Add G722 codec and packetizer

Parallelc 3 maanden geleden
bovenliggende
commit
71df5bc35d
5 gewijzigde bestanden met toevoegingen van 55 en 2 verwijderingen
  1. 1 0
      include/rtc/description.hpp
  2. 4 0
      include/rtc/rtc.h
  3. 1 0
      include/rtc/rtppacketizer.hpp
  4. 44 1
      src/capi.cpp
  5. 5 1
      src/description.cpp

+ 1 - 0
include/rtc/description.hpp

@@ -251,6 +251,7 @@ public:
 		void addPCMACodec(int payloadType, optional<string> profile = std::nullopt);
 		void addPCMUCodec(int payloadType, optional<string> profile = std::nullopt);
 		void addAACCodec(int payloadType, optional<string> profile = std::nullopt);
+		void addG722Codec(int payloadType, optional<string> profile = std::nullopt);
 
 		[[deprecated("Use addAACCodec")]] inline void
 		addAacCodec(int payloadType, optional<string> profile = std::nullopt) {

+ 4 - 0
include/rtc/rtc.h

@@ -132,6 +132,7 @@ typedef enum {
 	RTC_CODEC_PCMU = 129,
 	RTC_CODEC_PCMA = 130,
 	RTC_CODEC_AAC = 131,
+	RTC_CODEC_G722 = 132,
 } rtcCodec;
 
 typedef enum {
@@ -381,6 +382,9 @@ RTC_C_EXPORT int rtcSetH265Packetizer(int tr, const rtcPacketizerInit *init);
 RTC_C_EXPORT int rtcSetAV1Packetizer(int tr, const rtcPacketizerInit *init);
 RTC_C_EXPORT int rtcSetOpusPacketizer(int tr, const rtcPacketizerInit *init);
 RTC_C_EXPORT int rtcSetAACPacketizer(int tr, const rtcPacketizerInit *init);
+RTC_C_EXPORT int rtcSetPCMUPacketizer(int tr, const rtcPacketizerInit *init);
+RTC_C_EXPORT int rtcSetPCMAPacketizer(int tr, const rtcPacketizerInit *init);
+RTC_C_EXPORT int rtcSetG722Packetizer(int tr, const rtcPacketizerInit *init);
 
 // Deprecated, do not use
 RTC_DEPRECATED static inline int

+ 1 - 0
include/rtc/rtppacketizer.hpp

@@ -76,6 +76,7 @@ using OpusRtpPacketizer = AudioRtpPacketizer<48000>;
 using AACRtpPacketizer = AudioRtpPacketizer<48000>;
 using PCMARtpPacketizer = AudioRtpPacketizer<8000>;
 using PCMURtpPacketizer = AudioRtpPacketizer<8000>;
+using G722RtpPacketizer = AudioRtpPacketizer<8000>;
 
 // Dummy wrapper for backward compatibility, do not use
 class RTC_CPP_EXPORT PacketizationHandler final : public MediaHandler {

+ 44 - 1
src/capi.cpp

@@ -1089,7 +1089,8 @@ int rtcAddTrackEx(int pc, const rtcTrackInit *init) {
 		case RTC_CODEC_OPUS:
 		case RTC_CODEC_PCMU:
 		case RTC_CODEC_PCMA:
-		case RTC_CODEC_AAC: {
+		case RTC_CODEC_AAC: 
+		case RTC_CODEC_G722: {
 			auto audio = std::make_unique<Description::Audio>(mid, direction);
 			switch (init->codec) {
 			case RTC_CODEC_OPUS:
@@ -1104,6 +1105,9 @@ int rtcAddTrackEx(int pc, const rtcTrackInit *init) {
 			case RTC_CODEC_AAC:
 				audio->addAACCodec(pt, profile);
 				break;
+			case RTC_CODEC_G722:
+				audio->addG722Codec(pt, profile);
+				break;
 			default:
 				break;
 			}
@@ -1316,6 +1320,45 @@ int rtcSetAACPacketizer(int tr, const rtcPacketizerInit *init) {
 	});
 }
 
+int rtcSetPCMUPacketizer(int tr, const rtcPacketizerInit *init) {
+	return wrap([&] {
+		auto track = getTrack(tr);
+		// create RTP configuration
+		auto rtpConfig = createRtpPacketizationConfig(init);
+		emplaceRtpConfig(rtpConfig, tr);
+		// create packetizer
+		auto packetizer = std::make_shared<PCMURtpPacketizer>(rtpConfig);
+		track->setMediaHandler(packetizer);
+		return RTC_ERR_SUCCESS;
+	});
+}
+
+int rtcSetPCMAPacketizer(int tr, const rtcPacketizerInit *init) {
+	return wrap([&] {
+		auto track = getTrack(tr);
+		// create RTP configuration
+		auto rtpConfig = createRtpPacketizationConfig(init);
+		emplaceRtpConfig(rtpConfig, tr);
+		// create packetizer
+		auto packetizer = std::make_shared<PCMARtpPacketizer>(rtpConfig);
+		track->setMediaHandler(packetizer);
+		return RTC_ERR_SUCCESS;
+	});
+}
+
+int rtcSetG722Packetizer(int tr, const rtcPacketizerInit *init) {
+	return wrap([&] {
+		auto track = getTrack(tr);
+		// create RTP configuration
+		auto rtpConfig = createRtpPacketizationConfig(init);
+		emplaceRtpConfig(rtpConfig, tr);
+		// create packetizer
+		auto packetizer = std::make_shared<G722RtpPacketizer>(rtpConfig);
+		track->setMediaHandler(packetizer);
+		return RTC_ERR_SUCCESS;
+	});
+}
+
 int rtcChainRtcpReceivingSession(int tr) {
 	return wrap([&] {
 		auto track = getTrack(tr);

+ 5 - 1
src/description.cpp

@@ -1201,7 +1201,7 @@ Description::Audio::Audio(string mid, Direction dir)
 
 void Description::Audio::addAudioCodec(int payloadType, string codec, optional<string> profile) {
 	if (codec.find('/') == string::npos) {
-		if (codec == "PCMA" || codec == "PCMU")
+		if (codec == "PCMA" || codec == "PCMU" || codec == "G722")
 			codec += "/8000/1";
 		else
 			codec += "/48000/2";
@@ -1227,6 +1227,10 @@ void Description::Audio::addPCMUCodec(int payloadType, optional<string> profile)
 	addAudioCodec(payloadType, "PCMU", profile);
 }
 
+void Description::Audio::addG722Codec(int payloadType, optional<string> profile) {
+	addAudioCodec(payloadType, "G722", profile);
+}
+
 void Description::Audio::addAACCodec(int payloadType, optional<string> profile) {
 	if (profile) {
 		addAudioCodec(payloadType, "MP4A-LATM", profile);