GstBufferPool

GstBufferPool — Pool for buffers

Functions

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── GstObject
            ╰── GstBufferPool

Includes

#include <gst/gst.h>

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().

Once a pool is created, it needs to be configured. A call to gst_buffer_pool_get_config() returns 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.

Buffers 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.

Functions

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.

Parameters

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 .

Parameters

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.

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_validate_params ()

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

Validate that changes made to config are still valid in the context of the expected parameters. This function is a helper that can be used to validate changes made by a pool to a config when gst_buffer_pool_set_config() returns FALSE. This expects that caps haven't changed and that min_buffers aren't lower then what we initially expected. This does not check if options or allocator parameters are still valid, won't check if size have changed, since changing the size is valid to adapt padding.

Parameters

config

a GstBufferPool configuration.

[transfer none]

caps

the excepted caps of buffers.

[transfer none]

size

the expected size of each buffer, not including prefix and padding

 

min_buffers

the expected minimum amount of buffers to allocate.

 

max_buffers

the expect maximum amount of buffers to allocate or 0 for unlimited.

 

Returns

TRUE, if the parameters are valid in this context.

Since: 1.4


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 .

Parameters

config

a GstBufferPool configuration.

[transfer none]

allocator

a GstAllocator, or NULL.

[out][allow-none][transfer none]

params

GstAllocationParams, or NULL.

[out][allow-none]

Returns

TRUE, if the values are set.


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.

Parameters

config

a GstBufferPool configuration

 

allocator

a GstAllocator.

[allow-none]

params

GstAllocationParams.

[allow-none]

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.

Parameters

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().

Parameters

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.

Parameters

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 .

Parameters

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().

Parameters

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 .

Parameters

pool

a GstBufferPool

 

option

an option

 

Returns

TRUE if the buffer pool contains option .


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.

Parameters

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. If the pool is already configured, and the configuration haven't change, this function will return TRUE. If the pool is active, this method will return FALSE and active configuration will remain. 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 .

Parameters

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.

Parameters

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.

Parameters

pool

a GstBufferPool

 

Returns

TRUE when the pool is active.


gst_buffer_pool_set_flushing ()

void
gst_buffer_pool_set_flushing (GstBufferPool *pool,
                              gboolean flushing);

Enable or disable the flushing state of a pool without freeing or allocating buffers.

Parameters

pool

a GstBufferPool

 

flushing

whether to start or stop flushing

 

Since: 1.4


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.

Parameters

pool

a GstBufferPool

 

buffer

a location for a GstBuffer.

[out]

params

parameters.

[transfer none][allow-none]

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.

Parameters

pool

a GstBufferPool

 

buffer

a GstBuffer.

[transfer full]

Types and Values

GstBufferPool

typedef struct _GstBufferPool GstBufferPool;

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


struct GstBufferPoolClass

struct GstBufferPoolClass {
  GstObjectClass    object_class;

  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);
  void           (*flush_start)    (GstBufferPool *pool);
  void           (*flush_stop)     (GstBufferPool *pool);
};

The GstBufferPool class.

Members

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 . The buffer should have the GST_BUFFER_FLAG_TAG_MEMORY cleared.

 

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). If the GST_BUFFER_FLAG_TAG_MEMORY was set, this function can also try to restore the memory and clear the GST_BUFFER_FLAG_TAG_MEMORY again.

 

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 when the GST_BUFFER_FLAG_TAG_MEMORY is not set on the buffer. If GST_BUFFER_FLAG_TAG_MEMORY is set, the buffer will be freed with free_buffer .

 

free_buffer ()

free a buffer. The default implementation unrefs the buffer.

 

flush_start ()

enter the flushing state. (Since 1.4)

 

flush_stop ()

leave the flushign state. (Since 1.4)

 

enum GstBufferPoolAcquireFlags

Additional flags to control the allocation of a buffer

Members

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.

Members

GstFormat format;

the format of start and stop

 

gint64 start;

the start position

 

gint64 stop;

the stop position

 

GstBufferPoolAcquireFlags flags;

additional flags

 

See Also

GstBuffer