glcolorconvert: Improve passthrough check when no conversion is needed.
authorJan Schmidt <jan@centricular.com>
Sun, 3 May 2015 13:08:15 +0000 (23:08 +1000)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:32:00 +0000 (19:32 +0000)
Make the passthrough check contingent on only the fields we
can modify being unchanged, and pre-compute it when caps
change instead of checking on each buffer. Makes the passthrough
more lenient if consumers are lax about making input and output
caps complete.

gst-libs/gst/gl/gstglcolorconvert.c
gst-libs/gst/gl/gstglcolorconvert.h

index 4ff7c18..b99c2a4 100644 (file)
@@ -575,6 +575,35 @@ gst_gl_color_convert_reset (GstGLColorConvert * convert)
 }
 
 static gboolean
+_gst_gl_color_convert_can_passthrough (GstVideoInfo * in, GstVideoInfo * out)
+{
+  gint i;
+
+  if (GST_VIDEO_INFO_FORMAT (in) != GST_VIDEO_INFO_FORMAT (out))
+    return FALSE;
+  if (GST_VIDEO_INFO_WIDTH (in) != GST_VIDEO_INFO_WIDTH (out))
+    return FALSE;
+  if (GST_VIDEO_INFO_HEIGHT (in) != GST_VIDEO_INFO_HEIGHT (out))
+    return FALSE;
+  if (GST_VIDEO_INFO_SIZE (in) != GST_VIDEO_INFO_SIZE (out))
+    return FALSE;
+
+  for (i = 0; i < in->finfo->n_planes; i++) {
+    if (in->stride[i] != out->stride[i])
+      return FALSE;
+    if (in->offset[i] != out->offset[i])
+      return FALSE;
+  }
+
+  if (!gst_video_colorimetry_is_equal (&in->colorimetry, &out->colorimetry))
+    return FALSE;
+  if (in->chroma_site != out->chroma_site)
+    return FALSE;
+
+  return TRUE;
+}
+
+static gboolean
 _gst_gl_color_convert_set_caps_unlocked (GstGLColorConvert * convert,
     GstCaps * in_caps, GstCaps * out_caps)
 {
@@ -619,6 +648,19 @@ _gst_gl_color_convert_set_caps_unlocked (GstGLColorConvert * convert,
   convert->out_info = out_info;
   convert->initted = FALSE;
 
+  /* If input and output are identical, pass through directly */
+  convert->passthrough =
+      _gst_gl_color_convert_can_passthrough (&in_info, &out_info);
+#ifndef GST_DISABLE_GST_DEBUG
+  if (G_UNLIKELY (convert->passthrough))
+    GST_DEBUG_OBJECT (convert,
+        "Configuring passthrough mode for same in/out caps");
+  else {
+    GST_DEBUG_OBJECT (convert, "Color converting %" GST_PTR_FORMAT
+        " to %" GST_PTR_FORMAT, in_caps, out_caps);
+  }
+#endif
+
   return TRUE;
 }
 
@@ -730,7 +772,7 @@ _gst_gl_color_convert_perform_unlocked (GstGLColorConvert * convert,
   g_return_val_if_fail (convert != NULL, FALSE);
   g_return_val_if_fail (inbuf, FALSE);
 
-  if (gst_video_info_is_equal (&convert->in_info, &convert->out_info))
+  if (G_UNLIKELY (convert->passthrough))
     return gst_buffer_ref (inbuf);
 
   convert->inbuf = inbuf;
index 748ac90..4aa8985 100644 (file)
@@ -53,6 +53,7 @@ struct _GstGLColorConvert
   GstVideoInfo     out_info;
 
   gboolean         initted;
+  gboolean         passthrough;
 
   GstBuffer *    inbuf;
   GstBuffer *    outbuf;