videopool: re-indent all GstVaapiVideoPool related source code.

This commit is contained in:
Gwenole Beauchesne 2015-01-26 23:21:56 +01:00
parent f5af9d150e
commit e4e43cd842
7 changed files with 289 additions and 284 deletions

View file

@ -39,45 +39,45 @@
* *
* A pool of lazily allocated #GstVaapiImage objects. * A pool of lazily allocated #GstVaapiImage objects.
*/ */
struct _GstVaapiImagePool { struct _GstVaapiImagePool
/*< private >*/ {
GstVaapiVideoPool parent_instance; /*< private >*/
GstVaapiVideoPool parent_instance;
GstVideoFormat format; GstVideoFormat format;
guint width; guint width;
guint height; guint height;
}; };
static gboolean static gboolean
image_pool_init(GstVaapiVideoPool *base_pool, const GstVideoInfo *vip) image_pool_init (GstVaapiVideoPool * base_pool, const GstVideoInfo * vip)
{ {
GstVaapiImagePool * const pool = GST_VAAPI_IMAGE_POOL(base_pool); GstVaapiImagePool *const pool = GST_VAAPI_IMAGE_POOL (base_pool);
pool->format = GST_VIDEO_INFO_FORMAT(vip); pool->format = GST_VIDEO_INFO_FORMAT (vip);
pool->width = GST_VIDEO_INFO_WIDTH(vip); pool->width = GST_VIDEO_INFO_WIDTH (vip);
pool->height = GST_VIDEO_INFO_HEIGHT(vip); pool->height = GST_VIDEO_INFO_HEIGHT (vip);
return gst_vaapi_display_has_image_format(base_pool->display, pool->format); return gst_vaapi_display_has_image_format (base_pool->display, pool->format);
} }
static gpointer static gpointer
gst_vaapi_image_pool_alloc_object(GstVaapiVideoPool *base_pool) gst_vaapi_image_pool_alloc_object (GstVaapiVideoPool * base_pool)
{ {
GstVaapiImagePool * const pool = GST_VAAPI_IMAGE_POOL(base_pool); GstVaapiImagePool *const pool = GST_VAAPI_IMAGE_POOL (base_pool);
return gst_vaapi_image_new(base_pool->display, pool->format, return gst_vaapi_image_new (base_pool->display, pool->format,
pool->width, pool->height); pool->width, pool->height);
} }
static inline const GstVaapiMiniObjectClass * static inline const GstVaapiMiniObjectClass *
gst_vaapi_image_pool_class(void) gst_vaapi_image_pool_class (void)
{ {
static const GstVaapiVideoPoolClass GstVaapiImagePoolClass = { static const GstVaapiVideoPoolClass GstVaapiImagePoolClass = {
{ sizeof(GstVaapiImagePool), {sizeof (GstVaapiImagePool),
(GDestroyNotify)gst_vaapi_video_pool_finalize }, (GDestroyNotify) gst_vaapi_video_pool_finalize},
.alloc_object = gst_vaapi_image_pool_alloc_object
.alloc_object = gst_vaapi_image_pool_alloc_object };
}; return GST_VAAPI_MINI_OBJECT_CLASS (&GstVaapiImagePoolClass);
return GST_VAAPI_MINI_OBJECT_CLASS(&GstVaapiImagePoolClass);
} }
/** /**
@ -91,26 +91,26 @@ gst_vaapi_image_pool_class(void)
* Return value: the newly allocated #GstVaapiVideoPool * Return value: the newly allocated #GstVaapiVideoPool
*/ */
GstVaapiVideoPool * GstVaapiVideoPool *
gst_vaapi_image_pool_new(GstVaapiDisplay *display, const GstVideoInfo *vip) gst_vaapi_image_pool_new (GstVaapiDisplay * display, const GstVideoInfo * vip)
{ {
GstVaapiVideoPool *pool; GstVaapiVideoPool *pool;
g_return_val_if_fail(display != NULL, NULL); g_return_val_if_fail (display != NULL, NULL);
g_return_val_if_fail(vip != NULL, NULL); g_return_val_if_fail (vip != NULL, NULL);
pool = (GstVaapiVideoPool *) pool = (GstVaapiVideoPool *)
gst_vaapi_mini_object_new(gst_vaapi_image_pool_class()); gst_vaapi_mini_object_new (gst_vaapi_image_pool_class ());
if (!pool) if (!pool)
return NULL; return NULL;
gst_vaapi_video_pool_init(pool, display, gst_vaapi_video_pool_init (pool, display,
GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_IMAGE); GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_IMAGE);
if (!image_pool_init(pool, vip)) if (!image_pool_init (pool, vip))
goto error; goto error;
return pool; return pool;
error: error:
gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(pool)); gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (pool));
return NULL; return NULL;
} }

View file

@ -32,12 +32,12 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_IMAGE_POOL(obj) \ #define GST_VAAPI_IMAGE_POOL(obj) \
((GstVaapiImagePool *)(obj)) ((GstVaapiImagePool *)(obj))
typedef struct _GstVaapiImagePool GstVaapiImagePool; typedef struct _GstVaapiImagePool GstVaapiImagePool;
GstVaapiVideoPool * GstVaapiVideoPool *
gst_vaapi_image_pool_new(GstVaapiDisplay *display, const GstVideoInfo *vip); gst_vaapi_image_pool_new (GstVaapiDisplay * display, const GstVideoInfo * vip);
G_END_DECLS G_END_DECLS

View file

@ -39,63 +39,64 @@
* *
* A pool of lazily allocated #GstVaapiSurface objects. * A pool of lazily allocated #GstVaapiSurface objects.
*/ */
struct _GstVaapiSurfacePool { struct _GstVaapiSurfacePool
/*< private >*/ {
GstVaapiVideoPool parent_instance; /*< private >*/
GstVaapiVideoPool parent_instance;
GstVaapiChromaType chroma_type; GstVaapiChromaType chroma_type;
GstVideoFormat format; GstVideoFormat format;
guint width; guint width;
guint height; guint height;
}; };
static gboolean static gboolean
surface_pool_init(GstVaapiSurfacePool *pool, const GstVideoInfo *vip) surface_pool_init (GstVaapiSurfacePool * pool, const GstVideoInfo * vip)
{ {
pool->format = GST_VIDEO_INFO_FORMAT(vip); pool->format = GST_VIDEO_INFO_FORMAT (vip);
pool->width = GST_VIDEO_INFO_WIDTH(vip); pool->width = GST_VIDEO_INFO_WIDTH (vip);
pool->height = GST_VIDEO_INFO_HEIGHT(vip); pool->height = GST_VIDEO_INFO_HEIGHT (vip);
if (pool->format == GST_VIDEO_FORMAT_UNKNOWN) if (pool->format == GST_VIDEO_FORMAT_UNKNOWN)
return FALSE; return FALSE;
if (pool->format == GST_VIDEO_FORMAT_ENCODED) if (pool->format == GST_VIDEO_FORMAT_ENCODED)
pool->chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420; pool->chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
else else
pool->chroma_type = gst_vaapi_video_format_get_chroma_type(pool->format); pool->chroma_type = gst_vaapi_video_format_get_chroma_type (pool->format);
if (!pool->chroma_type) if (!pool->chroma_type)
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
static gpointer static gpointer
gst_vaapi_surface_pool_alloc_object(GstVaapiVideoPool *base_pool) gst_vaapi_surface_pool_alloc_object (GstVaapiVideoPool * base_pool)
{ {
GstVaapiSurfacePool * const pool = GST_VAAPI_SURFACE_POOL(base_pool); GstVaapiSurfacePool *const pool = GST_VAAPI_SURFACE_POOL (base_pool);
/* Try to allocate a surface with an explicit pixel format first */ /* Try to allocate a surface with an explicit pixel format first */
if (pool->format != GST_VIDEO_FORMAT_ENCODED) { if (pool->format != GST_VIDEO_FORMAT_ENCODED) {
GstVaapiSurface * const surface = gst_vaapi_surface_new_with_format( GstVaapiSurface *const surface =
base_pool->display, pool->format, pool->width, pool->height); gst_vaapi_surface_new_with_format (base_pool->display, pool->format,
if (surface) pool->width, pool->height);
return surface; if (surface)
} return surface;
}
/* Otherwise, fallback to the original interface, based on chroma format */ /* Otherwise, fallback to the original interface, based on chroma format */
return gst_vaapi_surface_new(base_pool->display, return gst_vaapi_surface_new (base_pool->display,
pool->chroma_type, pool->width, pool->height); pool->chroma_type, pool->width, pool->height);
} }
static inline const GstVaapiMiniObjectClass * static inline const GstVaapiMiniObjectClass *
gst_vaapi_surface_pool_class(void) gst_vaapi_surface_pool_class (void)
{ {
static const GstVaapiVideoPoolClass GstVaapiSurfacePoolClass = { static const GstVaapiVideoPoolClass GstVaapiSurfacePoolClass = {
{ sizeof(GstVaapiSurfacePool), {sizeof (GstVaapiSurfacePool),
(GDestroyNotify)gst_vaapi_video_pool_finalize }, (GDestroyNotify) gst_vaapi_video_pool_finalize},
.alloc_object = gst_vaapi_surface_pool_alloc_object
.alloc_object = gst_vaapi_surface_pool_alloc_object };
}; return GST_VAAPI_MINI_OBJECT_CLASS (&GstVaapiSurfacePoolClass);
return GST_VAAPI_MINI_OBJECT_CLASS(&GstVaapiSurfacePoolClass);
} }
/** /**
@ -109,25 +110,25 @@ gst_vaapi_surface_pool_class(void)
* Return value: the newly allocated #GstVaapiVideoPool * Return value: the newly allocated #GstVaapiVideoPool
*/ */
GstVaapiVideoPool * GstVaapiVideoPool *
gst_vaapi_surface_pool_new(GstVaapiDisplay *display, const GstVideoInfo *vip) gst_vaapi_surface_pool_new (GstVaapiDisplay * display, const GstVideoInfo * vip)
{ {
GstVaapiVideoPool *pool; GstVaapiVideoPool *pool;
g_return_val_if_fail(display != NULL, NULL); g_return_val_if_fail (display != NULL, NULL);
g_return_val_if_fail(vip != NULL, NULL); g_return_val_if_fail (vip != NULL, NULL);
pool = (GstVaapiVideoPool *) pool = (GstVaapiVideoPool *)
gst_vaapi_mini_object_new(gst_vaapi_surface_pool_class()); gst_vaapi_mini_object_new (gst_vaapi_surface_pool_class ());
if (!pool) if (!pool)
return NULL; return NULL;
gst_vaapi_video_pool_init(pool, display, gst_vaapi_video_pool_init (pool, display,
GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_SURFACE); GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_SURFACE);
if (!surface_pool_init(GST_VAAPI_SURFACE_POOL(pool), vip)) if (!surface_pool_init (GST_VAAPI_SURFACE_POOL (pool), vip))
goto error; goto error;
return pool; return pool;
error: error:
gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(pool)); gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (pool));
return NULL; return NULL;
} }

View file

@ -32,12 +32,13 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_SURFACE_POOL(obj) \ #define GST_VAAPI_SURFACE_POOL(obj) \
((GstVaapiSurfacePool *)(obj)) ((GstVaapiSurfacePool *)(obj))
typedef struct _GstVaapiSurfacePool GstVaapiSurfacePool; typedef struct _GstVaapiSurfacePool GstVaapiSurfacePool;
GstVaapiVideoPool * GstVaapiVideoPool *
gst_vaapi_surface_pool_new(GstVaapiDisplay *display, const GstVideoInfo *vip); gst_vaapi_surface_pool_new (GstVaapiDisplay * display,
const GstVideoInfo * vip);
G_END_DECLS G_END_DECLS

View file

@ -41,42 +41,42 @@
#undef gst_vaapi_video_pool_replace #undef gst_vaapi_video_pool_replace
#define GST_VAAPI_VIDEO_POOL_GET_CLASS(obj) \ #define GST_VAAPI_VIDEO_POOL_GET_CLASS(obj) \
gst_vaapi_video_pool_get_class(GST_VAAPI_VIDEO_POOL(obj)) gst_vaapi_video_pool_get_class (GST_VAAPI_VIDEO_POOL (obj))
static inline const GstVaapiVideoPoolClass * static inline const GstVaapiVideoPoolClass *
gst_vaapi_video_pool_get_class(GstVaapiVideoPool *pool) gst_vaapi_video_pool_get_class (GstVaapiVideoPool * pool)
{ {
return GST_VAAPI_VIDEO_POOL_CLASS(GST_VAAPI_MINI_OBJECT_GET_CLASS(pool)); return GST_VAAPI_VIDEO_POOL_CLASS (GST_VAAPI_MINI_OBJECT_GET_CLASS (pool));
} }
static inline gpointer static inline gpointer
gst_vaapi_video_pool_alloc_object(GstVaapiVideoPool *pool) gst_vaapi_video_pool_alloc_object (GstVaapiVideoPool * pool)
{ {
return GST_VAAPI_VIDEO_POOL_GET_CLASS(pool)->alloc_object(pool); return GST_VAAPI_VIDEO_POOL_GET_CLASS (pool)->alloc_object (pool);
} }
void void
gst_vaapi_video_pool_init(GstVaapiVideoPool *pool, GstVaapiDisplay *display, gst_vaapi_video_pool_init (GstVaapiVideoPool * pool, GstVaapiDisplay * display,
GstVaapiVideoPoolObjectType object_type) GstVaapiVideoPoolObjectType object_type)
{ {
pool->object_type = object_type; pool->object_type = object_type;
pool->display = gst_vaapi_display_ref(display); pool->display = gst_vaapi_display_ref (display);
pool->used_objects = NULL; pool->used_objects = NULL;
pool->used_count = 0; pool->used_count = 0;
pool->capacity = 0; pool->capacity = 0;
g_queue_init(&pool->free_objects); g_queue_init (&pool->free_objects);
g_mutex_init(&pool->mutex); g_mutex_init (&pool->mutex);
} }
void void
gst_vaapi_video_pool_finalize(GstVaapiVideoPool *pool) gst_vaapi_video_pool_finalize (GstVaapiVideoPool * pool)
{ {
g_list_free_full(pool->used_objects, gst_vaapi_object_unref); 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_foreach (&pool->free_objects, (GFunc) gst_vaapi_object_unref, NULL);
g_queue_clear(&pool->free_objects); g_queue_clear (&pool->free_objects);
gst_vaapi_display_replace(&pool->display, NULL); gst_vaapi_display_replace (&pool->display, NULL);
g_mutex_clear(&pool->mutex); g_mutex_clear (&pool->mutex);
} }
/** /**
@ -88,9 +88,9 @@ gst_vaapi_video_pool_finalize(GstVaapiVideoPool *pool)
* Returns: The same @pool argument * Returns: The same @pool argument
*/ */
GstVaapiVideoPool * GstVaapiVideoPool *
gst_vaapi_video_pool_ref(GstVaapiVideoPool *pool) gst_vaapi_video_pool_ref (GstVaapiVideoPool * pool)
{ {
return gst_vaapi_video_pool_ref_internal(pool); return gst_vaapi_video_pool_ref_internal (pool);
} }
/** /**
@ -101,9 +101,9 @@ gst_vaapi_video_pool_ref(GstVaapiVideoPool *pool)
* the reference count reaches zero, the pool will be free'd. * the reference count reaches zero, the pool will be free'd.
*/ */
void void
gst_vaapi_video_pool_unref(GstVaapiVideoPool *pool) gst_vaapi_video_pool_unref (GstVaapiVideoPool * pool)
{ {
gst_vaapi_video_pool_unref_internal(pool); gst_vaapi_video_pool_unref_internal (pool);
} }
/** /**
@ -116,10 +116,10 @@ gst_vaapi_video_pool_unref(GstVaapiVideoPool *pool)
* pool. However, @new_pool can be NULL. * pool. However, @new_pool can be NULL.
*/ */
void void
gst_vaapi_video_pool_replace(GstVaapiVideoPool **old_pool_ptr, gst_vaapi_video_pool_replace (GstVaapiVideoPool ** old_pool_ptr,
GstVaapiVideoPool *new_pool) GstVaapiVideoPool * new_pool)
{ {
gst_vaapi_video_pool_replace_internal(old_pool_ptr, new_pool); gst_vaapi_video_pool_replace_internal (old_pool_ptr, new_pool);
} }
/** /**
@ -132,11 +132,11 @@ gst_vaapi_video_pool_replace(GstVaapiVideoPool **old_pool_ptr,
* Return value: the #GstVaapiDisplay the @pool is bound to * Return value: the #GstVaapiDisplay the @pool is bound to
*/ */
GstVaapiDisplay * GstVaapiDisplay *
gst_vaapi_video_pool_get_display(GstVaapiVideoPool *pool) gst_vaapi_video_pool_get_display (GstVaapiVideoPool * pool)
{ {
g_return_val_if_fail(pool != NULL, NULL); g_return_val_if_fail (pool != NULL, NULL);
return pool->display; return pool->display;
} }
/** /**
@ -149,11 +149,11 @@ gst_vaapi_video_pool_get_display(GstVaapiVideoPool *pool)
* objects * objects
*/ */
GstVaapiVideoPoolObjectType GstVaapiVideoPoolObjectType
gst_vaapi_video_pool_get_object_type(GstVaapiVideoPool *pool) gst_vaapi_video_pool_get_object_type (GstVaapiVideoPool * pool)
{ {
g_return_val_if_fail(pool != NULL, (GstVaapiVideoPoolObjectType)0); g_return_val_if_fail (pool != NULL, (GstVaapiVideoPoolObjectType) 0);
return pool->object_type; return pool->object_type;
} }
/** /**
@ -168,36 +168,36 @@ gst_vaapi_video_pool_get_object_type(GstVaapiVideoPool *pool)
* Return value: a possibly newly allocated object, or %NULL on error * Return value: a possibly newly allocated object, or %NULL on error
*/ */
static gpointer static gpointer
gst_vaapi_video_pool_get_object_unlocked(GstVaapiVideoPool *pool) gst_vaapi_video_pool_get_object_unlocked (GstVaapiVideoPool * pool)
{ {
gpointer object; gpointer object;
if (pool->capacity && pool->used_count >= pool->capacity) if (pool->capacity && pool->used_count >= pool->capacity)
return NULL; return NULL;
object = g_queue_pop_head(&pool->free_objects); object = g_queue_pop_head (&pool->free_objects);
if (!object) { if (!object) {
object = gst_vaapi_video_pool_alloc_object(pool); object = gst_vaapi_video_pool_alloc_object (pool);
if (!object) if (!object)
return NULL; return NULL;
} }
++pool->used_count; ++pool->used_count;
pool->used_objects = g_list_prepend(pool->used_objects, object); pool->used_objects = g_list_prepend (pool->used_objects, object);
return gst_vaapi_object_ref(object); return gst_vaapi_object_ref (object);
} }
gpointer gpointer
gst_vaapi_video_pool_get_object(GstVaapiVideoPool *pool) gst_vaapi_video_pool_get_object (GstVaapiVideoPool * pool)
{ {
gpointer object; gpointer object;
g_return_val_if_fail(pool != NULL, NULL); g_return_val_if_fail (pool != NULL, NULL);
g_mutex_lock(&pool->mutex); g_mutex_lock (&pool->mutex);
object = gst_vaapi_video_pool_get_object_unlocked(pool); object = gst_vaapi_video_pool_get_object_unlocked (pool);
g_mutex_unlock(&pool->mutex); g_mutex_unlock (&pool->mutex);
return object; return object;
} }
/** /**
@ -211,30 +211,30 @@ gst_vaapi_video_pool_get_object(GstVaapiVideoPool *pool)
* behaviour. * behaviour.
*/ */
static void static void
gst_vaapi_video_pool_put_object_unlocked(GstVaapiVideoPool *pool, gst_vaapi_video_pool_put_object_unlocked (GstVaapiVideoPool * pool,
gpointer object) gpointer object)
{ {
GList *elem; GList *elem;
elem = g_list_find(pool->used_objects, object); elem = g_list_find (pool->used_objects, object);
if (!elem) if (!elem)
return; return;
gst_vaapi_object_unref(object); gst_vaapi_object_unref (object);
--pool->used_count; --pool->used_count;
pool->used_objects = g_list_delete_link(pool->used_objects, elem); pool->used_objects = g_list_delete_link (pool->used_objects, elem);
g_queue_push_tail(&pool->free_objects, object); g_queue_push_tail (&pool->free_objects, object);
} }
void void
gst_vaapi_video_pool_put_object(GstVaapiVideoPool *pool, gpointer object) gst_vaapi_video_pool_put_object (GstVaapiVideoPool * pool, gpointer object)
{ {
g_return_if_fail(pool != NULL); g_return_if_fail (pool != NULL);
g_return_if_fail(object != NULL); g_return_if_fail (object != NULL);
g_mutex_lock(&pool->mutex); g_mutex_lock (&pool->mutex);
gst_vaapi_video_pool_put_object_unlocked(pool, object); gst_vaapi_video_pool_put_object_unlocked (pool, object);
g_mutex_unlock(&pool->mutex); g_mutex_unlock (&pool->mutex);
} }
/** /**
@ -249,25 +249,25 @@ gst_vaapi_video_pool_put_object(GstVaapiVideoPool *pool, gpointer object)
* Return value: %TRUE on success. * Return value: %TRUE on success.
*/ */
static inline gboolean static inline gboolean
gst_vaapi_video_pool_add_object_unlocked(GstVaapiVideoPool *pool, gst_vaapi_video_pool_add_object_unlocked (GstVaapiVideoPool * pool,
gpointer object) gpointer object)
{ {
g_queue_push_tail(&pool->free_objects, gst_vaapi_object_ref(object)); g_queue_push_tail (&pool->free_objects, gst_vaapi_object_ref (object));
return TRUE; return TRUE;
} }
gboolean gboolean
gst_vaapi_video_pool_add_object(GstVaapiVideoPool *pool, gpointer object) gst_vaapi_video_pool_add_object (GstVaapiVideoPool * pool, gpointer object)
{ {
gboolean success; gboolean success;
g_return_val_if_fail(pool != NULL, FALSE); g_return_val_if_fail (pool != NULL, FALSE);
g_return_val_if_fail(object != NULL, FALSE); g_return_val_if_fail (object != NULL, FALSE);
g_mutex_lock(&pool->mutex); g_mutex_lock (&pool->mutex);
success = gst_vaapi_video_pool_add_object_unlocked(pool, object); success = gst_vaapi_video_pool_add_object_unlocked (pool, object);
g_mutex_unlock(&pool->mutex); g_mutex_unlock (&pool->mutex);
return success; return success;
} }
/** /**
@ -282,30 +282,30 @@ gst_vaapi_video_pool_add_object(GstVaapiVideoPool *pool, gpointer object)
* Return value: %TRUE on success. * Return value: %TRUE on success.
*/ */
static gboolean static gboolean
gst_vaapi_video_pool_add_objects_unlocked(GstVaapiVideoPool *pool, gst_vaapi_video_pool_add_objects_unlocked (GstVaapiVideoPool * pool,
GPtrArray *objects) GPtrArray * objects)
{ {
guint i; guint i;
for (i = 0; i < objects->len; i++) { for (i = 0; i < objects->len; i++) {
gpointer const object = g_ptr_array_index(objects, i); gpointer const object = g_ptr_array_index (objects, i);
if (!gst_vaapi_video_pool_add_object_unlocked(pool, object)) if (!gst_vaapi_video_pool_add_object_unlocked (pool, object))
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
gboolean gboolean
gst_vaapi_video_pool_add_objects(GstVaapiVideoPool *pool, GPtrArray *objects) gst_vaapi_video_pool_add_objects (GstVaapiVideoPool * pool, GPtrArray * objects)
{ {
gboolean success; gboolean success;
g_return_val_if_fail(pool != NULL, FALSE); g_return_val_if_fail (pool != NULL, FALSE);
g_mutex_lock(&pool->mutex); g_mutex_lock (&pool->mutex);
success = gst_vaapi_video_pool_add_objects_unlocked(pool, objects); success = gst_vaapi_video_pool_add_objects_unlocked (pool, objects);
g_mutex_unlock(&pool->mutex); g_mutex_unlock (&pool->mutex);
return success; return success;
} }
/** /**
@ -317,16 +317,16 @@ gst_vaapi_video_pool_add_objects(GstVaapiVideoPool *pool, GPtrArray *objects)
* Return value: number of free objects in the pool * Return value: number of free objects in the pool
*/ */
guint guint
gst_vaapi_video_pool_get_size(GstVaapiVideoPool *pool) gst_vaapi_video_pool_get_size (GstVaapiVideoPool * pool)
{ {
guint size; guint size;
g_return_val_if_fail(pool != NULL, 0); g_return_val_if_fail (pool != NULL, 0);
g_mutex_lock(&pool->mutex); g_mutex_lock (&pool->mutex);
size = g_queue_get_length(&pool->free_objects); size = g_queue_get_length (&pool->free_objects);
g_mutex_unlock(&pool->mutex); g_mutex_unlock (&pool->mutex);
return size; return size;
} }
/** /**
@ -342,37 +342,37 @@ gst_vaapi_video_pool_get_size(GstVaapiVideoPool *pool)
* Return value: %TRUE on success * Return value: %TRUE on success
*/ */
static gboolean static gboolean
gst_vaapi_video_pool_reserve_unlocked(GstVaapiVideoPool *pool, guint n) gst_vaapi_video_pool_reserve_unlocked (GstVaapiVideoPool * pool, guint n)
{ {
guint i, num_allocated; guint i, num_allocated;
num_allocated = gst_vaapi_video_pool_get_size(pool) + pool->used_count; num_allocated = gst_vaapi_video_pool_get_size (pool) + pool->used_count;
if (n < num_allocated) if (n < num_allocated)
return TRUE;
if ((n -= num_allocated) > pool->capacity)
n = pool->capacity;
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; return TRUE;
if ((n -= num_allocated) > pool->capacity)
n = pool->capacity;
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;
} }
gboolean gboolean
gst_vaapi_video_pool_reserve(GstVaapiVideoPool *pool, guint n) gst_vaapi_video_pool_reserve (GstVaapiVideoPool * pool, guint n)
{ {
gboolean success; gboolean success;
g_return_val_if_fail(pool != NULL, 0); g_return_val_if_fail (pool != NULL, 0);
g_mutex_lock(&pool->mutex); g_mutex_lock (&pool->mutex);
success = gst_vaapi_video_pool_reserve_unlocked(pool, n); success = gst_vaapi_video_pool_reserve_unlocked (pool, n);
g_mutex_unlock(&pool->mutex); g_mutex_unlock (&pool->mutex);
return success; return success;
} }
/** /**
@ -385,17 +385,17 @@ gst_vaapi_video_pool_reserve(GstVaapiVideoPool *pool, guint n)
* Return value: the capacity of the pool * Return value: the capacity of the pool
*/ */
guint guint
gst_vaapi_video_pool_get_capacity(GstVaapiVideoPool *pool) gst_vaapi_video_pool_get_capacity (GstVaapiVideoPool * pool)
{ {
guint capacity; guint capacity;
g_return_val_if_fail(pool != NULL, 0); g_return_val_if_fail (pool != NULL, 0);
g_mutex_lock(&pool->mutex); g_mutex_lock (&pool->mutex);
capacity = pool->capacity; capacity = pool->capacity;
g_mutex_unlock(&pool->mutex); g_mutex_unlock (&pool->mutex);
return capacity; return capacity;
} }
/** /**
@ -406,11 +406,11 @@ gst_vaapi_video_pool_get_capacity(GstVaapiVideoPool *pool)
* Sets the maximum number of objects that can be allocated in the pool. * Sets the maximum number of objects that can be allocated in the pool.
*/ */
void void
gst_vaapi_video_pool_set_capacity(GstVaapiVideoPool *pool, guint capacity) gst_vaapi_video_pool_set_capacity (GstVaapiVideoPool * pool, guint capacity)
{ {
g_return_if_fail(pool != NULL); g_return_if_fail (pool != NULL);
g_mutex_lock(&pool->mutex); g_mutex_lock (&pool->mutex);
pool->capacity = capacity; pool->capacity = capacity;
g_mutex_unlock(&pool->mutex); g_mutex_unlock (&pool->mutex);
} }

View file

@ -31,9 +31,9 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_VIDEO_POOL(obj) \ #define GST_VAAPI_VIDEO_POOL(obj) \
((GstVaapiVideoPool *)(obj)) ((GstVaapiVideoPool *)(obj))
typedef struct _GstVaapiVideoPool GstVaapiVideoPool; typedef struct _GstVaapiVideoPool GstVaapiVideoPool;
/** /**
* GstVaapiVideoPoolObjectType: * GstVaapiVideoPoolObjectType:
@ -43,51 +43,53 @@ typedef struct _GstVaapiVideoPool GstVaapiVideoPool;
* *
* The set of all supported #GstVaapiVideoPool object types. * The set of all supported #GstVaapiVideoPool object types.
*/ */
typedef enum { typedef enum
GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_IMAGE = 1, {
GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_SURFACE, GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_IMAGE = 1,
GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_CODED_BUFFER GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_SURFACE,
GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_CODED_BUFFER
} GstVaapiVideoPoolObjectType; } GstVaapiVideoPoolObjectType;
GstVaapiVideoPool * GstVaapiVideoPool *
gst_vaapi_video_pool_ref(GstVaapiVideoPool *pool); gst_vaapi_video_pool_ref (GstVaapiVideoPool * pool);
void void
gst_vaapi_video_pool_unref(GstVaapiVideoPool *pool); gst_vaapi_video_pool_unref (GstVaapiVideoPool * pool);
void void
gst_vaapi_video_pool_replace(GstVaapiVideoPool **old_pool_ptr, gst_vaapi_video_pool_replace (GstVaapiVideoPool ** old_pool_ptr,
GstVaapiVideoPool *new_pool); GstVaapiVideoPool * new_pool);
GstVaapiDisplay * GstVaapiDisplay *
gst_vaapi_video_pool_get_display(GstVaapiVideoPool *pool); gst_vaapi_video_pool_get_display (GstVaapiVideoPool * pool);
GstVaapiVideoPoolObjectType GstVaapiVideoPoolObjectType
gst_vaapi_video_pool_get_object_type(GstVaapiVideoPool *pool); gst_vaapi_video_pool_get_object_type (GstVaapiVideoPool * pool);
gpointer gpointer
gst_vaapi_video_pool_get_object(GstVaapiVideoPool *pool); gst_vaapi_video_pool_get_object (GstVaapiVideoPool * pool);
void void
gst_vaapi_video_pool_put_object(GstVaapiVideoPool *pool, gpointer object); gst_vaapi_video_pool_put_object (GstVaapiVideoPool * pool, gpointer object);
gboolean gboolean
gst_vaapi_video_pool_add_object(GstVaapiVideoPool *pool, gpointer object); gst_vaapi_video_pool_add_object (GstVaapiVideoPool * pool, gpointer object);
gboolean gboolean
gst_vaapi_video_pool_add_objects(GstVaapiVideoPool *pool, GPtrArray *objects); gst_vaapi_video_pool_add_objects (GstVaapiVideoPool * pool,
GPtrArray * objects);
guint guint
gst_vaapi_video_pool_get_size(GstVaapiVideoPool *pool); gst_vaapi_video_pool_get_size (GstVaapiVideoPool * pool);
gboolean gboolean
gst_vaapi_video_pool_reserve(GstVaapiVideoPool *pool, guint n); gst_vaapi_video_pool_reserve (GstVaapiVideoPool * pool, guint n);
guint guint
gst_vaapi_video_pool_get_capacity(GstVaapiVideoPool *pool); gst_vaapi_video_pool_get_capacity (GstVaapiVideoPool * pool);
void void
gst_vaapi_video_pool_set_capacity(GstVaapiVideoPool *pool, guint capacity); gst_vaapi_video_pool_set_capacity (GstVaapiVideoPool * pool, guint capacity);
G_END_DECLS G_END_DECLS

View file

@ -30,29 +30,29 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_VIDEO_POOL_CLASS(klass) \ #define GST_VAAPI_VIDEO_POOL_CLASS(klass) \
((GstVaapiVideoPoolClass *)(klass)) ((GstVaapiVideoPoolClass *)(klass))
#define GST_VAAPI_IS_VIDEO_POOL_CLASS(klass) \
((klass) != NULL)
#define GST_VAAPI_IS_VIDEO_POOL_CLASS(klass) \ typedef struct _GstVaapiVideoPoolClass GstVaapiVideoPoolClass;
((klass) != NULL)
typedef struct _GstVaapiVideoPoolClass GstVaapiVideoPoolClass;
/** /**
* GstVaapiVideoPool: * GstVaapiVideoPool:
* *
* A pool of lazily allocated video objects. e.g. surfaces, images. * A pool of lazily allocated video objects. e.g. surfaces, images.
*/ */
struct _GstVaapiVideoPool { struct _GstVaapiVideoPool
/*< private >*/ {
GstVaapiMiniObject parent_instance; /*< private >*/
GstVaapiMiniObject parent_instance;
guint object_type; guint object_type;
GstVaapiDisplay *display; GstVaapiDisplay *display;
GQueue free_objects; GQueue free_objects;
GList *used_objects; GList *used_objects;
guint used_count; guint used_count;
guint capacity; guint capacity;
GMutex mutex; GMutex mutex;
}; };
/** /**
@ -61,46 +61,47 @@ struct _GstVaapiVideoPool {
* *
* A pool base class used to hold video objects. e.g. surfaces, images. * A pool base class used to hold video objects. e.g. surfaces, images.
*/ */
struct _GstVaapiVideoPoolClass { struct _GstVaapiVideoPoolClass
/*< private >*/ {
GstVaapiMiniObjectClass parent_class; /*< private >*/
GstVaapiMiniObjectClass parent_class;
/*< public >*/ /*< public >*/
gpointer (*alloc_object)(GstVaapiVideoPool *pool); gpointer (*alloc_object) (GstVaapiVideoPool * pool);
}; };
G_GNUC_INTERNAL G_GNUC_INTERNAL
void void
gst_vaapi_video_pool_init(GstVaapiVideoPool *pool, GstVaapiDisplay *display, gst_vaapi_video_pool_init (GstVaapiVideoPool * pool, GstVaapiDisplay * display,
GstVaapiVideoPoolObjectType object_type); GstVaapiVideoPoolObjectType object_type);
G_GNUC_INTERNAL G_GNUC_INTERNAL
void void
gst_vaapi_video_pool_finalize(GstVaapiVideoPool *pool); gst_vaapi_video_pool_finalize (GstVaapiVideoPool * pool);
/* Internal aliases */ /* Internal aliases */
#define gst_vaapi_video_pool_ref_internal(pool) \ #define gst_vaapi_video_pool_ref_internal(pool) \
((gpointer)gst_vaapi_mini_object_ref(GST_VAAPI_MINI_OBJECT(pool))) ((gpointer)gst_vaapi_mini_object_ref (GST_VAAPI_MINI_OBJECT (pool)))
#define gst_vaapi_video_pool_unref_internal(pool) \ #define gst_vaapi_video_pool_unref_internal(pool) \
gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(pool)) gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (pool))
#define gst_vaapi_video_pool_replace_internal(old_pool_ptr, new_pool) \ #define gst_vaapi_video_pool_replace_internal(old_pool_ptr, new_pool) \
gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_pool_ptr), \ gst_vaapi_mini_object_replace ((GstVaapiMiniObject **)(old_pool_ptr), \
GST_VAAPI_MINI_OBJECT(new_pool)) GST_VAAPI_MINI_OBJECT (new_pool))
#undef gst_vaapi_video_pool_ref #undef gst_vaapi_video_pool_ref
#define gst_vaapi_video_pool_ref(pool) \ #define gst_vaapi_video_pool_ref(pool) \
gst_vaapi_video_pool_ref_internal((pool)) gst_vaapi_video_pool_ref_internal ((pool))
#undef gst_vaapi_video_pool_unref #undef gst_vaapi_video_pool_unref
#define gst_vaapi_video_pool_unref(pool) \ #define gst_vaapi_video_pool_unref(pool) \
gst_vaapi_video_pool_unref_internal((pool)) gst_vaapi_video_pool_unref_internal ((pool))
#undef gst_vaapi_video_pool_replace #undef gst_vaapi_video_pool_replace
#define gst_vaapi_video_pool_replace(old_pool_ptr, new_pool) \ #define gst_vaapi_video_pool_replace(old_pool_ptr, new_pool) \
gst_vaapi_video_pool_replace_internal((old_pool_ptr), (new_pool)) gst_vaapi_video_pool_replace_internal ((old_pool_ptr), (new_pool))
G_END_DECLS G_END_DECLS