source: trunk/third/gstreamer/docs/manual/basics-init.xml @ 21448

Revision 21448, 3.2 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21447, which included commits to RCS files with non-trunk default branches.
Line 
1<chapter id="chapter-init">
2  <title>Initializing &GStreamer;</title>
3  <para>
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
7    &GStreamer; library.
8  </para>
9
10  <sect1 id="section-init-c">
11    <title>Simple initialization</title>
12    <para>
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
17      line options.
18    </para>
19    <para>
20      A typical program &EXAFOOT; would have code to initialize
21      &GStreamer; that looks like this:
22    </para>
23    <programlisting>
24<!-- example-begin init.c -->
25#include &lt;gst/gst.h&gt;
26
27int
28main (int   argc,
29      char *argv[])
30{
31  guint major, minor, micro;
32
33  gst_init (&amp;argc, &amp;argv);
34
35  gst_version (&amp;major, &amp;minor, &amp;micro);
36  printf ("This program is linked against GStreamer %d.%d.%d\n",
37          major, minor, micro);
38
39  return 0;
40}
41<!-- example-end init.c -->
42    </programlisting>
43    <para>
44      Use the <symbol>GST_VERSION_MAJOR</symbol>,
45      <symbol>GST_VERSION_MINOR</symbol> and <symbol>GST_VERSION_MICRO</symbol>
46      macros to get the &GStreamer; version you are building against, or
47      use the function <function>gst_version</function> to get the version
48      your application is linked against. &GStreamer; currently uses a
49      scheme where versions with the same major and minor versions are
50      API-/ and ABI-compatible.
51    </para>
52    <para>
53      It is also possible to call the <function>gst_init</function> function
54      with two <symbol>NULL</symbol> arguments, in which case no command line
55      options will be parsed by <application>GStreamer</application>.
56    </para>
57  </sect1>
58
59  <sect1>
60    <title>The popt interface</title>
61    <para>
62      You can also use a popt table to initialize your own parameters as
63      shown in the next example:
64    </para>
65    <programlisting>
66<!-- example-begin popt.c -->
67#include &lt;gst/gst.h&gt;
68
69int
70main (int   argc,
71      char *argv[])
72{
73  gboolean silent = FALSE;
74  gchar *savefile = NULL;
75  struct poptOption options[] = {
76    {"silent",  's',  POPT_ARG_NONE|POPT_ARGFLAG_STRIP,   &amp;silent,   0,
77     "do not output status information", NULL},
78    {"output",  'o',  POPT_ARG_STRING|POPT_ARGFLAG_STRIP, &amp;savefile, 0,
79     "save xml representation of pipeline to FILE and exit", "FILE"},
80    POPT_TABLEEND
81  };
82
83  gst_init_with_popt_table (&amp;argc, &amp;argv, options);
84
85  printf ("Run me with --help to see the Application options appended.\n");
86
87  return 0;
88}
89<!-- example-end popt.c -->
90    </programlisting>
91    <para>
92      As shown in this fragment, you can use a <ulink
93      url="http://developer.gnome.org/doc/guides/popt/"
94      type="http">popt</ulink> table to define your application-specific
95      command line options, and pass this table to the
96      function <function>gst_init_with_popt_table</function>. Your
97      application options will be parsed in addition to the standard
98      <application>GStreamer</application> options.
99    </para>
100  </sect1>
101</chapter>
Note: See TracBrowser for help on using the repository browser.