1 <chapter id="chapter-init">
2 <title>Initializing &GStreamer;</title>
4 When writing a &GStreamer; application, you can simply include
5 <filename>gst/gst.h</filename> to get access to the library
6 functions. Besides that, you will also need to intialize the
10 <sect1 id="section-init-c">
11 <title>Simple initialization</title>
13 Before the &GStreamer; libraries can be used,
14 <function>gst_init</function> has to be called from the main
15 application. This call will perform the necessary initialization
16 of the library as well as parse the &GStreamer;-specific command
20 A typical program &EXAFOOT; would have code to initialize
21 &GStreamer; that looks like this:
24 #include <gst/gst.h>
30 guint major, minor, micro;
32 gst_init (&argc, &argv);
34 gst_version (&major, &minor, &micro);
35 printf ("This program is linked against GStreamer %d.%d.%d\n",
42 Use the <symbol>GST_VERSION_MAJOR</symbol>,
43 <symbol>GST_VERSION_MINOR</symbol> and <symbol>GST_VERSION_MICRO</symbol>
44 macros to get the &GStreamer; version you are building against, or
45 use the function <function>gst_version</function> to get the version
46 your application is linked against. &GStreamer; currently uses a
47 scheme where versions with the same major and minor versions are
48 API-/ and ABI-compatible.
51 It is also possible to call the <function>gst_init</function> function
52 with two <symbol>NULL</symbol> arguments, in which case no command line
53 options will be parsed by <application>GStreamer</application>.
58 <title>The popt interface</title>
60 You can also use a popt table to initialize your own parameters as
61 shown in the next example:
64 #include <gst/gst.h>
70 gboolean silent = FALSE;
71 gchar *savefile = NULL;
72 struct poptOption options[] = {
73 {"silent", 's', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &silent, 0,
74 "do not output status information", NULL},
75 {"output", 'o', POPT_ARG_STRING|POPT_ARGFLAG_STRIP, &savefile, 0,
76 "save xml representation of pipeline to FILE and exit", "FILE"},
80 gst_init_with_popt_table (&argc, &argv, options);
82 printf ("Run me with --help to see the Application options appended.\n");
88 As shown in this fragment, you can use a <ulink
89 url="http://developer.gnome.org/doc/guides/popt/"
90 type="http">popt</ulink> table to define your application-specific
91 command line options, and pass this table to the
92 function <function>gst_init_with_popt_table</function>. Your
93 application options will be parsed in addition to the standard
94 <application>GStreamer</application> options.