gst/gstsegment.c: Added some more docs.
authorWim Taymans <wim.taymans@gmail.com>
Mon, 10 Apr 2006 10:46:44 +0000 (10:46 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Mon, 10 Apr 2006 10:46:44 +0000 (10:46 +0000)
Original commit message from CVS:
* gst/gstsegment.c:
Added some more docs.
* libs/gst/base/gstbasesink.c: (gst_base_sink_perform_qos),
(gst_base_sink_reset_qos):
Calculate more accurate rate values.

ChangeLog
gst/gstsegment.c
libs/gst/base/gstbasesink.c

index b170324..e8324c9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-04-10  Wim Taymans  <wim@fluendo.com>
+
+       * gst/gstsegment.c:
+       Added some more docs.
+
+       * libs/gst/base/gstbasesink.c: (gst_base_sink_perform_qos),
+       (gst_base_sink_reset_qos):
+       Calculate more accurate rate values.
+
 2006-04-09  Sebastien Moutte  <sebastien@moutte.net>
 
        * gst/gst_private.h:
index 2d13f9a..78da722 100644 (file)
@@ -412,14 +412,18 @@ gst_segment_set_newsegment (GstSegment * segment, gboolean update, gdouble rate,
  * @position: the position in the segment
  *
  * Translate @position to stream time using the currently configured 
- * segment.
+ * segment. The @position value must be between @segment start and
+ * stop value. 
  *
  * This function is typically used by elements that need to operate on
  * the stream time of the buffers it receives, such as effect plugins.
+ * In those use cases, @position is typically the buffer timestamp that
+ * one wants to convert to the stream time.
  * The stream time is always between 0 and the total duration of the 
- * media stream.
+ * media stream. 
  *
- * Returns: the position in stream_time.
+ * Returns: the position in stream_time or -1 when an invalid position
+ * was given.
  */
 gint64
 gst_segment_to_stream_time (GstSegment * segment, GstFormat format,
index 2c9459d..078f16f 100644 (file)
@@ -1215,10 +1215,14 @@ gst_base_sink_perform_qos (GstBaseSink * sink, gboolean dropped)
 
   /* if we have the time when the last buffer left us, calculate
    * processing time */
-  if (priv->last_left != -1 && entered > priv->last_left) {
-    pt = entered - priv->last_left;
+  if (priv->last_left != -1) {
+    if (entered > priv->last_left) {
+      pt = entered - priv->last_left;
+    } else {
+      pt = 0;
+    }
   } else {
-    pt = 0;
+    pt = priv->avg_pt;
   }
 
   GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, sink, "start: %" GST_TIME_FORMAT
@@ -1233,9 +1237,6 @@ gst_base_sink_perform_qos (GstBaseSink * sink, gboolean dropped)
       GST_TIME_ARGS (priv->avg_duration), GST_TIME_ARGS (priv->avg_pt),
       priv->avg_rate);
 
-  /* record when this buffer will leave us */
-  priv->last_left = left;
-
   /* collect running averages. for first observations, we copy the
    * values */
   if (priv->avg_duration == -1)
@@ -1253,12 +1254,18 @@ gst_base_sink_perform_qos (GstBaseSink * sink, gboolean dropped)
         gst_guint64_to_gdouble (priv->avg_pt) /
         gst_guint64_to_gdouble (priv->avg_duration);
   else
-    rate = 1.0;
+    rate = 0.0;
 
-  if (rate > 1.0)
-    priv->avg_rate = UPDATE_RUNNING_AVG_N (priv->avg_rate, rate);
-  else
-    priv->avg_rate = UPDATE_RUNNING_AVG_P (priv->avg_rate, rate);
+  if (priv->last_left != -1) {
+    if (dropped || priv->avg_rate < 0.0) {
+      priv->avg_rate = rate;
+    } else {
+      if (rate > 1.0)
+        priv->avg_rate = UPDATE_RUNNING_AVG_N (priv->avg_rate, rate);
+      else
+        priv->avg_rate = UPDATE_RUNNING_AVG_P (priv->avg_rate, rate);
+    }
+  }
 
   GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, sink,
       "updated: avg_duration: %" GST_TIME_FORMAT ", avg_pt: %" GST_TIME_FORMAT
@@ -1266,13 +1273,14 @@ gst_base_sink_perform_qos (GstBaseSink * sink, gboolean dropped)
       GST_TIME_ARGS (priv->avg_pt), priv->avg_rate);
 
 
-  if (dropped) {
-    priv->avg_rate = 2.0;
+  /* if we have a valid rate, start sending QoS messages */
+  if (priv->avg_rate >= 0.0) {
+    gst_base_sink_send_qos (sink, priv->avg_rate, priv->current_rstart,
+        priv->current_jitter);
   }
 
-  /* always send QoS events */
-  gst_base_sink_send_qos (sink, priv->avg_rate, priv->current_rstart,
-      priv->current_jitter);
+  /* record when this buffer will leave us */
+  priv->last_left = left;
 }
 
 /* reset all qos measuring */
@@ -1287,7 +1295,7 @@ gst_base_sink_reset_qos (GstBaseSink * sink)
   priv->last_left = -1;
   priv->avg_duration = -1;
   priv->avg_pt = -1;
-  priv->avg_rate = 1.0;
+  priv->avg_rate = -1.0;
   priv->avg_render = -1;
   priv->rendered = 0;
   priv->dropped = 0;