2010-03-12 23:47:47 +00:00
|
|
|
/*
|
|
|
|
* gstvaapivideopool.c - Video object pool abstraction
|
|
|
|
*
|
2012-01-16 09:41:10 +00:00
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
|
2013-11-22 05:37:12 +00:00
|
|
|
* Copyright (C) 2012-2013 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2010-03-12 23:47:47 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-03-12 23:47:47 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-03-12 23:47:47 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-06-14 11:51:41 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-03-12 23:47:47 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
2010-03-12 23:47:47 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-19 16:08:48 +00:00
|
|
|
/**
|
2010-03-24 08:16:32 +00:00
|
|
|
* SECTION:gstvaapivideopool
|
|
|
|
* @short_description: Video object pool abstraction
|
2010-03-19 16:08:48 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-30 17:12:59 +00:00
|
|
|
#include "sysdeps.h"
|
2010-03-12 23:47:47 +00:00
|
|
|
#include "gstvaapivideopool.h"
|
2013-05-03 09:01:12 +00:00
|
|
|
#include "gstvaapivideopool_priv.h"
|
2013-04-30 15:22:15 +00:00
|
|
|
#include "gstvaapiobject.h"
|
2010-03-12 23:47:47 +00:00
|
|
|
|
|
|
|
#define DEBUG 1
|
2010-03-16 09:17:41 +00:00
|
|
|
#include "gstvaapidebug.h"
|
2010-03-12 23:47:47 +00:00
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
/* Ensure those symbols are actually defined in the resulting libraries */
|
|
|
|
#undef gst_vaapi_video_pool_ref
|
|
|
|
#undef gst_vaapi_video_pool_unref
|
|
|
|
#undef gst_vaapi_video_pool_replace
|
2010-03-12 23:47:47 +00:00
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
#define GST_VAAPI_VIDEO_POOL_GET_CLASS(obj) \
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_get_class (GST_VAAPI_VIDEO_POOL (obj))
|
2010-03-12 23:47:47 +00:00
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
static inline const GstVaapiVideoPoolClass *
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_get_class (GstVaapiVideoPool * pool)
|
2010-04-21 15:03:31 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
return GST_VAAPI_VIDEO_POOL_CLASS (GST_VAAPI_MINI_OBJECT_GET_CLASS (pool));
|
2010-04-21 15:03:31 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
static inline gpointer
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_alloc_object (GstVaapiVideoPool * pool)
|
2010-03-12 23:47:47 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
return GST_VAAPI_VIDEO_POOL_GET_CLASS (pool)->alloc_object (pool);
|
2010-03-12 23:47:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
void
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_init (GstVaapiVideoPool * pool, GstVaapiDisplay * display,
|
2013-05-23 16:45:23 +00:00
|
|
|
GstVaapiVideoPoolObjectType object_type)
|
2010-03-12 23:47:47 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
pool->object_type = object_type;
|
|
|
|
pool->display = gst_vaapi_display_ref (display);
|
|
|
|
pool->used_objects = NULL;
|
|
|
|
pool->used_count = 0;
|
|
|
|
pool->capacity = 0;
|
|
|
|
|
|
|
|
g_queue_init (&pool->free_objects);
|
|
|
|
g_mutex_init (&pool->mutex);
|
2010-03-12 23:47:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
void
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_finalize (GstVaapiVideoPool * pool)
|
2010-03-12 23:47:47 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
g_list_free_full (pool->used_objects, gst_vaapi_object_unref);
|
|
|
|
g_queue_foreach (&pool->free_objects, (GFunc) gst_vaapi_object_unref, NULL);
|
|
|
|
g_queue_clear (&pool->free_objects);
|
|
|
|
gst_vaapi_display_replace (&pool->display, NULL);
|
|
|
|
g_mutex_clear (&pool->mutex);
|
2010-03-12 23:47:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_ref:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
|
|
|
*
|
|
|
|
* Atomically increases the reference count of the given @pool by one.
|
|
|
|
*
|
|
|
|
* Returns: The same @pool argument
|
|
|
|
*/
|
|
|
|
GstVaapiVideoPool *
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_ref (GstVaapiVideoPool * pool)
|
2010-03-12 23:47:47 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
return gst_vaapi_video_pool_ref_internal (pool);
|
2010-03-12 23:47:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_unref:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
|
|
|
*
|
|
|
|
* Atomically decreases the reference count of the @pool by one. If
|
|
|
|
* the reference count reaches zero, the pool will be free'd.
|
|
|
|
*/
|
|
|
|
void
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_unref (GstVaapiVideoPool * pool)
|
2010-03-12 23:47:47 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_unref_internal (pool);
|
2010-03-12 23:47:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_replace:
|
|
|
|
* @old_pool_ptr: a pointer to a #GstVaapiVideoPool
|
|
|
|
* @new_pool: a #GstVaapiVideoPool
|
|
|
|
*
|
|
|
|
* Atomically replaces the pool pool held in @old_pool_ptr with
|
|
|
|
* @new_pool. This means that @old_pool_ptr shall reference a valid
|
|
|
|
* pool. However, @new_pool can be NULL.
|
|
|
|
*/
|
|
|
|
void
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_replace (GstVaapiVideoPool ** old_pool_ptr,
|
|
|
|
GstVaapiVideoPool * new_pool)
|
2010-03-12 23:47:47 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_replace_internal (old_pool_ptr, new_pool);
|
2010-03-12 23:47:47 +00:00
|
|
|
}
|
|
|
|
|
2010-05-11 12:06:59 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_get_display:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
|
|
|
*
|
|
|
|
* Retrieves the #GstVaapiDisplay the @pool is bound to. The @pool
|
|
|
|
* owns the returned object and it shall not be unref'ed.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiDisplay the @pool is bound to
|
|
|
|
*/
|
|
|
|
GstVaapiDisplay *
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_get_display (GstVaapiVideoPool * pool)
|
2010-05-11 12:06:59 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_val_if_fail (pool != NULL, NULL);
|
2010-05-11 12:06:59 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
return pool->display;
|
2010-03-12 23:47:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-23 16:45:23 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_get_object_type:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
|
|
|
*
|
|
|
|
* Retrieves the type of objects the video @pool supports.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiVideoPoolObjectType of the underlying pool
|
|
|
|
* objects
|
|
|
|
*/
|
|
|
|
GstVaapiVideoPoolObjectType
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_get_object_type (GstVaapiVideoPool * pool)
|
2013-05-23 16:45:23 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_val_if_fail (pool != NULL, (GstVaapiVideoPoolObjectType) 0);
|
2013-05-23 16:45:23 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
return pool->object_type;
|
2013-05-23 16:45:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 16:08:48 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_get_object:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
|
|
|
*
|
|
|
|
* Retrieves a new object from the @pool, or allocates a new one if
|
|
|
|
* none was found. The @pool holds a reference on the returned object
|
|
|
|
* and thus shall be released through gst_vaapi_video_pool_put_object()
|
|
|
|
* when it's no longer needed.
|
|
|
|
*
|
|
|
|
* Return value: a possibly newly allocated object, or %NULL on error
|
|
|
|
*/
|
2013-08-29 05:44:22 +00:00
|
|
|
static gpointer
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_get_object_unlocked (GstVaapiVideoPool * pool)
|
2010-03-12 23:47:47 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
gpointer object;
|
2010-03-12 23:47:47 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
if (pool->capacity && pool->used_count >= pool->capacity)
|
|
|
|
return NULL;
|
2010-04-21 15:03:31 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
object = g_queue_pop_head (&pool->free_objects);
|
|
|
|
if (!object) {
|
|
|
|
object = gst_vaapi_video_pool_alloc_object (pool);
|
|
|
|
if (!object)
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-03-12 23:47:47 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
++pool->used_count;
|
|
|
|
pool->used_objects = g_list_prepend (pool->used_objects, object);
|
|
|
|
return gst_vaapi_object_ref (object);
|
2010-03-12 23:47:47 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 05:44:22 +00:00
|
|
|
gpointer
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_get_object (GstVaapiVideoPool * pool)
|
2013-08-29 05:44:22 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
gpointer object;
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_val_if_fail (pool != NULL, NULL);
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_mutex_lock (&pool->mutex);
|
|
|
|
object = gst_vaapi_video_pool_get_object_unlocked (pool);
|
|
|
|
g_mutex_unlock (&pool->mutex);
|
|
|
|
return object;
|
2013-08-29 05:44:22 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 16:08:48 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_put_object:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
2010-04-21 15:03:31 +00:00
|
|
|
* @object: the object to add back to the pool
|
2010-03-19 16:08:48 +00:00
|
|
|
*
|
|
|
|
* Pushes the @object back into the pool. The @object shall be
|
2010-04-21 15:03:31 +00:00
|
|
|
* obtained from the @pool through gst_vaapi_video_pool_get_object().
|
|
|
|
* Calling this function with an arbitrary object yields undefined
|
|
|
|
* behaviour.
|
2010-03-19 16:08:48 +00:00
|
|
|
*/
|
2013-08-29 05:44:22 +00:00
|
|
|
static void
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_put_object_unlocked (GstVaapiVideoPool * pool,
|
2013-08-29 05:44:22 +00:00
|
|
|
gpointer object)
|
2010-03-12 23:47:47 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
GList *elem;
|
2010-03-12 23:47:47 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
elem = g_list_find (pool->used_objects, object);
|
|
|
|
if (!elem)
|
|
|
|
return;
|
2010-03-12 23:47:47 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_object_unref (object);
|
|
|
|
--pool->used_count;
|
|
|
|
pool->used_objects = g_list_delete_link (pool->used_objects, elem);
|
|
|
|
g_queue_push_tail (&pool->free_objects, object);
|
2010-03-12 23:47:47 +00:00
|
|
|
}
|
2010-04-21 15:03:31 +00:00
|
|
|
|
2013-08-29 05:44:22 +00:00
|
|
|
void
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_put_object (GstVaapiVideoPool * pool, gpointer object)
|
2013-08-29 05:44:22 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_if_fail (pool != NULL);
|
|
|
|
g_return_if_fail (object != NULL);
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_mutex_lock (&pool->mutex);
|
|
|
|
gst_vaapi_video_pool_put_object_unlocked (pool, object);
|
|
|
|
g_mutex_unlock (&pool->mutex);
|
2013-08-29 05:44:22 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 15:03:31 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_add_object:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
|
|
|
* @object: the object to add to the pool
|
|
|
|
*
|
|
|
|
* Adds the @object to the pool. The pool then holds a reference on
|
|
|
|
* the @object. This operation does not change the capacity of the
|
|
|
|
* pool.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success.
|
|
|
|
*/
|
2013-08-29 05:44:22 +00:00
|
|
|
static inline gboolean
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_add_object_unlocked (GstVaapiVideoPool * pool,
|
2013-08-29 05:44:22 +00:00
|
|
|
gpointer object)
|
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
g_queue_push_tail (&pool->free_objects, gst_vaapi_object_ref (object));
|
|
|
|
return TRUE;
|
2013-08-29 05:44:22 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 15:03:31 +00:00
|
|
|
gboolean
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_add_object (GstVaapiVideoPool * pool, gpointer object)
|
2010-04-21 15:03:31 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
gboolean success;
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_val_if_fail (pool != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (object != NULL, FALSE);
|
2010-04-21 15:03:31 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_mutex_lock (&pool->mutex);
|
|
|
|
success = gst_vaapi_video_pool_add_object_unlocked (pool, object);
|
|
|
|
g_mutex_unlock (&pool->mutex);
|
|
|
|
return success;
|
2010-04-21 15:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_add_objects:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
|
|
|
* @objects: a #GPtrArray of objects
|
|
|
|
*
|
|
|
|
* Adds the @objects to the pool. The pool then holds a reference on
|
|
|
|
* the @objects. This operation does not change the capacity of the
|
|
|
|
* pool and is just a wrapper around gst_vaapi_video_pool_add_object().
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success.
|
|
|
|
*/
|
2013-08-29 05:44:22 +00:00
|
|
|
static gboolean
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_add_objects_unlocked (GstVaapiVideoPool * pool,
|
|
|
|
GPtrArray * objects)
|
2010-04-21 15:03:31 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < objects->len; i++) {
|
|
|
|
gpointer const object = g_ptr_array_index (objects, i);
|
|
|
|
if (!gst_vaapi_video_pool_add_object_unlocked (pool, object))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2010-04-21 15:03:31 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 05:44:22 +00:00
|
|
|
gboolean
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_add_objects (GstVaapiVideoPool * pool, GPtrArray * objects)
|
2013-08-29 05:44:22 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
gboolean success;
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_val_if_fail (pool != NULL, FALSE);
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_mutex_lock (&pool->mutex);
|
|
|
|
success = gst_vaapi_video_pool_add_objects_unlocked (pool, objects);
|
|
|
|
g_mutex_unlock (&pool->mutex);
|
|
|
|
return success;
|
2013-08-29 05:44:22 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 15:03:31 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_get_size:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
|
|
|
*
|
|
|
|
* Returns the number of free objects available in the pool.
|
|
|
|
*
|
|
|
|
* Return value: number of free objects in the pool
|
|
|
|
*/
|
|
|
|
guint
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_get_size (GstVaapiVideoPool * pool)
|
2010-04-21 15:03:31 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
guint size;
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_val_if_fail (pool != NULL, 0);
|
2010-04-21 15:03:31 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_mutex_lock (&pool->mutex);
|
|
|
|
size = g_queue_get_length (&pool->free_objects);
|
|
|
|
g_mutex_unlock (&pool->mutex);
|
|
|
|
return size;
|
2010-04-21 15:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2013-08-29 05:44:22 +00:00
|
|
|
static gboolean
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_reserve_unlocked (GstVaapiVideoPool * pool, guint n)
|
2010-04-21 15:03:31 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
guint i, num_allocated;
|
2010-04-21 15:03:31 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
num_allocated = gst_vaapi_video_pool_get_size (pool) + pool->used_count;
|
|
|
|
if (n < num_allocated)
|
|
|
|
return TRUE;
|
2010-04-21 15:03:31 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
if ((n -= num_allocated) > pool->capacity)
|
|
|
|
n = pool->capacity;
|
2010-04-21 15:03:31 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
for (i = num_allocated; i < n; i++) {
|
|
|
|
gpointer const object = gst_vaapi_video_pool_alloc_object (pool);
|
|
|
|
if (!object)
|
|
|
|
return FALSE;
|
|
|
|
g_queue_push_tail (&pool->free_objects, object);
|
|
|
|
}
|
|
|
|
return TRUE;
|
2010-04-21 15:03:31 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 05:44:22 +00:00
|
|
|
gboolean
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_reserve (GstVaapiVideoPool * pool, guint n)
|
2013-08-29 05:44:22 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
gboolean success;
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_val_if_fail (pool != NULL, 0);
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_mutex_lock (&pool->mutex);
|
|
|
|
success = gst_vaapi_video_pool_reserve_unlocked (pool, n);
|
|
|
|
g_mutex_unlock (&pool->mutex);
|
|
|
|
return success;
|
2013-08-29 05:44:22 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 15:03:31 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_get_capacity:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
|
|
|
*
|
|
|
|
* Returns the maximum number of objects in the pool. i.e. the maximum
|
|
|
|
* number of objects that can be returned by gst_vaapi_video_pool_get_object().
|
|
|
|
*
|
|
|
|
* Return value: the capacity of the pool
|
|
|
|
*/
|
|
|
|
guint
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_get_capacity (GstVaapiVideoPool * pool)
|
2010-04-21 15:03:31 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
guint capacity;
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_val_if_fail (pool != NULL, 0);
|
2010-04-21 15:03:31 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_mutex_lock (&pool->mutex);
|
|
|
|
capacity = pool->capacity;
|
|
|
|
g_mutex_unlock (&pool->mutex);
|
2013-08-29 05:44:22 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
return capacity;
|
2010-04-21 15:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_video_pool_set_capacity:
|
|
|
|
* @pool: a #GstVaapiVideoPool
|
|
|
|
* @capacity: the maximal capacity of the pool
|
|
|
|
*
|
|
|
|
* Sets the maximum number of objects that can be allocated in the pool.
|
|
|
|
*/
|
|
|
|
void
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_set_capacity (GstVaapiVideoPool * pool, guint capacity)
|
2010-04-21 15:03:31 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_if_fail (pool != NULL);
|
2010-04-21 15:03:31 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_mutex_lock (&pool->mutex);
|
|
|
|
pool->capacity = capacity;
|
|
|
|
g_mutex_unlock (&pool->mutex);
|
2010-04-21 15:03:31 +00:00
|
|
|
}
|