summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Lespiau <damien.lespiau@intel.com>2010-01-09 11:23:45 +0000
committerDamien Lespiau <damien.lespiau@intel.com>2010-01-09 16:29:29 +0000
commit36be558b7ff6427f942d2243205e0a9eb4cf1bb5 (patch)
tree13b10b14b9221b9b820f2aa3ea432a0591189f1f
parentfe83d9b763b6613b4acad13991b3009c8b8331c9 (diff)
downloadclutter-gst-36be558b7ff6427f942d2243205e0a9eb4cf1bb5.tar.gz
[Audio] Fix notifications of duration
The "duration" message is sent on the GstBus when an element has a new duration. Then, this duration has to be queried from the pipeline. Instead of that we tried to parse the duration message that returned GST_CLOCK_TIME_NONE (which is the way to say "we have a new duration, please query it.") and we emitted a new signal with that value. This is basically the commit bd3a5266206ff3c730674655cea93a8d689efd8d but for ClutterGstAudio.
-rw-r--r--clutter-gst/clutter-gst-audio.c61
1 files changed, 36 insertions, 25 deletions
diff --git a/clutter-gst/clutter-gst-audio.c b/clutter-gst/clutter-gst-audio.c
index a6ccb9d..e2fb960 100644
--- a/clutter-gst/clutter-gst-audio.c
+++ b/clutter-gst/clutter-gst-audio.c
@@ -98,6 +98,36 @@ tick_timeout (gpointer data)
}
static void
+query_duration (ClutterGstAudio *audio)
+{
+ ClutterGstAudioPrivate *priv = audio->priv;
+ gboolean success;
+ GstFormat format = GST_FORMAT_TIME;
+ gint64 duration;
+ gdouble new_duration, difference;
+
+ success = gst_element_query_duration (priv->pipeline, &format, &duration);
+ if (G_UNLIKELY (success != TRUE))
+ return;
+
+ new_duration = (gdouble) duration / GST_SECOND;
+
+ /* while we store the new duration if it sligthly changes, the duration
+ * signal is sent only if the new duration is at least one second different
+ * from the old one (as the duration signal is mainly used to update the
+ * time displayed in a UI */
+ difference = ABS (priv->duration - new_duration);
+ if (difference > 1e-3)
+ {
+ CLUTTER_GST_NOTE (MEDIA, "duration: %.02f", new_duration);
+ priv->duration = new_duration;
+
+ if (difference > 1.0)
+ g_object_notify (G_OBJECT (audio), "duration");
+ }
+}
+
+static void
set_uri (ClutterGstAudio *audio,
const gchar *uri)
{
@@ -547,19 +577,15 @@ bus_message_duration_cb (GstBus *bus,
GstMessage *message,
ClutterGstAudio *audio)
{
- ClutterGstAudioPrivate *priv = audio->priv;
- GstFormat format;
gint64 duration;
- gst_message_parse_duration (message, &format, &duration);
- if (format != GST_FORMAT_TIME)
+ /* GstElements send a duration message on the bus with GST_CLOCK_TIME_NONE
+ * as duration to signal a new duration */
+ gst_message_parse_duration (message, NULL, &duration);
+ if (G_UNLIKELY (duration != GST_CLOCK_TIME_NONE))
return;
-
- priv->duration = (gdouble) duration / GST_SECOND;
- CLUTTER_GST_NOTE (MEDIA, "duration: %.02f", priv->duration);
-
- g_object_notify (G_OBJECT (audio), "duration");
+ query_duration (audio);
}
static void
@@ -612,22 +638,7 @@ bus_message_state_change_cb (GstBus *bus,
g_object_notify (G_OBJECT (audio), "can-seek");
- /* Determine the duration */
- query = gst_query_new_duration (GST_FORMAT_TIME);
-
- if (gst_element_query (audio->priv->pipeline, query))
- {
- gint64 duration;
-
- gst_query_parse_duration (query, NULL, &duration);
- priv->duration = (gdouble) duration / GST_SECOND;
-
- CLUTTER_GST_NOTE (MEDIA, "duration: %.02f", priv->duration);
-
- g_object_notify (G_OBJECT (audio), "duration");
- }
-
- gst_query_unref (query);
+ query_duration (audio);
}
}