Skip to content

Commit

Permalink
Merge pull request #1004 from paullouisageneau/capi-av1
Browse files Browse the repository at this point in the history
Add AV1 packetizer to C API
  • Loading branch information
paullouisageneau authored Oct 20, 2023
2 parents f986a80 + a2a98c0 commit e712c62
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
13 changes: 11 additions & 2 deletions include/rtc/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
28 changes: 28 additions & 0 deletions src/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -1055,12 +1056,16 @@ int rtcAddTrackEx(int pc, const rtcTrackInit *init) {

unique_ptr<Description::Media> 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<Description::Video>(mid, direction);
switch (init->codec) {
case RTC_CODEC_AV1:
video->addAV1Codec(pt, profile);
break;
case RTC_CODEC_H264:
video->addH264Codec(pt, profile);
break;
Expand Down Expand Up @@ -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<AV1RtpPacketizer>(packetization, rtpConfig, maxFragmentSize);
// create AV1 handler
auto av1Handler = std::make_shared<AV1PacketizationHandler>(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);
Expand Down

0 comments on commit e712c62

Please sign in to comment.