mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-31 03:29:50 +00:00
API: gst_queue_array_peek_nth
https://bugzilla.gnome.org/show_bug.cgi?id=795157
This commit is contained in:
parent
68761eecae
commit
03e27aa5f0
5 changed files with 79 additions and 0 deletions
|
@ -939,6 +939,7 @@ gst_queue_array_free
|
|||
gst_queue_array_get_length
|
||||
gst_queue_array_pop_head
|
||||
gst_queue_array_peek_head
|
||||
gst_queue_array_peek_nth
|
||||
gst_queue_array_push_tail
|
||||
gst_queue_array_pop_tail
|
||||
gst_queue_array_peek_tail
|
||||
|
@ -948,6 +949,7 @@ gst_queue_array_find
|
|||
gst_queue_array_new_for_struct
|
||||
gst_queue_array_push_tail_struct
|
||||
gst_queue_array_peek_head_struct
|
||||
gst_queue_array_peek_nth_struct
|
||||
gst_queue_array_pop_head_struct
|
||||
gst_queue_array_peek_tail_struct
|
||||
gst_queue_array_pop_tail_struct
|
||||
|
|
|
@ -217,6 +217,46 @@ gst_queue_array_peek_head (GstQueueArray * array)
|
|||
return *(gpointer *) (array->array + (sizeof (gpointer) * array->head));
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_queue_array_peek_nth: (skip)
|
||||
*
|
||||
* Returns the item at @idx in @array, but does not remove it from the queue.
|
||||
*
|
||||
* Returns: The item, or %NULL if @idx was out of bounds
|
||||
*
|
||||
* Since: 1.16
|
||||
*/
|
||||
gpointer
|
||||
gst_queue_array_peek_nth (GstQueueArray * array, guint idx)
|
||||
{
|
||||
g_return_val_if_fail (array != NULL, NULL);
|
||||
g_return_val_if_fail (idx < array->length, NULL);
|
||||
|
||||
idx = (array->head + idx) % array->size;
|
||||
|
||||
return *(gpointer *) (array->array + (sizeof (gpointer) * idx));
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_queue_array_peek_nth_struct: (skip)
|
||||
*
|
||||
* Returns the item at @idx in @array, but does not remove it from the queue.
|
||||
*
|
||||
* Returns: The item, or %NULL if @idx was out of bounds
|
||||
*
|
||||
* Since: 1.16
|
||||
*/
|
||||
gpointer
|
||||
gst_queue_array_peek_nth_struct (GstQueueArray * array, guint idx)
|
||||
{
|
||||
g_return_val_if_fail (array != NULL, NULL);
|
||||
g_return_val_if_fail (idx < array->length, NULL);
|
||||
|
||||
idx = (array->head + idx) % array->size;
|
||||
|
||||
return array->array + (array->elt_size * idx);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_queue_array_do_expand (GstQueueArray * array)
|
||||
{
|
||||
|
|
|
@ -45,6 +45,9 @@ gpointer gst_queue_array_pop_head (GstQueueArray * array);
|
|||
GST_BASE_API
|
||||
gpointer gst_queue_array_peek_head (GstQueueArray * array);
|
||||
|
||||
GST_BASE_API
|
||||
gpointer gst_queue_array_peek_nth (GstQueueArray * array, guint idx);
|
||||
|
||||
GST_BASE_API
|
||||
gpointer gst_queue_array_pop_tail (GstQueueArray * array);
|
||||
|
||||
|
@ -81,12 +84,16 @@ gpointer gst_queue_array_pop_head_struct (GstQueueArray * array);
|
|||
GST_BASE_API
|
||||
gpointer gst_queue_array_peek_head_struct (GstQueueArray * array);
|
||||
|
||||
GST_BASE_API
|
||||
gpointer gst_queue_array_peek_nth_struct (GstQueueArray * array, guint idx);
|
||||
|
||||
GST_BASE_API
|
||||
gboolean gst_queue_array_drop_struct (GstQueueArray * array,
|
||||
guint idx,
|
||||
gpointer p_struct);
|
||||
GST_BASE_API
|
||||
gpointer gst_queue_array_pop_tail_struct (GstQueueArray * array);
|
||||
|
||||
GST_BASE_API
|
||||
gpointer gst_queue_array_peek_tail_struct (GstQueueArray * array);
|
||||
|
||||
|
|
|
@ -261,6 +261,33 @@ GST_START_TEST (test_array_grow_from_prealloc1)
|
|||
}
|
||||
|
||||
GST_END_TEST;
|
||||
GST_START_TEST (test_array_peek_nth)
|
||||
{
|
||||
GstQueueArray *array;
|
||||
guint i;
|
||||
|
||||
/* Create an array of initial size 10 */
|
||||
array = gst_queue_array_new (10);
|
||||
|
||||
/* push 10 values in */
|
||||
for (i = 0; i < 10; i++)
|
||||
gst_queue_array_push_tail (array, GINT_TO_POINTER (i));
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_peek_nth (array,
|
||||
i)), i);
|
||||
|
||||
gst_queue_array_pop_head (array);
|
||||
|
||||
for (i = 0; i < 9; i++)
|
||||
fail_unless_equals_int (GPOINTER_TO_INT (gst_queue_array_peek_nth (array,
|
||||
i)), i + 1);
|
||||
|
||||
gst_queue_array_free (array);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
GST_START_TEST (test_array_peek_pop_tail)
|
||||
{
|
||||
|
@ -330,6 +357,7 @@ gst_queue_array_suite (void)
|
|||
tcase_add_test (tc_chain, test_array_drop2);
|
||||
tcase_add_test (tc_chain, test_array_grow_from_prealloc1);
|
||||
tcase_add_test (tc_chain, test_array_peek_pop_tail);
|
||||
tcase_add_test (tc_chain, test_array_peek_nth);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -316,6 +316,8 @@ EXPORTS
|
|||
gst_queue_array_new_for_struct
|
||||
gst_queue_array_peek_head
|
||||
gst_queue_array_peek_head_struct
|
||||
gst_queue_array_peek_nth
|
||||
gst_queue_array_peek_nth_struct
|
||||
gst_queue_array_peek_tail
|
||||
gst_queue_array_peek_tail_struct
|
||||
gst_queue_array_pop_head
|
||||
|
|
Loading…
Reference in a new issue