From 21f4c31a525bbca9cabe68b74ddf8d05e7925da5 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Tue, 13 Oct 2020 15:28:24 +0800 Subject: [PATCH] va: bufferpool: use release_buffer to clean the mem. The current bufferpool wastes all pre-allocate buffers when the buffer pool is actived. The pool->priv->size is 0 for va buffer pool. And every time, the reset_buffer() will clean all mem and make the buffer size 0, that can cache the gst_buffer in the buffer pool. But when the buffer pool is activing, the default_start() just allocate the buffer and release_buffer() immediately, all the pre allocated buffers and surfaces are destroyed because of gst_buffer_get_size (buffer) != pool->priv->size. We need to use release_buffer() to do the clean job at the pool start time. Part-of: --- sys/va/gstvapool.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sys/va/gstvapool.c b/sys/va/gstvapool.c index 63257bd..cd66998 100644 --- a/sys/va/gstvapool.c +++ b/sys/va/gstvapool.c @@ -249,16 +249,26 @@ 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 */ - if (G_LIKELY (!vpool->starting)) - gst_buffer_remove_all_memory (buffer); + gst_buffer_remove_all_memory (buffer); GST_BUFFER_POOL_CLASS (parent_class)->reset_buffer (pool, buffer); - if (G_LIKELY (!vpool->starting)) + GST_BUFFER_FLAGS (buffer) = 0; +} + +static void +gst_va_pool_release_buffer (GstBufferPool * pool, GstBuffer * buffer) +{ + GstVaPool *vpool = GST_VA_POOL (pool); + + /* Clears all the memories and only pool the GstBuffer objects */ + if (G_UNLIKELY (vpool->starting)) { + gst_buffer_remove_all_memory (buffer); GST_BUFFER_FLAGS (buffer) = 0; + } + + GST_BUFFER_POOL_CLASS (parent_class)->release_buffer (pool, buffer); } static GstFlowReturn @@ -337,6 +347,7 @@ gst_va_pool_class_init (GstVaPoolClass * klass) gstbufferpool_class->set_config = gst_va_pool_set_config; gstbufferpool_class->alloc_buffer = gst_va_pool_alloc; gstbufferpool_class->reset_buffer = gst_va_pool_reset_buffer; + gstbufferpool_class->release_buffer = gst_va_pool_release_buffer; gstbufferpool_class->acquire_buffer = gst_va_pool_acquire_buffer; gstbufferpool_class->flush_start = gst_va_pool_flush_start; gstbufferpool_class->start = gst_va_pool_start; -- 2.7.4