docs: Add overview documentation.
[profile/ivi/rygel.git] / src / librygel-renderer-gst / rygel-playbin-renderer.vala
1 /*
2  * Copyright (C) 2012 Openismus GmbH.
3  * Copyright (C) 2012 Intel Corporation.
4  *
5  * Author: Jens Georg <jensg@openismus.com>
6  *
7  * Rygel is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * Rygel is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21
22 using Gee;
23 using GUPnP;
24
25 internal class Rygel.Playbin.WrappingPlugin : Rygel.MediaRendererPlugin {
26     private MediaPlayer player;
27
28     public WrappingPlugin (Gst.Element playbin) {
29         base ("LibRygel-Renderer", _("LibRygel Renderer"));
30
31         return_val_if_fail (playbin != null, null);
32         return_val_if_fail (playbin.get_type ().name() == "GstPlayBin2", null);
33
34         this.player = new Player.wrap (playbin);
35     }
36
37
38     public override MediaPlayer? get_player () {
39         return this.player;
40     }
41 }
42
43 /**
44  * A UPnP renderer that uses a GStreamer Playbin2 element.
45  *
46  * Using GstPlayBin2 as a model, it reflects any changes done externally, such as
47  * changing the currently played URI, volume, pause/play etc., to UPnP.
48  *
49  * Likewise, the playbin can be modified externally using UPnP.
50  *
51  * You can retrieve the GstPlayBin2 by calling rygel_playbin_renderer_get_playbin().
52  * You should then set the "video-sink" and "audio-sink" properties of the
53  * playbin.
54  *
55  * Call rygel_media_device_add_interface() on the Renderer to allow it
56  * to be controlled by a control point and to retrieve data streams via that
57  * network interface.
58  *
59  * See the example code in the <link linkend="overview">overview</link>.
60  */
61 public class Rygel.Playbin.Renderer : Rygel.MediaDevice {
62     /**
63      * Create a new instance of Renderer.
64      *
65      * Renderer will instantiate its own instance of GstPlayBin2.
66      * The GstPlayBin2 can be accessed by using rygel_playbin_player_get_playbin().
67      *
68      * @param title Friendly name of the new UPnP renderer on the network.
69      */
70     public Renderer (string title) {
71         base ();
72         this.plugin = new Plugin ();
73         this.prepare_upnp (title);
74     }
75
76     /**
77      * Create a new instance of Renderer, wrapping an existing GstPlayBin2
78      * instance.
79      *
80      * @param pipeline Instance of GstPlayBin2 to wrap.
81      * @param title Friendly name of the new UPnP renderer on the network.
82      */
83     public Renderer.wrap (Gst.Element pipeline, string title) {
84         base ();
85
86         return_val_if_fail (pipeline != null, null);
87         return_val_if_fail (pipeline.get_type ().name() == "GstPlayBin2", null);
88
89         this.plugin = new WrappingPlugin (pipeline);
90         this.prepare_upnp (title);
91     }
92
93     /**
94      * Get the GstPlaybin2 used by this Renderer.
95      */
96     public Gst.Element? get_playbin () {
97         var player = Rygel.Playbin.Player.get_default ();
98         return_val_if_fail (player != null, null);
99
100         return player.playbin;
101     }
102
103     private void prepare_upnp (string title) {
104         this.plugin.title = title;
105
106         // Always listen on localhost
107         this.add_interface ("lo");
108     }
109 }