/**
* SECTION:element-multiqueue
+ * @title: multiqueue
* @see_also: #GstQueue
*
- * <refsect2>
- * <para>
* Multiqueue is similar to a normal #GstQueue with the following additional
* features:
- * <orderedlist>
- * <listitem>
- * <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%u) and
- * 'sometimes' src pads (src%u).
- * </para><para>
- * When requesting a given sinkpad with gst_element_request_pad(),
- * the associated srcpad for that stream will be created.
- * Example: requesting sink1 will generate src1.
- * </para></listitem>
- * </itemizedlist>
- * </listitem>
- * <listitem>
- * <itemizedlist><title>Non-starvation on multiple streams</title>
- * <listitem><para>
- * If more than one stream is used with the element, the streams' queues
- * will be dynamically grown (up to a limit), in order to ensure that no
- * stream is risking data starvation. This guarantees that at any given
- * time there are at least N bytes queued and available for each individual
- * stream.
- * </para><para>
- * If an EOS event comes through a srcpad, the associated queue will be
- * considered as 'not-empty' in the queue-size-growing algorithm.
- * </para></listitem>
- * </itemizedlist>
- * </listitem>
- * <listitem>
- * <itemizedlist><title>Non-linked srcpads graceful handling</title>
- * <listitem><para>
- * In order to better support dynamic switching between streams, the multiqueue
- * (unlike the current GStreamer queue) continues to push buffers on non-linked
- * pads rather than shutting down.
- * </para><para>
- * In addition, to prevent a non-linked stream from very quickly consuming all
- * available buffers and thus 'racing ahead' of the other streams, the element
- * must ensure that buffers and inlined events for a non-linked stream are pushed
- * in the same order as they were received, relative to the other streams
- * controlled by the element. This means that a buffer cannot be pushed to a
- * non-linked pad any sooner than buffers in any other stream which were received
- * before it.
- * </para></listitem>
- * </itemizedlist>
- * </listitem>
- * </orderedlist>
- * </para>
- * <para>
- * Data is queued until one of the limits specified by the
- * #GstMultiQueue:max-size-buffers, #GstMultiQueue:max-size-bytes and/or
- * #GstMultiQueue:max-size-time properties has been reached. Any attempt to push
- * more buffers into the queue will block the pushing thread until more space
- * becomes available. #GstMultiQueue:extra-size-buffers,
- * </para>
- * <para>
- * #GstMultiQueue:extra-size-bytes and #GstMultiQueue:extra-size-time are
- * currently unused.
- * </para>
- * <para>
- * The default queue size limits are 5 buffers, 10MB of data, or
- * two second worth of data, whichever is reached first. Note that the number
- * of buffers will dynamically grow depending on the fill level of
- * other queues.
- * </para>
- * <para>
- * The #GstMultiQueue::underrun signal is emitted when all of the queues
- * are empty. The #GstMultiQueue::overrun signal is emitted when one of the
- * queues is filled.
- * Both signals are emitted from the context of the streaming thread.
- * </para>
- * <para>
- * When using #GstMultiQueue:sync-by-running-time the unlinked streams will
- * be throttled by the highest running-time of linked streams. This allows
- * further relinking of those unlinked streams without them being in the
- * future (i.e. to achieve gapless playback).
- * When dealing with streams which have got different consumption requirements
- * downstream (ex: video decoders which will consume more buffer (in time) than
- * audio decoders), it is recommended to group streams of the same type
- * by using the pad "group-id" property. This will further throttle streams
- * in time within that group.
- * </para>
- * </refsect2>
+ *
+ * 1) Multiple streamhandling
+ *
+ * * The element handles queueing data on more than one stream at once. To
+ * achieve such a feature it has request sink pads (sink%u) and
+ * 'sometimes' src pads (src%u). When requesting a given sinkpad with gst_element_request_pad(),
+ * the associated srcpad for that stream will be created.
+ * Example: requesting sink1 will generate src1.
+ *
+ * 2) Non-starvation on multiple stream
+ *
+ * * If more than one stream is used with the element, the streams' queues
+ * will be dynamically grown (up to a limit), in order to ensure that no
+ * stream is risking data starvation. This guarantees that at any given
+ * time there are at least N bytes queued and available for each individual
+ * stream. If an EOS event comes through a srcpad, the associated queue will be
+ * considered as 'not-empty' in the queue-size-growing algorithm.
+ *
+ * 3) Non-linked srcpads graceful handling
+ *
+ * * In order to better support dynamic switching between streams, the multiqueue
+ * (unlike the current GStreamer queue) continues to push buffers on non-linked
+ * pads rather than shutting down. In addition, to prevent a non-linked stream from very quickly consuming all
+ * available buffers and thus 'racing ahead' of the other streams, the element
+ * must ensure that buffers and inlined events for a non-linked stream are pushed
+ * in the same order as they were received, relative to the other streams
+ * controlled by the element. This means that a buffer cannot be pushed to a
+ * non-linked pad any sooner than buffers in any other stream which were received
+ * before it.
+ *
+ * Data is queued until one of the limits specified by the
+ * #GstMultiQueue:max-size-buffers, #GstMultiQueue:max-size-bytes and/or
+ * #GstMultiQueue:max-size-time properties has been reached. Any attempt to push
+ * more buffers into the queue will block the pushing thread until more space
+ * becomes available. #GstMultiQueue:extra-size-buffers,
+ *
+ *
+ * #GstMultiQueue:extra-size-bytes and #GstMultiQueue:extra-size-time are
+ * currently unused.
+ *
+ * The default queue size limits are 5 buffers, 10MB of data, or
+ * two second worth of data, whichever is reached first. Note that the number
+ * of buffers will dynamically grow depending on the fill level of
+ * other queues.
+ *
+ * The #GstMultiQueue::underrun signal is emitted when all of the queues
+ * are empty. The #GstMultiQueue::overrun signal is emitted when one of the
+ * queues is filled.
+ * Both signals are emitted from the context of the streaming thread.
+ *
+ * When using #GstMultiQueue:sync-by-running-time the unlinked streams will
+ * be throttled by the highest running-time of linked streams. This allows
+ * further relinking of those unlinked streams without them being in the
+ * future (i.e. to achieve gapless playback).
+ * When dealing with streams which have got different consumption requirements
+ * downstream (ex: video decoders which will consume more buffer (in time) than
+ * audio decoders), it is recommended to group streams of the same type
+ * by using the pad "group-id" property. This will further throttle streams
+ * in time within that group.
*/
#ifdef HAVE_CONFIG_H
GstQuery *last_handled_query;
/* For interleave calculation */
- GThread *thread;
+ GThread *thread; /* Streaming thread of SingleQueue */
+ GstClockTime interleave; /* Calculated interleve within the thread */
};
static void gst_single_queue_flush_queue (GstSingleQueue * sq, gboolean full);
+static void calculate_interleave (GstMultiQueue * mq, GstSingleQueue * sq);
+
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink_%u",
GST_PAD_SINK,
GST_PAD_REQUEST,
#define DEFAULT_USE_INTERLEAVE FALSE
#define DEFAULT_UNLINKED_CACHE_TIME 250 * GST_MSECOND
+#define DEFAULT_MINIMUM_INTERLEAVE (250 * GST_MSECOND)
+
enum
{
PROP_0,
PROP_SYNC_BY_RUNNING_TIME,
PROP_USE_INTERLEAVE,
PROP_UNLINKED_CACHE_TIME,
+ PROP_MINIMUM_INTERLEAVE,
PROP_LAST
};
* size) is higher than the boundary values which can be set through the
* GObject properties.
*
- * This can be used as an indicator of pre-roll.
+ * This can be used as an indicator of pre-roll.
*/
gst_multi_queue_signals[SIGNAL_OVERRUN] =
g_signal_new ("overrun", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GstMultiQueue:use-buffering
- *
+ * GstMultiQueue:use-buffering:
+ *
* Enable the buffering option in multiqueue so that BUFFERING messages are
* emitted based on low-/high-percent thresholds.
*/
DEFAULT_USE_BUFFERING, G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING |
G_PARAM_STATIC_STRINGS));
/**
- * GstMultiQueue:low-percent
- *
+ * GstMultiQueue:low-percent:
+ *
* Low threshold percent for buffering to start.
*/
g_object_class_install_property (gobject_class, PROP_LOW_PERCENT,
0, 100, DEFAULT_LOW_WATERMARK * 100,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GstMultiQueue:high-percent
- *
+ * GstMultiQueue:high-percent:
+ *
* High threshold percent for buffering to finish.
*/
g_object_class_install_property (gobject_class, PROP_HIGH_PERCENT,
0, 100, DEFAULT_HIGH_WATERMARK * 100,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GstMultiQueue:low-watermark
+ * GstMultiQueue:low-watermark:
*
* Low threshold watermark for buffering to start.
*
0.0, 1.0, DEFAULT_LOW_WATERMARK,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GstMultiQueue:high-watermark
+ * GstMultiQueue:high-watermark:
*
* High threshold watermark for buffering to finish.
*
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GstMultiQueue:sync-by-running-time
- *
+ * GstMultiQueue:sync-by-running-time:
+ *
* If enabled multiqueue will synchronize deactivated or not-linked streams
* to the activated and linked streams by taking the running time.
* Otherwise multiqueue will synchronize the deactivated or not-linked
G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_MINIMUM_INTERLEAVE,
+ g_param_spec_uint64 ("min-interleave-time", "Minimum interleave time",
+ "Minimum extra buffering for deinterleaving (size of the queues) when use-interleave=true",
+ 0, G_MAXUINT64, DEFAULT_MINIMUM_INTERLEAVE,
+ G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING |
+ G_PARAM_STATIC_STRINGS));
gobject_class->finalize = gst_multi_queue_finalize;
mqueue->sync_by_running_time = DEFAULT_SYNC_BY_RUNNING_TIME;
mqueue->use_interleave = DEFAULT_USE_INTERLEAVE;
+ mqueue->min_interleave_time = DEFAULT_MINIMUM_INTERLEAVE;
mqueue->unlinked_cache_time = DEFAULT_UNLINKED_CACHE_TIME;
mqueue->counter = 1;
GST_MULTI_QUEUE_MUTEX_UNLOCK (mq);
gst_multi_queue_post_buffering (mq);
break;
+ case PROP_MINIMUM_INTERLEAVE:
+ GST_MULTI_QUEUE_MUTEX_LOCK (mq);
+ mq->min_interleave_time = g_value_get_uint64 (value);
+ if (mq->use_interleave)
+ calculate_interleave (mq, NULL);
+ GST_MULTI_QUEUE_MUTEX_UNLOCK (mq);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_UNLINKED_CACHE_TIME:
g_value_set_uint64 (value, mq->unlinked_cache_time);
break;
+ case PROP_MINIMUM_INTERLEAVE:
+ g_value_set_uint64 (value, mq->min_interleave_time);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
static void
-calculate_interleave (GstMultiQueue * mq)
+calculate_interleave (GstMultiQueue * mq, GstSingleQueue * sq)
{
GstClockTimeDiff low, high;
- GstClockTime interleave;
+ GstClockTime interleave, other_interleave = 0;
GList *tmp;
low = high = GST_CLOCK_STIME_NONE;
interleave = mq->interleave;
/* Go over all single queues and calculate lowest/highest value */
for (tmp = mq->queues; tmp; tmp = tmp->next) {
- GstSingleQueue *sq = (GstSingleQueue *) tmp->data;
+ GstSingleQueue *oq = (GstSingleQueue *) tmp->data;
/* Ignore sparse streams for interleave calculation */
- if (sq->is_sparse)
+ if (oq->is_sparse)
continue;
/* If a stream is not active yet (hasn't received any buffers), set
* a maximum interleave to allow it to receive more data */
- if (!sq->active) {
+ if (!oq->active) {
GST_LOG_OBJECT (mq,
- "queue %d is not active yet, forcing interleave to 5s", sq->id);
+ "queue %d is not active yet, forcing interleave to 5s", oq->id);
mq->interleave = 5 * GST_SECOND;
/* Update max-size time */
mq->max_size.time = mq->interleave;
SET_CHILD_PROPERTY (mq, time);
goto beach;
}
- if (GST_CLOCK_STIME_IS_VALID (sq->cached_sinktime)) {
- if (low == GST_CLOCK_STIME_NONE || sq->cached_sinktime < low)
- low = sq->cached_sinktime;
- if (high == GST_CLOCK_STIME_NONE || sq->cached_sinktime > high)
- high = sq->cached_sinktime;
+
+ /* Calculate within each streaming thread */
+ if (sq && sq->thread != oq->thread) {
+ if (oq->interleave > other_interleave)
+ other_interleave = oq->interleave;
+ continue;
+ }
+
+ if (GST_CLOCK_STIME_IS_VALID (oq->cached_sinktime)) {
+ if (low == GST_CLOCK_STIME_NONE || oq->cached_sinktime < low)
+ low = oq->cached_sinktime;
+ if (high == GST_CLOCK_STIME_NONE || oq->cached_sinktime > high)
+ high = oq->cached_sinktime;
}
GST_LOG_OBJECT (mq,
"queue %d , sinktime:%" GST_STIME_FORMAT " low:%" GST_STIME_FORMAT
- " high:%" GST_STIME_FORMAT, sq->id,
- GST_STIME_ARGS (sq->cached_sinktime), GST_STIME_ARGS (low),
+ " high:%" GST_STIME_FORMAT, oq->id,
+ GST_STIME_ARGS (oq->cached_sinktime), GST_STIME_ARGS (low),
GST_STIME_ARGS (high));
}
if (GST_CLOCK_STIME_IS_VALID (low) && GST_CLOCK_STIME_IS_VALID (high)) {
interleave = high - low;
/* Padding of interleave and minimum value */
- /* FIXME : Make the minimum time interleave a property */
- interleave = (150 * interleave / 100) + 250 * GST_MSECOND;
+ interleave = (150 * interleave / 100) + mq->min_interleave_time;
+ if (sq)
+ sq->interleave = interleave;
+
+ interleave = MAX (interleave, other_interleave);
/* Update the stored interleave if:
* * No data has arrived yet (high == low)
/* calculate the diff between running time on the sink and src of the queue.
- * This is the total amount of time in the queue.
+ * This is the total amount of time in the queue.
* WITH LOCK TAKEN */
static void
update_time_level (GstMultiQueue * mq, GstSingleQueue * sq)
sq->sink_tainted = FALSE;
if (mq->use_interleave) {
sq->cached_sinktime = sink_time;
- calculate_interleave (mq);
+ calculate_interleave (mq, sq);
}
}
} else
{
GST_MULTI_QUEUE_MUTEX_LOCK (mq);
- /* if no timestamp is set, assume it's continuous with the previous
+ /* if no timestamp is set, assume it's continuous with the previous
* time */
if (timestamp == GST_CLOCK_TIME_NONE)
timestamp = segment->position;
if (G_UNLIKELY (*allow_drop))
*allow_drop = FALSE;
break;
+ case GST_EVENT_STREAM_START:
+ result = GST_FLOW_OK;
+ if (G_UNLIKELY (*allow_drop))
+ *allow_drop = FALSE;
+ break;
case GST_EVENT_SEGMENT:
apply_segment (mq, sq, event, &sq->src_segment);
/* Applying the segment may have made the queue non-full again, unblock it if needed */
"Queue %d cached sink time now %" G_GINT64_FORMAT " %"
GST_STIME_FORMAT, sq->id, sq->cached_sinktime,
GST_STIME_ARGS (sq->cached_sinktime));
- calculate_interleave (mq);
+ calculate_interleave (mq, sq);
}
GST_MULTI_QUEUE_MUTEX_UNLOCK (mq);
}
stime = my_segment_to_running_time (&sq->sink_segment, val);
if (GST_CLOCK_STIME_IS_VALID (stime)) {
sq->cached_sinktime = stime;
- calculate_interleave (mq);
+ calculate_interleave (mq, sq);
}
GST_MULTI_QUEUE_MUTEX_UNLOCK (mq);
}
lowest = sq->nextid;
} else if (!GST_PAD_IS_EOS (sq->srcpad) && sq->srcresult != GST_FLOW_EOS) {
/* If we don't have a global highid, or the global highid is lower than
- * this single queue's last outputted id, store the queue's one,
+ * this single queue's last outputted id, store the queue's one,
* unless the singlequeue output is at EOS */
if ((highid == G_MAXUINT32) || (sq->oldid > highid))
highid = sq->oldid;