v4l2object: append non colorimetry structure to probed caps
authorShengqi Yu <shengqi.yu@mediatek.com>
Mon, 29 Jul 2024 01:07:40 +0000 (09:07 +0800)
committerBackport Bot <gitlab-backport-bot@gstreamer-foundation.org>
Tue, 24 Sep 2024 19:17:17 +0000 (21:17 +0200)
If the stream has a special colorimetry that is not in the colorimetry
list, it will cause negotiation to fail. We should allow passing any
colorimetry, so add an extra structure without the colorimetry field.

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

subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c

index 26743967c27f6cf52bd5e63fb599e0c3ad6b4b36..1eb71a32367956c3e1acb36eafd29c43a0359776 100644 (file)
@@ -1832,6 +1832,31 @@ add_alternate_variant (GstV4l2Object * v4l2object, GstCaps * caps,
       gst_caps_features_new (GST_CAPS_FEATURE_FORMAT_INTERLACED, NULL));
 }
 
+static void
+add_non_colorimetry_caps (GstV4l2Object * v4l2object, GstCaps * caps)
+{
+  gint caps_size;
+  gint i;
+
+  caps_size = gst_caps_get_size (caps);
+  for (i = 0; i < caps_size; i++) {
+    GstStructure *structure = gst_caps_get_structure (caps, i);
+    GstCapsFeatures *features = gst_caps_get_features (caps, i);
+
+    if (gst_structure_has_name (structure, "video/x-raw")
+        && gst_structure_has_field (structure, "colorimetry")) {
+      GstStructure *alt_s = gst_structure_copy (structure);
+      gst_structure_remove_field (alt_s, "colorimetry");
+      if (gst_caps_features_contains (features,
+              GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY))
+        gst_caps_append_structure (caps, alt_s);
+      else
+        gst_caps_append_structure_full (caps, alt_s,
+            gst_caps_features_copy (features));
+    }
+  }
+}
+
 static GstCaps *
 gst_v4l2_object_get_caps_helper (GstV4L2FormatFlags flags)
 {
@@ -5154,6 +5179,13 @@ gst_v4l2_object_probe_caps (GstV4l2Object * v4l2object, GstCaps * filter)
     gst_caps_unref (tmp);
   }
 
+  /* Add a variant of the caps without the colorimetry so that we can negotiate
+     successfully even if the detected colorimetry from upstream is not supported
+     by the device */
+  if (ret) {
+    add_non_colorimetry_caps (v4l2object, ret);
+  }
+
   GST_INFO_OBJECT (v4l2object->dbg_obj, "probed caps: %" GST_PTR_FORMAT, ret);
 
   return ret;