Skip to content

Commit 0fd40e6

Browse files
committed
sdp-utils: add AV1 profile parsing
1 parent a7c06eb commit 0fd40e6

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

sdp-utils.c

+28-4
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ int janus_sdp_get_codec_pt_full(janus_sdp *sdp, const char *codec, const char *p
659659
if(sdp == NULL || codec == NULL)
660660
return -1;
661661
/* Check the format string (note that we only parse what browsers can negotiate) */
662-
gboolean video = FALSE, vp9 = FALSE, h264 = FALSE;
662+
gboolean video = FALSE, vp9 = FALSE, av1 = FALSE, h264 = FALSE;
663663
const char *format = NULL, *format2 = NULL;
664664
if(!strcasecmp(codec, "opus")) {
665665
format = "opus/48000/2";
@@ -734,7 +734,7 @@ int janus_sdp_get_codec_pt_full(janus_sdp *sdp, const char *codec, const char *p
734734
if(pt < 0) {
735735
JANUS_LOG(LOG_ERR, "Invalid payload type (%s)\n", a->value);
736736
} else if(strstr(a->value, format) || strstr(a->value, format2)) {
737-
if(profile != NULL && (vp9 || h264)) {
737+
if(profile != NULL && (vp9 || h264 || av1)) {
738738
/* Let's keep track of this payload type */
739739
pts = g_list_append(pts, GINT_TO_POINTER(pt));
740740
} else {
@@ -790,6 +790,15 @@ int janus_sdp_get_codec_pt_full(janus_sdp *sdp, const char *codec, const char *p
790790
g_list_free(pts);
791791
return pt;
792792
}
793+
} else if(av1) {
794+
char av1_profile[20];
795+
g_snprintf(av1_profile, sizeof(profile), "profile=%s", profile);
796+
if(strstr(a->value, av1_profile) != NULL) {
797+
/* Found */
798+
JANUS_LOG(LOG_VERB, "AV1 profile %s found --> %d\n", profile, pt);
799+
g_list_free(pts);
800+
return pt;
801+
}
793802
}
794803
}
795804
ma = ma->next;
@@ -1214,7 +1223,7 @@ janus_sdp *janus_sdp_generate_offer(const char *name, const char *address, ...)
12141223
gboolean do_audio = TRUE, do_video = TRUE, do_data = TRUE,
12151224
audio_dtmf = FALSE, video_rtcpfb = TRUE, data_legacy = TRUE;
12161225
const char *audio_codec = NULL, *video_codec = NULL,
1217-
*vp9_profile = NULL, *h264_profile = NULL,
1226+
*vp9_profile = NULL, *av1_profile = NULL, *h264_profile = NULL,
12181227
*audio_fmtp = NULL, *video_fmtp = NULL;
12191228
int audio_pt = 111, video_pt = 96, opusred_pt = 0;
12201229
janus_sdp_mdirection audio_dir = JANUS_SDP_SENDRECV, video_dir = JANUS_SDP_SENDRECV;
@@ -1238,6 +1247,8 @@ janus_sdp *janus_sdp_generate_offer(const char *name, const char *address, ...)
12381247
video_codec = va_arg(args, char *);
12391248
} else if(property == JANUS_SDP_OA_VP9_PROFILE) {
12401249
vp9_profile = va_arg(args, char *);
1250+
} else if(property == JANUS_SDP_OA_AV1_PROFILE) {
1251+
av1_profile = va_arg(args, char *);
12411252
} else if(property == JANUS_SDP_OA_H264_PROFILE) {
12421253
h264_profile = va_arg(args, char *);
12431254
} else if(property == JANUS_SDP_OA_AUDIO_PT) {
@@ -1430,6 +1441,10 @@ janus_sdp *janus_sdp_generate_offer(const char *name, const char *address, ...)
14301441
/* Add a profile-id fmtp attribute */
14311442
a = janus_sdp_attribute_create("fmtp", "%d profile-id=%s", video_pt, vp9_profile);
14321443
m->attributes = g_list_append(m->attributes, a);
1444+
} else if(!strcasecmp(video_codec, "av1") && av1_profile) {
1445+
/* Add a profile fmtp attribute */
1446+
a = janus_sdp_attribute_create("fmtp", "%d profile=%s", video_pt, av1_profile);
1447+
m->attributes = g_list_append(m->attributes, a);
14331448
} else if(!strcasecmp(video_codec, "h264") && h264_profile) {
14341449
/* Add a profile-level-id fmtp attribute */
14351450
a = janus_sdp_attribute_create("fmtp", "%d profile-level-id=%s;packetization-mode=1", video_pt, h264_profile);
@@ -1484,7 +1499,7 @@ janus_sdp *janus_sdp_generate_answer(janus_sdp *offer, ...) {
14841499
gboolean do_audio = TRUE, do_video = TRUE, do_data = TRUE,
14851500
audio_dtmf = FALSE, audio_opusred = FALSE, video_rtcpfb = TRUE;
14861501
const char *audio_codec = NULL, *video_codec = NULL,
1487-
*vp9_profile = NULL, *h264_profile = NULL,
1502+
*vp9_profile = NULL, *av1_profile = NULL, *h264_profile = NULL,
14881503
*audio_fmtp = NULL, *video_fmtp = NULL;
14891504
char *custom_audio_fmtp = NULL;
14901505
GList *extmaps = NULL;
@@ -1507,6 +1522,8 @@ janus_sdp *janus_sdp_generate_answer(janus_sdp *offer, ...) {
15071522
video_codec = va_arg(args, char *);
15081523
} else if(property == JANUS_SDP_OA_VP9_PROFILE) {
15091524
vp9_profile = va_arg(args, char *);
1525+
} else if(property == JANUS_SDP_OA_AV1_PROFILE) {
1526+
av1_profile = va_arg(args, char *);
15101527
} else if(property == JANUS_SDP_OA_H264_PROFILE) {
15111528
h264_profile = va_arg(args, char *);
15121529
} else if(property == JANUS_SDP_OA_AUDIO_DTMF) {
@@ -1704,6 +1721,8 @@ janus_sdp *janus_sdp_generate_answer(janus_sdp *offer, ...) {
17041721
const char *video_profile = NULL;
17051722
if(codec && !strcasecmp(codec, "vp9"))
17061723
video_profile = vp9_profile;
1724+
else if(codec && !strcasecmp(codec, "av1"))
1725+
video_profile = av1_profile;
17071726
else if(codec && !strcasecmp(codec, "h264"))
17081727
video_profile = h264_profile;
17091728
int pt = janus_sdp_get_codec_pt_full(offer, codec, video_profile);
@@ -1802,6 +1821,10 @@ janus_sdp *janus_sdp_generate_answer(janus_sdp *offer, ...) {
18021821
/* Add a profile-id fmtp attribute */
18031822
a = janus_sdp_attribute_create("fmtp", "%d profile-id=%s", pt, vp9_profile);
18041823
am->attributes = g_list_append(am->attributes, a);
1824+
} else if(!strcasecmp(codec, "av1") && av1_profile) {
1825+
/* Add a profile fmtp attribute */
1826+
a = janus_sdp_attribute_create("fmtp", "%d profile=%s", pt, av1_profile);
1827+
am->attributes = g_list_append(am->attributes, a);
18051828
} else if(!strcasecmp(codec, "h264") && h264_profile) {
18061829
/* Add a profile-level-id fmtp attribute */
18071830
a = janus_sdp_attribute_create("fmtp", "%d profile-level-id=%s;packetization-mode=1", pt, h264_profile);
@@ -1856,6 +1879,7 @@ janus_sdp *janus_sdp_generate_answer(janus_sdp *offer, ...) {
18561879
/* Check if we need to copy the fmtp attribute too */
18571880
if(((!strcasecmp(codec, "vp8") && video_fmtp == NULL)) ||
18581881
((!strcasecmp(codec, "vp9") && vp9_profile == NULL && video_fmtp == NULL)) ||
1882+
((!strcasecmp(codec, "av1") && av1_profile == NULL && video_fmtp == NULL)) ||
18591883
((!strcasecmp(codec, "h264") && h264_profile == NULL && video_fmtp == NULL))) {
18601884
/* FIXME Copy the fmtp attribute (we should check if we support it) */
18611885
a = janus_sdp_attribute_create("fmtp", "%s", a->value);

sdp-utils.h

+2
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ JANUS_SDP_OA_AUDIO_CODEC,
262262
JANUS_SDP_OA_VIDEO_CODEC,
263263
/*! \brief When generating an offer or answer automatically, use this profile for VP9 (depends on value that follows) */
264264
JANUS_SDP_OA_VP9_PROFILE,
265+
/*! \brief When generating an offer or answer automatically, use this profile for AV1 (depends on value that follows) */
266+
JANUS_SDP_OA_AV1_PROFILE,
265267
/*! \brief When generating an offer or answer automatically, use this profile for H.264 (depends on value that follows) */
266268
JANUS_SDP_OA_H264_PROFILE,
267269
/*! \brief When generating an offer (this is ignored for answers), use this payload type for audio (depends on value that follows) */

0 commit comments

Comments
 (0)