[rygel] librenderer: Add API to wrap an existing playbin



commit bc778609cf4a1333864b01b0c6a467d769b32b52
Author: Jens Georg <mail jensge org>
Date:   Mon Jul 2 13:04:17 2012 +0200

    librenderer: Add API to wrap an existing playbin

 src/librygel-renderer/rygel-playbin-player.vala   |   31 +++++++++-----
 src/librygel-renderer/rygel-playbin-renderer.vala |   47 +++++++++++++++-----
 2 files changed, 55 insertions(+), 23 deletions(-)
---
diff --git a/src/librygel-renderer/rygel-playbin-player.vala b/src/librygel-renderer/rygel-playbin-player.vala
index 1a75056..392f21e 100644
--- a/src/librygel-renderer/rygel-playbin-player.vala
+++ b/src/librygel-renderer/rygel-playbin-player.vala
@@ -249,18 +249,12 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
 
     private Player () {
         this.playbin = ElementFactory.make ("playbin2", null);
-        // 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);
+        this.setup_playbin ();
+    }
 
-        // Bus handler
-        var bus = this.playbin.get_bus ();
-        bus.add_signal_watch ();
-        bus.message.connect (this.bus_handler);
+    public Player.wrap (Gst.Element playbin) {
+        this.playbin = playbin;
+        this.setup_playbin ();
     }
 
     public static Player get_default () {
@@ -404,4 +398,19 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
 
         return writer.get_string ();
     }
+
+    private void setup_playbin () {
+        // 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);
+
+        // Bus handler
+        var bus = this.playbin.get_bus ();
+        bus.add_signal_watch ();
+        bus.message.connect (this.bus_handler);
+    }
 }
diff --git a/src/librygel-renderer/rygel-playbin-renderer.vala b/src/librygel-renderer/rygel-playbin-renderer.vala
index 44b8f4a..0f584fd 100644
--- a/src/librygel-renderer/rygel-playbin-renderer.vala
+++ b/src/librygel-renderer/rygel-playbin-renderer.vala
@@ -26,7 +26,7 @@ internal class Rygel.Playbin.RendererContext {
     public RootDeviceFactory factory;
     public Context context;
 
-    public RendererContext (Context context, Plugin plugin) throws Error {
+    public RendererContext (Context context, MediaRendererPlugin plugin) throws Error {
         this.context = context;
         this.factory = new RootDeviceFactory (context);
         this.device = this.factory.create (plugin);
@@ -34,25 +34,35 @@ internal class Rygel.Playbin.RendererContext {
     }
 }
 
+internal class Rygel.Playbin.WrappingPlugin : Rygel.MediaRendererPlugin {
+    private MediaPlayer player;
+
+    public WrappingPlugin (Gst.Element playbin) {
+        base ("LibRygel-Renderer", _("LibRygel Renderer"));
+        this.player = new Player.wrap (playbin);
+    }
+
+
+    public override MediaPlayer? get_player () {
+        return this.player;
+    }
+}
+
 public class Rygel.Playbin.Renderer : Object {
     private ArrayList<string> interfaces;
     private HashMap<string, Context> contexts;
     private HashMap<string, RendererContext> renderer;
     private ContextManager manager;
-    private Plugin plugin;
+    private MediaRendererPlugin plugin;
 
     public Renderer (string title) {
-        manager = ContextManager.create (0);
-        manager.context_available.connect (this.on_context_available);
-        manager.context_unavailable.connect (this.on_context_unavailable);
-        this.interfaces = new ArrayList<string> ();
-        this.contexts = new HashMap<string, Context> ();
-        this.renderer = new HashMap<string, RendererContext> ();
-        plugin = new Plugin ();
-        plugin.title = title;
+        this.plugin = new Plugin ();
+        this.prepare_upnp (title);
+    }
 
-        // Always listen on localhost
-        this.add_interface ("lo");
+    public Renderer.wrap (Gst.Element pipeline, string title) {
+        this.plugin = new WrappingPlugin (pipeline);
+        this.prepare_upnp (title);
     }
 
     public void add_interface (string iface) {
@@ -111,4 +121,17 @@ public class Rygel.Playbin.Renderer : Object {
     private void on_context_unavailable (Context context) {
         this.remove_interface (context.interface);
     }
+
+    private void prepare_upnp (string title) {
+        this.manager = ContextManager.create (0);
+        this.manager.context_available.connect (this.on_context_available);
+        this.manager.context_unavailable.connect (this.on_context_unavailable);
+        this.interfaces = new ArrayList<string> ();
+        this.contexts = new HashMap<string, Context> ();
+        this.renderer = new HashMap<string, RendererContext> ();
+        this.plugin.title = title;
+
+        // Always listen on localhost
+        this.add_interface ("lo");
+    }
 }



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