media-export,engine-gst: Port to new GUPnP-DLNA
[profile/ivi/rygel.git] / src / media-engines / gstreamer / rygel-gst-media-engine.vala
1 /*
2  * Copyright (C) 2012 Intel Corporation.
3  *
4  * Author: Jens Georg <jensg@openismus.com>
5  *
6  * This file is part of Rygel.
7  *
8  * Rygel is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Rygel is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22
23 using Gst;
24 using Gee;
25
26 // Remove for GStreamer 1.0
27 [CCode (cname = "PRESET_DIR")]
28 internal extern static const string PRESET_DIR;
29
30 [CCode (cname="gst_preset_set_app_dir")]
31 extern bool gst_preset_set_app_dir (string app_dir);
32
33 public class Rygel.GstMediaEngine : Rygel.MediaEngine {
34     private GLib.List<DLNAProfile> dlna_profiles = null;
35     private GLib.List<Transcoder> transcoders = null;
36
37     public GstMediaEngine () {
38         unowned string[] args = null;
39
40         Gst.init (ref args);
41         gst_preset_set_app_dir (PRESET_DIR);
42
43         /* Get the possible DLNA profiles
44          * to add to the list of DLNA profiles supported by
45          * this media engine, for get_dlna_profiles():
46          */
47         var discoverer = new GUPnPDLNA.ProfileGuesser (true, false);
48         foreach (var profile in discoverer.list_profiles ()) {
49             var p = new DLNAProfile (profile.name, profile.mime);
50
51             /* TODO: Check that we (via GStreamer) really support this profile
52              * instead of just claiming to support everything.
53              */
54             this.dlna_profiles.prepend (p);
55         }
56         this.dlna_profiles.prepend (new DLNAProfile ("DIDL_S", "text/xml"));
57
58         this.dlna_profiles.reverse ();
59
60         var transcoding = true;
61         var transcoder_list = new ArrayList<string> ();
62
63         /* Allow some transcoders to be disabled by the Rygel Server configuration.
64          * For instance, some DLNA Renderers might incorrectly prefer inferior transcoded formats,
65          * sometimes even preferring transcoded formats over the original data,
66          * so this forces them to use other formats.
67          */
68         var config = MetaConfig.get_default ();
69         try {
70             transcoding = config.get_transcoding ();
71             transcoder_list = config.get_string_list ("GstMediaEngine",
72                                                       "transcoders");
73         } catch (Error err) {}
74
75         if (transcoding) {
76             foreach (var transcoder in transcoder_list) {
77                 switch (transcoder) {
78                     case "lpcm":
79                         this.transcoders.prepend (new L16Transcoder ());
80                         break;
81                     case "mp3":
82                         this.transcoders.prepend (new MP3Transcoder ());
83                         break;
84                     case "mp2ts":
85                         this.transcoders.prepend (new MP2TSTranscoder
86                                         (MP2TSProfile.SD_EU));
87                         this.transcoders.prepend (new MP2TSTranscoder
88                                         (MP2TSProfile.SD_NA));
89                         this.transcoders.prepend (new MP2TSTranscoder
90                                         (MP2TSProfile.HD_NA));
91                         break;
92                     case "wmv":
93                         this.transcoders.prepend (new WMVTranscoder ());
94                         break;
95                     case "aac":
96                         this.transcoders.prepend (new AACTranscoder ());
97                         break;
98                     case "avc":
99                         this.transcoders.prepend (new AVCTranscoder ());
100                         break;
101                     default:
102                         debug ("Unsupported transcoder \"%s\"", transcoder);
103                         break;
104                 }
105             }
106
107             this.transcoders.reverse ();
108         }
109     }
110
111     public override unowned GLib.List<DLNAProfile> get_dlna_profiles () {
112         return this.dlna_profiles;
113     }
114
115     public override unowned GLib.List<Transcoder>? get_transcoders () {
116         return this.transcoders;
117     }
118
119     public override DataSource? create_data_source (string uri) {
120         try {
121             return new GstDataSource (uri);
122         } catch (Error error) {
123             return null;
124         }
125     }
126
127     public DataSource create_data_source_from_element (Element element) {
128         return new GstDataSource.from_element (element);
129     }
130 }
131
132 public static Rygel.MediaEngine module_get_instance () {
133     return new Rygel.GstMediaEngine ();
134 }