GstBufferPool

## GstBufferPool GstBufferPool — Pool for buffers |

## Synopsis

    #include <gst/gst.h>

                        GstBufferPool;
    struct              GstBufferPoolClass;
    #define             GST_BUFFER_POOL_IS_FLUSHING         (pool)
    GstBufferPool *     gst_buffer_pool_new                 (void);
    gboolean            gst_buffer_pool_config_get_params   (GstStructure *config,
                                                             GstCaps **caps,
                                                             guint *size,
                                                             guint *min_buffers,
                                                             guint *max_buffers);
    void                gst_buffer_pool_config_set_params   (GstStructure *config,
                                                             GstCaps *caps,
                                                             guint size,
                                                             guint min_buffers,
                                                             guint max_buffers);
    gboolean            gst_buffer_pool_config_get_allocator
                                                            (GstStructure *config,
                                                             GstAllocator **allocator,
                                                             GstAllocationParams *params);
    void                gst_buffer_pool_config_set_allocator
                                                            (GstStructure *config,
                                                             GstAllocator *allocator,
                                                             const GstAllocationParams *params);
    guint               gst_buffer_pool_config_n_options    (GstStructure *config);
    void                gst_buffer_pool_config_add_option   (GstStructure *config,
                                                             const gchar *option);
    const gchar *       gst_buffer_pool_config_get_option   (GstStructure *config,
                                                             guint index);
    gboolean            gst_buffer_pool_config_has_option   (GstStructure *config,
                                                             const gchar *option);
    const gchar **      gst_buffer_pool_get_options         (GstBufferPool *pool);
    gboolean            gst_buffer_pool_has_option          (GstBufferPool *pool,
                                                             const gchar *option);
    GstStructure *      gst_buffer_pool_get_config          (GstBufferPool *pool);
    gboolean            gst_buffer_pool_set_config          (GstBufferPool *pool,
                                                             GstStructure *config);
    gboolean            gst_buffer_pool_set_active          (GstBufferPool *pool,
                                                             gboolean active);
    gboolean            gst_buffer_pool_is_active           (GstBufferPool *pool);
    enum                GstBufferPoolAcquireFlags;
    struct              GstBufferPoolAcquireParams;
    GstFlowReturn       gst_buffer_pool_acquire_buffer      (GstBufferPool *pool,
                                                             GstBuffer **buffer,
                                                             GstBufferPoolAcquireParams *params);
    void                gst_buffer_pool_release_buffer      (GstBufferPool *pool,
                                                             GstBuffer *buffer);

## Description

a GstBufferPool is an object that can be used to pre-allocate and recycle buffers of the same size and with the same properties.

A GstBufferPool is created with `gst_buffer_pool_new()`.

After the buffer is created, it needs to be configured. `gst_buffer_pool_get_config()` get the current configuration structure from the pool. With `gst_buffer_pool_config_set_params()` and `gst_buffer_pool_config_set_allocator()` the bufferpool parameters and allocator can be configured. Other properties can be configured in the pool depending on the pool implementation.

A bufferpool can have extra options that can be enabled with `gst_buffer_pool_config_add_option()`. The available options can be retrieved with `gst_buffer_pool_get_options()`. Some options allow for additional configuration properties to be set.

After the configuration structure has been configured, `gst_buffer_pool_set_config()` updates the configuration in the pool. This can fail when the configuration structure is not accepted.

After the a pool has been configured, it can be activated with `gst_buffer_pool_set_active()`. This will preallocate the configured resources in the pool.

When the pool is active, `gst_buffer_pool_acquire_buffer()` can be used to retrieve a buffer from the pool.

Buffer allocated from a bufferpool will automatically be returned to the pool with `gst_buffer_pool_release_buffer()` when their refcount drops to 0.

The bufferpool can be deactivated again with `gst_buffer_pool_set_active()`. All further `gst_buffer_pool_acquire_buffer()` calls will return an error. When all buffers are returned to the pool they will be freed.

Use `gst_object_unref()` to release the reference to a bufferpool. If the refcount of the pool reaches 0, the pool will be freed.

Last reviewed on 2012-03-28 (0.11.3)

## Details

### GstBufferPool

    typedef struct {
      GstObject            object;
    } GstBufferPool;

The structure of a GstBufferPool. Use the associated macros to access the public variables.

GstObject `object`; | the parent structure

### struct GstBufferPoolClass

    struct GstBufferPoolClass {
      GstObjectClass    object_class;

      /* vmethods */
      const gchar ** (*get_options)    (GstBufferPool *pool);
      gboolean       (*set_config)     (GstBufferPool *pool, GstStructure *config);

      gboolean       (*start)          (GstBufferPool *pool);
      gboolean       (*stop)           (GstBufferPool *pool);

      GstFlowReturn  (*acquire_buffer) (GstBufferPool *pool, GstBuffer **buffer,
                                        GstBufferPoolAcquireParams *params);
      GstFlowReturn  (*alloc_buffer)   (GstBufferPool *pool, GstBuffer **buffer,
                                        GstBufferPoolAcquireParams *params);
      void           (*reset_buffer)   (GstBufferPool *pool, GstBuffer *buffer);
      void           (*release_buffer) (GstBufferPool *pool, GstBuffer *buffer);
      void           (*free_buffer)    (GstBufferPool *pool, GstBuffer *buffer);
    };

The GstBufferPool class.

GstObjectClass `object_class`; | Object parent class
`get_options` () | get a list of options supported by this pool
`set_config` () | apply the bufferpool configuration. The default configuration will parse the default config parameters
`start` () | start the bufferpool. The default implementation will preallocate min-buffers buffers and put them in the queue
`stop` () | stop the bufferpool. the default implementation will free the preallocated buffers. This function is called when all the buffers are returned to the pool.
`acquire_buffer` () | get a new buffer from the pool. The default implementation will take a buffer from the queue and optionally wait for a buffer to be released when there are no buffers available.
`alloc_buffer` () | allocate a buffer. the default implementation allocates buffers from the configured memory allocator and with the configured parameters. All metadata that is present on the allocated buffer will be marked as GST_META_FLAG_POOLED and GST_META_FLAG_LOCKED and will not be removed from the buffer in `reset_buffer`.
`reset_buffer` () | reset the buffer to its state when it was freshly allocated. The default implementation will clear the flags, timestamps and will remove the metadata without the GST_META_FLAG_POOLED flag (even the metadata with GST_META_FLAG_LOCKED).
`release_buffer` () | release a buffer back in the pool. The default implementation will put the buffer back in the queue and notify any blocking acquire_buffer calls.
`free_buffer` () | free a buffer. The default implementation unrefs the buffer.

### GST_BUFFER_POOL_IS_FLUSHING()

    #define GST_BUFFER_POOL_IS_FLUSHING(pool)  (g_atomic_int_get (&pool->flushing))

Check if the bufferpool is flushing. Subclasses might want to check the state of the pool in the acquire function.

`pool` : | a GstBufferPool

### gst_buffer_pool_new ()

    GstBufferPool *     gst_buffer_pool_new                 (void);

Creates a new GstBufferPool instance.

Returns : | a new GstBufferPool instance. [transfer full]

### gst_buffer_pool_config_get_params ()

    gboolean            gst_buffer_pool_config_get_params   (GstStructure *config,
                                                             GstCaps **caps,
                                                             guint *size,
                                                             guint *min_buffers,
                                                             guint *max_buffers);

Get the configuration values from `config`.

`config` : | a GstBufferPool configuration. [transfer none]
`caps` : | the caps of buffers. [out][transfer none][allow-none]
`size` : | the size of each buffer, not including prefix and padding. [out][allow-none]
`min_buffers` : | the minimum amount of buffers to allocate. [out][allow-none]
`max_buffers` : | the maximum amount of buffers to allocate or 0 for unlimited. [out][allow-none]
Returns : | `TRUE` if all parameters could be fetched.

### gst_buffer_pool_config_set_params ()

    void                gst_buffer_pool_config_set_params   (GstStructure *config,
                                                             GstCaps *caps,
                                                             guint size,
                                                             guint min_buffers,
                                                             guint max_buffers);

Configure `config` with the given parameters.

`config` : | a GstBufferPool configuration
`caps` : | caps for the buffers
`size` : | the size of each buffer, not including prefix and padding
`min_buffers` : | the minimum amount of buffers to allocate.
`max_buffers` : | the maximum amount of buffers to allocate or 0 for unlimited.

### gst_buffer_pool_config_get_allocator ()

    gboolean            gst_buffer_pool_config_get_allocator
                                                            (GstStructure *config,
                                                             GstAllocator **allocator,
                                                             GstAllocationParams *params);

Get the allocator and params from `config`.

`config` : | a GstBufferPool configuration. [transfer none]
`allocator` : | a GstAllocator. [transfer none]
`params` : | GstAllocationParams

### gst_buffer_pool_config_set_allocator ()

    void                gst_buffer_pool_config_set_allocator
                                                            (GstStructure *config,
                                                             GstAllocator *allocator,
                                                             const GstAllocationParams *params);

Set the `allocator` and `params` on `config`.

One of `allocator` and `params` can be NULL, but not both. When `allocator` is NULL, the default allocator of the pool will use the values in `param` to perform its allocation. When `param` is NULL, the pool will use the provided allocator with its default GstAllocationParams.

A call to `gst_buffer_pool_set_config()` can update the allocator and params with the values that it is able to do. Some pools are, for example, not able to operate with different allocators or cannot allocate with the values specified in `params`. Use `gst_buffer_pool_get_config()` to get the currently used values.

`config` : | a GstBufferPool configuration
`allocator` : | a GstAllocator
`params` : | GstAllocationParams

### gst_buffer_pool_config_n_options ()

    guint               gst_buffer_pool_config_n_options    (GstStructure *config);

Retrieve the number of values currently stored in the options array of the `config` structure.

`config` : | a GstBufferPool configuration
Returns : | the options array size as a guint.

### gst_buffer_pool_config_add_option ()

    void                gst_buffer_pool_config_add_option   (GstStructure *config,
                                                             const gchar *option);

Enabled the option in `config`. This will instruct the `bufferpool` to enable the specified option on the buffers that it allocates.

The supported options by `pool` can be retrieved with `gst_buffer_pool_get_options()`.

`config` : | a GstBufferPool configuration
`option` : | an option to add

### gst_buffer_pool_config_get_option ()

    const gchar *       gst_buffer_pool_config_get_option   (GstStructure *config,
                                                             guint index);

Parse an available `config` and get the option at `index` of the options API array.

`config` : | a GstBufferPool configuration
`index` : | position in the option array to read
Returns : | a gchar of the option at `index`.

### gst_buffer_pool_config_has_option ()

    gboolean            gst_buffer_pool_config_has_option   (GstStructure *config,
                                                             const gchar *option);

Check if `config` contains `option`

`config` : | a GstBufferPool configuration
`option` : | an option
Returns : | TRUE if the options array contains `option`.

### gst_buffer_pool_get_options ()

    const gchar **      gst_buffer_pool_get_options         (GstBufferPool *pool);

Get a NULL terminated array of string with supported bufferpool options for `pool`. An option would typically be enabled with `gst_buffer_pool_config_add_option()`.

`pool` : | a GstBufferPool
Returns : | a NULL terminated array of strings. [array zero-terminated=1][transfer none]

### gst_buffer_pool_has_option ()

    gboolean            gst_buffer_pool_has_option          (GstBufferPool *pool,
                                                             const gchar *option);

Check if the bufferpool supports `option`.

`pool` : | a GstBufferPool
`option` : | an option
Returns : | a NULL terminated array of strings.

### gst_buffer_pool_get_config ()

    GstStructure *      gst_buffer_pool_get_config          (GstBufferPool *pool);

Get a copy of the current configuration of the pool. This configuration can either be modified and used for the `gst_buffer_pool_set_config()` call or it must be freed after usage.

`pool` : | a GstBufferPool
Returns : | a copy of the current configuration of `pool`. use `gst_structure_free()` after usage or `gst_buffer_pool_set_config()`. [transfer full]

### gst_buffer_pool_set_config ()

    gboolean            gst_buffer_pool_set_config          (GstBufferPool *pool,
                                                             GstStructure *config);

Set the configuration of the pool. The pool must be inactive and all buffers allocated form this pool must be returned or else this function will do nothing and return FALSE.

`config` 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_params()`, `gst_buffer_pool_config_set_allocator()` and `gst_buffer_pool_config_add_option()`.

If the parameters in `config` can not be set exactly, this function returns FALSE and will try to update as much state as possible. The new state can then be retrieved and refined with `gst_buffer_pool_get_config()`.

This function takes ownership of `config`.

`pool` : | a GstBufferPool
`config` : | a GstStructure. [transfer full]
Returns : | TRUE when the configuration could be set.

### gst_buffer_pool_set_active ()

    gboolean            gst_buffer_pool_set_active          (GstBufferPool *pool,
                                                             gboolean active);

Control the active state of `pool`. When the pool is inactive, new calls to `gst_buffer_pool_acquire_buffer()` will return with GST_FLOW_FLUSHING.

Activating the bufferpool will preallocate all resources in the pool based on the configuration of the pool.

Deactivating will free the resources again when there are no outstanding buffers. When there are outstanding buffers, they will be freed as soon as they are all returned to the pool.

`pool` : | a GstBufferPool
`active` : | the new active state
Returns : | `FALSE` when the pool was not configured or when preallocation of the buffers failed.

### gst_buffer_pool_is_active ()

    gboolean            gst_buffer_pool_is_active           (GstBufferPool *pool);

Check if `pool` is active. A pool can be activated with the `gst_buffer_pool_set_active()` call.

`pool` : | a GstBufferPool
Returns : | `TRUE` when the pool is active.

### enum GstBufferPoolAcquireFlags

    typedef enum {
      GST_BUFFER_POOL_ACQUIRE_FLAG_NONE     = 0,
      GST_BUFFER_POOL_ACQUIRE_FLAG_KEY_UNIT = (1 << 0),
      GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT = (1 << 1),
      GST_BUFFER_POOL_ACQUIRE_FLAG_DISCONT  = (1 << 2),
      GST_BUFFER_POOL_ACQUIRE_FLAG_LAST     = (1 << 16),
    } GstBufferPoolAcquireFlags;

Additional flags to control the allocation of a buffer

`GST_BUFFER_POOL_ACQUIRE_FLAG_NONE` | no flags
`GST_BUFFER_POOL_ACQUIRE_FLAG_KEY_UNIT` | buffer is keyframe
`GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT` | when the bufferpool is empty, acquire_buffer will by default block until a buffer is released into the pool again. Setting this flag makes acquire_buffer return GST_FLOW_EOS instead of blocking.
`GST_BUFFER_POOL_ACQUIRE_FLAG_DISCONT` | buffer is discont
`GST_BUFFER_POOL_ACQUIRE_FLAG_LAST` | last flag, subclasses can use private flags starting from this value.

### struct GstBufferPoolAcquireParams

    struct GstBufferPoolAcquireParams {
      GstFormat                 format;
      gint64                    start;
      gint64                    stop;
      GstBufferPoolAcquireFlags flags;
    };

Parameters passed to the `gst_buffer_pool_acquire_buffer()` function to control the allocation of the buffer.

The default implementation ignores the `start` and `stop` members but other implementations can use this extra information to decide what buffer to return.

GstFormat `format`; | the format of `start` and `stop`
gint64 `start`; | the start position
gint64 `stop`; | the stop position
GstBufferPoolAcquireFlags `flags`; | additional flags

### gst_buffer_pool_acquire_buffer ()

    GstFlowReturn       gst_buffer_pool_acquire_buffer      (GstBufferPool *pool,
                                                             GstBuffer **buffer,
                                                             GstBufferPoolAcquireParams *params);

Acquire a buffer from `pool`. `buffer` should point to a memory location that can hold a pointer to the new buffer.

`params` can be NULL or contain optional parameters to influence the allocation.

`pool` : | a GstBufferPool
`buffer` : | a location for a GstBuffer. [out]
`params` : | (transfer none) (allow-none) parameters.
Returns : | a GstFlowReturn such as GST_FLOW_FLUSHING when the pool is inactive.

### gst_buffer_pool_release_buffer ()

    void                gst_buffer_pool_release_buffer      (GstBufferPool *pool,
                                                             GstBuffer *buffer);

Release `buffer` to `pool`. `buffer` should have previously been allocated from `pool` with `gst_buffer_pool_acquire_buffer()`.

This function is usually called automatically when the last ref on `buffer` disappears.

`pool` : | a GstBufferPool
`buffer` : | a GstBuffer. [transfer full]

## See Also

GstBuffer