From 7a37b27c67e4e547c69a5c08c36139a0485f005a Mon Sep 17 00:00:00 2001 From: Shengqi Yu Date: Mon, 29 Jul 2024 09:07:40 +0800 Subject: [PATCH] v4l2object: append non colorimetry structure to probed caps 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: --- .../gst-plugins-good/sys/v4l2/gstv4l2object.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c index 26743967c2..1eb71a3236 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c @@ -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;