+static void
+calculate_interleave (GstMultiQueue * mq)
+{
+ GstClockTimeDiff low, high;
+ GstClockTime interleave;
+ 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;
+ /* Ignore sparse streams for interleave calculation */
+ if (sq->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) {
+ GST_LOG_OBJECT (mq,
+ "queue %d is not active yet, forcing interleave to 5s", sq->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;
+ }
+ 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),
+ 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;
+
+ /* Update the stored interleave if:
+ * * No data has arrived yet (high == low)
+ * * Or it went higher
+ * * Or it went lower and we've gone past the previous interleave needed */
+ if (high == low || interleave > mq->interleave ||
+ ((mq->last_interleave_update + (2 * MIN (GST_SECOND,
+ mq->interleave)) < low)
+ && interleave < (mq->interleave * 3 / 4))) {
+ /* Update the interleave */
+ mq->interleave = interleave;
+ mq->last_interleave_update = high;
+ /* Update max-size time */
+ mq->max_size.time = mq->interleave;
+ SET_CHILD_PROPERTY (mq, time);
+ }
+ }
+
+beach:
+ GST_DEBUG_OBJECT (mq,
+ "low:%" GST_STIME_FORMAT " high:%" GST_STIME_FORMAT " interleave:%"
+ GST_TIME_FORMAT " mq->interleave:%" GST_TIME_FORMAT
+ " last_interleave_update:%" GST_TIME_FORMAT, GST_TIME_ARGS (low),
+ GST_TIME_ARGS (high), GST_TIME_ARGS (interleave),
+ GST_TIME_ARGS (mq->interleave),
+ GST_TIME_ARGS (mq->last_interleave_update));
+}
+
+