gst: Fix sanitization of non-writable caps

`gst_caps_make_writable()` may create a copy which we have to keep
using afterwards. The return value was meant to be used for that,
but was promptly forgotten for the initial user.
Avoid such errors in the future by using an in-out parameter instead.

While on it, add a type check and remove a check for an impossible
condition.

Fixes: 8a271a87b ("gst: Sanitize caps before translating")
This commit is contained in:
Robert Mader 2024-03-07 06:55:09 +01:00 committed by Wim Taymans
parent 2df931483d
commit 1a6bb994a5
3 changed files with 9 additions and 8 deletions

View file

@ -1209,10 +1209,11 @@ filter_dmabuf_caps (GstCapsFeatures *features,
return TRUE;
}
GstCaps *
gst_caps_sanitize (GstCaps *caps)
void
gst_caps_sanitize (GstCaps **caps)
{
caps = gst_caps_make_writable (caps);
gst_caps_filter_and_map_in_place (caps, filter_dmabuf_caps, NULL);
return caps;
g_return_if_fail (GST_IS_CAPS (*caps));
*caps = gst_caps_make_writable (*caps);
gst_caps_filter_and_map_in_place (*caps, filter_dmabuf_caps, NULL);
}

View file

@ -15,7 +15,7 @@ GPtrArray * gst_caps_to_format_all (GstCaps *caps);
GstCaps * gst_caps_from_format (const struct spa_pod *format);
GstCaps * gst_caps_sanitize (GstCaps *caps);
void gst_caps_sanitize (GstCaps **caps);
G_END_DECLS

View file

@ -846,9 +846,9 @@ gst_pipewire_src_negotiate (GstBaseSrc * basesrc)
}
GST_DEBUG_OBJECT (basesrc, "have common caps: %" GST_PTR_FORMAT, caps);
gst_caps_sanitize (caps);
gst_caps_sanitize (&caps);
if (caps == NULL || gst_caps_is_empty (caps))
if (gst_caps_is_empty (caps))
goto no_common_caps;
GST_DEBUG_OBJECT (basesrc, "have common caps (sanitized): %" GST_PTR_FORMAT, caps);