#include "gstbufferpool.h"
+
+#define GST_BUFFER_POOL_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BUFFER_POOL, GstBufferPoolPrivate))
+
+struct _GstBufferPoolPrivate
+{
+ guint min_buffers;
+ guint max_buffers;
+ guint size;
+ guint prefix;
+ guint postfix;
+ guint align;
+};
+
enum
{
/* add more above */
static void default_set_flushing (GstBufferPool * pool, gboolean flushing);
static gboolean default_set_config (GstBufferPool * pool,
- GstBufferPoolConfig * config);
+ GstStructure * config);
static GstFlowReturn default_alloc_buffer (GstBufferPool * pool,
- GstBuffer ** buffer, GstBufferPoolConfig * config,
- GstBufferPoolParams * params);
+ GstBuffer ** buffer, GstBufferPoolParams * params);
static GstFlowReturn default_acquire_buffer (GstBufferPool * pool,
GstBuffer ** buffer, GstBufferPoolParams * params);
static void default_free_buffer (GstBufferPool * pool, GstBuffer * buffer);
static void
gst_buffer_pool_init (GstBufferPool * pool)
{
- pool->config.align = 1;
+ pool->priv = GST_BUFFER_POOL_GET_PRIVATE (pool);
+
+ pool->config = gst_structure_new ("GstBufferPoolConfig",
+ "size", G_TYPE_UINT, 0,
+ "min-buffers", G_TYPE_UINT, 0,
+ "max-buffers", G_TYPE_UINT, 0,
+ "prefix", G_TYPE_UINT, 0,
+ "postfix", G_TYPE_UINT, 0, "align", G_TYPE_UINT, 1, NULL);
pool->poll = gst_poll_new_timer ();
pool->queue = gst_atomic_queue_new (10);
default_set_flushing (pool, TRUE);
}
static gboolean
-default_set_config (GstBufferPool * pool, GstBufferPoolConfig * config)
+default_set_config (GstBufferPool * pool, GstStructure * config)
{
guint i;
GstBufferPoolClass *pclass;
+ GstBufferPoolPrivate *priv = pool->priv;
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
+ /* parse the config and keep around */
+ gst_buffer_pool_config_get (config, &priv->size, &priv->min_buffers,
+ &priv->max_buffers, &priv->prefix, &priv->postfix, &priv->align);
+
/* we need to prealloc buffers */
- for (i = config->min_buffers; i > 0; i--) {
+ for (i = priv->min_buffers; i > 0; i--) {
GstBuffer *buffer;
if (G_LIKELY (pclass->alloc_buffer)) {
- if (!pclass->alloc_buffer (pool, &buffer, config, NULL))
+ if (!pclass->alloc_buffer (pool, &buffer, NULL))
return FALSE;
} else
return FALSE;
/**
* gst_buffer_pool_set_config:
* @pool: a #GstBufferPool
- * @config: a #GstBufferPoolConfig
+ * @config: a #GstStructure
*
* Set the configuration of the pool. The pool must be flushing or else this
* function will do nothing and return FALSE.
*
+ * @condfig is a #GstStructure that contains the configuration parameters for
+ * the pool. A default and mandatory set of parameters can be configured with
+ * gst_buffer_pool_config_set().
+ *
* Returns: TRUE when the configuration could be set.
*/
gboolean
-gst_buffer_pool_set_config (GstBufferPool * pool, GstBufferPoolConfig * config)
+gst_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
{
gboolean result;
GstBufferPoolClass *pclass;
else
result = FALSE;
- if (result)
- pool->config = *config;
+ if (result) {
+ if (pool->config)
+ gst_structure_free (pool->config);
+ pool->config = config;
+ }
return result;
}
/**
* gst_buffer_pool_get_config:
* @pool: a #GstBufferPool
- * @config: a #GstBufferPoolConfig
*
- * Get the current configuration of the pool.
+ * Get the current configuration of the pool. This configuration is read-only,
+ * use gst_structure_copy() to make a writable copy.
+ */
+const GstStructure *
+gst_buffer_pool_get_config (GstBufferPool * pool)
+{
+ g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), NULL);
+
+ return pool->config;
+}
+
+
+/**
+ * gst_buffer_pool_config_set:
+ * @pool: a #GstBufferPool
+ * @size: the size of each buffer, not including pre and post fix
+ * @min_buffers: the minimum amount of buffers to allocate.
+ * @max_buffers: the maximum amount of buffers to allocate or 0 for unlimited.
+ * @prefix: prefix each buffer with this many bytes
+ * @postfix: postfix each buffer with this many bytes
+ * @align: alignment of the buffer data.
+ *
+ * Configure @config with the given parameters.
*/
void
-gst_buffer_pool_get_config (GstBufferPool * pool, GstBufferPoolConfig * config)
+gst_buffer_pool_config_set (GstStructure * config, guint size,
+ guint min_buffers, guint max_buffers, guint prefix, guint postfix,
+ guint align)
+{
+ g_return_if_fail (config != NULL);
+
+ gst_structure_set (config,
+ "size", G_TYPE_UINT, size,
+ "min-buffers", G_TYPE_UINT, min_buffers,
+ "max-buffers", G_TYPE_UINT, max_buffers,
+ "prefix", G_TYPE_UINT, prefix,
+ "postfix", G_TYPE_UINT, postfix, "align", G_TYPE_UINT, align, NULL);
+}
+
+/**
+ * gst_buffer_pool_config_get:
+ * @pool: a #GstBufferPool
+ * @size: the size of each buffer, not including pre and post fix
+ * @min_buffers: the minimum amount of buffers to allocate.
+ * @max_buffers: the maximum amount of buffers to allocate or 0 for unlimited.
+ * @prefix: prefix each buffer with this many bytes
+ * @postfix: postfix each buffer with this many bytes
+ * @align: alignment of the buffer data.
+ *
+ * Get the configuration values from @config.
+ */
+gboolean
+gst_buffer_pool_config_get (GstStructure * config, guint * size,
+ guint * min_buffers, guint * max_buffers, guint * prefix, guint * postfix,
+ guint * align)
{
- *config = pool->config;
+ g_return_val_if_fail (config != NULL, FALSE);
+
+ return gst_structure_get (config,
+ "size", G_TYPE_UINT, size,
+ "min-buffers", G_TYPE_UINT, min_buffers,
+ "max-buffers", G_TYPE_UINT, max_buffers,
+ "prefix", G_TYPE_UINT, prefix,
+ "postfix", G_TYPE_UINT, postfix, "align", G_TYPE_UINT, align, NULL);
}
static GstFlowReturn
default_alloc_buffer (GstBufferPool * pool, GstBuffer ** buffer,
- GstBufferPoolConfig * config, GstBufferPoolParams * params)
+ GstBufferPoolParams * params)
{
guint size, align;
+ GstBufferPoolPrivate *priv = pool->priv;
*buffer = gst_buffer_new ();
- align = config->align - 1;
- size = config->prefix + config->postfix + config->size + align;
+ align = priv->align - 1;
+ size = priv->prefix + priv->postfix + priv->size + align;
if (size > 0) {
guint8 *memptr;
memptr = g_malloc (size);
GST_BUFFER_MALLOCDATA (*buffer) = memptr;
memptr = (guint8 *) ((guintptr) (memptr + align) & ~align);
- GST_BUFFER_DATA (*buffer) = memptr + config->prefix;
- GST_BUFFER_SIZE (*buffer) = config->size;
+ GST_BUFFER_DATA (*buffer) = memptr + priv->prefix;
+ GST_BUFFER_SIZE (*buffer) = priv->size;
}
return GST_FLOW_OK;
{
GstFlowReturn result;
GstBufferPoolClass *pclass;
+ GstBufferPoolPrivate *priv = pool->priv;
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
}
/* no buffer */
- if (pool->config.max_buffers == 0) {
+ if (priv->max_buffers == 0) {
/* no max_buffers, we allocate some more */
if (G_LIKELY (pclass->alloc_buffer))
- result = pclass->alloc_buffer (pool, buffer, &pool->config, params);
+ result = pclass->alloc_buffer (pool, buffer, params);
else
result = GST_FLOW_NOT_SUPPORTED;
break;
GstBufferPoolClass *pclass;
GstFlowReturn result;
+ g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), GST_FLOW_ERROR);
+ g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
+
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
if (G_LIKELY (pclass->acquire_buffer))
{
GstBufferPoolClass *pclass;
+ g_return_if_fail (GST_IS_BUFFER_POOL (pool));
+ g_return_if_fail (buffer != NULL);
+
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
if (G_LIKELY (pclass->release_buffer))
G_BEGIN_DECLS
typedef struct _GstBufferPool GstBufferPool;
+typedef struct _GstBufferPoolPrivate GstBufferPoolPrivate;
typedef struct _GstBufferPoolClass GstBufferPoolClass;
/**
} GstBufferPoolParams;
/**
- * GstBufferPoolAlloc:
- * @min_buffers: the minimum amount of buffers to allocate.
- * @max_buffers: the maximum amount of buffers to allocate or 0 for unlimited.
- * @size: the size of each buffer, not including pre and post fix
- * @prefix: prefix each buffer with this many bytes
- * @postfix: postfix each buffer with this many bytes
- * @align: alignment of the buffer data.
- *
- * Properties for controlling the allocation of buffers. Buffer memory will be
- * allocated with the given alignment and the returned buffers will have their
- * data pointer set to this memory + prefix.
- */
-typedef struct _GstBufferPoolConfig {
- guint min_buffers;
- guint max_buffers;
- guint size;
- guint prefix;
- guint postfix;
- guint align;
-} GstBufferPoolConfig;
-
-/**
* GstBufferPool:
* @mini_object: the parent structure
*
GstAtomicQueue *queue;
GstPoll *poll;
- GstBufferPoolConfig config;
+ GstStructure *config;
+
+ GstBufferPoolPrivate *priv;
gpointer _gst_reserved[GST_PADDING];
};
/* vmethods */
void (*set_flushing) (GstBufferPool *pool, gboolean flushing);
- gboolean (*set_config) (GstBufferPool *pool, GstBufferPoolConfig *config);
+ gboolean (*set_config) (GstBufferPool *pool, GstStructure *config);
GstFlowReturn (*acquire_buffer) (GstBufferPool *pool, GstBuffer **buffer,
GstBufferPoolParams *params);
GstFlowReturn (*alloc_buffer) (GstBufferPool *pool, GstBuffer **buffer,
- GstBufferPoolConfig *config,
GstBufferPoolParams *params);
void (*release_buffer) (GstBufferPool *pool, GstBuffer *buffer);
void (*free_buffer) (GstBufferPool *pool, GstBuffer *buffer);
GType gst_buffer_pool_get_type (void);
/* allocation */
-GstBufferPool * gst_buffer_pool_new (void);
-
+GstBufferPool * gst_buffer_pool_new (void);
/* state management */
-void gst_buffer_pool_set_flushing (GstBufferPool *pool, gboolean flushing);
+void gst_buffer_pool_set_flushing (GstBufferPool *pool, gboolean flushing);
+
+gboolean gst_buffer_pool_set_config (GstBufferPool *pool, GstStructure *config);
+const GstStructure * gst_buffer_pool_get_config (GstBufferPool *pool);
-gboolean gst_buffer_pool_set_config (GstBufferPool *pool, GstBufferPoolConfig *config);
-void gst_buffer_pool_get_config (GstBufferPool *pool, GstBufferPoolConfig *config);
+/* helpers for configuring the config structure */
+void gst_buffer_pool_config_set (GstStructure *config, guint size,
+ guint min_buffers, guint max_buffers,
+ guint prefix, guint postfix, guint align);
+gboolean gst_buffer_pool_config_get (GstStructure *config, guint *size,
+ guint *min_buffers, guint *max_buffers,
+ guint *prefix, guint *postfix, guint *align);
/* buffer management */
-GstFlowReturn gst_buffer_pool_acquire_buffer (GstBufferPool *pool, GstBuffer **buffer, GstBufferPoolParams *params);
-void gst_buffer_pool_release_buffer (GstBufferPool *pool, GstBuffer *buffer);
+GstFlowReturn gst_buffer_pool_acquire_buffer (GstBufferPool *pool, GstBuffer **buffer,
+ GstBufferPoolParams *params);
+void gst_buffer_pool_release_buffer (GstBufferPool *pool, GstBuffer *buffer);
G_END_DECLS