From a1e8cb76e79ec8ca69ec048f37e54760a8f30798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Fri, 13 Nov 2020 20:20:47 +0100 Subject: [PATCH] va: allocator: dmabuf: destroy VASurface if no pooled buffer When gst_va_dmabuf_allocator_setup_buffer_full() receives info (not NULL) it is supposed that this buffer is not part of the allocator pool, so it has to be de-allocated as soon it is freed. This patch sets the destroy notify of the assigned GstVaBufferSurface if info is not NULL. Part-of: --- sys/va/gstvaallocator.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sys/va/gstvaallocator.c b/sys/va/gstvaallocator.c index 49d7825a40..0aeb75e80f 100644 --- a/sys/va/gstvaallocator.c +++ b/sys/va/gstvaallocator.c @@ -533,6 +533,7 @@ gst_va_dmabuf_allocator_setup_buffer_full (GstAllocator * allocator, VADRMPRIMESurfaceDescriptor desc = { 0, }; VASurfaceID surface; guint32 i, fourcc, rt_format, export_flags; + GDestroyNotify buffer_destroy = NULL; g_return_val_if_fail (GST_IS_VA_DMABUF_ALLOCATOR (allocator), FALSE); @@ -590,12 +591,18 @@ gst_va_dmabuf_allocator_setup_buffer_full (GstAllocator * allocator, gst_buffer_append_memory (buffer, mem); - if (G_LIKELY (!info)) + if (G_LIKELY (!info)) { GST_MINI_OBJECT (mem)->dispose = gst_va_dmabuf_memory_release; + } else { + /* if no @info, surface will be destroyed as soon as buffer is + * destroyed (e.g. gst_va_dmabuf_allocator_try()) */ + buf->display = gst_object_ref (self->display); + buffer_destroy = gst_va_buffer_surface_unref; + } g_atomic_int_add (&buf->ref_count, 1); gst_mini_object_set_qdata (GST_MINI_OBJECT (mem), - gst_va_buffer_surface_quark (), buf, NULL); + gst_va_buffer_surface_quark (), buf, buffer_destroy); *drm_mod = desc.objects[i].drm_format_modifier; gst_mini_object_set_qdata (GST_MINI_OBJECT (mem), gst_va_drm_mod_quark (),