sdpmessage: Avoid duplicating the extmap when adding multiple codecs

The extmap aren't per-codec in SDP, so if one adds multiple codecs
to the same SDP media, the extmap were duplicated. Look if they are
already present and skip them if they are.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9031>
This commit is contained in:
Olivier Crête 2025-05-19 23:16:43 -04:00 committed by GStreamer Marge Bot
parent feedb9a769
commit 7fb6965ded

View File

@ -3813,6 +3813,29 @@ no_rate:
}
}
static gboolean
_sdp_media_has_extmap (const GstSDPMedia * media, guint id)
{
gchar id_str_space[5];
gchar id_str_slash[5];
guint i;
g_snprintf (id_str_space, 5, "%u ", id);
g_snprintf (id_str_slash, 5, "%u/", id);
for (i = 0;; i++) {
const gchar *fval = gst_sdp_media_get_attribute_val_n (media, "extmap", i);
if (fval == NULL)
return FALSE;
if (g_str_has_prefix (fval, id_str_space) ||
g_str_has_prefix (fval, id_str_slash))
return TRUE;
}
}
static GstSDPResult
_add_media_format_from_structure (const GstStructure * s, GstSDPMedia * media)
{
@ -3961,6 +3984,12 @@ _add_media_format_from_structure (const GstStructure * s, GstSDPMedia * media)
if (*endptr != '\0' || id == 0 || id == 15 || id > 9999)
continue;
/* The extmap are not per codec, so we don't want to duplicate them
* across codecs in the same media.
*/
if (_sdp_media_has_extmap (media, id))
continue;
if ((fval = gst_structure_get_string (s, fname))) {
gchar *extmap = g_strdup_printf ("%u %s", id, fval);
gst_sdp_media_add_attribute (media, "extmap", extmap);