From b1dfe92f5cdf766631159a244a88335ce5ad05d0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 1 Mar 2012 14:49:38 +0100 Subject: [PATCH] query: add method to remove allocation_meta Also g_return_if_fail for out-of-bounds access instead of silently failing. --- gst/gstquery.c | 50 ++++++++++++++++++++++++++++++++------------------ gst/gstquery.h | 9 +++++---- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/gst/gstquery.c b/gst/gstquery.c index 61391dd..52c1118 100644 --- a/gst/gstquery.c +++ b/gst/gstquery.c @@ -1500,9 +1500,7 @@ gst_query_parse_nth_buffering_range (GstQuery * query, guint index, array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES), sizeof (GstQueryBufferingRange), NULL); - - if (index >= array->len) - return FALSE; + g_return_val_if_fail (index < array->len, FALSE); range = &g_array_index (array, GstQueryBufferingRange, index); @@ -1770,7 +1768,6 @@ GType gst_query_parse_nth_allocation_meta (GstQuery * query, guint index) { GArray *array; - GType ret = 0; GstStructure *structure; g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0); @@ -1778,10 +1775,32 @@ gst_query_parse_nth_allocation_meta (GstQuery * query, guint index) structure = GST_QUERY_STRUCTURE (query); array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL); - if (index < array->len) - ret = g_array_index (array, GType, index); + g_return_val_if_fail (index < array->len, 0); - return ret; + return g_array_index (array, GType, index); +} + +/** + * gst_query_remove_nth_allocation_meta: + * @query: a GST_QUERY_ALLOCATION type query #GstQuery + * @index: position in the metadata API array to remove + * + * Remove the metadata API at @index of the metadata API array. + */ +void +gst_query_remove_nth_allocation_meta (GstQuery * query, guint index) +{ + GArray *array; + 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); + array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL); + g_return_if_fail (index < array->len); + + g_array_remove_index (array, index); } /** @@ -1882,7 +1901,6 @@ GstAllocator * gst_query_parse_nth_allocation_memory (GstQuery * query, guint index) { GArray *array; - GstAllocator *ret = NULL; GstStructure *structure; g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL); @@ -1891,11 +1909,9 @@ gst_query_parse_nth_allocation_memory (GstQuery * query, guint index) array = ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *), (GDestroyNotify) gst_allocator_unref); + g_return_val_if_fail (index < array->len, NULL); - if (index < array->len) - ret = g_array_index (array, GstAllocator *, index); - - return ret; + return g_array_index (array, GstAllocator *, index); } /** @@ -2036,20 +2052,18 @@ gst_query_get_n_scheduling_modes (GstQuery * query) GstPadMode gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index) { - GstPadMode ret = GST_PAD_MODE_NONE; GstStructure *structure; GArray *array; - g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, ret); + g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, + GST_PAD_MODE_NONE); structure = GST_QUERY_STRUCTURE (query); array = ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL); + g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE); - if (index < array->len) - ret = g_array_index (array, GstPadMode, index); - - return ret; + return g_array_index (array, GstPadMode, index); } /** diff --git a/gst/gstquery.h b/gst/gstquery.h index 38ef3fe..20cbca1 100644 --- a/gst/gstquery.h +++ b/gst/gstquery.h @@ -372,10 +372,11 @@ void gst_query_parse_allocation_params (GstQuery *query, guint *size, guint *max_buffers, guint *prefix, guint *alignment, GstBufferPool **pool); -void gst_query_add_allocation_meta (GstQuery *query, GType api); -guint gst_query_get_n_allocation_metas (GstQuery *query); -GType gst_query_parse_nth_allocation_meta (GstQuery *query, guint index); -gboolean gst_query_has_allocation_meta (GstQuery *query, GType api); +void gst_query_add_allocation_meta (GstQuery *query, GType api); +guint gst_query_get_n_allocation_metas (GstQuery *query); +GType gst_query_parse_nth_allocation_meta (GstQuery *query, guint index); +void gst_query_remove_nth_allocation_meta (GstQuery *query, guint index); +gboolean gst_query_has_allocation_meta (GstQuery *query, GType api); void gst_query_add_allocation_memory (GstQuery *query, GstAllocator *allocator); guint gst_query_get_n_allocation_memories (GstQuery *query); -- 2.7.4