aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2013-03-22 18:10:09 +0100
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2013-03-22 18:10:09 +0100
commite4f7e7387835f2d104054b356866aff3d409e3e0 (patch)
tree14da13804a8ea53eb86f19d46ec2cb335a29706f /plugins
parent0dae307117a84152263d4c8b2c6aacf7e98a2f7c (diff)
Imported Upstream version 1.0.6upstream/1.0.6
Diffstat (limited to 'plugins')
-rw-r--r--plugins/elements/gstdataqueue.c4
-rw-r--r--plugins/elements/gstqueue.c9
-rw-r--r--plugins/elements/gstqueuearray.c97
3 files changed, 77 insertions, 33 deletions
diff --git a/plugins/elements/gstdataqueue.c b/plugins/elements/gstdataqueue.c
index dff49c6..04e3221 100644
--- a/plugins/elements/gstdataqueue.c
+++ b/plugins/elements/gstdataqueue.c
@@ -519,7 +519,7 @@ flushing:
static gint
is_of_type (gconstpointer a, gconstpointer b)
{
- return !G_TYPE_CHECK_INSTANCE_TYPE (a, GPOINTER_TO_INT (b));
+ return !G_TYPE_CHECK_INSTANCE_TYPE (a, GPOINTER_TO_SIZE (b));
}
/**
@@ -544,7 +544,7 @@ gst_data_queue_drop_head (GstDataQueue * queue, GType type)
GST_DATA_QUEUE_MUTEX_LOCK (queue);
idx =
- gst_queue_array_find (&queue->queue, is_of_type, GINT_TO_POINTER (type));
+ gst_queue_array_find (&queue->queue, is_of_type, GSIZE_TO_POINTER (type));
if (idx == -1)
goto done;
diff --git a/plugins/elements/gstqueue.c b/plugins/elements/gstqueue.c
index 2989823..0cba033 100644
--- a/plugins/elements/gstqueue.c
+++ b/plugins/elements/gstqueue.c
@@ -811,7 +811,16 @@ gst_queue_handle_sink_query (GstPad * pad, GstObject * parent, GstQuery * query)
/* ERRORS */
out_flushing:
{
+ gint index;
+
GST_DEBUG_OBJECT (queue, "we are flushing");
+
+ /* Remove query from queue if still there, since we hold no ref to it */
+ index = gst_queue_array_find (&queue->queue, NULL, query);
+
+ if (index >= 0)
+ gst_queue_array_drop_element (&queue->queue, index);
+
GST_QUEUE_MUTEX_UNLOCK (queue);
return FALSE;
}
diff --git a/plugins/elements/gstqueuearray.c b/plugins/elements/gstqueuearray.c
index f16f7ae..17e6418 100644
--- a/plugins/elements/gstqueuearray.c
+++ b/plugins/elements/gstqueuearray.c
@@ -124,42 +124,68 @@ gst_queue_array_free (GstQueueArray * array)
void
gst_queue_array_drop_element (GstQueueArray * array, guint idx)
{
- if (idx == array->head) {
- /* just move the head */
+ int first_item_index = array->head;
+ /* tail points to the first free spot */
+ int last_item_index = (array->tail - 1 + array->size) % array->size;
+
+ g_assert (array->length > 0);
+
+ /* simply case idx == first item */
+ if (idx == first_item_index) {
+ /* move head by plus one */
array->head++;
array->head %= array->size;
+ array->length--;
return;
}
- if (idx == array->tail - 1) {
- /* just move the tail */
+
+ /* simply case idx == last item */
+ if (idx == last_item_index) {
+ /* move tail minus one, potentially wrapping */
array->tail = (array->tail - 1 + array->size) % array->size;
+ array->length--;
return;
}
- /* drop the element #idx... and readjust the array */
- if (array->head < array->tail) {
- /* Make sure it's within the boundaries */
- g_assert (array->head < idx && idx <= array->tail);
- /* ends not wrapped */
- /* move head-idx to head+1 */
- memcpy (&array->array[array->head + 1],
- &array->array[array->head], (idx - array->head) * sizeof (gpointer));
+
+ /* non-wrapped case */
+ if (first_item_index < last_item_index) {
+ g_assert (first_item_index < idx && idx < last_item_index);
+ /* move everything beyond idx one step towards zero in array */
+ memmove (&array->array[idx],
+ &array->array[idx + 1], (last_item_index - idx) * sizeof (gpointer));
+ /* tail might wrap, ie if tail == 0 (and last_item_index == size) */
+ array->tail = (array->tail - 1 + array->size) % array->size;
+ array->length--;
+ return;
+ }
+
+ /* only wrapped cases left */
+ g_assert (first_item_index > last_item_index);
+
+ if (idx < last_item_index) {
+ /* idx is before last_item_index, move data towards zero */
+ memmove (&array->array[idx],
+ &array->array[idx + 1], (last_item_index - idx) * sizeof (gpointer));
+ /* tail should not wrap in this case! */
+ g_assert (array->tail > 0);
array->tail--;
- } else {
- /* ends are wrapped */
- if (idx < array->tail) {
- /* move idx-tail backwards one */
- memcpy (&array->array[idx - 1],
- &array->array[idx], (array->tail - idx) * sizeof (gpointer));
- array->tail--;
- } else if (idx >= array->head) {
- /* move head-idx forwards one */
- memcpy (&array->array[array->head],
- &array->array[array->head + 1],
- (idx - array->head) * sizeof (gpointer));
- array->head++;
- } else
- g_assert_not_reached ();
+ array->length--;
+ return;
}
+
+ if (idx > first_item_index) {
+ /* idx is after first_item_index, move data to higher indices */
+ memmove (&array->array[first_item_index + 1],
+ &array->array[first_item_index],
+ (idx - first_item_index) * sizeof (gpointer));
+ array->head++;
+ /* head should not wrap in this case! */
+ g_assert (array->head < array->size);
+ array->length--;
+ return;
+ }
+
+ g_assert_not_reached ();
}
guint
@@ -167,9 +193,18 @@ gst_queue_array_find (GstQueueArray * array, GCompareFunc func, gpointer data)
{
guint i;
- /* Scan from head to tail */
- for (i = array->head; i < array->length; i = (i + 1) % array->size)
- if (func (array->array[i], data) == 0)
- return i;
+ if (func != NULL) {
+ /* Scan from head to tail */
+ for (i = 0; i < array->length; i++) {
+ if (func (array->array[(i + array->head) % array->size], data) == 0)
+ return (i + array->head) % array->size;
+ }
+ } else {
+ for (i = 0; i < array->length; i++) {
+ if (array->array[(i + array->head) % array->size] == data)
+ return (i + array->head) % array->size;
+ }
+ }
+
return -1;
}