2004-01-28 15:08:17 +00:00
|
|
|
<chapter id="chapter-gnome">
|
2003-10-09 12:42:49 +00:00
|
|
|
<title>GNOME integration</title>
|
2002-09-14 12:48:06 +00:00
|
|
|
<para>
|
2003-10-09 12:42:49 +00:00
|
|
|
GStreamer is fairly easy to integrate with GNOME applications.
|
2002-09-14 12:48:06 +00:00
|
|
|
GStreamer uses libxml 2.0, GLib 2.0 and popt, as do all other
|
2003-10-09 12:42:49 +00:00
|
|
|
GNOME applications.
|
|
|
|
There are however some basic issues you need to address in your GNOME
|
2002-09-14 12:48:06 +00:00
|
|
|
applications.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect1>
|
|
|
|
<title>Command line options</title>
|
|
|
|
<para>
|
2003-10-09 12:42:49 +00:00
|
|
|
GNOME applications call gnome_program_init () to parse command-line
|
2002-09-14 12:48:06 +00:00
|
|
|
options and initialize the necessary gnome modules.
|
|
|
|
GStreamer applications normally call gst_init (&argc, &argv) to
|
|
|
|
do the same for GStreamer.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Each of these two swallows the program options passed to the program,
|
2003-10-09 12:42:49 +00:00
|
|
|
so we need a different way to allow both GNOME and GStreamer to parse
|
2002-09-14 12:48:06 +00:00
|
|
|
the command-line options. This is shown in the following example.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
/* example-begin gnome.c */
|
|
|
|
#include <gnome.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2004-02-03 14:59:32 +00:00
|
|
|
GstPoptOption options[] = {
|
2002-09-14 12:48:06 +00:00
|
|
|
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, NULL, 0, "GStreamer", NULL },
|
|
|
|
POPT_TABLEEND
|
|
|
|
};
|
2003-10-09 22:21:51 +00:00
|
|
|
GnomeProgram *program;
|
2002-09-14 12:48:06 +00:00
|
|
|
poptContext context;
|
|
|
|
const gchar **argvn;
|
|
|
|
|
2004-02-03 14:59:32 +00:00
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *src, *sink;
|
|
|
|
|
2002-09-14 12:48:06 +00:00
|
|
|
options[0].arg = (void *) gst_init_get_popt_table ();
|
2004-02-03 14:59:32 +00:00
|
|
|
g_print ("Calling gnome_program_init with the GStreamer popt table\n");
|
|
|
|
/* gnome_program_init will initialize GStreamer now
|
|
|
|
* as a side effect of having the GStreamer popt table passed. */
|
2003-06-29 14:36:31 +00:00
|
|
|
if (! (program = gnome_program_init ("my_package", "0.1", LIBGNOMEUI_MODULE,
|
2002-09-14 12:48:06 +00:00
|
|
|
argc, argv,
|
|
|
|
GNOME_PARAM_POPT_TABLE, options,
|
|
|
|
NULL)))
|
2004-02-03 14:59:32 +00:00
|
|
|
g_error ("gnome_program_init failed");
|
2002-09-14 12:48:06 +00:00
|
|
|
|
2004-02-03 14:59:32 +00:00
|
|
|
g_print ("Getting gnome-program popt context\n");
|
2002-09-14 12:48:06 +00:00
|
|
|
g_object_get (program, "popt-context", &context, NULL);
|
|
|
|
argvn = poptGetArgs (context);
|
|
|
|
if (!argvn) {
|
|
|
|
g_print ("Run this example with some arguments to see how it works.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-02-03 14:59:32 +00:00
|
|
|
g_print ("Printing rest of arguments\n");
|
2002-09-14 12:48:06 +00:00
|
|
|
while (*argvn) {
|
|
|
|
g_print ("argument: %s\n", *argvn);
|
|
|
|
++argvn;
|
|
|
|
}
|
|
|
|
|
2004-02-03 14:59:32 +00:00
|
|
|
/* do some GStreamer things to show everything's initialized properly */
|
|
|
|
g_print ("Doing some GStreamer stuff to show that everything works\n");
|
|
|
|
pipeline = gst_pipeline_new ("pipeline");
|
|
|
|
src = gst_element_factory_make ("fakesrc", "src");
|
|
|
|
sink = gst_element_factory_make ("fakesink", "sink");
|
|
|
|
gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
|
|
|
|
gst_element_link (src, sink);
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
gst_bin_iterate (GST_BIN (pipeline));
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
|
2002-09-14 12:48:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* example-end gnome.c */
|
|
|
|
</programlisting>
|
|
|
|
<para>
|
|
|
|
If you try out this program, you will see that when called with
|
2003-10-09 12:42:49 +00:00
|
|
|
--help, it will print out both GStreamer and GNOME help arguments.
|
2002-09-14 12:48:06 +00:00
|
|
|
All of the arguments that didn't belong to either end up in the
|
|
|
|
argvn pointer array.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
FIXME: flesh this out more. How do we get the GStreamer arguments
|
|
|
|
at the end ?
|
2002-09-14 14:18:55 +00:00
|
|
|
FIXME: add a GConf bit.
|
|
|
|
</para>
|
2002-09-14 12:48:06 +00:00
|
|
|
</sect1>
|
|
|
|
</chapter>
|