baseparse: send duration message when updating internal duration
authorMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Thu, 6 Oct 2011 12:34:09 +0000 (14:34 +0200)
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Thu, 6 Oct 2011 12:47:54 +0000 (14:47 +0200)
libs/gst/base/gstbaseparse.c

index 157a3180e4483e576dda272257b3533633f12b58..80587351cfb7b17e6b8c4541a5f64b2b04662a89 100644 (file)
@@ -231,6 +231,7 @@ struct _GstBaseParsePrivate
   gint64 duration;
   GstFormat duration_fmt;
   gint64 estimated_duration;
+  gint64 estimated_drift;
 
   guint min_frame_size;
   gboolean passthrough;
@@ -688,6 +689,7 @@ gst_base_parse_reset (GstBaseParse * parse)
   parse->priv->first_frame_ts = GST_CLOCK_TIME_NONE;
   parse->priv->first_frame_offset = -1;
   parse->priv->estimated_duration = -1;
+  parse->priv->estimated_drift = 0;
   parse->priv->next_ts = 0;
   parse->priv->syncable = TRUE;
   parse->priv->passthrough = FALSE;
@@ -1239,6 +1241,17 @@ gst_base_parse_update_duration (GstBaseParse * baseparse)
     if (qres) {
       if (gst_base_parse_convert (parse, pformat, ptot,
               GST_FORMAT_TIME, &dest_value)) {
+
+        /* inform if duration changed, but try to avoid spamming */
+        parse->priv->estimated_drift +=
+            dest_value - parse->priv->estimated_duration;
+        if (parse->priv->estimated_drift > GST_SECOND ||
+            parse->priv->estimated_drift < -GST_SECOND) {
+          gst_element_post_message (GST_ELEMENT (parse),
+              gst_message_new_duration (GST_OBJECT (parse),
+                  GST_FORMAT_TIME, dest_value));
+          parse->priv->estimated_drift = 0;
+        }
         parse->priv->estimated_duration = dest_value;
         GST_LOG_OBJECT (parse,
             "updated estimated duration to %" GST_TIME_FORMAT,