From 1a6bb994a502d95434e326a35a83a1fb5f4ebad8 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Thu, 7 Mar 2024 06:55:09 +0100 Subject: [PATCH] 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") --- src/gst/gstpipewireformat.c | 11 ++++++----- src/gst/gstpipewireformat.h | 2 +- src/gst/gstpipewiresrc.c | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/gst/gstpipewireformat.c b/src/gst/gstpipewireformat.c index b4ec24f23..1c63013bd 100644 --- a/src/gst/gstpipewireformat.c +++ b/src/gst/gstpipewireformat.c @@ -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); } diff --git a/src/gst/gstpipewireformat.h b/src/gst/gstpipewireformat.h index ca76b70c2..1c3a239ba 100644 --- a/src/gst/gstpipewireformat.h +++ b/src/gst/gstpipewireformat.h @@ -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 diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c index b8e1a271f..dd7b942cd 100644 --- a/src/gst/gstpipewiresrc.c +++ b/src/gst/gstpipewiresrc.c @@ -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);