query: use more generic structure for meta params

This commit is contained in:
Wim Taymans 2012-07-06 11:49:47 +02:00
parent 8bca7537e6
commit 3f80cb272e
4 changed files with 43 additions and 29 deletions

View file

@ -1661,19 +1661,27 @@ gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
typedef struct typedef struct
{ {
GType api; GType api;
guint flags; GstStructure *params;
} AllocationMeta; } AllocationMeta;
static void
allocation_meta_free (AllocationMeta * am)
{
if (am->params)
gst_structure_free (am->params);
}
/** /**
* gst_query_add_allocation_meta: * gst_query_add_allocation_meta:
* @query: a GST_QUERY_ALLOCATION type query #GstQuery * @query: a GST_QUERY_ALLOCATION type query #GstQuery
* @api: the metadata API * @api: the metadata API
* @flags: API specific flags * @params: (transfer full) (allow-none): API specific parameters
* *
* Add @api with @flags as one of the supported metadata API to @query. * Add @api with @params as one of the supported metadata API to @query.
*/ */
void void
gst_query_add_allocation_meta (GstQuery * query, GType api, guint flags) gst_query_add_allocation_meta (GstQuery * query, GType api,
GstStructure * params)
{ {
GArray *array; GArray *array;
GstStructure *structure; GstStructure *structure;
@ -1685,10 +1693,11 @@ gst_query_add_allocation_meta (GstQuery * query, GType api, guint flags)
structure = GST_QUERY_STRUCTURE (query); structure = GST_QUERY_STRUCTURE (query);
array = array =
ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta), NULL); ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
(GDestroyNotify) allocation_meta_free);
am.api = api; am.api = api;
am.flags = flags; am.params = params;
g_array_append_val (array, am); g_array_append_val (array, am);
} }
@ -1712,7 +1721,8 @@ gst_query_get_n_allocation_metas (GstQuery * query)
structure = GST_QUERY_STRUCTURE (query); structure = GST_QUERY_STRUCTURE (query);
array = array =
ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta), NULL); ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
(GDestroyNotify) allocation_meta_free);
return array->len; return array->len;
} }
@ -1721,7 +1731,7 @@ gst_query_get_n_allocation_metas (GstQuery * query)
* gst_query_parse_nth_allocation_meta: * gst_query_parse_nth_allocation_meta:
* @query: a GST_QUERY_ALLOCATION type query #GstQuery * @query: a GST_QUERY_ALLOCATION type query #GstQuery
* @index: position in the metadata API array to read * @index: position in the metadata API array to read
* @flags: (out) (allow-none): API specific flags * @params: (out) (allow-none): API specific flags
* *
* Parse an available query and get the metadata API * Parse an available query and get the metadata API
* at @index of the metadata API array. * at @index of the metadata API array.
@ -1730,7 +1740,7 @@ gst_query_get_n_allocation_metas (GstQuery * query)
*/ */
GType GType
gst_query_parse_nth_allocation_meta (GstQuery * query, guint index, gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
guint * flags) const GstStructure ** params)
{ {
GArray *array; GArray *array;
GstStructure *structure; GstStructure *structure;
@ -1740,14 +1750,15 @@ gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
structure = GST_QUERY_STRUCTURE (query); structure = GST_QUERY_STRUCTURE (query);
array = array =
ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta), NULL); ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
(GDestroyNotify) allocation_meta_free);
g_return_val_if_fail (index < array->len, 0); g_return_val_if_fail (index < array->len, 0);
am = &g_array_index (array, AllocationMeta, index); am = &g_array_index (array, AllocationMeta, index);
if (flags) if (params)
*flags = am->flags; *params = am->params;
return am->api; return am->api;
} }
@ -1770,7 +1781,8 @@ gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
structure = GST_QUERY_STRUCTURE (query); structure = GST_QUERY_STRUCTURE (query);
array = array =
ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta), NULL); ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
(GDestroyNotify) allocation_meta_free);
g_return_if_fail (index < array->len); g_return_if_fail (index < array->len);
g_array_remove_index (array, index); g_array_remove_index (array, index);
@ -1800,7 +1812,8 @@ gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
structure = GST_QUERY_STRUCTURE (query); structure = GST_QUERY_STRUCTURE (query);
array = array =
ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta), NULL); ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
(GDestroyNotify) allocation_meta_free);
len = array->len; len = array->len;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
@ -1830,8 +1843,8 @@ allocation_param_free (AllocationParam * ap)
/** /**
* gst_query_add_allocation_param: * gst_query_add_allocation_param:
* @query: a GST_QUERY_ALLOCATION type query #GstQuery * @query: a GST_QUERY_ALLOCATION type query #GstQuery
* @allocator: the memory allocator * @allocator: (transfer none) (allow-none): the memory allocator
* @params: a #GstAllocationParams * @params: (transfer none) (allow-none): a #GstAllocationParams
* *
* Add @allocator and its @params as a supported memory allocator. * Add @allocator and its @params as a supported memory allocator.
*/ */
@ -1892,8 +1905,8 @@ gst_query_get_n_allocation_params (GstQuery * query)
* gst_query_parse_nth_allocation_param: * gst_query_parse_nth_allocation_param:
* @query: a GST_QUERY_ALLOCATION type query #GstQuery * @query: a GST_QUERY_ALLOCATION type query #GstQuery
* @index: position in the allocator array to read * @index: position in the allocator array to read
* @allocator: (transfer none): variable to hold the result * @allocator: (out) (transfer none) (allow-none): variable to hold the result
* @params: parameters for the allocator * @params: (out) (allow-none): parameters for the allocator
* *
* Parse an available query and get the alloctor and its params * Parse an available query and get the alloctor and its params
* at @index of the allocator array. * at @index of the allocator array.
@ -1926,8 +1939,8 @@ gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
* gst_query_set_nth_allocation_param: * gst_query_set_nth_allocation_param:
* @query: a GST_QUERY_ALLOCATION type query #GstQuery * @query: a GST_QUERY_ALLOCATION type query #GstQuery
* @index: position in the allocator array to set * @index: position in the allocator array to set
* @allocator: (transfer full): new allocator to set * @allocator: (transfer none) (allow-none): new allocator to set
* @params: parameters for the allocator * @params: (transfer none) (allow-none): parameters for the allocator
* *
* Parse an available query and get the alloctor and its params * Parse an available query and get the alloctor and its params
* at @index of the allocator array. * at @index of the allocator array.

View file

@ -427,9 +427,10 @@ void gst_query_set_nth_allocation_param (GstQuery *query, guint ind
const GstAllocationParams *params); const GstAllocationParams *params);
/* metadata */ /* metadata */
void gst_query_add_allocation_meta (GstQuery *query, GType api, guint flags); void gst_query_add_allocation_meta (GstQuery *query, GType api, GstStructure *params);
guint gst_query_get_n_allocation_metas (GstQuery *query); guint gst_query_get_n_allocation_metas (GstQuery *query);
GType gst_query_parse_nth_allocation_meta (GstQuery *query, guint index, guint *flags); GType gst_query_parse_nth_allocation_meta (GstQuery *query, guint index,
const GstStructure **params);
void gst_query_remove_nth_allocation_meta (GstQuery *query, guint index); void gst_query_remove_nth_allocation_meta (GstQuery *query, guint index);
gboolean gst_query_find_allocation_meta (GstQuery *query, GType api, guint *index); gboolean gst_query_find_allocation_meta (GstQuery *query, GType api, guint *index);

View file

@ -813,10 +813,10 @@ gst_base_transform_default_decide_allocation (GstBaseTransform * trans,
n_metas = gst_query_get_n_allocation_metas (query); n_metas = gst_query_get_n_allocation_metas (query);
for (i = 0; i < n_metas; i++) { for (i = 0; i < n_metas; i++) {
GType api; GType api;
guint flags; const GstStructure *params;
gboolean remove; gboolean remove;
api = gst_query_parse_nth_allocation_meta (query, i, &flags); api = gst_query_parse_nth_allocation_meta (query, i, &params);
/* by default we remove all metadata, subclasses should implement a /* by default we remove all metadata, subclasses should implement a
* filter_meta function */ * filter_meta function */
@ -828,7 +828,7 @@ gst_base_transform_default_decide_allocation (GstBaseTransform * trans,
remove = TRUE; remove = TRUE;
} else if (G_LIKELY (klass->filter_meta)) { } else if (G_LIKELY (klass->filter_meta)) {
/* remove if the subclass said so */ /* remove if the subclass said so */
remove = !klass->filter_meta (trans, query, api, flags); remove = !klass->filter_meta (trans, query, api, params);
GST_LOG_OBJECT (trans, "filter_meta for api %s returned: %s", GST_LOG_OBJECT (trans, "filter_meta for api %s returned: %s",
g_type_name (api), (remove ? "remove" : "keep")); g_type_name (api), (remove ? "remove" : "keep"));
} else { } else {
@ -1369,11 +1369,11 @@ gst_base_transform_default_propose_allocation (GstBaseTransform * trans,
n_metas = gst_query_get_n_allocation_metas (decide_query); n_metas = gst_query_get_n_allocation_metas (decide_query);
for (i = 0; i < n_metas; i++) { for (i = 0; i < n_metas; i++) {
GType api; GType api;
guint flags; const GstStructure *params;
api = gst_query_parse_nth_allocation_meta (decide_query, i, &flags); api = gst_query_parse_nth_allocation_meta (decide_query, i, &params);
GST_DEBUG_OBJECT (trans, "proposing metadata %s", g_type_name (api)); GST_DEBUG_OBJECT (trans, "proposing metadata %s", g_type_name (api));
gst_query_add_allocation_meta (query, api, flags); gst_query_add_allocation_meta (query, api, gst_structure_copy (params));
} }
ret = TRUE; ret = TRUE;
} }

View file

@ -226,7 +226,7 @@ struct _GstBaseTransformClass {
/* decide allocation query for output buffers */ /* decide allocation query for output buffers */
gboolean (*decide_allocation) (GstBaseTransform *trans, GstQuery *query); gboolean (*decide_allocation) (GstBaseTransform *trans, GstQuery *query);
gboolean (*filter_meta) (GstBaseTransform *trans, GstQuery *query, gboolean (*filter_meta) (GstBaseTransform *trans, GstQuery *query,
GType api, guint flags); GType api, const GstStructure *params);
/* propose allocation query parameters for input buffers */ /* propose allocation query parameters for input buffers */
gboolean (*propose_allocation) (GstBaseTransform *trans, GstQuery *decide_query, gboolean (*propose_allocation) (GstBaseTransform *trans, GstQuery *decide_query,