From 4b70bfe52ed611d20e9a003fcaf602a38a387e46 Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Wed, 6 Sep 2023 12:04:15 +0200 Subject: [PATCH] Pass track profile for any codec in C API --- include/rtc/rtc.h | 5 +---- src/capi.cpp | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/rtc/rtc.h b/include/rtc/rtc.h index ba0ed037a..0210a0f2c 100644 --- a/include/rtc/rtc.h +++ b/include/rtc/rtc.h @@ -275,10 +275,7 @@ typedef struct { const char *name; // optional const char *msid; // optional const char *trackId; // optional, track ID used in MSID - - //indicate the coder capability and configuration - //e.g: aac latm streammuxconfig - const char *profile; + const char *profile; // optional, codec profile } rtcTrackInit; RTC_C_EXPORT int rtcSetTrackCallback(int pc, rtcTrackCallbackFunc cb); diff --git a/src/capi.cpp b/src/capi.cpp index f105d3fde..d494096e4 100644 --- a/src/capi.cpp +++ b/src/capi.cpp @@ -1036,6 +1036,12 @@ int rtcAddTrackEx(int pc, const rtcTrackInit *init) { } } + int pt = init->payloadType; + + optional profile; + if (init->profile) + profile.emplace(string(init->profile)); + optional optDescription = nullopt; switch (init->codec) { @@ -1046,16 +1052,16 @@ int rtcAddTrackEx(int pc, const rtcTrackInit *init) { auto desc = Description::Video(mid, direction); switch (init->codec) { case RTC_CODEC_H264: - desc.addH264Codec(init->payloadType); + desc.addH264Codec(pt, profile); break; case RTC_CODEC_H265: - desc.addH265Codec(init->payloadType); + desc.addH265Codec(pt, profile); break; case RTC_CODEC_VP8: - desc.addVP8Codec(init->payloadType); + desc.addVP8Codec(pt, profile); break; case RTC_CODEC_VP9: - desc.addVP9Codec(init->payloadType); + desc.addVP9Codec(pt, profile); break; default: break; @@ -1070,18 +1076,16 @@ int rtcAddTrackEx(int pc, const rtcTrackInit *init) { auto desc = Description::Audio(mid, direction); switch (init->codec) { case RTC_CODEC_OPUS: - desc.addOpusCodec(init->payloadType); + desc.addOpusCodec(pt, profile); break; case RTC_CODEC_PCMU: - desc.addPCMUCodec(init->payloadType); + desc.addPCMUCodec(pt, profile); break; case RTC_CODEC_PCMA: - desc.addPCMACodec(init->payloadType); + desc.addPCMACodec(pt, profile); break; case RTC_CODEC_AAC: - desc.addAacCodec(init->payloadType, init->profile - ? std::make_optional(string(init->profile)) - : nullopt); + desc.addAacCodec(pt, profile); break; default: break;