From 6a8fa67f4238a354480aaddf58a4299a2ccb4956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 8 Oct 2020 10:26:54 +0200 Subject: [PATCH] va: pool: call parent's start() method Without preallocating buffers and memories a deadlock in pool allocator is highly probably since it might hit the case were buffer is returned to the pool but their memories are still hold by a copy downstream, without other preallocated buffers available. This kind of a hack, where buffer_reset() follow the normal path if it's called from start(). Part-of: --- sys/va/gstvapool.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/sys/va/gstvapool.c b/sys/va/gstvapool.c index a8f7d5ce20..b86a115a78 100644 --- a/sys/va/gstvapool.c +++ b/sys/va/gstvapool.c @@ -40,6 +40,8 @@ struct _GstVaPool gboolean add_videometa; gboolean need_alignment; GstVideoAlignment video_align; + + gboolean starting; }; #define gst_va_pool_parent_class parent_class @@ -223,10 +225,16 @@ no_memory: static void gst_va_pool_reset_buffer (GstBufferPool * pool, GstBuffer * buffer) { + GstVaPool *vpool = GST_VA_POOL (pool); + /* Clears all the memories and only pool the GstBuffer objects */ - gst_buffer_remove_all_memory (buffer); + if (G_LIKELY (!vpool->starting)) + gst_buffer_remove_all_memory (buffer); + GST_BUFFER_POOL_CLASS (parent_class)->reset_buffer (pool, buffer); - GST_BUFFER_FLAGS (buffer) = 0; + + if (G_LIKELY (!vpool->starting)) + GST_BUFFER_FLAGS (buffer) = 0; } static GstFlowReturn @@ -268,6 +276,19 @@ gst_va_pool_flush_start (GstBufferPool * pool) gst_va_allocator_flush (vpool->allocator); } +static gboolean +gst_va_pool_start (GstBufferPool * pool) +{ + GstVaPool *vpool = GST_VA_POOL (pool); + gboolean ret; + + vpool->starting = TRUE; + ret = GST_BUFFER_POOL_CLASS (parent_class)->start (pool); + vpool->starting = FALSE; + + return ret; +} + static void gst_va_pool_dispose (GObject * object) { @@ -294,7 +315,7 @@ gst_va_pool_class_init (GstVaPoolClass * klass) gstbufferpool_class->reset_buffer = gst_va_pool_reset_buffer; gstbufferpool_class->acquire_buffer = gst_va_pool_acquire_buffer; gstbufferpool_class->flush_start = gst_va_pool_flush_start; - gstbufferpool_class->start = NULL; + gstbufferpool_class->start = gst_va_pool_start; } static void