videoconvertscale: Don't claim we can support any kind of memory
authorThibault Saunier <tsaunier@igalia.com>
Fri, 21 May 2021 22:55:25 +0000 (18:55 -0400)
committerThibault Saunier <tsaunier@igalia.com>
Wed, 20 Apr 2022 21:03:21 +0000 (17:03 -0400)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/898>

subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvert.c
subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvertscale.c
subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoconvertscale.h
subprojects/gst-plugins-base/gst/videoconvertscale/gstvideoscale.c

index 8424bbf..ff8b4f1 100644 (file)
@@ -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
index df168ca..a5d9b52 100644 (file)
@@ -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;
index 9d25e03..64be8b1 100644 (file)
@@ -36,6 +36,8 @@ G_DECLARE_DERIVABLE_TYPE (GstVideoConvertScale, gst_video_convert_scale, GST, VI
 struct _GstVideoConvertScaleClass
 {
   GstVideoFilterClass parent;
+
+  gboolean any_memory;
 };
 
 /**
index b246bf9..e8e41f1 100644 (file)
@@ -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,