aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2014-04-18 15:23:46 +0200
committerSebastian Dröge <sebastian@centricular.com>2014-04-18 15:23:46 +0200
commit1adbba7bfff7853fca8b02aec57dbe1850d4a55c (patch)
tree261df891c5ef1634a7342cf03255cba70d9d9030 /plugins
parent54ba965e6376891d6d7e580732f2ab2de3d4a9cc (diff)
Imported Upstream version 1.2.4upstream/1.2.4
Diffstat (limited to 'plugins')
-rw-r--r--plugins/elements/gstmultiqueue.c4
-rw-r--r--plugins/elements/gstqueue2.c55
2 files changed, 40 insertions, 19 deletions
diff --git a/plugins/elements/gstmultiqueue.c b/plugins/elements/gstmultiqueue.c
index df0c65d..de2dd61 100644
--- a/plugins/elements/gstmultiqueue.c
+++ b/plugins/elements/gstmultiqueue.c
@@ -35,8 +35,8 @@
* <itemizedlist><title>Multiple streamhandling</title>
* <listitem><para>
* The element handles queueing data on more than one stream at once. To
- * achieve such a feature it has request sink pads (sink&percnt;d) and
- * 'sometimes' src pads (src&percnt;d).
+ * achieve such a feature it has request sink pads (sink&percnt;u) and
+ * 'sometimes' src pads (src&percnt;u).
* </para><para>
* When requesting a given sinkpad with gst_element_get_request_pad(),
* the associated srcpad for that stream will be created.
diff --git a/plugins/elements/gstqueue2.c b/plugins/elements/gstqueue2.c
index f675a45..d023d1c 100644
--- a/plugins/elements/gstqueue2.c
+++ b/plugins/elements/gstqueue2.c
@@ -1065,6 +1065,8 @@ perform_seek_to_offset (GstQueue2 * queue, guint64 offset)
queue->seeking = TRUE;
GST_QUEUE2_MUTEX_UNLOCK (queue);
+ debug_ranges (queue);
+
GST_DEBUG_OBJECT (queue, "Seeking to %" G_GUINT64_FORMAT, offset);
event =
@@ -1089,6 +1091,22 @@ perform_seek_to_offset (GstQueue2 * queue, guint64 offset)
return res;
}
+/* get the threshold for when we decide to seek rather than wait */
+static guint64
+get_seek_threshold (GstQueue2 * queue)
+{
+ guint64 threshold;
+
+ /* FIXME, find a good threshold based on the incoming rate. */
+ threshold = 1024 * 512;
+
+ if (QUEUE_IS_USING_RING_BUFFER (queue)) {
+ threshold = MIN (threshold,
+ QUEUE_MAX_BYTES (queue) - queue->cur_level.bytes);
+ }
+ return threshold;
+}
+
/* see if there is enough data in the file to read a full buffer */
static gboolean
gst_queue2_have_data (GstQueue2 * queue, guint64 offset, guint length)
@@ -1127,13 +1145,8 @@ gst_queue2_have_data (GstQueue2 * queue, guint64 offset, guint length)
" 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;
+ guint64 threshold = get_seek_threshold (queue);
- if (QUEUE_IS_USING_RING_BUFFER (queue)) {
- threshold = MIN (threshold,
- QUEUE_MAX_BYTES (queue) - queue->cur_level.bytes);
- }
if (offset >= queue->current->offset && offset <=
queue->current->writing_pos + threshold) {
GST_INFO_OBJECT (queue,
@@ -1530,10 +1543,10 @@ gst_queue2_flush_temp_file (GstQueue2 * queue)
}
static void
-gst_queue2_locked_flush (GstQueue2 * queue, gboolean full)
+gst_queue2_locked_flush (GstQueue2 * queue, gboolean full, gboolean clear_temp)
{
if (!QUEUE_IS_USING_QUEUE (queue)) {
- if (QUEUE_IS_USING_TEMP_FILE (queue))
+ if (QUEUE_IS_USING_TEMP_FILE (queue) && clear_temp)
gst_queue2_flush_temp_file (queue);
init_ranges (queue);
} else {
@@ -1615,6 +1628,7 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer)
guint size, rb_size;
guint64 writing_pos, new_writing_pos;
GstQueue2Range *range, *prev, *next;
+ gboolean do_seek = FALSE;
if (QUEUE_IS_USING_RING_BUFFER (queue))
writing_pos = queue->current->rb_writing_pos;
@@ -1788,15 +1802,19 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer)
GST_DEBUG_OBJECT (queue, "merging ranges %" G_GUINT64_FORMAT,
next->writing_pos);
- /* remove the group, we could choose to not read the data in this range
- * again. This would involve us doing a seek to the current writing position
- * in the range. FIXME, It would probably make sense to do a seek when there
- * is a lot of data in the range we merged with to avoid reading it all
- * again. */
+ /* remove the group */
queue->current->next = next->next;
- g_slice_free (GstQueue2Range, next);
- debug_ranges (queue);
+ /* We use the threshold to decide if we want to do a seek or simply
+ * read the data again. If there is not so much data in the range we
+ * prefer to avoid to seek and read it again. */
+ if (next->writing_pos > new_writing_pos + get_seek_threshold (queue)) {
+ /* the new range had more data than the threshold, it's worth keeping
+ * it and doing a seek. */
+ new_writing_pos = next->writing_pos;
+ do_seek = TRUE;
+ }
+ g_slice_free (GstQueue2Range, next);
}
goto update_and_signal;
}
@@ -1846,6 +1864,9 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer)
} else {
queue->current->writing_pos = writing_pos = new_writing_pos;
}
+ if (do_seek)
+ perform_seek_to_offset (queue, new_writing_pos);
+
update_cur_level (queue, queue->current);
/* update the buffering status */
@@ -2236,7 +2257,7 @@ gst_queue2_handle_sink_event (GstPad * pad, GstObject * parent,
ret = gst_pad_push_event (queue->srcpad, event);
GST_QUEUE2_MUTEX_LOCK (queue);
- gst_queue2_locked_flush (queue, FALSE);
+ gst_queue2_locked_flush (queue, FALSE, TRUE);
queue->srcresult = GST_FLOW_OK;
queue->sinkresult = GST_FLOW_OK;
queue->is_eos = FALSE;
@@ -3097,7 +3118,7 @@ gst_queue2_sink_activate_mode (GstPad * pad, GstObject * parent,
/* wait until it is unblocked and clean up */
GST_PAD_STREAM_LOCK (pad);
GST_QUEUE2_MUTEX_LOCK (queue);
- gst_queue2_locked_flush (queue, TRUE);
+ gst_queue2_locked_flush (queue, TRUE, FALSE);
GST_QUEUE2_MUTEX_UNLOCK (queue);
GST_PAD_STREAM_UNLOCK (pad);
}