diff --git a/include/rtc/rtc.h b/include/rtc/rtc.h index 7990c071f..db0754848 100644 --- a/include/rtc/rtc.h +++ b/include/rtc/rtc.h @@ -113,6 +113,7 @@ typedef enum { RTC_CODEC_VP8 = 1, RTC_CODEC_VP9 = 2, RTC_CODEC_H265 = 3, + RTC_CODEC_AV1 = 4, // audio RTC_CODEC_OPUS = 128, @@ -315,9 +316,14 @@ typedef struct { uint16_t sequenceNumber; uint32_t timestamp; - // H264/H265 + // H264/H265 only rtcNalUnitSeparator nalSeparator; // NAL unit separator - uint16_t maxFragmentSize; // Maximum NAL unit fragment size + + // H264, H265, AV1 + uint16_t maxFragmentSize; // Maximum fragment size + + // AV1 only + rtcObuPacketization obuPacketization; // OBU paketization for AV1 samples } rtcPacketizationHandlerInit; @@ -348,6 +354,9 @@ RTC_C_EXPORT int rtcSetH264PacketizationHandler(int tr, const rtcPacketizationHa // Set H265PacketizationHandler for track RTC_C_EXPORT int rtcSetH265PacketizationHandler(int tr, const rtcPacketizationHandlerInit *init); +// Set AV1PacketizationHandler for track +RTC_C_EXPORT int rtcSetAV1PacketizationHandler(int tr, const rtcPacketizationHandlerInit *init); + // Set OpusPacketizationHandler for track RTC_C_EXPORT int rtcSetOpusPacketizationHandler(int tr, const rtcPacketizationHandlerInit *init); diff --git a/src/capi.cpp b/src/capi.cpp index e7dfc2aff..ffea82c29 100644 --- a/src/capi.cpp +++ b/src/capi.cpp @@ -1032,6 +1032,7 @@ int rtcAddTrackEx(int pc, const rtcTrackInit *init) { mid = string(init->mid); } else { switch (init->codec) { + case RTC_CODEC_AV1: case RTC_CODEC_H264: case RTC_CODEC_H265: case RTC_CODEC_VP8: @@ -1055,12 +1056,16 @@ int rtcAddTrackEx(int pc, const rtcTrackInit *init) { unique_ptr description; switch (init->codec) { + case RTC_CODEC_AV1: case RTC_CODEC_H264: case RTC_CODEC_H265: case RTC_CODEC_VP8: case RTC_CODEC_VP9: { auto video = std::make_unique(mid, direction); switch (init->codec) { + case RTC_CODEC_AV1: + video->addAV1Codec(pt, profile); + break; case RTC_CODEC_H264: video->addH264Codec(pt, profile); break; @@ -1256,6 +1261,29 @@ int rtcSetH265PacketizationHandler(int tr, const rtcPacketizationHandlerInit *in }); } +int rtcSetAV1PacketizationHandler(int tr, const rtcPacketizationHandlerInit *init) { + return wrap([&] { + auto track = getTrack(tr); + // create RTP configuration + auto rtpConfig = createRtpPacketizationConfig(init); + // create packetizer + auto maxFragmentSize = init && init->maxFragmentSize ? init->maxFragmentSize + : RTC_DEFAULT_MAXIMUM_FRAGMENT_SIZE; + auto packetization = init->obuPacketization == RTC_OBU_PACKETIZED_TEMPORAL_UNIT + ? AV1RtpPacketizer::Packetization::TemporalUnit + : AV1RtpPacketizer::Packetization::Obu; + auto packetizer = + std::make_shared(packetization, rtpConfig, maxFragmentSize); + // create AV1 handler + auto av1Handler = std::make_shared(packetizer); + emplaceMediaChainableHandler(av1Handler, tr); + emplaceRtpConfig(rtpConfig, tr); + // set handler + track->setMediaHandler(av1Handler); + return RTC_ERR_SUCCESS; + }); +} + int rtcSetOpusPacketizationHandler(int tr, const rtcPacketizationHandlerInit *init) { return wrap([&] { auto track = getTrack(tr);