From 8292acfdd458419db836d1b8ca01151779447313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Tue, 31 May 2016 08:26:33 +0200 Subject: [PATCH] plugins: cache VASurfaces from dmabufs This patch avoids the creation of a VASurface each time a new input buffer is processed, caching them in the input buffer itself. https://bugzilla.gnome.org/show_bug.cgi?id=765435 --- gst/vaapi/gstvaapipluginbase.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/gst/vaapi/gstvaapipluginbase.c b/gst/vaapi/gstvaapipluginbase.c index b623abd293..e631b74d44 100644 --- a/gst/vaapi/gstvaapipluginbase.c +++ b/gst/vaapi/gstvaapipluginbase.c @@ -145,6 +145,21 @@ default_display_changed (GstVaapiPluginBase * plugin) { } +static GstVaapiSurface * +_get_cached_surface (GstBuffer * buf) +{ + return gst_mini_object_get_qdata (GST_MINI_OBJECT (buf), + g_quark_from_static_string ("GstVaapiDMABufSurface")); +} + +static void +_set_cached_surface (GstBuffer * buf, GstVaapiSurface * surface) +{ + return gst_mini_object_set_qdata (GST_MINI_OBJECT (buf), + g_quark_from_static_string ("GstVaapiDMABufSurface"), surface, + (GDestroyNotify) gst_vaapi_object_unref); +} + static gboolean plugin_update_sinkpad_info_from_buffer (GstVaapiPluginBase * plugin, GstBuffer * buf) @@ -205,13 +220,18 @@ plugin_bind_dma_to_vaapi_buffer (GstVaapiPluginBase * plugin, meta = gst_buffer_get_vaapi_video_meta (outbuf); g_return_val_if_fail (meta != NULL, FALSE); - surface = - gst_vaapi_surface_new_with_dma_buf_handle (plugin->display, fd, vip); - if (!surface) - goto error_create_surface; + /* Check for a VASurface cached in the buffer */ + surface = _get_cached_surface (inbuf); + if (!surface) { + /* otherwise create one and cache it */ + surface = + gst_vaapi_surface_new_with_dma_buf_handle (plugin->display, fd, vip); + if (!surface) + goto error_create_surface; + _set_cached_surface (inbuf, surface); + } proxy = gst_vaapi_surface_proxy_new (surface); - gst_vaapi_object_unref (surface); if (!proxy) goto error_create_proxy;