~ubuntu-branches/ubuntu/trusty/gstreamer1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to plugins/elements/gstqueue2.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2012-09-14 09:04:41 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120914090441-1ul912ezvm3xfael
Tags: 0.11.94-1
* New upstream release:
  + debian/libgstreamer.symbols:
    - Update symbols file.
  + debian/control.in:
    - Build-depend on gtk-doc >= 1.12.
  + debian/patches/0001-netclientclock-simplify-by-using-g_socket_condition_.patch:
    - Dropped, merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
549
549
 
550
550
/* make a new range for @offset or reuse an existing range */
551
551
static GstQueue2Range *
552
 
add_range (GstQueue2 * queue, guint64 offset)
 
552
add_range (GstQueue2 * queue, guint64 offset, gboolean update_existing)
553
553
{
554
554
  GstQueue2Range *range, *prev, *next;
555
555
 
559
559
    GST_DEBUG_OBJECT (queue,
560
560
        "reusing range %" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT, range->offset,
561
561
        range->writing_pos);
562
 
    range->writing_pos = offset;
 
562
    if (update_existing && range->writing_pos != offset) {
 
563
      GST_DEBUG_OBJECT (queue, "updating range writing position to "
 
564
          "%" G_GUINT64_FORMAT, offset);
 
565
      range->writing_pos = offset;
 
566
    }
563
567
  } else {
564
568
    GST_DEBUG_OBJECT (queue,
565
569
        "new range %" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT, offset, offset);
612
616
  /* get rid of all the current ranges */
613
617
  clean_ranges (queue);
614
618
  /* make a range for offset 0 */
615
 
  queue->current = add_range (queue, 0);
 
619
  queue->current = add_range (queue, 0, TRUE);
616
620
}
617
621
 
618
622
/* calculate the diff between running time on the sink and src of the queue.
656
660
  if (segment->format == GST_FORMAT_BYTES) {
657
661
    if (!QUEUE_IS_USING_QUEUE (queue) && is_sink) {
658
662
      /* start is where we'll be getting from and as such writing next */
659
 
      queue->current = add_range (queue, segment->start);
 
663
      queue->current = add_range (queue, segment->start, TRUE);
660
664
    }
661
665
  }
662
666
 
1010
1014
  res = gst_pad_push_event (queue->sinkpad, event);
1011
1015
  GST_QUEUE2_MUTEX_LOCK (queue);
1012
1016
 
1013
 
  if (res)
1014
 
    queue->current = add_range (queue, offset);
 
1017
  if (res) {
 
1018
    /* Between us sending the seek event and re-acquiring the lock, the source
 
1019
     * thread might already have pushed data and moved along the range's
 
1020
     * writing_pos beyond the seek offset. In that case we don't want to set
 
1021
     * the writing position back to the requested seek position, as it would
 
1022
     * cause data to be written to the wrong offset in the file or ring buffer.
 
1023
     * We still do the add_range call to switch the current range to the
 
1024
     * requested range, or create one if one doesn't exist yet. */
 
1025
    queue->current = add_range (queue, offset, FALSE);
 
1026
  }
1015
1027
 
1016
1028
  return res;
1017
1029
}
1550
1562
  GST_DEBUG_OBJECT (queue, "Writing %u bytes to %" G_GUINT64_FORMAT, size,
1551
1563
      writing_pos);
1552
1564
 
 
1565
  /* sanity check */
 
1566
  if (GST_BUFFER_OFFSET_IS_VALID (buffer) &&
 
1567
      GST_BUFFER_OFFSET (buffer) != queue->current->writing_pos) {
 
1568
    GST_WARNING_OBJECT (queue, "buffer offset does not match current writing "
 
1569
        "position! %" G_GINT64_FORMAT " != %" G_GINT64_FORMAT,
 
1570
        GST_BUFFER_OFFSET (buffer), queue->current->writing_pos);
 
1571
  }
 
1572
 
1553
1573
  while (size > 0) {
1554
1574
    guint to_write;
1555
1575