[rygel-gst-0-10-fullscreen-renderer] cleanup



commit f081ebef91632da64948943a2bc16c6e9d25a42b
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Jan 28 11:33:42 2013 +0100

    cleanup

 src/rygel-playbin-player.c |  305 +++++++++++++++-----------------------------
 1 files changed, 101 insertions(+), 204 deletions(-)
---
diff --git a/src/rygel-playbin-player.c b/src/rygel-playbin-player.c
index 1ad5263..34d71da 100644
--- a/src/rygel-playbin-player.c
+++ b/src/rygel-playbin-player.c
@@ -95,14 +95,13 @@ static gboolean rygel_playbin_player_real_seek (RygelMediaPlayer *base, gint64 t
 static gchar **rygel_playbin_player_real_get_protocols (RygelMediaPlayer *base, int *result_length1);
 static gchar **rygel_playbin_player_real_get_mime_types (RygelMediaPlayer *base, int *result_length1);
 static gboolean rygel_playbin_player_is_rendering_image (RygelPlaybinPlayer *self);
-static void rygel_playbin_player_bus_handler (RygelPlaybinPlayer *self, GstBus *bus, GstMessage *message);
+static void rygel_playbin_player_bus_handler (GstBus *bus, GstMessage *message, gpointer user_data);
 static inline gchar *_dynamic_get_uri1 (GstElement *obj);
 static inline gchar *_dynamic_get_uri2 (GstElement *obj);
 static gchar *rygel_playbin_player_generate_basic_didl (RygelPlaybinPlayer *self);
 static void rygel_playbin_player_on_source_setup (GstElement *sender, GstElement *source, gpointer user_data);
 static void rygel_playbin_player_on_uri_notify (GObject *sender, GParamSpec *pspec, gpointer user_data);
 static inline void _dynamic_set_auto_flush_bus4 (GstElement *obj, gboolean value);
-static void _rygel_playbin_player_bus_handler_gst_bus_message (GstBus *_sender, GstMessage *message, gpointer self);
 static inline void _dynamic_set_uri5 (GstElement *obj, const gchar *value);
 static inline void _dynamic_set_volume7 (GstElement *obj, gdouble value);
 static void rygel_playbin_player_finalize (GObject *obj);
@@ -247,128 +246,75 @@ static inline gchar *_dynamic_get_uri2 (GstElement *obj) {
 }
 
 
-static void rygel_playbin_player_bus_handler (RygelPlaybinPlayer *self, GstBus *bus, GstMessage *message) {
-  GstMessage *_tmp0_;
-  GstMessageType _tmp1_;
+static void
+rygel_playbin_player_bus_handler (GstBus *bus, GstMessage *message, gpointer user_data) {
+  RygelPlaybinPlayer *self = RYGEL_PLAYBIN_PLAYER (user_data);
   g_return_if_fail (self);
+
   g_return_if_fail (bus);
   g_return_if_fail (message);
-  _tmp0_ = message;
-  _tmp1_ = _tmp0_->type;
-  switch (_tmp1_) {
+
+  switch (message->type) {
     case GST_MESSAGE_DURATION:
     {
-      self->priv->duration_hint = TRUE;
+      GstFormat format = GST_FORMAT_TIME;
+      if (gst_element_query_duration (self->priv->_playbin, &format, NULL)) {
+        g_object_notify (G_OBJECT (self), "duration");
+      }
+
       break;
     }
     case GST_MESSAGE_STATE_CHANGED:
     {
-      GstMessage *_tmp2_;
-      GstObject *_tmp3_;
-      GstElement *_tmp4_;
-      _tmp2_ = message;
-      _tmp3_ = _tmp2_->src;
-      _tmp4_ = self->priv->_playbin;
-      if (_tmp3_ == G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GST_TYPE_OBJECT, GstObject)) {
+      if (message->src == GST_OBJECT (self->priv->_playbin)) {
         GstState old_state = 0;
         GstState new_state = 0;
         GstState pending = 0;
-        GstMessage *_tmp5_;
-        GstState _tmp6_ = 0;
-        GstState _tmp7_ = 0;
-        GstState _tmp8_ = 0;
-        gboolean _tmp9_ = FALSE;
-        GstState _tmp10_;
-        gboolean _tmp12_;
-        gboolean _tmp25_ = FALSE;
-        GstState _tmp26_;
-        gboolean _tmp28_;
-        gboolean _tmp30_ = FALSE;
-        GstState _tmp31_;
-        gboolean _tmp33_;
-        _tmp5_ = message;
-        gst_message_parse_state_changed (_tmp5_, &_tmp6_, &_tmp7_, &_tmp8_);
-        old_state = _tmp6_;
-        new_state = _tmp7_;
-        pending = _tmp8_;
-        _tmp10_ = old_state;
-        if (_tmp10_ == GST_STATE_READY) {
-          GstState _tmp11_;
-          _tmp11_ = new_state;
-          _tmp9_ = _tmp11_ == GST_STATE_PAUSED;
-        } else {
-          _tmp9_ = FALSE;
-        }
-        _tmp12_ = _tmp9_;
-        if (_tmp12_) {
-          gboolean _tmp13_;
-          gboolean _tmp14_;
-          _tmp13_ = self->priv->duration_hint;
-          if (_tmp13_) {
-            g_object_notify ((GObject*) self, "duration");
-            self->priv->duration_hint = FALSE;
-          }
-          _tmp14_ = self->priv->uri_update_hint;
-          if (_tmp14_) {
-            GstElement *_tmp15_;
-            gchar *_tmp16_;
-            gchar *_tmp17_;
-            gchar *uri;
-            const gchar *_tmp18_;
-            const gchar *_tmp19_;
+        gst_message_parse_state_changed (message, &old_state, &new_state, &pending);
+        if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED) {
+          if (self->priv->uri_update_hint) {
             self->priv->uri_update_hint = FALSE;
-            _tmp15_ = self->priv->_playbin;
-            _tmp16_ = _dynamic_get_uri1 (_tmp15_);
-            _tmp17_ = _tmp16_;
-            uri = _tmp17_;
-            _tmp18_ = self->priv->_uri;
-            _tmp19_ = uri;
-            if (g_strcmp0 (_tmp18_, _tmp19_) != 0) {
-              GstElement *_tmp20_;
-              gchar *_tmp21_;
-              gchar *_tmp22_;
-              gchar *_tmp23_ = NULL;
-              gchar *_tmp24_;
-              _tmp20_ = self->priv->_playbin;
-              _tmp21_ = _dynamic_get_uri2 (_tmp20_);
-              _tmp22_ = _tmp21_;
-              g_free (self->priv->_uri);
-              self->priv->_uri = _tmp22_;
-              g_object_notify ((GObject*) self, "uri");
-              _tmp23_ = rygel_playbin_player_generate_basic_didl (self);
-              _tmp24_ = _tmp23_;
-              rygel_media_player_set_metadata ((RygelMediaPlayer*) self, _tmp24_);
-              g_free (_tmp24_);
+
+            gchar *current_uri = NULL;
+            g_object_get (self->priv->_playbin, "current-uri", &current_uri, NULL);
+
+            if (g_strcmp0 (self->priv->_uri, current_uri) != 0
+              && g_strcmp0 (current_uri, "") != 0) {
+
+              // uri changed externally
+              if (self->priv->_uri)
+                g_free (self->priv->_uri);
+
+              gchar *uri = NULL;
+              g_object_get (self->priv->_playbin, "uri", &uri, NULL);
+              self->priv->_uri = uri;
+              g_object_notify (G_OBJECT (self), "uri");
+
+              gchar *metadata = rygel_playbin_player_generate_basic_didl (self);
+              rygel_media_player_set_metadata (RYGEL_MEDIA_PLAYER (self), metadata);
+              g_free (metadata);
             }
-            g_free (uri);
+
+            g_free (current_uri);
           }
         }
-        _tmp26_ = pending;
-        if (_tmp26_ == GST_STATE_VOID_PENDING) {
-          gboolean _tmp27_;
-          _tmp27_ = self->priv->buffering;
-          _tmp25_ = !_tmp27_;
-        } else {
-          _tmp25_ = FALSE;
-        }
-        _tmp28_ = _tmp25_;
-        if (_tmp28_) {
-          GstState _tmp29_;
-          _tmp29_ = new_state;
-          switch (_tmp29_) {
+
+        if (pending == GST_STATE_VOID_PENDING
+          && !self->priv->buffering) {
+          switch (new_state) {
             case GST_STATE_PAUSED:
             {
-              rygel_media_player_set_playback_state ((RygelMediaPlayer*) self, "PAUSED_PLAYBACK");
+              rygel_media_player_set_playback_state (RYGEL_MEDIA_PLAYER (self), "PAUSED_PLAYBACK");
               break;
             }
             case GST_STATE_NULL:
             {
-              rygel_media_player_set_playback_state ((RygelMediaPlayer*) self, "STOPPED");
+              rygel_media_player_set_playback_state (RYGEL_MEDIA_PLAYER (self), "STOPPED");
               break;
             }
             case GST_STATE_PLAYING:
             {
-              rygel_media_player_set_playback_state ((RygelMediaPlayer*) self, "PLAYING");
+              rygel_media_player_set_playback_state (RYGEL_MEDIA_PLAYER (self), "PLAYING");
               break;
             }
             default:
@@ -377,113 +323,68 @@ static void rygel_playbin_player_bus_handler (RygelPlaybinPlayer *self, GstBus *
             }
           }
         }
-        _tmp31_ = old_state;
-        if (_tmp31_ == GST_STATE_PAUSED) {
-          GstState _tmp32_;
-          _tmp32_ = new_state;
-          _tmp30_ = _tmp32_ == GST_STATE_PLAYING;
-        } else {
-          _tmp30_ = FALSE;
-        }
-        _tmp33_ = _tmp30_;
-        if (_tmp33_) {
+
+        if (old_state == GST_STATE_PAUSED
+          && new_state == GST_STATE_PLAYING) {
           self->priv->buffering = FALSE;
-          rygel_media_player_set_playback_state ((RygelMediaPlayer*) self, "PLAYING");
+          rygel_media_player_set_playback_state (RYGEL_MEDIA_PLAYER (self), "PLAYING");
         }
       }
+
       break;
     }
     case GST_MESSAGE_BUFFERING:
     {
-      gboolean _tmp34_ = FALSE;
-      gboolean _tmp35_;
-      gboolean _tmp37_;
-      _tmp35_ = self->priv->is_live;
-      if (_tmp35_) {
-        _tmp34_ = TRUE;
-      } else {
-        gboolean _tmp36_;
-        _tmp36_ = self->priv->foreign;
-        _tmp34_ = _tmp36_;
-      }
-      _tmp37_ = _tmp34_;
-      if (!_tmp37_) {
+      // Assume the original application takes care of this.
+      if (!self->priv->is_live || self->priv->foreign) {
         gint percent = 0;
-        GstMessage *_tmp38_;
-        gint _tmp39_ = 0;
-        gint _tmp40_;
-        _tmp38_ = message;
-        gst_message_parse_buffering (_tmp38_, &_tmp39_);
-        percent = _tmp39_;
-        _tmp40_ = percent;
-        if (_tmp40_ < 100) {
-          GstElement *_tmp41_;
+        gst_message_parse_buffering (message, &percent);
+ 
+        if (percent < 100) {
           self->priv->buffering = TRUE;
-          _tmp41_ = self->priv->_playbin;
-          gst_element_set_state (_tmp41_, GST_STATE_PAUSED);
+          gst_element_set_state (self->priv->_playbin, GST_STATE_PAUSED);
         } else {
-          GstElement *_tmp42_;
-          _tmp42_ = self->priv->_playbin;
-          gst_element_set_state (_tmp42_, GST_STATE_PLAYING);
+          gst_element_set_state (self->priv->_playbin, GST_STATE_PLAYING);
         }
       }
+
       break;
     }
     case GST_MESSAGE_CLOCK_LOST:
     {
-      gboolean _tmp43_;
-      _tmp43_ = self->priv->foreign;
-      if (!_tmp43_) {
-        GstElement *_tmp44_;
-        GstElement *_tmp45_;
-        _tmp44_ = self->priv->_playbin;
-        gst_element_set_state (_tmp44_, GST_STATE_PAUSED);
-        _tmp45_ = self->priv->_playbin;
-        gst_element_set_state (_tmp45_, GST_STATE_PLAYING);
+      // Assume the original application takes care of this.
+      if (!self->priv->foreign) {
+        gst_element_set_state (self->priv->_playbin, GST_STATE_PAUSED);
+        gst_element_set_state (self->priv->_playbin, GST_STATE_PLAYING);
       }
+
       break;
     }
     case GST_MESSAGE_EOS:
     {
-      gboolean _tmp46_ = FALSE;
-      _tmp46_ = rygel_playbin_player_is_rendering_image (self);
-      if (!_tmp46_) {
-        g_debug ("rygel-playbin-player.vala:400: EOS");
-        rygel_media_player_set_playback_state ((RygelMediaPlayer*) self, "STOPPED");
+      if(!rygel_playbin_player_is_rendering_image (self)) {
+        g_debug ("rygel-playbin-player.c: EOS");
+        rygel_media_player_set_playback_state (RYGEL_MEDIA_PLAYER (self), "STOPPED");
       } else {
-        g_debug ("rygel-playbin-player.vala:403: Content is image, ignoring EOS");
+        g_debug ("rygel-playbin-player.c: Content is image. Ignoring EOS");
       }
+
       break;
     }
     case GST_MESSAGE_ERROR:
     {
-      GError *_error_ = NULL;
       gchar *error_message = NULL;
-      GstMessage *_tmp47_;
-      GError *_tmp48_ = NULL;
-      gchar *_tmp49_ = NULL;
-      GstElement *_tmp50_;
-      gchar *_tmp51_;
-      gchar *_tmp52_;
-      gchar *_tmp53_;
-      const gchar *_tmp54_;
-      _tmp47_ = message;
-      gst_message_parse_error (_tmp47_, &_tmp48_, &_tmp49_);
-      g_error_free (_error_);
-      _error_ = _tmp48_;
-      g_free (error_message);
-      error_message = _tmp49_;
-      _tmp50_ = self->priv->_playbin;
-      _tmp51_ = gst_object_get_name ((GstObject*) _tmp50_);
-      _tmp52_ = _tmp51_;
-      _tmp53_ = _tmp52_;
-      _tmp54_ = error_message;
-      g_warning ("rygel-playbin-player.vala:413: Error from GStreamer element %s: %s", _tmp53_, _tmp54_);
-      g_free (_tmp53_);
-      g_warning ("rygel-playbin-player.vala:416: Going to STOPPED state");
-      rygel_media_player_set_playback_state ((RygelMediaPlayer*) self, "STOPPED");
+      gst_message_parse_error (message, NULL, &error_message);
+
+      gchar *name = gst_object_get_name (GST_OBJECT (self->priv->_playbin));
+
+      g_warning ("rygel-playbin-player.c: Error from GStreamer element %s: %s", name, error_message);
+      g_warning ("rygel-playbin-player.c: Going to STOPPED state");
+      g_free (name);
+
+      rygel_media_player_set_playback_state (RYGEL_MEDIA_PLAYER (self), "STOPPED");
       g_free (error_message);
-      g_error_free (_error_);
+
       break;
     }
     default:
@@ -570,21 +471,17 @@ static void rygel_playbin_player_on_uri_notify (GObject *sender, GParamSpec *psp
   self->priv->uri_update_hint = TRUE;
 }
 
-static void _rygel_playbin_player_bus_handler_gst_bus_message (GstBus *_sender, GstMessage *message, gpointer self) {
-  rygel_playbin_player_bus_handler (self, _sender, message);
-}
-
-
 static void rygel_playbin_player_setup_playbin (RygelPlaybinPlayer *self) {
   GstBus *bus = NULL;
 
   g_return_if_fail (self);
   g_return_if_fail (self->priv->_playbin);
 
+  self->priv->duration_hint = FALSE;
+
   /* Needed to get "Stop" events from the playbin.
    * We can do this because we have a bus watch.
    */
-  self->priv->duration_hint = FALSE;
   self->priv->is_live = FALSE;
 
   g_object_set (self->priv->_playbin, "auto-flush-bus", FALSE, NULL);
@@ -598,7 +495,7 @@ static void rygel_playbin_player_setup_playbin (RygelPlaybinPlayer *self) {
   g_return_if_fail (bus);
 
   gst_bus_add_signal_watch (bus);
-  g_signal_connect_object (bus, "message", (GCallback) _rygel_playbin_player_bus_handler_gst_bus_message, self, 0);
+  g_signal_connect_object (bus, "message", (GCallback) rygel_playbin_player_bus_handler, self, 0);
 
   gst_object_unref (bus);
 }
@@ -873,7 +770,7 @@ static void rygel_playbin_player_real_set_uri (RygelMediaPlayer *base, const gch
           _tmp10_ = g_strdup ("STOPPED");
           g_free (self->priv->_playback_state);
           self->priv->_playback_state = _tmp10_;
-          g_object_notify ((GObject*) self, "playback-state");
+          g_object_notify (G_OBJECT (self), "playback-state");
           break;
         }
       }
@@ -921,7 +818,7 @@ static void rygel_playbin_player_real_set_uri (RygelMediaPlayer *base, const gch
     _tmp15_ = g_strdup ("NO_MEDIA_PRESENT");
     g_free (self->priv->_playback_state);
     self->priv->_playback_state = _tmp15_;
-    g_object_notify ((GObject*) self, "playback-state");
+    g_object_notify (G_OBJECT (self), "playback-state");
   }
   _tmp16_ = value;
   g_debug ("rygel-playbin-player.vala:179: URI set to %s.", _tmp16_);
@@ -1007,7 +904,7 @@ static void rygel_playbin_player_real_set_content_features (RygelMediaPlayer *ba
   gchar *_tmp16_;
   GError *_inner_error_ = NULL;
   self = (RygelPlaybinPlayer*) base;
-  _tmp0_ = rygel_media_player_get_mime_type ((RygelMediaPlayer*) self);
+  _tmp0_ = rygel_media_player_get_mime_type (RYGEL_MEDIA_PLAYER (self));
   _tmp1_ = _tmp0_;
   _tmp2_ = _tmp1_;
   _tmp3_ = value;
@@ -1250,40 +1147,40 @@ static void _vala_rygel_playbin_player_get_property (GObject *object, guint prop
     g_value_set_object (value, rygel_playbin_player_get_playbin (self));
     break;
     case RYGEL_PLAYBIN_PLAYER_PLAYBACK_STATE:
-    g_value_take_string (value, rygel_media_player_get_playback_state ((RygelMediaPlayer*) self));
+    g_value_take_string (value, rygel_media_player_get_playback_state (RYGEL_MEDIA_PLAYER (self)));
     break;
     case RYGEL_PLAYBIN_PLAYER_ALLOWED_PLAYBACK_SPEEDS:
     {
       int length;
-      g_value_take_boxed (value, rygel_media_player_get_allowed_playback_speeds ((RygelMediaPlayer*) self, &length));
+      g_value_take_boxed (value, rygel_media_player_get_allowed_playback_speeds (RYGEL_MEDIA_PLAYER (self), &length));
     }
     break;
     case RYGEL_PLAYBIN_PLAYER_PLAYBACK_SPEED:
-    g_value_take_string (value, rygel_media_player_get_playback_speed ((RygelMediaPlayer*) self));
+    g_value_take_string (value, rygel_media_player_get_playback_speed (RYGEL_MEDIA_PLAYER (self)));
     break;
     case RYGEL_PLAYBIN_PLAYER_URI:
-    g_value_take_string (value, rygel_media_player_get_uri ((RygelMediaPlayer*) self));
+    g_value_take_string (value, rygel_media_player_get_uri (RYGEL_MEDIA_PLAYER (self)));
     break;
     case RYGEL_PLAYBIN_PLAYER_MIME_TYPE:
-    g_value_take_string (value, rygel_media_player_get_mime_type ((RygelMediaPlayer*) self));
+    g_value_take_string (value, rygel_media_player_get_mime_type (RYGEL_MEDIA_PLAYER (self)));
     break;
     case RYGEL_PLAYBIN_PLAYER_METADATA:
-    g_value_take_string (value, rygel_media_player_get_metadata ((RygelMediaPlayer*) self));
+    g_value_take_string (value, rygel_media_player_get_metadata (RYGEL_MEDIA_PLAYER (self)));
     break;
     case RYGEL_PLAYBIN_PLAYER_CAN_SEEK:
-    g_value_set_boolean (value, rygel_media_player_get_can_seek ((RygelMediaPlayer*) self));
+    g_value_set_boolean (value, rygel_media_player_get_can_seek (RYGEL_MEDIA_PLAYER (self)));
     break;
     case RYGEL_PLAYBIN_PLAYER_CONTENT_FEATURES:
-    g_value_take_string (value, rygel_media_player_get_content_features ((RygelMediaPlayer*) self));
+    g_value_take_string (value, rygel_media_player_get_content_features (RYGEL_MEDIA_PLAYER (self)));
     break;
     case RYGEL_PLAYBIN_PLAYER_VOLUME:
-    g_value_set_double (value, rygel_media_player_get_volume ((RygelMediaPlayer*) self));
+    g_value_set_double (value, rygel_media_player_get_volume (RYGEL_MEDIA_PLAYER (self)));
     break;
     case RYGEL_PLAYBIN_PLAYER_DURATION:
-    g_value_set_int64 (value, rygel_media_player_get_duration ((RygelMediaPlayer*) self));
+    g_value_set_int64 (value, rygel_media_player_get_duration (RYGEL_MEDIA_PLAYER (self)));
     break;
     case RYGEL_PLAYBIN_PLAYER_POSITION:
-    g_value_set_int64 (value, rygel_media_player_get_position ((RygelMediaPlayer*) self));
+    g_value_set_int64 (value, rygel_media_player_get_position (RYGEL_MEDIA_PLAYER (self)));
     break;
     default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -1300,25 +1197,25 @@ static void _vala_rygel_playbin_player_set_property (GObject *object, guint prop
     rygel_playbin_player_set_playbin (self, g_value_get_object (value));
     break;
     case RYGEL_PLAYBIN_PLAYER_PLAYBACK_STATE:
-    rygel_media_player_set_playback_state ((RygelMediaPlayer*) self, g_value_get_string (value));
+    rygel_media_player_set_playback_state (RYGEL_MEDIA_PLAYER (self), g_value_get_string (value));
     break;
     case RYGEL_PLAYBIN_PLAYER_PLAYBACK_SPEED:
-    rygel_media_player_set_playback_speed ((RygelMediaPlayer*) self, g_value_get_string (value));
+    rygel_media_player_set_playback_speed (RYGEL_MEDIA_PLAYER (self), g_value_get_string (value));
     break;
     case RYGEL_PLAYBIN_PLAYER_URI:
-    rygel_media_player_set_uri ((RygelMediaPlayer*) self, g_value_get_string (value));
+    rygel_media_player_set_uri (RYGEL_MEDIA_PLAYER (self), g_value_get_string (value));
     break;
     case RYGEL_PLAYBIN_PLAYER_MIME_TYPE:
-    rygel_media_player_set_mime_type ((RygelMediaPlayer*) self, g_value_get_string (value));
+    rygel_media_player_set_mime_type (RYGEL_MEDIA_PLAYER (self), g_value_get_string (value));
     break;
     case RYGEL_PLAYBIN_PLAYER_METADATA:
-    rygel_media_player_set_metadata ((RygelMediaPlayer*) self, g_value_get_string (value));
+    rygel_media_player_set_metadata (RYGEL_MEDIA_PLAYER (self), g_value_get_string (value));
     break;
     case RYGEL_PLAYBIN_PLAYER_CONTENT_FEATURES:
-    rygel_media_player_set_content_features ((RygelMediaPlayer*) self, g_value_get_string (value));
+    rygel_media_player_set_content_features (RYGEL_MEDIA_PLAYER (self), g_value_get_string (value));
     break;
     case RYGEL_PLAYBIN_PLAYER_VOLUME:
-    rygel_media_player_set_volume ((RygelMediaPlayer*) self, g_value_get_double (value));
+    rygel_media_player_set_volume (RYGEL_MEDIA_PLAYER (self), g_value_get_double (value));
     break;
     default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);



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