vapostproc: optimization for va memory to system memory only
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Wed, 21 Feb 2024 17:14:36 +0000 (18:14 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 23 Feb 2024 12:40:38 +0000 (12:40 +0000)
When the conversion is only caps feature from memory:VAMemory to system memory,
it's possible to optimize by doing a pseudo pass-through since the va-backed
buffers are the same for system memory buffers.

This change will also mitigates #2940

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

subprojects/gst-plugins-bad/sys/va/gstvavpp.c

index 44b045ae77f6740cedce2bfe0e6bef396d183847..f908d573a54cf402ada3ceb4f9a99d0edcfe3776 100644 (file)
@@ -125,6 +125,8 @@ struct _GstVaVpp
   gboolean has_hdr_meta;
   VAHdrMetaDataHDR10 hdr_meta;
 
+  gboolean pseudo_passthrough;
+
   GList *channels;
 };
 
@@ -818,6 +820,26 @@ gst_va_vpp_before_transform (GstBaseTransform * trans, GstBuffer * inbuf)
   GST_OBJECT_UNLOCK (self);
 }
 
+static GstFlowReturn
+gst_va_vpp_prepare_output_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
+    GstBuffer ** outbuf)
+{
+  GstVaVpp *self = GST_VA_VPP (trans);
+  GstVaBaseTransform *btrans = GST_VA_BASE_TRANSFORM (self);
+
+  if (((self->op_flags & VPP_CONVERT_FEATURE) == self->op_flags)
+      && gst_caps_is_vamemory (btrans->in_caps)
+      && gst_caps_is_raw (btrans->out_caps)) {
+    self->pseudo_passthrough = TRUE;
+    *outbuf = inbuf;
+    return GST_FLOW_OK;
+  }
+
+  self->pseudo_passthrough = FALSE;
+  return GST_BASE_TRANSFORM_CLASS (parent_class)->prepare_output_buffer (trans,
+      inbuf, outbuf);
+}
+
 static GstFlowReturn
 gst_va_vpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
     GstBuffer * outbuf)
@@ -835,6 +857,9 @@ gst_va_vpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
   if (res != GST_FLOW_OK)
     return res;
 
+  if (self->pseudo_passthrough && (inbuf == buf))
+    goto bail;
+
   /* *INDENT-OFF* */
   src = (GstVaSample) {
     .buffer = buf,
@@ -854,6 +879,7 @@ gst_va_vpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
     res = GST_BASE_TRANSFORM_FLOW_DROPPED;
   }
 
+bail:
   gst_buffer_unref (buf);
 
   return res;
@@ -2257,6 +2283,8 @@ gst_va_vpp_class_init (gpointer g_class, gpointer class_data)
   trans_class->transform_meta = GST_DEBUG_FUNCPTR (gst_va_vpp_transform_meta);
   trans_class->src_event = GST_DEBUG_FUNCPTR (gst_va_vpp_src_event);
   trans_class->sink_event = GST_DEBUG_FUNCPTR (gst_va_vpp_sink_event);
+  trans_class->prepare_output_buffer =
+      GST_DEBUG_FUNCPTR (gst_va_vpp_prepare_output_buffer);
 
   trans_class->transform_ip_on_passthrough = FALSE;