hopefully the last commit on libgst wrt bufferpools

Original commit message from CVS:
hopefully the last commit on libgst wrt bufferpools
This commit is contained in:
Andy Wingo 2001-08-27 06:01:11 +00:00
parent 82a13836c2
commit b6a69722aa
3 changed files with 47 additions and 63 deletions

View file

@ -95,10 +95,12 @@ gst_buffer_new_from_pool (GstBufferPool *pool, guint64 location, gint size)
GstBuffer *buffer;
g_return_val_if_fail (pool != NULL, NULL);
g_return_val_if_fail (pool->new_buffer != NULL, NULL);
g_return_val_if_fail (pool->buffer_new != NULL, NULL);
buffer = pool->new_buffer (pool, location, size, pool->user_data);
buffer = pool->buffer_new (pool, location, size, pool->user_data);
buffer->pool = pool;
buffer->free = pool->buffer_free;
buffer->pool_private = pool->user_data;
return buffer;
}
@ -228,15 +230,8 @@ void gst_buffer_destroy (GstBuffer *buffer)
g_return_if_fail (buffer != NULL);
if (buffer->pool) {
GST_INFO (GST_CAT_BUFFER,"calling %sbuffer %p\'s pool destroy function", (buffer->parent?"sub":""),buffer);
buffer->pool->destroy_buffer(buffer->pool, buffer,
buffer->pool->user_data);
return;
}
GST_INFO (GST_CAT_BUFFER,"freeing %sbuffer %p", (buffer->parent?"sub":""),buffer);
// free the data only if there is some, DONTFREE isn't set, and not sub
if (GST_BUFFER_DATA (buffer) &&
!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_DONTFREE) &&

View file

@ -28,9 +28,9 @@
static GMutex *_default_pool_lock;
static GHashTable *_default_pools;
static GstBuffer* gst_buffer_pool_default_buffer_create (GstBufferPool *pool, gint64 location, gint size, gpointer user_data);
static void gst_buffer_pool_default_buffer_destroy (GstBufferPool *pool, GstBuffer *buffer, gpointer user_data);
static void gst_buffer_pool_default_pool_destroy_hook (GstBufferPool *pool, gpointer user_data);
static GstBuffer* gst_buffer_pool_default_buffer_new (GstBufferPool *pool, gint64 location, gint size, gpointer user_data);
static void gst_buffer_pool_default_buffer_free (GstBuffer *buffer);
static void gst_buffer_pool_default_destroy_hook (GstBufferPool *pool, gpointer user_data);
typedef struct _GstBufferPoolDefault GstBufferPoolDefault;
@ -155,7 +155,7 @@ gst_buffer_pool_unref (GstBufferPool *pool)
}
/**
* gst_buffer_pool_set_buffer_create_function:
* gst_buffer_pool_set_buffer_new_function:
* @pool: the pool to set the buffer create function for
* @create: the create function
*
@ -163,12 +163,12 @@ gst_buffer_pool_unref (GstBufferPool *pool)
* from this pool.
*/
void
gst_buffer_pool_set_buffer_create_function (GstBufferPool *pool,
GstBufferPoolBufferCreateFunction create)
gst_buffer_pool_set_buffer_new_function (GstBufferPool *pool,
GstBufferPoolBufferNewFunction create)
{
g_return_if_fail (pool != NULL);
pool->new_buffer = create;
pool->buffer_new = create;
}
/**
@ -180,12 +180,12 @@ gst_buffer_pool_set_buffer_create_function (GstBufferPool *pool,
* from this pool.
*/
void
gst_buffer_pool_set_buffer_destroy_function (GstBufferPool *pool,
GstBufferPoolBufferDestroyFunction destroy)
gst_buffer_pool_set_buffer_free_function (GstBufferPool *pool,
GstBufferFreeFunc destroy)
{
g_return_if_fail (pool != NULL);
pool->destroy_buffer = destroy;
pool->buffer_free = destroy;
}
/**
@ -198,11 +198,11 @@ gst_buffer_pool_set_buffer_destroy_function (GstBufferPool *pool,
*/
void
gst_buffer_pool_set_pool_destroy_hook (GstBufferPool *pool,
GstBufferPoolPoolDestroyHook destroy)
GstBufferPoolDestroyHook destroy)
{
g_return_if_fail (pool != NULL);
pool->destroy_pool_hook = destroy;
pool->destroy_hook = destroy;
}
/**
@ -250,15 +250,14 @@ gst_buffer_pool_destroy (GstBufferPool *pool)
{
g_return_if_fail (pool != NULL);
if (pool->destroy_pool_hook)
pool->destroy_pool_hook (pool, pool->user_data);
if (pool->destroy_hook)
pool->destroy_hook (pool, pool->user_data);
g_free(pool);
}
/**
* gst_buffer_pool_get_default:
* @oldpool: instance of GstBufferPool which is no longer required (or NULL if it doesn't exist)
* @buffer_size: the number of bytes this buffer will store
* @pool_size: the default number of buffers to be preallocated
*
@ -270,7 +269,7 @@ gst_buffer_pool_destroy (GstBufferPool *pool)
* Returns: an instance of GstBufferPool
*/
GstBufferPool*
gst_buffer_pool_get_default (GstBufferPool *oldpool, guint buffer_size, guint pool_size)
gst_buffer_pool_get_default (guint buffer_size, guint pool_size)
{
GstBufferPool *pool;
GMemChunk *data_chunk;
@ -287,24 +286,17 @@ gst_buffer_pool_get_default (GstBufferPool *oldpool, guint buffer_size, guint po
g_mutex_unlock (_default_pool_lock);
if (pool != NULL){
if (oldpool != pool){
gst_buffer_pool_ref(pool);
if (oldpool != NULL){
gst_buffer_pool_unref(oldpool);
}
}
gst_buffer_pool_ref(pool);
return pool;
}
data_chunk = g_mem_chunk_new ("GstBufferPoolDefault", real_buffer_size,
real_buffer_size * pool_size, G_ALLOC_AND_FREE);
pool = gst_buffer_pool_new();
gst_buffer_pool_set_buffer_create_function (pool, gst_buffer_pool_default_buffer_create);
gst_buffer_pool_set_buffer_destroy_function (pool, gst_buffer_pool_default_buffer_destroy);
gst_buffer_pool_set_pool_destroy_hook (pool, gst_buffer_pool_default_pool_destroy_hook);
gst_buffer_pool_set_buffer_new_function (pool, gst_buffer_pool_default_buffer_new);
gst_buffer_pool_set_buffer_free_function (pool, gst_buffer_pool_default_buffer_free);
gst_buffer_pool_set_destroy_hook (pool, gst_buffer_pool_default_destroy_hook);
def = g_new0 (GstBufferPoolDefault, 1);
def->size = buffer_size;
@ -317,15 +309,12 @@ gst_buffer_pool_get_default (GstBufferPool *oldpool, guint buffer_size, guint po
GST_DEBUG(GST_CAT_BUFFER,"new buffer pool %p bytes:%d size:%d\n", pool, real_buffer_size, pool_size);
if (oldpool != NULL){
gst_buffer_pool_unref(oldpool);
}
return pool;
}
static GstBuffer*
gst_buffer_pool_default_buffer_create (GstBufferPool *pool, gint64 location /*unused*/,
gint size /*unused*/, gpointer user_data)
gst_buffer_pool_default_buffer_new (GstBufferPool *pool, gint64 location /*unused*/,
gint size /*unused*/, gpointer user_data)
{
GstBuffer *buffer;
GstBufferPoolDefault *def = (GstBufferPoolDefault*) user_data;
@ -347,29 +336,30 @@ gst_buffer_pool_default_buffer_create (GstBufferPool *pool, gint64 location /*un
}
static void
gst_buffer_pool_default_buffer_destroy (GstBufferPool *pool, GstBuffer *buffer, gpointer user_data)
gst_buffer_pool_default_buffer_free (GstBuffer *buffer)
{
GstBufferPoolDefault *def = (GstBufferPoolDefault*) user_data;
GstBufferPool *pool = buffer->pool;
GstBufferPoolDefault *def = (GstBufferPoolDefault*) pool->user_data;
GMemChunk *data_chunk = def->mem_chunk;
gpointer data = GST_BUFFER_DATA(buffer);
g_mutex_lock (pool->lock);
g_mem_chunk_free (data_chunk,data);
g_mutex_unlock (pool->lock);
buffer->pool = NULL;
gst_buffer_pool_unref(pool);
gst_buffer_destroy (buffer);
}
static void
gst_buffer_pool_default_pool_destroy_hook (GstBufferPool *pool, gpointer user_data)
gst_buffer_pool_default_destroy_hook (GstBufferPool *pool, gpointer user_data)
{
GstBufferPoolDefault *def = (GstBufferPoolDefault*) user_data;
GMemChunk *data_chunk = def->mem_chunk;
GST_DEBUG(GST_CAT_BUFFER,"destroying default buffer pool %p\n", pool);
g_mutex_free (pool->lock);
g_mem_chunk_reset(data_chunk);
g_free(data_chunk);
g_free(def);

View file

@ -38,9 +38,8 @@ extern "C" {
typedef struct _GstBufferPool GstBufferPool;
typedef GstBuffer* (*GstBufferPoolBufferCreateFunction) (GstBufferPool *pool, gint64 location, gint size, gpointer user_data);
typedef void (*GstBufferPoolBufferDestroyFunction) (GstBufferPool *pool, GstBuffer *buffer, gpointer user_data);
typedef void (*GstBufferPoolPoolDestroyHook) (GstBufferPool *pool, gpointer user_data);
typedef GstBuffer* (*GstBufferPoolBufferNewFunction) (GstBufferPool *pool, gint64 location, gint size, gpointer user_data);
typedef void (*GstBufferPoolDestroyHook) (GstBufferPool *pool, gpointer user_data);
struct _GstBufferPool {
/* locking */
@ -55,9 +54,9 @@ struct _GstBufferPool {
#define GST_BUFFER_POOL_REFCOUNT(pool) (GST_BUFFER_POOL(pool)->refcount)
#endif
GstBufferPoolBufferCreateFunction new_buffer;
GstBufferPoolBufferDestroyFunction destroy_buffer;
GstBufferPoolPoolDestroyHook destroy_pool_hook;
GstBufferPoolBufferNewFunction buffer_new;
GstBufferFreeFunc buffer_free;
GstBufferPoolDestroyHook destroy_hook;
gpointer user_data;
};
@ -73,12 +72,12 @@ void gst_buffer_pool_ref_by_count (GstBufferPool *pool, int count);
void gst_buffer_pool_unref (GstBufferPool *buffer);
/* setting create and destroy functions */
void gst_buffer_pool_set_buffer_create_function (GstBufferPool *pool,
GstBufferPoolBufferCreateFunction create);
void gst_buffer_pool_set_buffer_destroy_function (GstBufferPool *pool,
GstBufferPoolBufferDestroyFunction destroy);
void gst_buffer_pool_set_pool_destroy_hook (GstBufferPool *pool,
GstBufferPoolPoolDestroyHook destroy);
void gst_buffer_pool_set_buffer_new_function (GstBufferPool *pool,
GstBufferPoolBufferNewFunction create);
void gst_buffer_pool_set_buffer_free_function (GstBufferPool *pool,
GstBufferFreeFunc destroy);
void gst_buffer_pool_set_destroy_hook (GstBufferPool *pool,
GstBufferPoolDestroyHook destroy);
void gst_buffer_pool_set_user_data (GstBufferPool *pool,
gpointer user_data);
gpointer gst_buffer_pool_get_user_data (GstBufferPool *pool,
@ -88,7 +87,7 @@ gpointer gst_buffer_pool_get_user_data (GstBufferPool *pool,
void gst_buffer_pool_destroy (GstBufferPool *pool);
/* a default buffer pool implementation */
GstBufferPool* gst_buffer_pool_get_default (GstBufferPool *oldpool, guint buffer_size, guint pool_size);
GstBufferPool* gst_buffer_pool_get_default (guint buffer_size, guint pool_size);
#ifdef __cplusplus
}