gconf.c 7.39 KB
Newer Older
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
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * this library handles interaction with GConf
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

30
31
#include <gst/gst.h>

32
#include "gconf.h"
33
#include "gstgconfelements.h"   /* for debug category */
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#ifndef GST_GCONF_DIR
#error "GST_GCONF_DIR is not defined !"
#endif

static GConfClient *_gst_gconf_client = NULL;   /* GConf connection */


/* internal functions */

static GConfClient *
gst_gconf_get_client (void)
{
  if (!_gst_gconf_client)
    _gst_gconf_client = gconf_client_get_default ();

  return _gst_gconf_client;
}

/* external functions */

/**
 * gst_gconf_get_string:
 * @key: a #gchar corresponding to the key you want to get.
 *
 * Get GConf key @key's string value.
 *
 * Returns: a newly allocated #gchar string containing @key's value,
 * or NULL in the case of an error..
 */
gchar *
gst_gconf_get_string (const gchar * key)
{
  GError *error = NULL;
  gchar *value = NULL;
69
  gchar *full_key;
70

71
72
73
74
  if (!g_str_has_prefix (key, GST_GCONF_DIR))
    full_key = g_strdup_printf ("%s/%s", GST_GCONF_DIR, key);
  else
    full_key = g_strdup (key);
75
76
77
78
79
80
81
82
83
84
85
86
87

  value = gconf_client_get_string (gst_gconf_get_client (), full_key, &error);
  g_free (full_key);

  if (error) {
    g_warning ("gst_gconf_get_string: error: %s\n", error->message);
    g_error_free (error);
    return NULL;
  }

  return value;
}

88
const gchar *
89
gst_gconf_get_key_for_sink_profile (GstGConfProfile profile)
90
91
92
{
  switch (profile) {
    case GCONF_PROFILE_SOUNDS:
93
      return GST_GCONF_DIR "/" GST_GCONF_AUDIOSINK_KEY;
94
    case GCONF_PROFILE_MUSIC:
95
      return GST_GCONF_DIR "/" GST_GCONF_MUSIC_AUDIOSINK_KEY;
96
    case GCONF_PROFILE_CHAT:
97
      return GST_GCONF_DIR "/" GST_GCONF_CHAT_AUDIOSINK_KEY;
98
99
100
101
    default:
      break;
  }

102
  g_return_val_if_reached (GST_GCONF_DIR "/" GST_GCONF_AUDIOSINK_KEY);
103
104
}

105
106
107
108
109
110
111
112
113
114
115
/**
 * gst_gconf_set_string:
 * @key: a #gchar corresponding to the key you want to set.
 * @value: a #gchar containing key value.
 *
 * Set GConf key @key to string value @value.
 */
void
gst_gconf_set_string (const gchar * key, const gchar * value)
{
  GError *error = NULL;
116
117
118
119
120
121
  gchar *full_key;

  if (!g_str_has_prefix (key, GST_GCONF_DIR))
    full_key = g_strdup_printf ("%s/%s", GST_GCONF_DIR, key);
  else
    full_key = g_strdup (key);
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

  gconf_client_set_string (gst_gconf_get_client (), full_key, value, &error);
  if (error) {
    GST_ERROR ("gst_gconf_set_string: error: %s\n", error->message);
    g_error_free (error);
  }
  g_free (full_key);
}

/**
 * gst_gconf_render_bin_from_key:
 * @key: a #gchar string corresponding to a GConf key.
 *
 * Render bin from GConf key @key.
 *
 * Returns: a #GstElement containing the rendered bin.
 */
GstElement *
gst_gconf_render_bin_from_key (const gchar * key)
{
  GstElement *bin = NULL;
  gchar *value;

  value = gst_gconf_get_string (key);
146
147
148

  GST_LOG ("%s = %s", GST_STR_NULL (key), GST_STR_NULL (value));

149
150
151
152
153
154
155
156
157
158
159
  if (value) {
    GError *err = NULL;

    bin = gst_parse_bin_from_description (value, TRUE, &err);
    if (err) {
      GST_ERROR ("gconf: error creating bin '%s': %s", value, err->message);
      g_error_free (err);
    }

    g_free (value);
  }
160
161
162
163
  return bin;
}

/**
164
 * gst_gconf_render_bin_with_default:
165
166
 * @bin: a #gchar string describing the pipeline to construct.
 * @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
174
gst_gconf_render_bin_with_default (const gchar * bin,
    const gchar * default_sink)
175
{
176
  GstElement *ret = NULL;
177
  GError *err = NULL;
178

179
180
  if (bin != NULL)
    ret = gst_parse_bin_from_description (bin, TRUE, &err);
181

182
  if (ret == NULL || err != NULL) {
183
    ret = gst_element_factory_make (default_sink, NULL);
184
185

    if (!ret)
186
187
      g_warning
          ("Could not build GConf audio sink and the replacement %s doesn't work",
188
189
190
191
192
193
194
195
196
197
          DEFAULT_AUDIOSINK);
  }

  return ret;
}

/**
 * gst_gconf_get_default_video_sink:
 *
 * Render video output bin from GStreamer GConf key : "default/videosink".
198
199
 * If key is invalid, the default video sink for the platform is used
 * (typically xvimagesink or ximagesink).
200
201
202
203
204
205
206
 *
 * Returns: a #GstElement containing the video output bin, or NULL if
 * everything failed.
 */
GstElement *
gst_gconf_get_default_video_sink (void)
{
207
  GstElement *ret = gst_gconf_render_bin_from_key (GST_GCONF_VIDEOSINK_KEY);
208
209

  if (!ret) {
210
    ret = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL);
211
212
213
214
215
216
217
218
219
220
221
222
223

    if (!ret)
      g_warning ("No GConf default video sink key and %s doesn't work",
          DEFAULT_VIDEOSINK);
  }

  return ret;
}

/**
 * gst_gconf_get_default_audio_src:
 *
 * Render audio acquisition bin from GStreamer GConf key : "default/audiosrc".
224
 * If key is invalid, the default audio source for the plaform is used.
225
226
227
228
229
230
231
232
 * (typically osssrc or sunaudiosrc).
 *
 * Returns: a #GstElement containing the audio source bin, or NULL if
 * everything failed.
 */
GstElement *
gst_gconf_get_default_audio_src (void)
{
233
  GstElement *ret = gst_gconf_render_bin_from_key (GST_GCONF_AUDIOSRC_KEY);
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

  if (!ret) {
    ret = gst_element_factory_make (DEFAULT_AUDIOSRC, NULL);

    if (!ret)
      g_warning ("No GConf default audio src key and %s doesn't work",
          DEFAULT_AUDIOSRC);
  }

  return ret;
}

/**
 * gst_gconf_get_default_video_src:
 *
 * Render video acquisition bin from GStreamer GConf key :
 * "default/videosrc". If key is invalid, the default video source
 * for the platform is used (typically videotestsrc).
 *
 * Returns: a #GstElement containing the video source bin, or NULL if
 * everything failed.
 */
GstElement *
gst_gconf_get_default_video_src (void)
{
259
  GstElement *ret = gst_gconf_render_bin_from_key (GST_GCONF_VIDEOSRC_KEY);
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296

  if (!ret) {
    ret = gst_element_factory_make (DEFAULT_VIDEOSRC, NULL);

    if (!ret)
      g_warning ("No GConf default video src key and %s doesn't work",
          DEFAULT_VIDEOSRC);
  }

  return ret;
}

/**
 * gst_gconf_get_default_visualization_element:
 *
 * Render visualization bin from GStreamer GConf key : "default/visualization".
 * If key is invalid, the default visualization element is used.
 *
 * Returns: a #GstElement containing the visualization bin, or NULL if
 * everything failed.
 */
GstElement *
gst_gconf_get_default_visualization_element (void)
{
  GstElement *ret = gst_gconf_render_bin_from_key ("default/visualization");

  if (!ret) {
    ret = gst_element_factory_make (DEFAULT_VISUALIZER, NULL);

    if (!ret)
      g_warning
          ("No GConf default visualization plugin key and %s doesn't work",
          DEFAULT_VISUALIZER);
  }

  return ret;
}