+2007-09-17 Wim Taymans <wim.taymans@gmail.com>
+
+ * plugins/elements/gstqueue.c: (apply_buffer),
+ (gst_queue_locked_enqueue), (gst_queue_locked_dequeue):
+ Measure queue level based on the diff between head and tail timestamps
+ even when pushing the first buffer.
+
2007-09-14 Wim Taymans <wim.taymans@gmail.com>
* libs/gst/base/gstbasesink.c: (gst_base_sink_preroll_queue_flush),
/* take a buffer and update segment, updating the time level of the queue. */
static void
-apply_buffer (GstQueue * queue, GstBuffer * buffer, GstSegment * segment)
+apply_buffer (GstQueue * queue, GstBuffer * buffer, GstSegment * segment,
+ gboolean with_duration)
{
GstClockTime duration, timestamp;
timestamp = segment->last_stop;
/* add duration */
- if (duration != GST_CLOCK_TIME_NONE)
+ if (with_duration && duration != GST_CLOCK_TIME_NONE)
timestamp += duration;
GST_DEBUG_OBJECT (queue, "last_stop updated to %" GST_TIME_FORMAT,
/* add buffer to the statistics */
queue->cur_level.buffers++;
queue->cur_level.bytes += GST_BUFFER_SIZE (buffer);
- apply_buffer (queue, buffer, &queue->sink_segment);
+ apply_buffer (queue, buffer, &queue->sink_segment, TRUE);
+ /* if this is the first buffer update the end side as well, but without the
+ * duration. */
+ if (queue->cur_level.buffers == 1)
+ apply_buffer (queue, buffer, &queue->src_segment, FALSE);
} else if (GST_IS_EVENT (item)) {
GstEvent *event = GST_EVENT_CAST (item);
GST_QUEUE_SIGNAL_ADD (queue);
}
-/* dequeue an item from the queue and update level stats */
+/* dequeue an item from the queue and update level stats, with QUEUE_LOCK */
static GstMiniObject *
gst_queue_locked_dequeue (GstQueue * queue)
{
queue->cur_level.buffers--;
queue->cur_level.bytes -= GST_BUFFER_SIZE (buffer);
- apply_buffer (queue, buffer, &queue->src_segment);
+ apply_buffer (queue, buffer, &queue->src_segment, TRUE);
+ /* if the queue is empty now, update the other side */
+ if (queue->cur_level.buffers == 0)
+ queue->cur_level.time = 0;
} else if (GST_IS_EVENT (item)) {
GstEvent *event = GST_EVENT_CAST (item);