From e96a435756b78f477bc29c465c62554f26bb8bc3 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Thu, 30 May 2019 23:52:51 +0800 Subject: [PATCH] libs: videopool: fix undocumented behavior and counting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gst_vaapi_video_pool_reserve_unlocked() hit an undocumented behavoir because it locks twice the same mutex. Also, n had different meanings in the current code: as an increase value and as a new total of allocated surfaces. This patche removes the undocumented behavoir (usually a deadlock) and fixes the meaning of n as the new total of allocated surfaces. Signed-off-by: Víctor Manuel Jáquez Leal --- gst-libs/gst/vaapi/gstvaapivideopool.c | 32 ++++++++++++-------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapivideopool.c b/gst-libs/gst/vaapi/gstvaapivideopool.c index 52ed1e812a..e431b52d1c 100644 --- a/gst-libs/gst/vaapi/gstvaapivideopool.c +++ b/gst-libs/gst/vaapi/gstvaapivideopool.c @@ -328,30 +328,16 @@ gst_vaapi_video_pool_get_size (GstVaapiVideoPool * pool) return size; } -/** - * gst_vaapi_video_pool_reserve: - * @pool: a #GstVaapiVideoPool - * @n: the number of objects to pre-allocate - * - * Pre-allocates up to @n objects in the pool. If @n is less than or - * equal to the number of free and used objects in the pool, this call - * has no effect. Otherwise, it is a request for allocation of - * additional objects. - * - * Return value: %TRUE on success - */ static gboolean gst_vaapi_video_pool_reserve_unlocked (GstVaapiVideoPool * pool, guint n) { guint i, num_allocated; - num_allocated = gst_vaapi_video_pool_get_size (pool) + pool->used_count; - if (n < num_allocated) + num_allocated = g_queue_get_length (&pool->free_objects) + pool->used_count; + if (n <= num_allocated) return TRUE; - if ((n -= num_allocated) > pool->capacity) - n = pool->capacity; - + n = MIN (n, pool->capacity); for (i = num_allocated; i < n; i++) { gpointer object; @@ -365,6 +351,18 @@ gst_vaapi_video_pool_reserve_unlocked (GstVaapiVideoPool * pool, guint n) return TRUE; } +/** + * gst_vaapi_video_pool_reserve: + * @pool: a #GstVaapiVideoPool + * @n: the number of objects to pre-allocate + * + * Pre-allocates up to @n objects in the pool. If @n is less than or + * equal to the number of free and used objects in the pool, this call + * has no effect. Otherwise, it is a request for allocation of + * additional objects. + * + * Return value: %TRUE on success + */ gboolean gst_vaapi_video_pool_reserve (GstVaapiVideoPool * pool, guint n) { -- 2.34.1