Improve and fix LATENCY query handling
authorSebastian Dröge <sebastian@centricular.com>
Wed, 11 Feb 2015 12:41:56 +0000 (13:41 +0100)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 11 Feb 2015 15:53:04 +0000 (17:53 +0200)
This now follows the design docs everywhere.

https://bugzilla.gnome.org/show_bug.cgi?id=744106

gst/gstquery.c
libs/gst/base/gstbaseparse.c
libs/gst/base/gstbasesink.c
libs/gst/base/gstbasesrc.c
plugins/elements/gstqueue.c

index 38fc5c5..fa82eca 100644 (file)
@@ -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,
index acbb517..fb9fd73 100644 (file)
@@ -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);
 
index ef95850..8876d04 100644 (file)
@@ -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;
       }
index 4d41b29..07d4ab0 100644 (file)
@@ -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),
index 4addd19..ebd88cd 100644 (file)
@@ -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);