query: add methods to query allocators
authorWim Taymans <wim.taymans@collabora.co.uk>
Tue, 7 Jun 2011 14:35:07 +0000 (16:35 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 7 Jun 2011 14:35:07 +0000 (16:35 +0200)
Add API to add and query allocator implementations to/from the ALLOCATION query.

gst/gstquark.c
gst/gstquark.h
gst/gstquery.c
gst/gstquery.h

index 360c644..7254eb2 100644 (file)
@@ -54,7 +54,7 @@ static const gchar *_quark_strings[] = {
   "min-buffers", "max-buffers", "prefix", "postfix", "align", "time",
   "GstQueryAllocation", "need-pool", "meta", "pool", "GstEventCaps",
   "GstEventReconfigure", "segment", "GstQueryScheduling", "pull-mode",
-  "random-access", "sequential"
+  "random-access", "sequential", "allocator"
 };
 
 GQuark _priv_gst_quark_table[GST_QUARK_MAX];
index b671922..cb1f470 100644 (file)
@@ -152,8 +152,9 @@ typedef enum _GstQuarkId
   GST_QUARK_PULL_MODE = 123,
   GST_QUARK_RANDOM_ACCESS = 124,
   GST_QUARK_SEQUENTIAL = 125,
+  GST_QUARK_ALLOCATOR = 126,
 
-  GST_QUARK_MAX = 126
+  GST_QUARK_MAX = 127
 } GstQuarkId;
 
 extern GQuark _priv_gst_quark_table[GST_QUARK_MAX];
index 7efa34c..3136dff 100644 (file)
@@ -1760,6 +1760,108 @@ gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
 }
 
 /**
+ * gst_query_add_allocation_memory
+ * @query: a GST_QUERY_ALLOCATION type query #GstQuery
+ * @alloc: the memory allocator
+ *
+ * Add @alloc as a supported memory allocator.
+ */
+void
+gst_query_add_allocation_memory (GstQuery * query, const gchar * alloc)
+{
+  GValueArray *array;
+  const GValue *value;
+  GValue alloc_value = { 0 };
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
+  g_return_if_fail (gst_query_is_writable (query));
+
+  structure = GST_QUERY_STRUCTURE (query);
+  value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
+  if (value) {
+    array = (GValueArray *) g_value_get_boxed (value);
+  } else {
+    GValue new_array_val = { 0, };
+
+    array = g_value_array_new (0);
+
+    g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
+    g_value_take_boxed (&new_array_val, array);
+
+    gst_structure_id_take_value (structure, GST_QUARK (ALLOCATOR),
+        &new_array_val);
+  }
+
+  g_value_init (&alloc_value, G_TYPE_STRING);
+  g_value_set_string (&alloc_value, alloc);
+  g_value_array_append (array, &alloc_value);
+  g_value_unset (&alloc_value);
+}
+
+/**
+ * gst_query_get_n_allocation_memories:
+ * @query: a GST_QUERY_ALLOCATION type query #GstQuery
+ *
+ * Retrieve the number of values currently stored in the
+ * allocator array of the query's structure.
+ *
+ * Returns: the allocator array size as a #guint.
+ */
+guint
+gst_query_get_n_allocation_memories (GstQuery * query)
+{
+  GValueArray *array;
+  const GValue *value;
+  guint size = 0;
+  GstStructure *structure;
+
+  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
+
+  structure = GST_QUERY_STRUCTURE (query);
+  value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
+  if (value) {
+    array = (GValueArray *) g_value_get_boxed (value);
+    size = array->n_values;
+  }
+  return size;
+}
+
+/**
+ * gst_query_parse_nth_allocation_memory
+ * @query: a GST_QUERY_ALLOCATION type query #GstQuery
+ * @index: position in the allocator array to read
+ *
+ * Parse an available query and get the alloctor
+ * at @index of the allocator array.
+ *
+ * Returns: the name of the allocator at @index.
+ */
+const gchar *
+gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
+{
+  const GValue *value;
+  const gchar *ret = NULL;
+  GstStructure *structure;
+
+  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
+
+  structure = GST_QUERY_STRUCTURE (query);
+  value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
+  if (value) {
+    GValueArray *memory;
+    GValue *alloc_value;
+
+    memory = (GValueArray *) g_value_get_boxed (value);
+    alloc_value = g_value_array_get_nth (memory, index);
+
+    if (alloc_value)
+      ret = g_value_get_string (alloc_value);
+  }
+  return ret;
+}
+
+/**
  * gst_query_new_scheduling
  *
  * Constructs a new query object for querying the scheduling properties.
index f520175..f1f3041 100644 (file)
@@ -364,6 +364,10 @@ void            gst_query_add_allocation_meta       (GstQuery *query, const gcha
 guint           gst_query_get_n_allocation_metas    (GstQuery *query);
 const gchar *   gst_query_parse_nth_allocation_meta (GstQuery *query, guint index);
 
+void            gst_query_add_allocation_memory       (GstQuery *query, const gchar *alloc);
+guint           gst_query_get_n_allocation_memories   (GstQuery *query);
+const gchar *   gst_query_parse_nth_allocation_memory (GstQuery *query, guint index);
+
 /* scheduling query */
 GstQuery *      gst_query_new_scheduling          (void);