[rygel] renderer-gst,playbin: Don't exit when playbin is missing



commit 33caa39d4d8bf643e68bbc49cd7466d88df5db65
Author: Jens Georg <mail jensge org>
Date:   Thu May 1 14:17:23 2014 +0200

    renderer-gst,playbin: Don't exit when playbin is missing
    
    Signed-off-by: Jens Georg <mail jensge org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710443

 .../rygel-playbin-player.vala                      |   24 ++++++++++++++++++-
 .../rygel-playbin-renderer.vala                    |   21 +++++++++++++----
 src/plugins/playbin/rygel-playbin-module.vala      |    9 +++++--
 src/plugins/playbin/rygel-playbin-plugin.vala      |   16 +++++++-----
 4 files changed, 53 insertions(+), 17 deletions(-)
---
diff --git a/src/librygel-renderer-gst/rygel-playbin-player.vala 
b/src/librygel-renderer-gst/rygel-playbin-player.vala
index 0bfb912..b71c5cc 100644
--- a/src/librygel-renderer-gst/rygel-playbin-player.vala
+++ b/src/librygel-renderer-gst/rygel-playbin-player.vala
@@ -30,6 +30,10 @@
 using Gst;
 using GUPnP;
 
+public errordomain Rygel.Playbin.PlayerError {
+    NO_ELEMENT
+}
+
 /**
  * Implementation of RygelMediaPlayer for GStreamer.
  *
@@ -339,8 +343,12 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
         }
     }
 
-    private Player () {
+    private Player () throws Error {
         this.playbin = ElementFactory.make ("playbin", null);
+        if (this.playbin == null) {
+            throw new PlayerError.NO_ELEMENT (
+                _("Your GStreamer installation seems to be missing the \"playbin\" element. The Rygel 
GStreamer renderer implementation cannot work without it"));
+        }
         this.setup_playbin ();
     }
 
@@ -351,8 +359,21 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
         this.setup_playbin ();
     }
 
+    [Deprecated (since="0.23.1")]
     public static Player get_default () {
         if (player == null) {
+            try {
+                player = new Player ();
+            } catch (Error error) {
+                assert_not_reached ();
+            }
+        }
+
+        return player;
+    }
+
+    public static Player instance () throws Error {
+        if (player == null) {
             player = new Player ();
         }
 
@@ -607,7 +628,6 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
         // Needed to get "Stop" events from the playbin.
         // We can do this because we have a bus watch
         this.playbin.auto_flush_bus = false;
-        assert (this.playbin != null);
 
         this.playbin.source_setup.connect (this.on_source_setup);
         this.playbin.notify["uri"].connect (this.on_uri_notify);
diff --git a/src/librygel-renderer-gst/rygel-playbin-renderer.vala 
b/src/librygel-renderer-gst/rygel-playbin-renderer.vala
index 0bc335d..14b6fd3 100644
--- a/src/librygel-renderer-gst/rygel-playbin-renderer.vala
+++ b/src/librygel-renderer-gst/rygel-playbin-renderer.vala
@@ -50,8 +50,14 @@ public class Rygel.Playbin.Renderer : Rygel.MediaRenderer {
      * @param title Friendly name of the new UPnP renderer on the network.
      */
     public Renderer (string title) {
-        Object (title: title,
-                player: Player.get_default ());
+        try {
+            Object (title: title,
+                    player: Player.instance ());
+        } catch (Error error) {
+            warning (error.message);
+
+            return_val_if_fail (false, null);
+        }
     }
 
     /**
@@ -73,9 +79,14 @@ public class Rygel.Playbin.Renderer : Rygel.MediaRenderer {
      * Get the GstPlayBin used by this Renderer.
      */
     public Gst.Element? get_playbin () {
-        var player = Rygel.Playbin.Player.get_default ();
-        return_val_if_fail (player != null, null);
+        try {
+            var player = Rygel.Playbin.Player.instance ();
+
+            return player.playbin;
+        } catch (Error error) {
+            warning (error.message);
 
-        return player.playbin;
+            return null;
+        }
     }
 }
diff --git a/src/plugins/playbin/rygel-playbin-module.vala b/src/plugins/playbin/rygel-playbin-module.vala
index 29d8668..9b03271 100644
--- a/src/plugins/playbin/rygel-playbin-module.vala
+++ b/src/plugins/playbin/rygel-playbin-module.vala
@@ -34,8 +34,11 @@ public void module_init (PluginLoader loader) {
     unowned string[] args = null;
 
     Gst.init (ref args);
+    try {
+        var plugin = new Playbin.Plugin ();
 
-    var plugin = new Playbin.Plugin ();
-
-    loader.add_plugin (plugin);
+        loader.add_plugin (plugin);
+    } catch (Error error) {
+        warning (error.message);
+    }
 }
diff --git a/src/plugins/playbin/rygel-playbin-plugin.vala b/src/plugins/playbin/rygel-playbin-plugin.vala
index 8f0e3ed..7507e19 100644
--- a/src/plugins/playbin/rygel-playbin-plugin.vala
+++ b/src/plugins/playbin/rygel-playbin-plugin.vala
@@ -31,16 +31,18 @@ using Gee;
 internal class Rygel.Playbin.Plugin : Rygel.MediaRendererPlugin {
     public const string NAME = "Playbin";
 
-    public Plugin () {
+    public Plugin () throws Error {
         base (Plugin.NAME, _("GStreamer Player"));
-    }
-
-    public override void constructed () {
-        base.constructed ();
-        this.supported_profiles = Player.get_default ().supported_profiles;
+        this.supported_profiles = Player.instance ().supported_profiles;
     }
 
     public override MediaPlayer? get_player () {
-        return Playbin.Player.get_default ();
+        try {
+            return Playbin.Player.instance ();
+        } catch (Error error) {
+            warning (_("Could not create GStreamer player"));
+
+            return null;
+        }
     }
 }


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