queue2: Keep track of the seeking state

Set the seeking flag right before we send a seek event upstream and discard all
data untill we see a flush-stop again. We need to do this because we activate
the range that we seek to immediately after sending the seek event and it is
possible that we receive data in our chain function from before the seek
which would then be added to the wrong range resulting in data corruption.
This commit is contained in:
Wim Taymans 2012-04-10 11:20:09 +02:00
parent 49a4b801ac
commit 5755e24379
2 changed files with 16 additions and 0 deletions

View file

@ -1096,6 +1096,8 @@ perform_seek_to_offset (GstQueue2 * queue, guint64 offset)
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, GST_SEEK_TYPE_SET, offset,
GST_SEEK_TYPE_NONE, -1);
/* until we receive the FLUSH_STOP from this seek, we skip data */
queue->seeking = TRUE;
res = gst_pad_push_event (queue->sinkpad, event);
GST_QUEUE2_MUTEX_LOCK (queue);
@ -2181,6 +2183,7 @@ gst_queue2_handle_sink_event (GstPad * pad, GstEvent * event)
queue->sinkresult = GST_FLOW_OK;
queue->is_eos = FALSE;
queue->unexpected = FALSE;
queue->seeking = FALSE;
/* reset rate counters */
reset_rate_timer (queue);
gst_pad_start_task (queue->srcpad, (GstTaskFunction) gst_queue2_loop,
@ -2307,6 +2310,10 @@ gst_queue2_chain_buffer_or_buffer_list (GstQueue2 * queue,
if (queue->unexpected)
goto out_unexpected;
/* while we didn't receive the newsegment, we're seeking and we skip data */
if (queue->seeking)
goto out_seeking;
if (!gst_queue2_wait_free_space (queue))
goto out_flushing;
@ -2336,6 +2343,14 @@ out_eos:
return GST_FLOW_UNEXPECTED;
}
out_seeking:
{
GST_CAT_LOG_OBJECT (queue_dataflow, queue, "exit because we are seeking");
GST_QUEUE2_MUTEX_UNLOCK (queue);
gst_mini_object_unref (item);
return GST_FLOW_OK;
}
out_unexpected:
{
GST_CAT_LOG_OBJECT (queue_dataflow, queue,

View file

@ -143,6 +143,7 @@ struct _GstQueue2
* because we can't save it on the file */
gboolean segment_event_received;
GstEvent *starting_segment;
gboolean seeking;
guint64 ring_buffer_max_size;
guint8 * ring_buffer;