From: Wim Taymans Date: Tue, 7 Jun 2011 14:35:07 +0000 (+0200) Subject: query: add methods to query allocators X-Git-Tag: RELEASE-0.11.0~144 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=78ea732149ea10253b9b91378fa1e59fb0c43888;p=platform%2Fupstream%2Fgstreamer.git query: add methods to query allocators Add API to add and query allocator implementations to/from the ALLOCATION query. --- diff --git a/gst/gstquark.c b/gst/gstquark.c index 360c644..7254eb2 100644 --- a/gst/gstquark.c +++ b/gst/gstquark.c @@ -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]; diff --git a/gst/gstquark.h b/gst/gstquark.h index b671922..cb1f470 100644 --- a/gst/gstquark.h +++ b/gst/gstquark.h @@ -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]; diff --git a/gst/gstquery.c b/gst/gstquery.c index 7efa34c..3136dff 100644 --- a/gst/gstquery.c +++ b/gst/gstquery.c @@ -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. diff --git a/gst/gstquery.h b/gst/gstquery.h index f520175..f1f3041 100644 --- a/gst/gstquery.h +++ b/gst/gstquery.h @@ -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);