bufferpool: add options API to bufferpool

Make it possible to query the supported options of a bufferpool and enable
options. This is a bit more generic than the API to enable metadata. The purpose
is to make it possible to add new custom config options to the configuration of
the bufferpool when supported.
This commit is contained in:
Wim Taymans 2011-07-29 17:10:09 +02:00
parent 388548222d
commit 733e94ada8
5 changed files with 65 additions and 63 deletions

View file

@ -491,20 +491,20 @@ gst_buffer_pool_get_config (GstBufferPool * pool)
return result; return result;
} }
static const gchar *empty_meta[] = { NULL }; static const gchar *empty_option[] = { NULL };
/** /**
* gst_buffer_pool_get_metas: * gst_buffer_pool_get_options:
* @pool: a #GstBufferPool * @pool: a #GstBufferPool
* *
* Get a NULL terminated array of string with supported #GstMeta apis for * Get a NULL terminated array of string with supported bufferpool options for
* @pool. The requested api would typically be added to the config with * @pool. An option would typically be enabled with
* gst_buffer_pool_config_add_meta(). * gst_buffer_pool_config_add_option().
* *
* Returns: a NULL terminated array of strings. * Returns: a NULL terminated array of strings.
*/ */
const gchar ** const gchar **
gst_buffer_pool_get_metas (GstBufferPool * pool) gst_buffer_pool_get_options (GstBufferPool * pool)
{ {
GstBufferPoolClass *pclass; GstBufferPoolClass *pclass;
const gchar **result; const gchar **result;
@ -513,10 +513,10 @@ gst_buffer_pool_get_metas (GstBufferPool * pool)
pclass = GST_BUFFER_POOL_GET_CLASS (pool); pclass = GST_BUFFER_POOL_GET_CLASS (pool);
if (G_LIKELY (pclass->get_metas)) if (G_LIKELY (pclass->get_options))
result = pclass->get_metas (pool); result = pclass->get_options (pool);
else else
result = empty_meta; result = empty_option;
return result; return result;
} }
@ -549,25 +549,25 @@ gst_buffer_pool_config_set (GstStructure * config, const GstCaps * caps,
} }
/** /**
* gst_buffer_pool_config_add_meta: * gst_buffer_pool_config_add_option:
* @config: a #GstBufferPool configuration * @config: a #GstBufferPool configuration
* @api: an API to add * @option: an option to add
* *
* Adds the metadata api to @config. This will instruct the @bufferpool to use * Enabled the option in @config. This will instruct the @bufferpool to enable
* the specified metadata api on the buffers that it allocates. * the specified option on the buffers that it allocates.
* *
* The supported API by @pool can be retrieved with gst_buffer_pool_get_metas(). * The supported options by @pool can be retrieved with gst_buffer_pool_get_options().
*/ */
void void
gst_buffer_pool_config_add_meta (GstStructure * config, const gchar * api) gst_buffer_pool_config_add_option (GstStructure * config, const gchar * option)
{ {
GValueArray *array; GValueArray *array;
const GValue *value; const GValue *value;
GValue api_value = { 0 }; GValue option_value = { 0 };
g_return_if_fail (config != NULL); g_return_if_fail (config != NULL);
value = gst_structure_id_get_value (config, GST_QUARK (META)); value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
if (value) { if (value) {
array = (GValueArray *) g_value_get_boxed (value); array = (GValueArray *) g_value_get_boxed (value);
} else { } else {
@ -578,26 +578,26 @@ gst_buffer_pool_config_add_meta (GstStructure * config, const gchar * api)
g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY); g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
g_value_take_boxed (&new_array_val, array); g_value_take_boxed (&new_array_val, array);
gst_structure_id_take_value (config, GST_QUARK (META), &new_array_val); gst_structure_id_take_value (config, GST_QUARK (OPTIONS), &new_array_val);
} }
g_value_init (&api_value, G_TYPE_STRING); g_value_init (&option_value, G_TYPE_STRING);
g_value_set_string (&api_value, api); g_value_set_string (&option_value, option);
g_value_array_append (array, &api_value); g_value_array_append (array, &option_value);
g_value_unset (&api_value); g_value_unset (&option_value);
} }
/** /**
* gst_buffer_pool_config_n_metas: * gst_buffer_pool_config_n_options:
* @config: a #GstBufferPool configuration * @config: a #GstBufferPool configuration
* *
* Retrieve the number of values currently stored in the * Retrieve the number of values currently stored in the
* meta API array of the @config structure. * options array of the @config structure.
* *
* Returns: the metadata API array size as a #guint. * Returns: the options array size as a #guint.
*/ */
guint guint
gst_buffer_pool_config_n_metas (GstStructure * config) gst_buffer_pool_config_n_options (GstStructure * config)
{ {
GValueArray *array; GValueArray *array;
const GValue *value; const GValue *value;
@ -605,7 +605,7 @@ gst_buffer_pool_config_n_metas (GstStructure * config)
g_return_val_if_fail (config != NULL, 0); g_return_val_if_fail (config != NULL, 0);
value = gst_structure_id_get_value (config, GST_QUARK (META)); value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
if (value) { if (value) {
array = (GValueArray *) g_value_get_boxed (value); array = (GValueArray *) g_value_get_boxed (value);
size = array->n_values; size = array->n_values;
@ -614,63 +614,63 @@ gst_buffer_pool_config_n_metas (GstStructure * config)
} }
/** /**
* gst_buffer_pool_config_get_meta: * gst_buffer_pool_config_get_option:
* @config: a #GstBufferPool configuration * @config: a #GstBufferPool configuration
* @index: position in the metadata API array to read * @index: position in the option array to read
* *
* Parse an available @config and get the metadata API * Parse an available @config and get the option
* at @index of the metadata API array. * at @index of the options API array.
* *
* Returns: a #gchar of the metadata API at @index. * Returns: a #gchar of the option at @index.
*/ */
const gchar * const gchar *
gst_buffer_pool_config_get_meta (GstStructure * config, guint index) gst_buffer_pool_config_get_option (GstStructure * config, guint index)
{ {
const GValue *value; const GValue *value;
const gchar *ret = NULL; const gchar *ret = NULL;
g_return_val_if_fail (config != NULL, 0); g_return_val_if_fail (config != NULL, 0);
value = gst_structure_id_get_value (config, GST_QUARK (META)); value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
if (value) { if (value) {
GValueArray *meta; GValueArray *array;
GValue *api_value; GValue *option_value;
meta = (GValueArray *) g_value_get_boxed (value); array = (GValueArray *) g_value_get_boxed (value);
api_value = g_value_array_get_nth (meta, index); option_value = g_value_array_get_nth (array, index);
if (api_value) if (option_value)
ret = g_value_get_string (api_value); ret = g_value_get_string (option_value);
} }
return ret; return ret;
} }
/** /**
* gst_buffer_pool_config_has_meta: * gst_buffer_pool_config_has_option:
* @config: a #GstBufferPool configuration * @config: a #GstBufferPool configuration
* @api: a metadata api * @option: an option
* *
* Check if @config contains @api metadata. * Check if @config contains @option
* *
* Returns: TRUE if the metadata array contain @api. * Returns: TRUE if the options array contains @option.
*/ */
gboolean gboolean
gst_buffer_pool_config_has_meta (GstStructure * config, const gchar * api) gst_buffer_pool_config_has_option (GstStructure * config, const gchar * option)
{ {
const GValue *value; const GValue *value;
g_return_val_if_fail (config != NULL, 0); g_return_val_if_fail (config != NULL, 0);
value = gst_structure_id_get_value (config, GST_QUARK (META)); value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
if (value) { if (value) {
GValueArray *array; GValueArray *array;
GValue *api_value; GValue *option_value;
gint i; gint i;
array = (GValueArray *) g_value_get_boxed (value); array = (GValueArray *) g_value_get_boxed (value);
for (i = 0; i < array->n_values; i++) { for (i = 0; i < array->n_values; i++) {
api_value = g_value_array_get_nth (array, i); option_value = g_value_array_get_nth (array, i);
if (!strcmp (api, g_value_get_string (api_value))) if (!strcmp (option, g_value_get_string (option_value)))
return TRUE; return TRUE;
} }
} }

View file

@ -127,7 +127,7 @@ struct _GstBufferPool {
/** /**
* GstBufferPoolClass: * GstBufferPoolClass:
* @object_class: Object parent class * @object_class: Object parent class
* @get_metas: get a list of metadata supported by this pool * @get_options: get a list of options supported by this pool
* @set_config: apply the bufferpool configuration. The default configuration * @set_config: apply the bufferpool configuration. The default configuration
* will parse the default config parameters * will parse the default config parameters
* @start: start the bufferpool. The default implementation will preallocate * @start: start the bufferpool. The default implementation will preallocate
@ -154,7 +154,7 @@ struct _GstBufferPoolClass {
GstObjectClass object_class; GstObjectClass object_class;
/* vmethods */ /* vmethods */
const gchar ** (*get_metas) (GstBufferPool *pool); const gchar ** (*get_options) (GstBufferPool *pool);
gboolean (*set_config) (GstBufferPool *pool, GstStructure *config); gboolean (*set_config) (GstBufferPool *pool, GstStructure *config);
gboolean (*start) (GstBufferPool *pool); gboolean (*start) (GstBufferPool *pool);
@ -183,7 +183,7 @@ gboolean gst_buffer_pool_set_active (GstBufferPool *pool, gboolean
gboolean gst_buffer_pool_set_config (GstBufferPool *pool, GstStructure *config); gboolean gst_buffer_pool_set_config (GstBufferPool *pool, GstStructure *config);
GstStructure * gst_buffer_pool_get_config (GstBufferPool *pool); GstStructure * gst_buffer_pool_get_config (GstBufferPool *pool);
const gchar ** gst_buffer_pool_get_metas (GstBufferPool *pool); const gchar ** gst_buffer_pool_get_options (GstBufferPool *pool);
/* helpers for configuring the config structure */ /* helpers for configuring the config structure */
void gst_buffer_pool_config_set (GstStructure *config, const GstCaps *caps, void gst_buffer_pool_config_set (GstStructure *config, const GstCaps *caps,
@ -193,10 +193,11 @@ gboolean gst_buffer_pool_config_get (GstStructure *config, const Gs
guint *size, guint *min_buffers, guint *max_buffers, guint *size, guint *min_buffers, guint *max_buffers,
guint *prefix, guint *align); guint *prefix, guint *align);
guint gst_buffer_pool_config_n_metas (GstStructure *config); /* options */
void gst_buffer_pool_config_add_meta (GstStructure *config, const gchar *api); guint gst_buffer_pool_config_n_options (GstStructure *config);
const gchar * gst_buffer_pool_config_get_meta (GstStructure *config, guint index); void gst_buffer_pool_config_add_option (GstStructure *config, const gchar *option);
gboolean gst_buffer_pool_config_has_meta (GstStructure *config, const gchar *api); const gchar * gst_buffer_pool_config_get_option (GstStructure *config, guint index);
gboolean gst_buffer_pool_config_has_option (GstStructure *config, const gchar *option);
/* buffer management */ /* buffer management */
GstFlowReturn gst_buffer_pool_acquire_buffer (GstBufferPool *pool, GstBuffer **buffer, GstFlowReturn gst_buffer_pool_acquire_buffer (GstBufferPool *pool, GstBuffer **buffer,

View file

@ -54,7 +54,7 @@ static const gchar *_quark_strings[] = {
"min-buffers", "max-buffers", "prefix", "postfix", "align", "time", "min-buffers", "max-buffers", "prefix", "postfix", "align", "time",
"GstQueryAllocation", "need-pool", "meta", "pool", "GstEventCaps", "GstQueryAllocation", "need-pool", "meta", "pool", "GstEventCaps",
"GstEventReconfigure", "segment", "GstQueryScheduling", "pull-mode", "GstEventReconfigure", "segment", "GstQueryScheduling", "pull-mode",
"random-access", "sequential", "allocator", "GstEventFlushStop" "random-access", "sequential", "allocator", "GstEventFlushStop", "options"
}; };
GQuark _priv_gst_quark_table[GST_QUARK_MAX]; GQuark _priv_gst_quark_table[GST_QUARK_MAX];

View file

@ -154,8 +154,9 @@ typedef enum _GstQuarkId
GST_QUARK_SEQUENTIAL = 125, GST_QUARK_SEQUENTIAL = 125,
GST_QUARK_ALLOCATOR = 126, GST_QUARK_ALLOCATOR = 126,
GST_QUARK_EVENT_FLUSH_STOP = 127, GST_QUARK_EVENT_FLUSH_STOP = 127,
GST_QUARK_OPTIONS = 128,
GST_QUARK_MAX = 128 GST_QUARK_MAX = 129
} GstQuarkId; } GstQuarkId;
extern GQuark _priv_gst_quark_table[GST_QUARK_MAX]; extern GQuark _priv_gst_quark_table[GST_QUARK_MAX];

View file

@ -124,15 +124,15 @@ EXPORTS
gst_buffer_new_wrapped_full gst_buffer_new_wrapped_full
gst_buffer_peek_memory gst_buffer_peek_memory
gst_buffer_pool_acquire_buffer gst_buffer_pool_acquire_buffer
gst_buffer_pool_config_add_meta gst_buffer_pool_config_add_option
gst_buffer_pool_config_get gst_buffer_pool_config_get
gst_buffer_pool_config_get_meta gst_buffer_pool_config_get_option
gst_buffer_pool_config_has_meta gst_buffer_pool_config_has_option
gst_buffer_pool_config_n_metas gst_buffer_pool_config_n_options
gst_buffer_pool_config_set gst_buffer_pool_config_set
gst_buffer_pool_flags_get_type gst_buffer_pool_flags_get_type
gst_buffer_pool_get_config gst_buffer_pool_get_config
gst_buffer_pool_get_metas gst_buffer_pool_get_options
gst_buffer_pool_get_type gst_buffer_pool_get_type
gst_buffer_pool_new gst_buffer_pool_new
gst_buffer_pool_release_buffer gst_buffer_pool_release_buffer