queue2: update current read position before waiting
[platform/upstream/gstreamer.git] / plugins / elements / gstqueue2.c
index ab725b5..f0dd2ec 100644 (file)
@@ -740,11 +740,9 @@ apply_segment (GstQueue2 * queue, GstEvent * event, GstSegment * segment,
       G_GINT64_FORMAT, update, rate, arate, format, start, stop, time);
 
   if (format == GST_FORMAT_BYTES) {
-    if (!QUEUE_IS_USING_QUEUE (queue)) {
+    if (!QUEUE_IS_USING_QUEUE (queue) && is_sink) {
       /* start is where we'll be getting from and as such writing next */
       queue->current = add_range (queue, start);
-      /* update the stats for this range */
-      update_cur_level (queue, queue->current);
     }
   }
 
@@ -1087,6 +1085,8 @@ perform_seek_to_offset (GstQueue2 * queue, guint64 offset)
   GstEvent *event;
   gboolean res;
 
+  /* until we receive the FLUSH_STOP from this seek, we skip data */
+  queue->seeking = TRUE;
   GST_QUEUE2_MUTEX_UNLOCK (queue);
 
   GST_DEBUG_OBJECT (queue, "Seeking to %" G_GUINT64_FORMAT, offset);
@@ -1096,8 +1096,6 @@ 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);
 
@@ -1306,15 +1304,11 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
       }
 
       if (read_length == 0) {
-        if (QUEUE_IS_USING_RING_BUFFER (queue)
-            && queue->current->max_reading_pos > rpos) {
-          /* protect cached data (data between offset and max_reading_pos)
-           * and update current level */
+        if (QUEUE_IS_USING_RING_BUFFER (queue)) {
           GST_DEBUG_OBJECT (queue,
-              "protecting cached data [%" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT
-              "]", rpos, queue->current->max_reading_pos);
-          queue->current->max_reading_pos = rpos;
-          update_cur_level (queue, queue->current);
+              "update current position [%" G_GUINT64_FORMAT "-%"
+              G_GUINT64_FORMAT "]", rpos, queue->current->max_reading_pos);
+          update_cur_pos (queue, queue->current, rpos);
         }
         GST_DEBUG_OBJECT (queue, "waiting for add");
         GST_QUEUE2_WAIT_ADD_CHECK (queue, queue->srcresult, out_flushing);
@@ -1626,7 +1620,7 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer)
   data = GST_BUFFER_DATA (buffer);
 
   GST_DEBUG_OBJECT (queue, "Writing %u bytes to %" G_GUINT64_FORMAT, size,
-      GST_BUFFER_OFFSET (buffer));
+      writing_pos);
 
   while (size > 0) {
     guint to_write;
@@ -2195,6 +2189,7 @@ gst_queue2_handle_sink_event (GstPad * pad, GstEvent * event)
         queue->is_eos = FALSE;
         queue->unexpected = FALSE;
         queue->sinkresult = GST_FLOW_OK;
+        queue->seeking = FALSE;
         GST_QUEUE2_MUTEX_UNLOCK (queue);
 
         gst_event_unref (event);