vapostproc: Traverse caps features in gst_va_vpp_caps_remove_fields()
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Wed, 13 Oct 2021 17:27:41 +0000 (19:27 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 18 Oct 2021 19:14:15 +0000 (19:14 +0000)
The previous code had a potential failure for multiple caps features. Now
each caps feature in each structure is reviewed, and if it has a supported
feature, the structure is processed.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1024>

subprojects/gst-plugins-bad/sys/va/gstvavpp.c

index 23ec905..0f671ba 100644 (file)
@@ -782,7 +782,7 @@ gst_va_vpp_caps_remove_fields (GstCaps * caps)
   GstCaps *ret;
   GstStructure *structure;
   GstCapsFeatures *features;
-  gint i, n;
+  gint i, j, n, m;
 
   ret = gst_caps_new_empty ();
 
@@ -798,23 +798,30 @@ gst_va_vpp_caps_remove_fields (GstCaps * caps)
 
     structure = gst_structure_copy (structure);
 
-    if (gst_caps_features_is_equal (features,
-            GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)
-        || gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_DMABUF)
-        || gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_VA)) {
-      /* rangify frame size */
-      gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
-          "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
-
-      /* if pixel aspect ratio, make a range of it */
-      if (gst_structure_has_field (structure, "pixel-aspect-ratio")) {
-        gst_structure_set (structure, "pixel-aspect-ratio",
-            GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1, NULL);
-      }
+    m = gst_caps_features_get_size (features);
+    for (j = 0; j < m; j++) {
+      const gchar *feature = gst_caps_features_get_nth (features, j);
+
+      if (g_strcmp0 (feature, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY) == 0
+          || g_strcmp0 (feature, GST_CAPS_FEATURE_MEMORY_DMABUF) == 0
+          || g_strcmp0 (feature, GST_CAPS_FEATURE_MEMORY_VA) == 0) {
 
-      /* remove format-related fields */
-      gst_structure_remove_fields (structure, "format", "colorimetry",
-          "chroma-site", NULL);
+        /* rangify frame size */
+        gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
+            "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
+
+        /* if pixel aspect ratio, make a range of it */
+        if (gst_structure_has_field (structure, "pixel-aspect-ratio")) {
+          gst_structure_set (structure, "pixel-aspect-ratio",
+              GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1, NULL);
+        }
+
+        /* remove format-related fields */
+        gst_structure_remove_fields (structure, "format", "colorimetry",
+            "chroma-site", NULL);
+
+        break;
+      }
     }
 
     gst_caps_append_structure_full (ret, structure,