From f3fd4d7e90807927e9ddead6b4302c669d99c269 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Fri, 21 May 2021 18:55:25 -0400 Subject: [PATCH] videoconvertscale: Don't claim we can support any kind of memory Since d0133a2d11566ff4c0cded7af8dfdff0046e0e8b "videoconvert: Allow passthrough for ANY caps features" videoconvert will always claim that it supports any kind of memory which is true in very specific case (when it is running in passthrough mode). To get elements that autoplug converters depending on the caps running in the pipeline (like autovideoconvert), we need to have converters no lie about what they can do when queried `accept_caps` or `query_caps`. This still accepts any caps feature as before but it introduces a restriction in the way we handle memory capsfeatures. We keep previous behaviour in videoconvert and videoscale. Part-of: --- .../gst/videoconvertscale/gstvideoconvert.c | 2 +- .../videoconvertscale/gstvideoconvertscale.c | 23 +++++++++++++++++++ .../videoconvertscale/gstvideoconvertscale.h | 2 ++ .../gst/videoconvertscale/gstvideoscale.c | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvert.c b/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvert.c index 8424bbfe2b..ff8b4f10de 100644 --- a/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvert.c +++ b/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvert.c @@ -49,7 +49,7 @@ GST_ELEMENT_REGISTER_DEFINE (videoconvert, "videoconvert", static void gst_video_convert_class_init (GstVideoConvertClass * klass) { - + ((GstVideoConvertScaleClass *) klass)->any_memory = TRUE; } static void diff --git a/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvertscale.c b/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvertscale.c index df168caf82..a5d9b52de4 100644 --- a/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvertscale.c +++ b/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvertscale.c @@ -617,6 +617,7 @@ static GstCaps * gst_video_convert_scale_transform_caps (GstBaseTransform * trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter) { + gint i; GstCaps *ret; GST_DEBUG_OBJECT (trans, @@ -633,6 +634,28 @@ gst_video_convert_scale_transform_caps (GstBaseTransform * trans, ret = intersection; } + if (GST_VIDEO_CONVERT_SCALE_GET_CLASS (trans)->any_memory) + return ret; + + for (i = 0; i < gst_caps_get_size (ret); i++) { + gint j; + GstCapsFeatures *f = gst_caps_get_features (ret, i); + + if (!f || gst_caps_features_is_any (f) || + gst_caps_features_is_equal (f, GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)) + continue; + + for (j = 0; j < gst_caps_features_get_size (f); j++) { + const gchar *feature = gst_caps_features_get_nth (f, j); + + if (g_str_has_prefix (feature, "memory:")) { + GST_DEBUG_OBJECT (trans, "Can not work with memory `%s`", feature); + gst_caps_remove_structure (ret, i); + break; + } + } + } + GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, ret); return ret; diff --git a/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvertscale.h b/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvertscale.h index 9d25e039b6..64be8b1eaa 100644 --- a/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvertscale.h +++ b/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvertscale.h @@ -36,6 +36,8 @@ G_DECLARE_DERIVABLE_TYPE (GstVideoConvertScale, gst_video_convert_scale, GST, VI struct _GstVideoConvertScaleClass { GstVideoFilterClass parent; + + gboolean any_memory; }; /** diff --git a/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoscale.c b/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoscale.c index b246bf97b1..e8e41f152c 100644 --- a/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoscale.c +++ b/subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoscale.c @@ -112,6 +112,8 @@ gst_video_scale_class_init (GstVideoScaleClass * klass) gobject_class->set_property = gst_video_scale_set_property; gobject_class->get_property = gst_video_scale_get_property; + ((GstVideoConvertScaleClass *) klass)->any_memory = TRUE; + g_object_class_install_property (gobject_class, PROP_GAMMA_DECODE, g_param_spec_boolean ("gamma-decode", "Gamma Decode", "Decode gamma before scaling", DEFAULT_PROP_GAMMA_DECODE,