2003-07-25 10:50:48 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2002> Thomas Vander Stichele <thomas@apestaart.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2002-07-01 15:39:58 +00:00
|
|
|
/*
|
|
|
|
* this library handles interaction with GConf
|
|
|
|
*/
|
|
|
|
|
2003-11-07 12:47:02 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-07-01 15:39:58 +00:00
|
|
|
#include "gconf.h"
|
|
|
|
|
2004-02-23 22:31:48 +00:00
|
|
|
#ifndef GST_GCONF_DIR
|
|
|
|
#error "GST_GCONF_DIR is not defined !"
|
|
|
|
#endif
|
2002-07-01 15:39:58 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
static GConfClient *_gst_gconf_client = NULL; /* GConf connection */
|
2002-07-01 15:39:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* internal functions */
|
|
|
|
|
2002-10-16 19:47:05 +00:00
|
|
|
static GConfClient *
|
2002-07-01 15:39:58 +00:00
|
|
|
gst_gconf_get_client (void)
|
|
|
|
{
|
|
|
|
if (!_gst_gconf_client)
|
|
|
|
_gst_gconf_client = gconf_client_get_default ();
|
|
|
|
|
|
|
|
return _gst_gconf_client;
|
|
|
|
}
|
2002-10-16 19:47:05 +00:00
|
|
|
|
2002-07-12 09:41:25 +00:00
|
|
|
/* go through a bin, finding the one pad that is unconnected in the given
|
|
|
|
* * direction, and return that pad */
|
2002-10-16 19:47:05 +00:00
|
|
|
static GstPad *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_bin_find_unconnected_pad (GstBin * bin, GstPadDirection direction)
|
2002-07-12 09:41:25 +00:00
|
|
|
{
|
|
|
|
GstPad *pad = NULL;
|
|
|
|
GList *elements = NULL;
|
2002-09-12 20:53:56 +00:00
|
|
|
const GList *pads = NULL;
|
2002-07-12 09:41:25 +00:00
|
|
|
GstElement *element = NULL;
|
|
|
|
|
|
|
|
elements = (GList *) gst_bin_get_list (bin);
|
|
|
|
/* traverse all elements looking for unconnected pads */
|
2004-03-14 22:34:34 +00:00
|
|
|
while (elements && pad == NULL) {
|
2002-07-12 09:41:25 +00:00
|
|
|
element = GST_ELEMENT (elements->data);
|
|
|
|
pads = gst_element_get_pad_list (element);
|
2004-03-14 22:34:34 +00:00
|
|
|
while (pads) {
|
2002-07-12 09:41:25 +00:00
|
|
|
/* check if the direction matches */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (GST_PAD_DIRECTION (GST_PAD (pads->data)) == direction) {
|
2004-03-15 19:32:28 +00:00
|
|
|
if (GST_PAD_PEER (GST_PAD (pads->data)) == NULL) {
|
|
|
|
/* found it ! */
|
|
|
|
pad = GST_PAD (pads->data);
|
|
|
|
}
|
2002-07-12 09:41:25 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
if (pad)
|
2004-03-15 19:32:28 +00:00
|
|
|
break; /* found one already */
|
2002-07-12 09:41:25 +00:00
|
|
|
pads = g_list_next (pads);
|
|
|
|
}
|
|
|
|
elements = g_list_next (elements);
|
|
|
|
}
|
|
|
|
return pad;
|
|
|
|
}
|
2002-07-01 15:39:58 +00:00
|
|
|
|
|
|
|
/* external functions */
|
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gconf_get_string:
|
|
|
|
* @key: a #gchar corresponding to the key you want to get.
|
|
|
|
*
|
|
|
|
* Get GConf key @key's string value.
|
|
|
|
*
|
2004-04-01 08:42:30 +00:00
|
|
|
* Returns: a newly allocated #gchar string containing @key's value,
|
|
|
|
* or NULL in the case of an error..
|
2003-03-29 19:48:38 +00:00
|
|
|
*/
|
2002-07-01 15:39:58 +00:00
|
|
|
gchar *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_gconf_get_string (const gchar * key)
|
2002-07-01 15:39:58 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar *value = NULL;
|
2002-11-20 12:15:49 +00:00
|
|
|
gchar *full_key = g_strdup_printf ("%s/%s", GST_GCONF_DIR, key);
|
2002-07-01 15:39:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
value = gconf_client_get_string (gst_gconf_get_client (), full_key, &error);
|
|
|
|
g_free (full_key);
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (error) {
|
2004-04-01 08:42:30 +00:00
|
|
|
g_warning ("gst_gconf_get_string: error: %s\n", error->message);
|
2002-11-20 12:15:49 +00:00
|
|
|
g_error_free (error);
|
2004-04-01 08:42:30 +00:00
|
|
|
return NULL;
|
2002-11-20 12:15:49 +00:00
|
|
|
}
|
2004-04-01 08:42:30 +00:00
|
|
|
|
2002-11-20 12:15:49 +00:00
|
|
|
return value;
|
2002-07-01 15:39:58 +00:00
|
|
|
}
|
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2002-07-01 15:39:58 +00:00
|
|
|
void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_gconf_set_string (const gchar * key, const gchar * value)
|
2002-07-01 15:39:58 +00:00
|
|
|
{
|
2002-11-20 12:15:49 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar *full_key = g_strdup_printf ("%s/%s", GST_GCONF_DIR, key);
|
|
|
|
|
|
|
|
gconf_client_set_string (gst_gconf_get_client (), full_key, value, &error);
|
2004-03-14 22:34:34 +00:00
|
|
|
if (error) {
|
2003-05-29 17:00:55 +00:00
|
|
|
g_print ("gst_gconf_set_string: error: %s\n", error->message);
|
2002-11-20 12:15:49 +00:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (full_key);
|
2002-07-01 15:39:58 +00:00
|
|
|
}
|
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gconf_render_bin_from_description:
|
|
|
|
* @description: a #gchar string describing the bin.
|
|
|
|
*
|
|
|
|
* Render bin from description @description.
|
|
|
|
*
|
|
|
|
* Returns: a #GstElement containing the rendered bin.
|
|
|
|
*/
|
2002-07-12 09:41:25 +00:00
|
|
|
GstElement *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_gconf_render_bin_from_description (const gchar * description)
|
2002-07-01 15:39:58 +00:00
|
|
|
{
|
2002-07-12 09:41:25 +00:00
|
|
|
GstElement *bin = NULL;
|
|
|
|
GstPad *pad = NULL;
|
2002-07-01 15:39:58 +00:00
|
|
|
GError *error = NULL;
|
2002-07-12 13:40:53 +00:00
|
|
|
gchar *desc = NULL;
|
2002-07-01 15:39:58 +00:00
|
|
|
|
2002-07-12 13:40:53 +00:00
|
|
|
/* parse the pipeline to a bin */
|
|
|
|
desc = g_strdup_printf ("bin.( %s )", description);
|
|
|
|
bin = GST_ELEMENT (gst_parse_launch (desc, &error));
|
|
|
|
g_free (desc);
|
2004-03-14 22:34:34 +00:00
|
|
|
if (error) {
|
2002-07-01 15:39:58 +00:00
|
|
|
g_print ("DEBUG: gstgconf: error parsing pipeline %s\n%s\n",
|
2004-03-15 19:32:28 +00:00
|
|
|
description, error->message);
|
2002-07-01 15:39:58 +00:00
|
|
|
g_error_free (error);
|
2002-07-12 09:41:25 +00:00
|
|
|
return NULL;
|
2002-07-01 15:39:58 +00:00
|
|
|
}
|
2002-07-12 09:41:25 +00:00
|
|
|
|
|
|
|
/* find pads and ghost them if necessary */
|
2004-03-14 22:34:34 +00:00
|
|
|
if ((pad = gst_bin_find_unconnected_pad (GST_BIN (bin), GST_PAD_SRC))) {
|
2002-07-12 09:41:25 +00:00
|
|
|
gst_element_add_ghost_pad (bin, pad, "src");
|
2002-07-28 15:06:06 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
if ((pad = gst_bin_find_unconnected_pad (GST_BIN (bin), GST_PAD_SINK))) {
|
2002-07-12 09:41:25 +00:00
|
|
|
gst_element_add_ghost_pad (bin, pad, "sink");
|
2002-07-28 15:06:06 +00:00
|
|
|
}
|
2002-07-12 09:41:25 +00:00
|
|
|
return bin;
|
|
|
|
}
|
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2002-07-12 09:41:25 +00:00
|
|
|
GstElement *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_gconf_render_bin_from_key (const gchar * key)
|
2002-07-12 09:41:25 +00:00
|
|
|
{
|
2002-10-16 19:47:05 +00:00
|
|
|
GstElement *bin = NULL;
|
2002-07-28 15:06:06 +00:00
|
|
|
gchar *value;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-07-12 09:41:25 +00:00
|
|
|
value = gst_gconf_get_string (key);
|
2002-10-16 19:47:05 +00:00
|
|
|
if (value)
|
|
|
|
bin = gst_gconf_render_bin_from_description (value);
|
2004-04-01 08:42:30 +00:00
|
|
|
g_free (value);
|
2002-07-12 09:41:25 +00:00
|
|
|
return bin;
|
2002-07-01 15:39:58 +00:00
|
|
|
}
|
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gconf_get_default_audio_sink:
|
|
|
|
*
|
|
|
|
* Render audio output bin from GStreamer GConf key : "default/audiosink".
|
|
|
|
* If key is invalid osssink is used as default output plugin.
|
|
|
|
*
|
|
|
|
* Returns: a #GstElement containing the audio output bin, or NULL if
|
|
|
|
* everything failed.
|
|
|
|
*/
|
2002-10-16 19:47:05 +00:00
|
|
|
GstElement *
|
|
|
|
gst_gconf_get_default_audio_sink (void)
|
|
|
|
{
|
|
|
|
GstElement *ret = gst_gconf_render_bin_from_key ("default/audiosink");
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-16 19:47:05 +00:00
|
|
|
if (!ret) {
|
|
|
|
ret = gst_element_factory_make ("osssink", NULL);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-16 19:47:05 +00:00
|
|
|
if (!ret)
|
|
|
|
g_warning ("No GConf default audio sink key and osssink doesn't work");
|
|
|
|
else
|
2004-02-24 17:16:07 +00:00
|
|
|
g_print ("GConf audio sink not found, using osssink\n");
|
2002-10-16 19:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gconf_get_default_video_sink:
|
|
|
|
*
|
|
|
|
* Render video output bin from GStreamer GConf key : "default/videosink".
|
|
|
|
* If key is invalid xvideosink is used as default output plugin.
|
|
|
|
*
|
|
|
|
* Returns: a #GstElement containing the video output bin, or NULL if
|
|
|
|
* everything failed.
|
|
|
|
*/
|
2002-10-16 19:47:05 +00:00
|
|
|
GstElement *
|
|
|
|
gst_gconf_get_default_video_sink (void)
|
|
|
|
{
|
|
|
|
GstElement *ret = gst_gconf_render_bin_from_key ("default/videosink");
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-16 19:47:05 +00:00
|
|
|
if (!ret) {
|
2004-03-03 11:41:50 +00:00
|
|
|
ret = gst_element_factory_make ("ximagesink", NULL);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-16 19:47:05 +00:00
|
|
|
if (!ret)
|
2004-03-03 11:41:50 +00:00
|
|
|
g_warning ("No GConf default video sink key and ximagesink doesn't work");
|
2002-10-16 19:47:05 +00:00
|
|
|
else
|
2004-03-03 11:41:50 +00:00
|
|
|
g_print ("GConf video sink not found, using ximagesink\n");
|
2002-10-16 19:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gconf_get_default_audio_src:
|
|
|
|
*
|
|
|
|
* Render audio acquisition bin from GStreamer GConf key : "default/audiosrc".
|
|
|
|
* If key is invalid osssrc is used as default source.
|
|
|
|
*
|
|
|
|
* Returns: a #GstElement containing the audio source bin, or NULL if
|
|
|
|
* everything failed.
|
|
|
|
*/
|
2002-10-25 14:31:15 +00:00
|
|
|
GstElement *
|
|
|
|
gst_gconf_get_default_audio_src (void)
|
|
|
|
{
|
|
|
|
GstElement *ret = gst_gconf_render_bin_from_key ("default/audiosrc");
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-25 14:31:15 +00:00
|
|
|
if (!ret) {
|
|
|
|
ret = gst_element_factory_make ("osssrc", NULL);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-25 14:31:15 +00:00
|
|
|
if (!ret)
|
|
|
|
g_warning ("No GConf default audio src key and osssrc doesn't work");
|
|
|
|
else
|
2004-02-24 17:16:07 +00:00
|
|
|
g_print ("GConf audio src not found, using osssrc\n");
|
2002-10-25 14:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gconf_get_default_video_src:
|
|
|
|
*
|
|
|
|
* Render video acquisition bin from GStreamer GConf key :
|
|
|
|
* "default/videosrc". If key is invalid videotestsrc
|
|
|
|
* is used as default source.
|
|
|
|
*
|
|
|
|
* Returns: a #GstElement containing the video source bin, or NULL if
|
|
|
|
* everything failed.
|
|
|
|
*/
|
2002-10-25 14:31:15 +00:00
|
|
|
GstElement *
|
|
|
|
gst_gconf_get_default_video_src (void)
|
|
|
|
{
|
|
|
|
GstElement *ret = gst_gconf_render_bin_from_key ("default/videosrc");
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-25 14:31:15 +00:00
|
|
|
if (!ret) {
|
|
|
|
ret = gst_element_factory_make ("videotestsrc", NULL);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-25 14:31:15 +00:00
|
|
|
if (!ret)
|
|
|
|
g_warning ("No GConf default video src key and videotestrc doesn't work");
|
|
|
|
else
|
2004-02-24 17:16:07 +00:00
|
|
|
g_print ("GConf video src not found, using videotestrc\n");
|
2002-10-25 14:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
/**
|
2003-10-06 10:29:27 +00:00
|
|
|
* gst_gconf_get_default_visualization_element:
|
2003-03-29 19:48:38 +00:00
|
|
|
*
|
2003-10-06 10:29:27 +00:00
|
|
|
* Render visualization bin from GStreamer GConf key : "default/visualization".
|
|
|
|
* If key is invalid goom is used as default visualization element.
|
2003-03-29 19:48:38 +00:00
|
|
|
*
|
2003-10-06 10:29:27 +00:00
|
|
|
* Returns: a #GstElement containing the visualization bin, or NULL if
|
2003-03-29 19:48:38 +00:00
|
|
|
* everything failed.
|
|
|
|
*/
|
|
|
|
GstElement *
|
2003-10-06 10:29:27 +00:00
|
|
|
gst_gconf_get_default_visualization_element (void)
|
2003-03-29 19:48:38 +00:00
|
|
|
{
|
2003-10-06 10:29:27 +00:00
|
|
|
GstElement *ret = gst_gconf_render_bin_from_key ("default/visualization");
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
if (!ret) {
|
|
|
|
ret = gst_element_factory_make ("goom", NULL);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-03-29 19:48:38 +00:00
|
|
|
if (!ret)
|
2004-03-14 22:34:34 +00:00
|
|
|
g_warning
|
2004-03-15 19:32:28 +00:00
|
|
|
("No GConf default visualization plugin key and goom doesn't work");
|
2003-03-29 19:48:38 +00:00
|
|
|
else
|
2004-02-24 17:16:07 +00:00
|
|
|
g_print ("GConf visualization plugin not found, using goom\n");
|
2003-03-29 19:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|