diff options
author | Damien Lespiau <damien.lespiau@intel.com> | 2010-01-05 01:27:09 +0000 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2010-01-05 13:55:58 +0000 |
commit | bd3a5266206ff3c730674655cea93a8d689efd8d (patch) | |
tree | da0d1876cf93254fcdc1f7f9ccf99a7433f79fc5 | |
parent | 79ce07a7ee571fac116c07321382b418ebbc8b9d (diff) | |
download | clutter-gst-bd3a5266206ff3c730674655cea93a8d689efd8d.tar.gz |
[VideoTexture] 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.
Let's try to limit the duration signal emission even further. The signal
will only be emitted if it's useful to update a UI (1s precision). if
one need a more accurate duration, he can always get the duration
property when needed.
-rw-r--r-- | clutter-gst/clutter-gst-video-texture.c | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/clutter-gst/clutter-gst-video-texture.c b/clutter-gst/clutter-gst-video-texture.c index 0015d4a..ebd6937 100644 --- a/clutter-gst/clutter-gst-video-texture.c +++ b/clutter-gst/clutter-gst-video-texture.c @@ -175,6 +175,36 @@ autoload_subtitle (ClutterGstVideoTexture *video_texture, } static void +query_duration (ClutterGstVideoTexture *video_texture) +{ + ClutterGstVideoTexturePrivate *priv = video_texture->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 (video_texture), "duration"); + } +} + +static void set_uri (ClutterGstVideoTexture *video_texture, const gchar *uri) { @@ -631,19 +661,15 @@ bus_message_duration_cb (GstBus *bus, GstMessage *message, ClutterGstVideoTexture *video_texture) { - ClutterGstVideoTexturePrivate *priv = video_texture->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 (video_texture), "duration"); + query_duration (video_texture); } static void @@ -695,23 +721,8 @@ bus_message_state_change_cb (GstBus *bus, CLUTTER_GST_NOTE (MEDIA, "can-seek: %d", priv->can_seek); g_object_notify (G_OBJECT (video_texture), "can-seek"); - - /* Determine the duration */ - query = gst_query_new_duration (GST_FORMAT_TIME); - - if (gst_element_query (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 (video_texture), "duration"); - } - - gst_query_unref (query); + query_duration (video_texture); } } |