summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2018-02-15 19:32:19 +0100
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2018-02-20 10:57:12 -0600
commit2c36610748ce2840690601f4ce09fa929f64aa8c (patch)
treea082b251ab524c5e9e84772dd21ff7912d7bebb9
parent5842e9cf879c8efb03a3e61d833be6627c8ad737 (diff)
plugins: add gst_vaapi_copy_va_buffer()
This helper function aims to copy buffers with VA memory to dumb buffers, when GstVideoMeta is not available dowstream. https://bugzilla.gnome.org/show_bug.cgi?id=785054
-rw-r--r--gst/vaapi/gstvaapipluginbase.c66
-rw-r--r--gst/vaapi/gstvaapipluginbase.h6
2 files changed, 72 insertions, 0 deletions
diff --git a/gst/vaapi/gstvaapipluginbase.c b/gst/vaapi/gstvaapipluginbase.c
index 568c42e7..b5dd1df5 100644
--- a/gst/vaapi/gstvaapipluginbase.c
+++ b/gst/vaapi/gstvaapipluginbase.c
@@ -34,6 +34,7 @@
# include <gst/gl/gl.h>
#endif
+GST_DEBUG_CATEGORY_STATIC (CAT_PERFORMANCE);
/* Default debug category is from the subclass */
#define GST_CAT_DEFAULT (plugin->debug_category)
@@ -1374,3 +1375,68 @@ gst_vaapi_plugin_base_set_srcpad_can_dmabuf (GstVaapiPluginBase * plugin,
"EGL_EXT_image_dma_buf_import"));
#endif
}
+
+static void
+_init_performance_debug (void)
+{
+#ifndef GST_DISABLE_GST_DEBUG
+ static volatile gsize _init = 0;
+
+ if (g_once_init_enter (&_init)) {
+ GST_DEBUG_CATEGORY_GET (CAT_PERFORMANCE, "GST_PERFORMANCE");
+ g_once_init_leave (&_init, 1);
+ }
+#endif
+}
+
+/**
+ * gst_vaapi_plugin_copy_va_buffer:
+ * @plugin: a #GstVaapiPluginBase
+ * @inbuf: a #GstBuffer with VA memory type
+ * @outbuf: a #GstBuffer with system allocated memory
+ *
+ * Copy @inbuf to @outbuf. This if required when downstream doesn't
+ * support GstVideoMeta, and since VA memory may have custom strides a
+ * frame copy is required.
+ *
+ * Returns: %FALSE if the copy failed, otherwise %TRUE. Also returns
+ * %TRUE if it is not required to do the copy
+ **/
+gboolean
+gst_vaapi_plugin_copy_va_buffer (GstVaapiPluginBase * plugin,
+ GstBuffer * inbuf, GstBuffer * outbuf)
+{
+ GstVideoMeta *vmeta;
+ GstVideoFrame src_frame, dst_frame;
+ gboolean success;
+
+ if (!plugin->copy_output_frame)
+ return TRUE;
+
+ /* inbuf shall have video meta */
+ vmeta = gst_buffer_get_video_meta (inbuf);
+ if (!vmeta)
+ return FALSE;
+
+ _init_performance_debug ();
+ GST_CAT_INFO (CAT_PERFORMANCE, "copying VA buffer to system memory buffer");
+
+ if (!gst_video_frame_map (&src_frame, &plugin->srcpad_info, inbuf,
+ GST_MAP_READ))
+ return FALSE;
+ if (!gst_video_frame_map (&dst_frame, &plugin->srcpad_info, outbuf,
+ GST_MAP_WRITE)) {
+ gst_video_frame_unmap (&src_frame);
+ return FALSE;
+ }
+ success = gst_video_frame_copy (&dst_frame, &src_frame);
+ gst_video_frame_unmap (&dst_frame);
+ gst_video_frame_unmap (&src_frame);
+
+ if (success) {
+ gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS
+ | GST_BUFFER_COPY_FLAGS, 0, -1);
+ }
+
+ return success;
+}
diff --git a/gst/vaapi/gstvaapipluginbase.h b/gst/vaapi/gstvaapipluginbase.h
index b58fdbea..c0d07496 100644
--- a/gst/vaapi/gstvaapipluginbase.h
+++ b/gst/vaapi/gstvaapipluginbase.h
@@ -258,6 +258,12 @@ void
gst_vaapi_plugin_base_set_srcpad_can_dmabuf (GstVaapiPluginBase * plugin,
GstObject * object);
+G_GNUC_INTERNAL
+gboolean
+gst_vaapi_plugin_copy_va_buffer (GstVaapiPluginBase * plugin,
+ GstBuffer * inbuf, GstBuffer * outbuf);
+
+
G_END_DECLS
#endif /* GST_VAAPI_PLUGIN_BASE_H */