From 0bb0c68566e53849583f6ce447d227ad3e9cd2a8 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 4 Apr 2012 13:07:27 +0200 Subject: [PATCH] queue2: avoid waiting for a filled buffer Use a threshold variable to hold the maximum distance from the current position for with we will wait instead of doing a seek. When using the ringbuffer and the requested offset is not available, avoid waiting until the complete ringbuffer is filled but instead do a seek when the requested data is further than the threshold. Avoid doing the seek twice in the ringbuffer case. Use the same threshold for ringbuffer and download buffering. --- plugins/elements/gstqueue2.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/elements/gstqueue2.c b/plugins/elements/gstqueue2.c index 8c4e4ccad4..347c64a696 100644 --- a/plugins/elements/gstqueue2.c +++ b/plugins/elements/gstqueue2.c @@ -1139,20 +1139,27 @@ gst_queue2_have_data (GstQueue2 * queue, guint64 offset, guint length) (offset + length) - range->writing_pos); } else { - GST_INFO_OBJECT (queue, "not found in any range"); - /* we don't have the range, see how far away we are, FIXME, find a good - * threshold based on the incoming rate. */ + GST_INFO_OBJECT (queue, "not found in any range off %" G_GUINT64_FORMAT + " len %u", offset, length); + /* we don't have the range, see how far away we are */ if (!queue->is_eos && queue->current) { + /* FIXME, find a good threshold based on the incoming rate. */ + guint64 threshold = 1024 * 512; + if (QUEUE_IS_USING_RING_BUFFER (queue)) { - if (offset < queue->current->offset || offset > - queue->current->writing_pos + QUEUE_MAX_BYTES (queue) - - queue->cur_level.bytes) { - perform_seek_to_offset (queue, offset); - } else { + guint64 distance; + + distance = QUEUE_MAX_BYTES (queue) - queue->cur_level.bytes; + /* don't wait for the complete buffer to fill */ + distance = MIN (distance, threshold); + + if (offset >= queue->current->offset && offset <= + queue->current->writing_pos + distance) { GST_INFO_OBJECT (queue, "requested data is within range, wait for data"); + return FALSE; } - } else if (offset < queue->current->writing_pos + 200000) { + } else if (offset < queue->current->writing_pos + threshold) { update_cur_pos (queue, queue->current, offset + length); GST_INFO_OBJECT (queue, "wait for data"); return FALSE;