query: add method to check for metadata
authorWim Taymans <wim.taymans@collabora.co.uk>
Thu, 23 Jun 2011 16:03:22 +0000 (18:03 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Thu, 23 Jun 2011 16:03:22 +0000 (18:03 +0200)
Add a method to check if a certain metadata is supported in the ALLOCATION
query.

gst/gstquery.c
gst/gstquery.h

index 9c308be..7fcbf2c 100644 (file)
@@ -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);
@@ -1768,6 +1769,41 @@ gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
 }
 
 /**
+ * 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
  * @alloc: the memory allocator
index 96c5506..7b83cbc 100644 (file)
@@ -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);