From 2c36610748ce2840690601f4ce09fa929f64aa8c Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 15 Feb 2018 19:32:19 +0100 Subject: [PATCH] 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 --- gst/vaapi/gstvaapipluginbase.c | 66 ++++++++++++++++++++++++++++++++++++++++++ gst/vaapi/gstvaapipluginbase.h | 6 ++++ 2 files changed, 72 insertions(+) diff --git a/gst/vaapi/gstvaapipluginbase.c b/gst/vaapi/gstvaapipluginbase.c index 568c42e..b5dd1df 100644 --- a/gst/vaapi/gstvaapipluginbase.c +++ b/gst/vaapi/gstvaapipluginbase.c @@ -34,6 +34,7 @@ # include #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 b58fdbe..c0d0749 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 */ -- 2.7.4