From 8deec238cba69818d32af78f516cb9dd728863d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Sun, 7 Feb 2021 16:12:56 +0100 Subject: [PATCH] va: pool: use allocator pool at alloc() Check if the allocator pool has memories available before creating a new one, but only iif pool is not starting. Part-of: --- sys/va/gstvaallocator.c | 11 +++++++++++ sys/va/gstvaallocator.h | 2 ++ sys/va/gstvapool.c | 20 ++++++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/sys/va/gstvaallocator.c b/sys/va/gstvaallocator.c index a16d250afe..98c5fb0cb4 100644 --- a/sys/va/gstvaallocator.c +++ b/sys/va/gstvaallocator.c @@ -1389,6 +1389,17 @@ gst_va_allocator_new (GstVaDisplay * display, GArray * surface_formats) return GST_ALLOCATOR (self); } +gboolean +gst_va_allocator_setup_buffer (GstAllocator * allocator, GstBuffer * buffer) +{ + GstMemory *mem = gst_va_allocator_alloc (allocator); + if (!mem) + return FALSE; + + gst_buffer_append_memory (buffer, mem); + return TRUE; +} + static VASurfaceID gst_va_allocator_prepare_buffer_unlocked (GstVaAllocator * self, GstBuffer * buffer) diff --git a/sys/va/gstvaallocator.h b/sys/va/gstvaallocator.h index 4324e70dbc..2dca1292c8 100644 --- a/sys/va/gstvaallocator.h +++ b/sys/va/gstvaallocator.h @@ -64,6 +64,8 @@ G_DECLARE_FINAL_TYPE (GstVaAllocator, gst_va_allocator, GST, VA_ALLOCATOR, GstAl GstAllocator * gst_va_allocator_new (GstVaDisplay * display, GArray * surface_formats); GstMemory * gst_va_allocator_alloc (GstAllocator * allocator); +gboolean gst_va_allocator_setup_buffer (GstAllocator * allocator, + GstBuffer * buffer); gboolean gst_va_allocator_prepare_buffer (GstAllocator * allocator, GstBuffer * buffer); gboolean gst_va_allocator_wait_for_memory (GstAllocator * allocator, diff --git a/sys/va/gstvapool.c b/sys/va/gstvapool.c index 31753efb57..23f6854258 100644 --- a/sys/va/gstvapool.c +++ b/sys/va/gstvapool.c @@ -228,13 +228,21 @@ gst_va_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer, buf = gst_buffer_new (); if (GST_IS_VA_DMABUF_ALLOCATOR (vpool->allocator)) { - if (!gst_va_dmabuf_allocator_setup_buffer (vpool->allocator, buf)) - goto no_memory; + if (vpool->starting) { + if (!gst_va_dmabuf_allocator_setup_buffer (vpool->allocator, buf)) + goto no_memory; + } else if (!gst_va_dmabuf_allocator_prepare_buffer (vpool->allocator, buf)) { + if (!gst_va_dmabuf_allocator_setup_buffer (vpool->allocator, buf)) + goto no_memory; + } } else if (GST_IS_VA_ALLOCATOR (vpool->allocator)) { - GstMemory *mem = gst_va_allocator_alloc (vpool->allocator); - if (!mem) - goto no_memory; - gst_buffer_append_memory (buf, mem); + if (vpool->starting) { + if (!gst_va_allocator_setup_buffer (vpool->allocator, buf)) + goto no_memory; + } else if (!gst_va_allocator_prepare_buffer (vpool->allocator, buf)) { + if (!gst_va_allocator_setup_buffer (vpool->allocator, buf)) + goto no_memory; + } } else goto no_memory;