Top |
GstBufferPool | |
struct | GstBufferPoolClass |
enum | GstBufferPoolAcquireFlags |
struct | GstBufferPoolAcquireParams |
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.
#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.
GstBufferPool *
gst_buffer_pool_new (void
);
Creates a new GstBufferPool instance.
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] |
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. |
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
and size
haven't changed, and that
min_buffers
aren't lower then what we initially expected. This does not check
if options or allocator 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. |
Since 1.4
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 |
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. |
[allow-none] |
params |
[allow-none] |
guint
gst_buffer_pool_config_n_options (GstStructure *config
);
Retrieve the number of values currently stored in the options array of the
config
structure.
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()
.
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.
gboolean gst_buffer_pool_config_has_option (GstStructure *config
,const gchar *option
);
Check if config
contains option
.
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()
.
gboolean gst_buffer_pool_has_option (GstBufferPool *pool
,const gchar *option
);
Check if the bufferpool supports option
.
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.
a copy of the current configuration of pool
. use
gst_structure_free()
after usage or gst_buffer_pool_set_config()
.
[transfer full]
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 function will try deactivating it. 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
.
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.
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.
void gst_buffer_pool_set_flushing (GstBufferPool *pool
,gboolean flushing
);
Enable or disable the flushing state of a pool
without freeing or
allocating buffers.
Since 1.4
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 |
||
buffer |
a location for a GstBuffer. |
[out] |
params |
parameters. |
[transfer none][allow-none] |
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.
typedef struct _GstBufferPool GstBufferPool;
The structure of a GstBufferPool. Use the associated macros to access the public variables.
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.
GstObjectClass |
Object parent class |
|
get a list of options supported by this pool |
||
apply the bufferpool configuration. The default configuration will parse the default config parameters |
||
start the bufferpool. The default implementation will preallocate min-buffers buffers and put them in the queue |
||
stop the bufferpool. the default implementation will free the preallocated buffers. This function is called when all the buffers are returned to the pool. |
||
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. |
||
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 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 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 a buffer. The default implementation unrefs the buffer. |
||
enter the flushing state. Since: 1.4 |
||
leave the flushign state. Since: 1.4 |
Additional flags to control the allocation of a buffer
no flags |
||
buffer is keyframe |
||
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. |
||
buffer is discont |
||
last flag, subclasses can use private flags starting from this value. |
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 |
the format of |
|
the start position |
||
the stop position |
||
GstBufferPoolAcquireFlags |
additional flags |