From 4a5ce862a2a36bd0ec20fe63a1b92731bc2ae205 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 11 Feb 2015 13:41:56 +0100 Subject: [PATCH] Improve and fix LATENCY query handling This now follows the design docs everywhere. https://bugzilla.gnome.org/show_bug.cgi?id=744106 --- gst/gstquery.c | 1 + libs/gst/base/gstbaseparse.c | 10 +++++++--- libs/gst/base/gstbasesink.c | 3 +-- libs/gst/base/gstbasesrc.c | 2 +- plugins/elements/gstqueue.c | 8 ++++++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/gst/gstquery.c b/gst/gstquery.c index 38fc5c5..fa82eca 100644 --- a/gst/gstquery.c +++ b/gst/gstquery.c @@ -413,6 +413,7 @@ gst_query_set_latency (GstQuery * query, gboolean live, GstStructure *structure; g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY); + g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency)); structure = GST_QUERY_STRUCTURE (query); gst_structure_id_set (structure, diff --git a/libs/gst/base/gstbaseparse.c b/libs/gst/base/gstbaseparse.c index acbb517..fb9fd73 100644 --- a/libs/gst/base/gstbaseparse.c +++ b/libs/gst/base/gstbaseparse.c @@ -3754,6 +3754,9 @@ void gst_base_parse_set_latency (GstBaseParse * parse, GstClockTime min_latency, GstClockTime max_latency) { + g_return_if_fail (min_latency != GST_CLOCK_TIME_NONE); + g_return_if_fail (min_latency <= max_latency); + GST_OBJECT_LOCK (parse); parse->priv->min_latency = min_latency; parse->priv->max_latency = max_latency; @@ -3923,9 +3926,10 @@ gst_base_parse_src_query_default (GstBaseParse * parse, GstQuery * query) GST_OBJECT_LOCK (parse); /* add our latency */ - if (min_latency != -1) - min_latency += parse->priv->min_latency; - if (max_latency != -1) + min_latency += parse->priv->min_latency; + if (max_latency == -1 || parse->priv->max_latency == -1) + max_latency = -1; + else max_latency += parse->priv->max_latency; GST_OBJECT_UNLOCK (parse); diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index ef95850..8876d04 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -1086,8 +1086,7 @@ gst_base_sink_query_latency (GstBaseSink * sink, gboolean * live, } if (l) { /* we need to add the render delay if we are live */ - if (min != -1) - min += render_delay; + min += render_delay; if (max != -1) max += render_delay; } diff --git a/libs/gst/base/gstbasesrc.c b/libs/gst/base/gstbasesrc.c index 4d41b29..07d4ab0 100644 --- a/libs/gst/base/gstbasesrc.c +++ b/libs/gst/base/gstbasesrc.c @@ -726,7 +726,7 @@ gst_base_src_query_latency (GstBaseSrc * src, gboolean * live, if (min_latency) *min_latency = min; if (max_latency) - *max_latency = -1; + *max_latency = min; GST_LOG_OBJECT (src, "latency: live %d, min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT, src->is_live, GST_TIME_ARGS (min), diff --git a/plugins/elements/gstqueue.c b/plugins/elements/gstqueue.c index 4addd19..ebd88cd 100644 --- a/plugins/elements/gstqueue.c +++ b/plugins/elements/gstqueue.c @@ -1435,13 +1435,17 @@ gst_queue_handle_src_query (GstPad * pad, GstObject * parent, GstQuery * query) * limit, the best thing we can do is to return an infinite delay. In * reality a better estimate would be the byte/buffer rate but that is not * possible right now. */ - if (queue->max_size.time > 0 && max != -1) + /* TODO: Use CONVERT query? */ + if (queue->max_size.time > 0 && max != -1 + && queue->leaky == GST_QUEUE_NO_LEAK) max += queue->max_size.time; + else if (queue->max_size.time > 0 && queue->leaky != GST_QUEUE_NO_LEAK) + max = MIN (queue->max_size.time, max); else max = -1; /* adjust for min-threshold */ - if (queue->min_threshold.time > 0 && min != -1) + if (queue->min_threshold.time > 0) min += queue->min_threshold.time; gst_query_set_latency (query, live, min, max); -- 2.7.4