Branch data Line data Source code
1 : : /* GStreamer
2 : : * nf_get_default_audio_sink
3 : : * Copyright (C) <2002> Thomas Vander Stichele <thomas@apestaart.org>
4 : : * Copyright (C) <2006> Jürg Billeter <j@bitron.ch>
5 : : *
6 : : * This library is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU Library General Public
8 : : * License as published by the Free Software Foundation; either
9 : : * version 2 of the License, or (at your option) any later version.
10 : : *
11 : : * This library is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : : * Library General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU Library General Public
17 : : * License along with this library; if not, write to the
18 : : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 : : * Boston, MA 02111-1307, USA.
20 : : */
21 : :
22 : : /*
23 : : * this library handles interaction with GConf
24 : : */
25 : :
26 : : #ifdef HAVE_CONFIG_H
27 : : #include "config.h"
28 : : #endif
29 : :
30 : : #include <gst/gst.h>
31 : :
32 : : #include "gstgconf.h"
33 : : #include "gstgconfelements.h" /* for debug category */
34 : :
35 : : #ifndef GST_GCONF_DIR
36 : : #error "GST_GCONF_DIR is not defined !"
37 : : #endif
38 : :
39 : : static GConfClient *_gst_gconf_client = NULL; /* GConf connection */
40 : :
41 : :
42 : : /* internal functions */
43 : :
44 : : static GConfClient *
45 : 0 : gst_gconf_get_client (void)
46 : : {
47 [ # # ]: 0 : if (!_gst_gconf_client)
48 : 0 : _gst_gconf_client = gconf_client_get_default ();
49 : :
50 : 0 : return _gst_gconf_client;
51 : : }
52 : :
53 : : /* external functions */
54 : :
55 : : /**
56 : : * gst_gconf_get_string:
57 : : * @key: a #gchar corresponding to the key you want to get.
58 : : *
59 : : * Get GConf key @key's string value.
60 : : *
61 : : * Returns: a newly allocated #gchar string containing @key's value,
62 : : * or NULL in the case of an error..
63 : : */
64 : : gchar *
65 : 0 : gst_gconf_get_string (const gchar * key)
66 : : {
67 : 0 : GError *error = NULL;
68 : 0 : gchar *value = NULL;
69 : : gchar *full_key;
70 : :
71 [ # # ]: 0 : if (!g_str_has_prefix (key, GST_GCONF_DIR))
72 : 0 : full_key = g_strdup_printf ("%s/%s", GST_GCONF_DIR, key);
73 : : else
74 : 0 : full_key = g_strdup (key);
75 : :
76 : 0 : value = gconf_client_get_string (gst_gconf_get_client (), full_key, &error);
77 : 0 : g_free (full_key);
78 : :
79 [ # # ]: 0 : if (error) {
80 : 0 : g_warning ("gst_gconf_get_string: error: %s\n", error->message);
81 : 0 : g_error_free (error);
82 : 0 : return NULL;
83 : : }
84 : :
85 : 0 : return value;
86 : : }
87 : :
88 : : const gchar *
89 : 3 : gst_gconf_get_key_for_sink_profile (GstGConfProfile profile)
90 : : {
91 [ + - - - ]: 3 : switch (profile) {
92 : : case GCONF_PROFILE_SOUNDS:
93 : 3 : return GST_GCONF_DIR "/" GST_GCONF_AUDIOSINK_KEY;
94 : : case GCONF_PROFILE_MUSIC:
95 : 0 : return GST_GCONF_DIR "/" GST_GCONF_MUSIC_AUDIOSINK_KEY;
96 : : case GCONF_PROFILE_CHAT:
97 : 0 : return GST_GCONF_DIR "/" GST_GCONF_CHAT_AUDIOSINK_KEY;
98 : : default:
99 : 0 : break;
100 : : }
101 : :
102 : 3 : g_return_val_if_reached (GST_GCONF_DIR "/" GST_GCONF_AUDIOSINK_KEY);
103 : : }
104 : :
105 : : /**
106 : : * gst_gconf_set_string:
107 : : * @key: a #gchar corresponding to the key you want to set.
108 : : * @value: a #gchar containing key value.
109 : : *
110 : : * Set GConf key @key to string value @value.
111 : : */
112 : : void
113 : 0 : gst_gconf_set_string (const gchar * key, const gchar * value)
114 : : {
115 : 0 : GError *error = NULL;
116 : : gchar *full_key;
117 : :
118 [ # # ]: 0 : if (!g_str_has_prefix (key, GST_GCONF_DIR))
119 : 0 : full_key = g_strdup_printf ("%s/%s", GST_GCONF_DIR, key);
120 : : else
121 : 0 : full_key = g_strdup (key);
122 : :
123 : 0 : gconf_client_set_string (gst_gconf_get_client (), full_key, value, &error);
124 [ # # ]: 0 : if (error) {
125 [ # # ]: 0 : GST_ERROR ("gst_gconf_set_string: error: %s\n", error->message);
126 : 0 : g_error_free (error);
127 : : }
128 : 0 : g_free (full_key);
129 : 0 : }
130 : :
131 : : /**
132 : : * gst_gconf_render_bin_from_key:
133 : : * @key: a #gchar string corresponding to a GConf key.
134 : : *
135 : : * Render bin from GConf key @key.
136 : : *
137 : : * Returns: a #GstElement containing the rendered bin.
138 : : */
139 : : GstElement *
140 : 0 : gst_gconf_render_bin_from_key (const gchar * key)
141 : : {
142 : 0 : GstElement *bin = NULL;
143 : : gchar *value;
144 : :
145 : 0 : value = gst_gconf_get_string (key);
146 : :
147 [ # # ][ # # ]: 0 : GST_LOG ("%s = %s", GST_STR_NULL (key), GST_STR_NULL (value));
[ # # ]
148 : :
149 [ # # ]: 0 : if (value) {
150 : 0 : GError *err = NULL;
151 : :
152 : 0 : bin = gst_parse_bin_from_description (value, TRUE, &err);
153 [ # # ]: 0 : if (err) {
154 [ # # ]: 0 : GST_ERROR ("gconf: error creating bin '%s': %s", value, err->message);
155 : 0 : g_error_free (err);
156 : : }
157 : :
158 : 0 : g_free (value);
159 : : }
160 : 0 : return bin;
161 : : }
162 : :
163 : : /**
164 : : * gst_gconf_render_bin_with_default:
165 : : * @bin: a #gchar string describing the pipeline to construct.
166 : : * @default_sink: an element to use as default if the given pipeline fails to construct.
167 : : *
168 : : * Render bin from description @bin using @default_sink element as a fallback.
169 : : *
170 : : * Returns: a #GstElement containing the rendered bin.
171 : : */
172 : : GstElement *
173 : 0 : gst_gconf_render_bin_with_default (const gchar * bin,
174 : : const gchar * default_sink)
175 : : {
176 : 0 : GstElement *ret = NULL;
177 : 0 : GError *err = NULL;
178 : :
179 [ # # ]: 0 : if (bin != NULL)
180 : 0 : ret = gst_parse_bin_from_description (bin, TRUE, &err);
181 : :
182 [ # # ][ # # ]: 0 : if (ret == NULL || err != NULL) {
183 [ # # ]: 0 : if (err) {
184 [ # # ]: 0 : GST_DEBUG ("Could not create audio sink from GConf settings: %s",
185 : : err->message);
186 : 0 : g_error_free (err);
187 : : } else {
188 [ # # ]: 0 : GST_DEBUG ("Could not create audio sink from GConf settings");
189 : : }
190 : :
191 : 0 : ret = gst_element_factory_make (default_sink, NULL);
192 : :
193 [ # # ]: 0 : if (!ret)
194 : 0 : g_warning
195 : : ("Could not build GConf audio sink and the replacement %s doesn't work",
196 : : DEFAULT_AUDIOSINK);
197 : : }
198 : :
199 : 0 : return ret;
200 : : }
201 : :
202 : : /**
203 : : * gst_gconf_get_default_video_sink:
204 : : *
205 : : * Render video output bin from GStreamer GConf key : "default/videosink".
206 : : * If key is invalid, the default video sink for the platform is used
207 : : * (typically xvimagesink or ximagesink).
208 : : *
209 : : * Returns: a #GstElement containing the video output bin, or NULL if
210 : : * everything failed.
211 : : */
212 : : GstElement *
213 : 0 : gst_gconf_get_default_video_sink (void)
214 : : {
215 : 0 : GstElement *ret = gst_gconf_render_bin_from_key (GST_GCONF_VIDEOSINK_KEY);
216 : :
217 [ # # ]: 0 : if (!ret) {
218 : 0 : ret = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL);
219 : :
220 [ # # ]: 0 : if (!ret)
221 : 0 : g_warning ("No GConf default video sink key and %s doesn't work",
222 : : DEFAULT_VIDEOSINK);
223 : : }
224 : :
225 : 0 : return ret;
226 : : }
227 : :
228 : : /**
229 : : * gst_gconf_get_default_audio_src:
230 : : *
231 : : * Render audio acquisition bin from GStreamer GConf key : "default/audiosrc".
232 : : * If key is invalid, the default audio source for the plaform is used.
233 : : * (typically osssrc or sunaudiosrc).
234 : : *
235 : : * Returns: a #GstElement containing the audio source bin, or NULL if
236 : : * everything failed.
237 : : */
238 : : GstElement *
239 : 0 : gst_gconf_get_default_audio_src (void)
240 : : {
241 : 0 : GstElement *ret = gst_gconf_render_bin_from_key (GST_GCONF_AUDIOSRC_KEY);
242 : :
243 [ # # ]: 0 : if (!ret) {
244 : 0 : ret = gst_element_factory_make (DEFAULT_AUDIOSRC, NULL);
245 : :
246 [ # # ]: 0 : if (!ret)
247 : 0 : g_warning ("No GConf default audio src key and %s doesn't work",
248 : : DEFAULT_AUDIOSRC);
249 : : }
250 : :
251 : 0 : return ret;
252 : : }
253 : :
254 : : /**
255 : : * gst_gconf_get_default_video_src:
256 : : *
257 : : * Render video acquisition bin from GStreamer GConf key :
258 : : * "default/videosrc". If key is invalid, the default video source
259 : : * for the platform is used (typically videotestsrc).
260 : : *
261 : : * Returns: a #GstElement containing the video source bin, or NULL if
262 : : * everything failed.
263 : : */
264 : : GstElement *
265 : 0 : gst_gconf_get_default_video_src (void)
266 : : {
267 : 0 : GstElement *ret = gst_gconf_render_bin_from_key (GST_GCONF_VIDEOSRC_KEY);
268 : :
269 [ # # ]: 0 : if (!ret) {
270 : 0 : ret = gst_element_factory_make (DEFAULT_VIDEOSRC, NULL);
271 : :
272 [ # # ]: 0 : if (!ret)
273 : 0 : g_warning ("No GConf default video src key and %s doesn't work",
274 : : DEFAULT_VIDEOSRC);
275 : : }
276 : :
277 : 0 : return ret;
278 : : }
279 : :
280 : : /**
281 : : * gst_gconf_get_default_visualization_element:
282 : : *
283 : : * Render visualization bin from GStreamer GConf key : "default/visualization".
284 : : * If key is invalid, the default visualization element is used.
285 : : *
286 : : * Returns: a #GstElement containing the visualization bin, or NULL if
287 : : * everything failed.
288 : : */
289 : : GstElement *
290 : 0 : gst_gconf_get_default_visualization_element (void)
291 : : {
292 : 0 : GstElement *ret = gst_gconf_render_bin_from_key ("default/visualization");
293 : :
294 [ # # ]: 0 : if (!ret) {
295 : 0 : ret = gst_element_factory_make (DEFAULT_VISUALIZER, NULL);
296 : :
297 [ # # ]: 0 : if (!ret)
298 : 0 : g_warning
299 : : ("No GConf default visualization plugin key and %s doesn't work",
300 : : DEFAULT_VISUALIZER);
301 : : }
302 : :
303 : 0 : return ret;
304 : : }
|