From 0aa1465bbcecdc1320268966eea8437aaa1ae1f6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 23 Jun 2011 18:03:22 +0200 Subject: [PATCH] query: add method to check for metadata Add a method to check if a certain metadata is supported in the ALLOCATION query. --- gst/gstquery.c | 36 ++++++++++++++++++++++++++++++++++++ gst/gstquery.h | 1 + 2 files changed, 37 insertions(+) diff --git a/gst/gstquery.c b/gst/gstquery.c index 9c308be059..7fcbf2c06f 100644 --- a/gst/gstquery.c +++ b/gst/gstquery.c @@ -1682,6 +1682,7 @@ gst_query_add_allocation_meta (GstQuery * query, const gchar * api) GstStructure *structure; g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION); + g_return_if_fail (api != NULL); g_return_if_fail (gst_query_is_writable (query)); structure = GST_QUERY_STRUCTURE (query); @@ -1767,6 +1768,41 @@ gst_query_parse_nth_allocation_meta (GstQuery * query, guint index) return ret; } +/** + * gst_query_has_allocation_meta + * @query: a GST_QUERY_ALLOCATION type query #GstQuery + * @api: the metadata API + * + * Check if @query has metadata @api set. + * + * Returns: TRUE when @api is in the list of metadata. + */ +gboolean +gst_query_has_allocation_meta (GstQuery * query, const gchar * api) +{ + const GValue *value; + GstStructure *structure; + + g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE); + g_return_val_if_fail (api != NULL, FALSE); + + structure = GST_QUERY_STRUCTURE (query); + value = gst_structure_id_get_value (structure, GST_QUARK (META)); + if (value) { + GValueArray *array; + GValue *api_value; + guint i; + + array = (GValueArray *) g_value_get_boxed (value); + for (i = 0; i < array->n_values; i++) { + api_value = g_value_array_get_nth (array, i); + if (!strcmp (api, g_value_get_string (api_value))) + return TRUE; + } + } + return FALSE; +} + /** * gst_query_add_allocation_memory * @query: a GST_QUERY_ALLOCATION type query #GstQuery diff --git a/gst/gstquery.h b/gst/gstquery.h index 96c5506ac7..7b83cbc143 100644 --- a/gst/gstquery.h +++ b/gst/gstquery.h @@ -363,6 +363,7 @@ void gst_query_parse_allocation_params (GstQuery *query, guint *size, void gst_query_add_allocation_meta (GstQuery *query, const gchar *api); guint gst_query_get_n_allocation_metas (GstQuery *query); const gchar * gst_query_parse_nth_allocation_meta (GstQuery *query, guint index); +gboolean gst_query_has_allocation_meta (GstQuery *query, const gchar *api); void gst_query_add_allocation_memory (GstQuery *query, const gchar *alloc); guint gst_query_get_n_allocation_memories (GstQuery *query);