2004-12-15 17:32:49 +00:00
|
|
|
<chapter id="chapter-init">
|
|
|
|
<title>Initializing &GStreamer;</title>
|
2004-12-15 07:30:55 +00:00
|
|
|
<para>
|
2004-12-15 17:32:49 +00:00
|
|
|
When writing a &GStreamer; application, you can simply include
|
|
|
|
<filename>gst/gst.h</filename> to get access to the library
|
2011-09-07 11:14:38 +00:00
|
|
|
functions. Besides that, you will also need to initialize the
|
2004-12-15 17:32:49 +00:00
|
|
|
&GStreamer; library.
|
2004-12-15 07:30:55 +00:00
|
|
|
</para>
|
|
|
|
|
2004-12-15 17:32:49 +00:00
|
|
|
<sect1 id="section-init-c">
|
|
|
|
<title>Simple initialization</title>
|
|
|
|
<para>
|
|
|
|
Before the &GStreamer; libraries can be used,
|
|
|
|
<function>gst_init</function> has to be called from the main
|
|
|
|
application. This call will perform the necessary initialization
|
|
|
|
of the library as well as parse the &GStreamer;-specific command
|
|
|
|
line options.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
A typical program &EXAFOOT; would have code to initialize
|
|
|
|
&GStreamer; that looks like this:
|
|
|
|
</para>
|
2006-01-30 21:11:38 +00:00
|
|
|
<example id="ex-init-c">
|
|
|
|
<title>Initializing GStreamer</title>
|
|
|
|
<programlisting>
|
2004-12-15 17:32:49 +00:00
|
|
|
<!-- example-begin init.c -->
|
2009-10-07 07:00:05 +00:00
|
|
|
#include <stdio.h>
|
2004-12-15 17:32:49 +00:00
|
|
|
#include <gst/gst.h>
|
2004-12-15 07:30:55 +00:00
|
|
|
|
|
|
|
int
|
2004-12-15 17:32:49 +00:00
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
2004-12-15 07:30:55 +00:00
|
|
|
{
|
2006-05-16 16:10:38 +00:00
|
|
|
const gchar *nano_str;
|
|
|
|
guint major, minor, micro, nano;
|
2004-12-15 07:30:55 +00:00
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
2006-05-16 16:10:38 +00:00
|
|
|
gst_version (&major, &minor, &micro, &nano);
|
|
|
|
|
|
|
|
if (nano == 1)
|
|
|
|
nano_str = "(CVS)";
|
|
|
|
else if (nano == 2)
|
|
|
|
nano_str = "(Prerelease)";
|
|
|
|
else
|
|
|
|
nano_str = "";
|
|
|
|
|
|
|
|
printf ("This program is linked against GStreamer %d.%d.%d %s\n",
|
|
|
|
major, minor, micro, nano_str);
|
2004-12-15 07:30:55 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2004-12-15 17:32:49 +00:00
|
|
|
<!-- example-end init.c -->
|
2006-01-30 21:11:38 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
2004-12-15 17:32:49 +00:00
|
|
|
<para>
|
|
|
|
Use the <symbol>GST_VERSION_MAJOR</symbol>,
|
|
|
|
<symbol>GST_VERSION_MINOR</symbol> and <symbol>GST_VERSION_MICRO</symbol>
|
|
|
|
macros to get the &GStreamer; version you are building against, or
|
|
|
|
use the function <function>gst_version</function> to get the version
|
|
|
|
your application is linked against. &GStreamer; currently uses a
|
|
|
|
scheme where versions with the same major and minor versions are
|
|
|
|
API-/ and ABI-compatible.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
It is also possible to call the <function>gst_init</function> function
|
|
|
|
with two <symbol>NULL</symbol> arguments, in which case no command line
|
|
|
|
options will be parsed by <application>GStreamer</application>.
|
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
2004-12-15 07:30:55 +00:00
|
|
|
<sect1>
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
<title>The GOption interface</title>
|
2004-12-15 07:30:55 +00:00
|
|
|
<para>
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
You can also use a GOption table to initialize your own parameters as
|
2004-12-15 17:32:49 +00:00
|
|
|
shown in the next example:
|
2004-12-15 07:30:55 +00:00
|
|
|
</para>
|
2006-01-30 21:11:38 +00:00
|
|
|
<example id="ex-goption-c">
|
|
|
|
<title>Initialisation using the GOption interface</title>
|
|
|
|
<programlisting>
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
<!-- example-begin goption.c -->
|
2004-12-15 17:32:49 +00:00
|
|
|
#include <gst/gst.h>
|
2004-12-15 07:30:55 +00:00
|
|
|
|
|
|
|
int
|
2004-12-15 17:32:49 +00:00
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
2004-12-15 07:30:55 +00:00
|
|
|
{
|
|
|
|
gboolean silent = FALSE;
|
|
|
|
gchar *savefile = NULL;
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
GOptionContext *ctx;
|
|
|
|
GError *err = NULL;
|
|
|
|
GOptionEntry entries[] = {
|
2006-05-16 16:10:38 +00:00
|
|
|
{ "silent", 's', 0, G_OPTION_ARG_NONE, &silent,
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
"do not output status information", NULL },
|
2006-05-16 16:10:38 +00:00
|
|
|
{ "output", 'o', 0, G_OPTION_ARG_STRING, &savefile,
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
"save xml representation of pipeline to FILE and exit", "FILE" },
|
|
|
|
{ NULL }
|
2004-12-15 07:30:55 +00:00
|
|
|
};
|
|
|
|
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
ctx = g_option_context_new ("- Your application");
|
2006-05-16 16:10:38 +00:00
|
|
|
g_option_context_add_main_entries (ctx, entries, NULL);
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
g_option_context_add_group (ctx, gst_init_get_option_group ());
|
|
|
|
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
|
|
|
|
g_print ("Failed to initialize: %s\n", err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
return 1;
|
|
|
|
}
|
2004-12-15 07:30:55 +00:00
|
|
|
|
|
|
|
printf ("Run me with --help to see the Application options appended.\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
<!-- example-end goption.c -->
|
2006-01-30 21:11:38 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
2004-12-15 07:30:55 +00:00
|
|
|
<para>
|
|
|
|
As shown in this fragment, you can use a <ulink
|
Merged in popt removal + GOption addition patch from Ronald, bug #169772.
Original commit message from CVS:
2005-10-10 Andy Wingo <wingo@pobox.com>
Merged in popt removal + GOption addition patch from Ronald, bug
#169772.
* docs/gst/gstreamer-sections.txt: Add STATE_(UN)LOCK_FULL, move
GstElement macros around, remove popt-related symbols, add goption
stuff.
* configure.ac: Remove popt checks, require GLib 2.6 for GOption.
* docs/gst/Makefile.am:
* docs/libs/Makefile.am: No POPT_CFLAGS.
* examples/manual/Makefile.am:
* docs/manual/basics-init.xml: Doc updates with an example.
* gst/gst.c: (gst_init_get_option_group), (gst_init_check),
(gst_init), (parse_one_option), (parse_goption_arg):
* gst/gst.h: Removed gst_init_with_popt_table and friends. Took a
bit of hand merging and debugging to get the GOption stuff working
tho.
* tests/Makefile.am:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-run.c: (main):
* tools/gst-xmlinspect.c: (main): Thanks Ronald!
2005-10-10 15:53:59 +00:00
|
|
|
url="http://developer.gnome.org/doc/API/2.0/glib/glib-Commandline-option-parser.html"
|
|
|
|
type="http">GOption</ulink> table to define your application-specific
|
|
|
|
command line options, and pass this table to the GLib initialization
|
|
|
|
function along with the option group returned from the
|
|
|
|
function <function>gst_init_get_option_group</function>. Your
|
2004-12-15 07:30:55 +00:00
|
|
|
application options will be parsed in addition to the standard
|
|
|
|
<application>GStreamer</application> options.
|
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
</chapter>
|