[clutter-gst] video-texture: Clean up and fix the stream buffering



commit 5b95570da3b65cd6f558eeafaf9e933404ca6eb6
Author: Damien Lespiau <damien lespiau intel com>
Date:   Wed Mar 30 19:36:59 2011 +0100

    video-texture: Clean up and fix the stream buffering
    
    * Don't use GStreamer structures directly but the gst_message API
      instead,
    * Pause the pipeline when buffering. This is explicitely documented as
      required,
    * A new "buffering" debug category has been introduced.
    * The minimum GStreamer version has never been specified, which is
      somewhat of a mistake since a lot of API addition has orccurred since
      0.10.0. Bump it to 0.10.20 for gst_message_parse_buffering_stats()

 README                                  |    2 +-
 clutter-gst/clutter-gst-debug.c         |    3 +-
 clutter-gst/clutter-gst-debug.h         |    3 +-
 clutter-gst/clutter-gst-video-texture.c |   64 ++++++++++++++++++++++--------
 configure.ac                            |    2 +-
 5 files changed, 53 insertions(+), 21 deletions(-)
---
diff --git a/README b/README
index fbdcebe..763e558 100644
--- a/README
+++ b/README
@@ -21,7 +21,7 @@ Clutter-GStreamer requires:
 
   GLib >= 2.18.0
   Clutter >= 1.4.0
-  GStreamer >= 0.10
+  GStreamer >= 0.10.20
 
 Copyright (C) 2006, 2007, 2008  OpenedHand
 Copyright (C) 2009, 2010, 2011 Intel Corporation
diff --git a/clutter-gst/clutter-gst-debug.c b/clutter-gst/clutter-gst-debug.c
index fac4798..bdba41e 100644
--- a/clutter-gst/clutter-gst-debug.c
+++ b/clutter-gst/clutter-gst-debug.c
@@ -38,7 +38,8 @@ static GTimer *clutter_gst_timer;
 static const GDebugKey clutter_gst_debug_keys[] = {
   { "misc",         CLUTTER_GST_DEBUG_MISC },
   { "media",        CLUTTER_GST_DEBUG_MEDIA },
-  { "aspect-ratio", CLUTTER_GST_DEBUG_ASPECT_RATIO }
+  { "aspect-ratio", CLUTTER_GST_DEBUG_ASPECT_RATIO },
+  { "buffering",    CLUTTER_GST_DEBUG_BUFFERING }
 };
 
 /**
diff --git a/clutter-gst/clutter-gst-debug.h b/clutter-gst/clutter-gst-debug.h
index 02b218a..1fc5051 100644
--- a/clutter-gst/clutter-gst-debug.h
+++ b/clutter-gst/clutter-gst-debug.h
@@ -36,7 +36,8 @@ G_BEGIN_DECLS
 typedef enum {
   CLUTTER_GST_DEBUG_MISC            = 1 << 0,
   CLUTTER_GST_DEBUG_MEDIA           = 1 << 1,
-  CLUTTER_GST_DEBUG_ASPECT_RATIO    = 1 << 2
+  CLUTTER_GST_DEBUG_ASPECT_RATIO    = 1 << 2,
+  CLUTTER_GST_DEBUG_BUFFERING       = 1 << 3
 } ClutterDebugFlag;
 
 #ifdef __GNUC__
diff --git a/clutter-gst/clutter-gst-video-texture.c b/clutter-gst/clutter-gst-video-texture.c
index f932390..47dd8d4 100644
--- a/clutter-gst/clutter-gst-video-texture.c
+++ b/clutter-gst/clutter-gst-video-texture.c
@@ -63,8 +63,11 @@ struct _ClutterGstVideoTexturePrivate
   guint in_seek : 1;
   guint is_idle : 1;
   guint is_changing_uri : 1;
+
   gdouble stacked_progress;
+
   gdouble target_progress;
+  GstState target_state;
 
   guint tick_timeout_id;
 
@@ -444,16 +447,13 @@ set_playing (ClutterGstVideoTexture *video_texture,
 
   CLUTTER_GST_NOTE (MEDIA, "set playing: %d", playing);
 
+  priv->target_state = playing ? GST_STATE_PLAYING : GST_STATE_PAUSED;
+
   if (priv->uri)
     {
-      GstState state = GST_STATE_PAUSED;
-
-      if (playing)
-	state = GST_STATE_PLAYING;
-
       priv->in_seek = FALSE;
 
-      gst_element_set_state (priv->pipeline, state);
+      gst_element_set_state (priv->pipeline, priv->target_state);
     }
   else
     {
@@ -1184,24 +1184,51 @@ bus_message_buffering_cb (GstBus                 *bus,
                           ClutterGstVideoTexture *video_texture)
 {
   ClutterGstVideoTexturePrivate *priv = video_texture->priv;
-  const GstStructure *str;
+  GstBufferingMode mode;
+  GstState current_state, pending_state = -1;
   gint buffer_percent;
-  gboolean res;
 
-  str = gst_message_get_structure (message);
-  if (!str)
-    return;
+  gst_message_parse_buffering_stats (message, &mode, NULL, NULL, NULL);
 
-  res = gst_structure_get_int (str, "buffer-percent", &buffer_percent);
-  if (res)
+  switch (mode)
     {
-      priv->buffer_fill = CLAMP ((gdouble) buffer_percent / 100.0,
-                                 0.0,
-                                 1.0);
+    case GST_BUFFERING_STREAM:
+      gst_message_parse_buffering (message, &buffer_percent);
+      priv->buffer_fill = CLAMP ((gdouble) buffer_percent / 100.0, 0.0, 1.0);
+
+      CLUTTER_GST_NOTE (BUFFERING, "buffer-fill: %.02f", priv->buffer_fill);
 
-      CLUTTER_GST_NOTE (MEDIA, "buffer-fill: %.02f", priv->buffer_fill);
+      /* The playbin2 documentation says that we need to pause the pipeline
+       * when there's not enough data yet. We try to limit the calls to
+       * gst_element_set_state() */
+      gst_element_get_state (priv->pipeline, &current_state, NULL, 0);
+
+      if (priv->buffer_fill < 1.0)
+        {
+          if (current_state != GST_STATE_PAUSED)
+            {
+              CLUTTER_GST_NOTE (BUFFERING, "pausing the pipeline");
+              gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
+            }
+        }
+      else
+        {
+          if (current_state != priv->target_state)
+            {
+              CLUTTER_GST_NOTE (BUFFERING, "restoring the pipeline");
+              gst_element_set_state (priv->pipeline, priv->target_state);
+            }
+        }
 
       g_object_notify (G_OBJECT (video_texture), "buffer-fill");
+      break;
+
+    case GST_BUFFERING_DOWNLOAD:
+    case GST_BUFFERING_TIMESHIFT:
+    case GST_BUFFERING_LIVE:
+    default:
+      g_warning ("Buffering mode %d not handled", mode);
+      break;
     }
 }
 
@@ -1428,6 +1455,9 @@ clutter_gst_video_texture_init (ClutterGstVideoTexture *video_texture)
 
   priv->par_n = priv->par_d = 1;
 
+  /* We default to not playing until someone calls set_playing(TRUE) */
+  priv->target_state = GST_STATE_PAUSED;
+
   /* Default to a fast seek, ie. same effect than set_seek_flags (NONE); */
   priv->seek_flags = GST_SEEK_FLAG_KEY_UNIT;
 
diff --git a/configure.ac b/configure.ac
index 325f1a7..2e2b980 100644
--- a/configure.ac
+++ b/configure.ac
@@ -130,7 +130,7 @@ dnl ========================================================================
 
 GST_MAJORMINOR=0.10
 
-pkg_modules="gstreamer-$GST_MAJORMINOR gstreamer-plugins-base-$GST_MAJORMINOR gstreamer-base-$GST_MAJORMINOR gstreamer-interfaces-$GST_MAJORMINOR gstreamer-video-$GST_MAJORMINOR gstreamer-audio-$GST_MAJORMINOR"
+pkg_modules="gstreamer-$GST_MAJORMINOR >= 0.10.20 gstreamer-plugins-base-$GST_MAJORMINOR gstreamer-base-$GST_MAJORMINOR gstreamer-interfaces-$GST_MAJORMINOR gstreamer-video-$GST_MAJORMINOR gstreamer-audio-$GST_MAJORMINOR"
 PKG_CHECK_MODULES(GST, [$pkg_modules])
 
 dnl ========================================================================



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]