videoconvert: Forward colorimetry and chroma-site from upstream.
authorJan Schmidt <jan@centricular.com>
Mon, 15 Feb 2021 07:34:33 +0000 (18:34 +1100)
committerSebastian Dröge <slomo@coaxion.net>
Fri, 19 Feb 2021 09:45:07 +0000 (09:45 +0000)
If downstream has expressed no preference for particular colorimetry
and chroma-site configuration, transfer them from the input caps.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/614

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1033>

gst/videoconvert/gstvideoconvert.c

index 2d5b6ee..b344ba6 100644 (file)
@@ -337,6 +337,20 @@ gst_video_convert_fixate_format (GstBaseTransform * base, GstCaps * caps,
         GST_VIDEO_FORMAT_INFO_NAME (out_info), NULL);
 }
 
+/* If a field is missing from `result` but present in `caps`, copy the field to `caps` */
+static void
+transfer_field_from_upstream_caps (GstCaps * result, GstCaps * caps,
+    const gchar * field_name)
+{
+  GstStructure *result_s = gst_caps_get_structure (result, 0);
+  GstStructure *caps_s = gst_caps_get_structure (caps, 0);
+
+  const GValue *result_field = gst_structure_get_value (result_s, field_name);
+  const GValue *caps_field = gst_structure_get_value (caps_s, field_name);
+
+  if (result_field == NULL && caps_field != NULL)
+    gst_structure_set_value (result_s, field_name, caps_field);
+}
 
 static GstCaps *
 gst_video_convert_fixate_caps (GstBaseTransform * trans,
@@ -366,6 +380,10 @@ gst_video_convert_fixate_caps (GstBaseTransform * trans,
   if (direction == GST_PAD_SINK) {
     if (gst_caps_is_subset (caps, result)) {
       gst_caps_replace (&result, caps);
+    } else {
+      /* Transfer colorimetry and chroma-site from input caps if downstream had no preference */
+      transfer_field_from_upstream_caps (result, caps, "colorimetry");
+      transfer_field_from_upstream_caps (result, caps, "chroma-site");
     }
   }