From 21cad29bcd429d9b196a320b0c9c63ae898ffeb3 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Mon, 23 Jan 2023 17:26:07 +0100 Subject: [PATCH] multiqueue: Handle use-interleave latency live pipelines Due to the dynamic nature of multiqueue, when `use-interleave` is used we can't report a maximum tolerated latency (when queried) since it is calculated dynamically. When in such live pipelines, we need to make sure multiqueue can handle the lowest global latency (provided by this event). Failure to do that would result in not providing enough buffering for a realtime pipeline. Fixes #1732 Part-of: --- .../plugins/elements/gstmultiqueue.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/subprojects/gstreamer/plugins/elements/gstmultiqueue.c b/subprojects/gstreamer/plugins/elements/gstmultiqueue.c index f604096828..c53838a990 100644 --- a/subprojects/gstreamer/plugins/elements/gstmultiqueue.c +++ b/subprojects/gstreamer/plugins/elements/gstmultiqueue.c @@ -2964,6 +2964,34 @@ gst_multi_queue_src_event (GstPad * pad, GstObject * parent, GstEvent * event) } switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_LATENCY: + { + GstClockTime latency = GST_CLOCK_TIME_NONE; + gst_event_parse_latency (event, &latency); + if (GST_CLOCK_TIME_IS_VALID (latency)) { + GST_MULTI_QUEUE_MUTEX_LOCK (mq); + if (latency > mq->min_interleave_time) { + /* Due to the dynamic nature of multiqueue, whe `use-interleave` is + * used we can't report a maximum tolerated latency (when queried) + * since it is calculated dynamically. + * + * When in such live pipelines, we need to make sure multiqueue can + * handle the lowest global latency (provided by this event). Failure + * to do that would result in not providing enough buffering for a + * realtime pipeline. + */ + GST_DEBUG_OBJECT (mq, + "Raising minimum interleave time to %" GST_TIME_FORMAT, + GST_TIME_ARGS (latency)); + mq->min_interleave_time = latency; + if (mq->use_interleave) + calculate_interleave (mq, NULL); + } + GST_MULTI_QUEUE_MUTEX_UNLOCK (mq); + } + ret = gst_pad_push_event (sinkpad, event); + } + break; case GST_EVENT_RECONFIGURE: GST_MULTI_QUEUE_MUTEX_LOCK (mq); if (sq->srcresult == GST_FLOW_NOT_LINKED) {