glfilter: Remove format information to allow color convert again
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>
Sun, 25 May 2014 13:03:32 +0000 (09:03 -0400)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:31:41 +0000 (19:31 +0000)
We also need to remove the format information,  as glfilter can do
color convertion. This code was imported from videoconvert.

https://bugzilla.gnome.org/show_bug.cgi?id=729861

gst-libs/gst/gl/gstglfilter.c

index 4007ac2..2d44686 100644 (file)
@@ -687,6 +687,41 @@ gst_gl_filter_set_caps_features (const GstCaps * caps,
   return tmp;
 }
 
+/* copies the given caps */
+static GstCaps *
+gst_gl_filter_caps_remove_format_info (GstCaps * caps)
+{
+  GstStructure *st;
+  GstCapsFeatures *f;
+  gint i, n;
+  GstCaps *res;
+
+  res = gst_caps_new_empty ();
+
+  n = gst_caps_get_size (caps);
+  for (i = 0; i < n; i++) {
+    st = gst_caps_get_structure (caps, i);
+    f = gst_caps_get_features (caps, i);
+
+    /* If this is already expressed by the existing caps
+     * skip this structure */
+    if (i > 0 && gst_caps_is_subset_structure_full (res, st, f))
+      continue;
+
+    st = gst_structure_copy (st);
+    /* Only remove format info for the cases when we can actually convert */
+    if (!gst_caps_features_is_any (f)
+        && gst_caps_features_is_equal (f,
+            GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))
+      gst_structure_remove_fields (st, "format", "colorimetry", "chroma-site",
+          NULL);
+
+    gst_caps_append_structure_full (res, st, gst_caps_features_copy (f));
+  }
+
+  return res;
+}
+
 static GstCaps *
 gst_gl_filter_transform_caps (GstBaseTransform * bt,
     GstPadDirection direction, GstCaps * caps, GstCaps * filter)
@@ -694,6 +729,8 @@ gst_gl_filter_transform_caps (GstBaseTransform * bt,
   GstCaps *tmp = NULL;
   GstCaps *result = NULL;
 
+  tmp = gst_caps_new_empty ();
+
   if (direction == GST_PAD_SINK) {
     GstCaps *glcaps = gst_gl_filter_set_caps_features (caps,
         GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
@@ -704,18 +741,15 @@ gst_gl_filter_transform_caps (GstBaseTransform * bt,
     GstCaps *uploadcaps = gst_gl_filter_set_caps_features (caps,
         GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META);
 
-    tmp = gst_caps_new_empty ();
-
     tmp = gst_caps_merge (tmp, glcaps);
 #if GST_GL_HAVE_PLATFORM_EGL
     tmp = gst_caps_merge (tmp, eglcaps);
 #endif
     tmp = gst_caps_merge (tmp, uploadcaps);
-    tmp = gst_caps_merge (tmp, gst_caps_copy (caps));
-  } else {
-    tmp = gst_caps_copy (caps);
   }
 
+  tmp = gst_caps_merge (tmp, gst_gl_filter_caps_remove_format_info (caps));
+
   if (filter) {
     result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
     gst_caps_unref (tmp);