mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 00:36:51 +00:00
added a default bufferpool factory function. it reuses existing instances of bufferpool if requests are made for exis...
Original commit message from CVS: added a default bufferpool factory function. it reuses existing instances of bufferpool if requests are made for existing buffer sizes
This commit is contained in:
parent
acc22ba11c
commit
921392eee7
3 changed files with 77 additions and 0 deletions
|
@ -84,6 +84,7 @@ gst_init (int *argc, char **argv[])
|
|||
_gst_caps_initialize ();
|
||||
_gst_plugin_initialize ();
|
||||
_gst_buffer_initialize ();
|
||||
_gst_buffer_pool_initialize ();
|
||||
|
||||
/* register some standard builtin types */
|
||||
gst_elementfactory_new ("bin", gst_bin_get_type (), &gst_bin_details);
|
||||
|
|
|
@ -25,6 +25,18 @@
|
|||
|
||||
#include "gstbuffer.h"
|
||||
|
||||
static GMutex *default_pool_lock;
|
||||
static GHashTable *_default_pools;
|
||||
|
||||
static GstBuffer* gst_buffer_pool_default_create (GstBufferPool *pool, gpointer user_data);
|
||||
static void gst_buffer_pool_default_destroy (GstBufferPool *pool, GstBuffer *buffer, gpointer user_data);
|
||||
|
||||
void
|
||||
_gst_buffer_pool_initialize (void)
|
||||
{
|
||||
_default_pools = g_hash_table_new(NULL,NULL);
|
||||
default_pool_lock = g_mutex_new ();
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_buffer_pool_new:
|
||||
|
@ -138,3 +150,64 @@ gst_buffer_pool_destroy_buffer (GstBufferPool *pool,
|
|||
|
||||
pool->destroy_buffer (pool, buffer, pool->new_user_data);
|
||||
}
|
||||
|
||||
GstBufferPool*
|
||||
gst_buffer_pool_get_default (guint buffer_size, guint pool_size)
|
||||
{
|
||||
GstBufferPool *pool;
|
||||
GMemChunk *data_chunk;
|
||||
guint real_buffer_size;
|
||||
|
||||
// check for an existing GstBufferPool with the same buffer_size
|
||||
// (we won't worry about the pool_size)
|
||||
if ((pool = (GstBufferPool*)g_hash_table_lookup(_default_pools,GINT_TO_POINTER(buffer_size)))){
|
||||
return pool;
|
||||
}
|
||||
|
||||
// g_print("new buffer pool bytes:%d size:%d\n", buffer_size, pool_size);
|
||||
|
||||
// round up to the nearest 32 bytes for cache-line and other efficiencies
|
||||
real_buffer_size = ((buffer_size-1 / 32) + 1) * 32;
|
||||
|
||||
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_create_function (pool, gst_buffer_pool_default_create, data_chunk);
|
||||
gst_buffer_pool_set_destroy_function (pool, gst_buffer_pool_default_destroy, data_chunk);
|
||||
|
||||
g_hash_table_insert(_default_pools,GINT_TO_POINTER(buffer_size),pool);
|
||||
return pool;
|
||||
}
|
||||
|
||||
static GstBuffer*
|
||||
gst_buffer_pool_default_create (GstBufferPool *pool, gpointer user_data)
|
||||
{
|
||||
GMemChunk *data_chunk = (GMemChunk*)user_data;
|
||||
GstBuffer *buffer;
|
||||
|
||||
buffer = gst_buffer_new();
|
||||
GST_BUFFER_FLAG_SET(buffer,GST_BUFFER_DONTFREE);
|
||||
buffer->pool = pool;
|
||||
|
||||
g_mutex_lock (default_pool_lock);
|
||||
GST_BUFFER_DATA(buffer) = g_mem_chunk_alloc(data_chunk);
|
||||
g_mutex_unlock (default_pool_lock);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_buffer_pool_default_destroy (GstBufferPool *pool, GstBuffer *buffer, gpointer user_data)
|
||||
{
|
||||
GMemChunk *data_chunk = (GMemChunk*)user_data;
|
||||
gpointer data = GST_BUFFER_DATA(buffer);
|
||||
|
||||
g_mutex_lock (default_pool_lock);
|
||||
g_mem_chunk_free (data_chunk,data);
|
||||
g_mutex_unlock (default_pool_lock);
|
||||
|
||||
buffer->pool = NULL;
|
||||
gst_buffer_destroy (buffer);
|
||||
|
||||
}
|
||||
|
|
|
@ -67,6 +67,9 @@ void gst_buffer_pool_set_destroy_function (GstBufferPool *pool,
|
|||
/* destroying the buffer pool */
|
||||
void gst_buffer_pool_destroy (GstBufferPool *pool);
|
||||
|
||||
/* a default buffer pool implementation */
|
||||
GstBufferPool* gst_buffer_pool_get_default (guint buffer_size, guint pool_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
Loading…
Reference in a new issue