From 4312119d167405f726c39ec5517d7124e1e99444 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Mon, 7 Aug 2017 12:24:37 +0200 Subject: [PATCH] queue2: Handle buffering levels on NOT_LINKED When downstream returns NOT_LINKED, we return the buffering level as being 100%. Since the queue is no longer being consumed/used downstream, we want applications to essentially "ignore" this queue for buffering purposes. If other streams are still being used, those stream buffering levels will be used. If none are used, upstream will post an error message on the bus indicating no streams are used. https://bugzilla.gnome.org/show_bug.cgi?id=785799 --- plugins/elements/gstqueue2.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/elements/gstqueue2.c b/plugins/elements/gstqueue2.c index 8d92838..fab1402 100644 --- a/plugins/elements/gstqueue2.c +++ b/plugins/elements/gstqueue2.c @@ -958,11 +958,11 @@ get_buffering_level (GstQueue2 * queue, gboolean * is_buffering, #define GET_BUFFER_LEVEL_FOR_QUANTITY(format,alt_max) \ normalize_to_buffering_level (queue->cur_level.format,queue->max_level.format,(alt_max)) - if (queue->is_eos) { - /* on EOS we are always 100% full, we set the var here so that it we can - * reuse the logic below to stop buffering */ + if (queue->is_eos || queue->srcresult == GST_FLOW_NOT_LINKED) { + /* on EOS and NOT_LINKED we are always 100% full, we set the var + * here so that we can reuse the logic below to stop buffering */ buflevel = MAX_BUFFERING_LEVEL; - GST_LOG_OBJECT (queue, "we are EOS"); + GST_LOG_OBJECT (queue, "we are %s", queue->is_eos ? "EOS" : "NOT_LINKED"); } else { GST_LOG_OBJECT (queue, "Cur level bytes/time/buffers %u/%" GST_TIME_FORMAT "/%u", @@ -3064,6 +3064,12 @@ out_flushing: GST_QUEUE2_MUTEX_UNLOCK (queue); GST_CAT_LOG_OBJECT (queue_dataflow, queue, "pause task, reason: %s", gst_flow_get_name (queue->srcresult)); + /* Recalculate buffering levels before stopping since the source flow + * might cause a different buffering level (like NOT_LINKED making + * the queue appear as full) */ + if (queue->use_buffering) + update_buffering (queue); + gst_queue2_post_buffering (queue); /* let app know about us giving up if upstream is not expected to do so */ /* EOS is already taken care of elsewhere */ if (eos && (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS)) { -- 2.7.4