docs/manual/: - Explicitely include glib.h.

Original commit message from CVS:
patch by: Luc Pionchon  <luc.pionchon@nokia.com>
* docs/manual/basics-helloworld.xml:
* docs/manual/hello-world.fig:
- Explicitely include glib.h.
- Do not use global variables.
- Use g_printerr() instead of g_print().
- Minor formating/renaming to increase readibility.
- Renamed new_pad() to on_pad_added()
- Improved explenatory comments.
- renamed ogg parser to ogg demuxer
- Use "autoaudiosink" instead of "alsasink".
Fixes: #538619
This commit is contained in:
Luc Pionchon 2008-06-25 14:32:53 +00:00 committed by Stefan Kost
parent 954ddd9645
commit 4302aa48c2
3 changed files with 231 additions and 82 deletions

View file

@ -1,3 +1,19 @@
2008-06-25 Stefan Kost <ensonic@users.sf.net>
patch by: Luc Pionchon <luc.pionchon@nokia.com>
* docs/manual/basics-helloworld.xml:
* docs/manual/hello-world.fig:
- Explicitely include glib.h.
- Do not use global variables.
- Use g_printerr() instead of g_print().
- Minor formating/renaming to increase readibility.
- Renamed new_pad() to on_pad_added()
- Improved explenatory comments.
- renamed ogg parser to ogg demuxer
- Use "autoaudiosink" instead of "alsasink".
Fixes: #538619
2008-06-25 Stefan Kost <ensonic@users.sf.net>
* ChangeLog:

View file

@ -37,10 +37,10 @@
Since <quote>oggdemux</quote> creates dynamic pads for each elementary
stream, you'll need to set a <quote>pad-added</quote> event handler
on the <quote>oggdemux</quote> element, like you've learned in
<xref linkend="section-pads-dynamic"/>, to link the Ogg parser and
<xref linkend="section-pads-dynamic"/>, to link the Ogg demuxer and
the Vorbis decoder elements together. At last, we'll also need an
audio output element, we will use <quote>alsasink</quote>, which
outputs sound to an ALSA audio device.
audio output element, we will use <quote>autoaudiosink</quote>, which
automatically detects your audio device.
</para>
<para>
The last thing left to do is to add all elements into a container
@ -59,35 +59,32 @@
<programlisting>
<!-- example-begin helloworld.c -->
#include &lt;gst/gst.h&gt;
#include &lt;glib.h&gt;
/*
* Global objects are usually a bad thing. For the purpose of this
* example, we will use them, however.
*/
GstElement *pipeline, *source, *parser, *decoder, *conv, *sink;
static gboolean
bus_call (GstBus *bus,
GstMessage *msg,
gpointer data)
GstMessage *msg,
gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End-of-stream\n");
g_print ("End of stream\n");
g_main_loop_quit (loop);
break;
case GST_MESSAGE_ERROR: {
gchar *debug;
GError *err;
gst_message_parse_error (msg, &amp;err, &amp;debug);
case GST_MESSAGE_ERROR: {
gchar *debug;
GError *error;
gst_message_parse_error (msg, &amp;error, &amp;debug);
g_free (debug);
g_print ("Error: %s\n", err->message);
g_error_free (err);
g_printerr ("Error: %s\n", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
@ -99,78 +96,105 @@ bus_call (GstBus *bus,
return TRUE;
}
static void
new_pad (GstElement *element,
GstPad *pad,
gpointer data)
on_pad_added (GstElement *element,
GstPad *pad,
gpointer data)
{
GstPad *sinkpad;
/* We can now link this pad with the audio decoder */
g_print ("Dynamic pad created, linking parser/decoder\n");
GstElement *decoder = (GstElement *) data;
/* We can now link this pad with the vorbis-decoder sink pad */
g_print ("Dynamic pad created, linking demuxer/decoder\n");
sinkpad = gst_element_get_static_pad (decoder, "sink");
gst_pad_link (pad, sinkpad);
gst_object_unref (sinkpad);
}
int
main (int argc,
char *argv[])
{
GMainLoop *loop;
GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
GstBus *bus;
/* initialize GStreamer */
/* Initialisation */
gst_init (&amp;argc, &amp;argv);
loop = g_main_loop_new (NULL, FALSE);
/* check input arguments */
/* Check input arguments */
if (argc != 2) {
g_print ("Usage: %s &lt;Ogg/Vorbis filename&gt;\n", argv[0]);
g_printerr ("Usage: %s &lt;Ogg/Vorbis filename&gt;\n", argv[0]);
return -1;
}
/* create elements */
/* Create gstreamer elements */
pipeline = gst_pipeline_new ("audio-player");
source = gst_element_factory_make ("filesrc", "file-source");
parser = gst_element_factory_make ("oggdemux", "ogg-parser");
decoder = gst_element_factory_make ("vorbisdec", "vorbis-decoder");
conv = gst_element_factory_make ("audioconvert", "converter");
sink = gst_element_factory_make ("alsasink", "alsa-output");
if (!pipeline || !source || !parser || !decoder || !conv || !sink) {
g_print ("One element could not be created\n");
source = gst_element_factory_make ("filesrc", "file-source");
demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer");
decoder = gst_element_factory_make ("vorbisdec", "vorbis-decoder");
conv = gst_element_factory_make ("audioconvert", "converter");
sink = gst_element_factory_make ("autoaudiosink", "audio-output");
if (!pipeline || !source || !demuxer || !decoder || !conv || !sink) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* set filename property on the file source. Also add a message
* handler. */
/* Set up the pipeline */
/* we set the input filename to the source element */
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
/* put all elements in a bin */
/* we add all elements into the pipeline */
/* file-source | ogg-demuxer | vorbis-decoder | converter | alsa-output */
gst_bin_add_many (GST_BIN (pipeline),
source, parser, decoder, conv, sink, NULL);
source, demuxer, decoder, conv, sink, NULL);
/* link together - note that we cannot link the parser and
* decoder yet, because the parser uses dynamic pads. For that,
* we set a pad-added signal handler. */
gst_element_link (source, parser);
/* we link the elements together */
/* file-source -&gt; ogg-demuxer ~&gt; vorbis-decoder -&gt; converter -&gt; alsa-output */
gst_element_link (source, demuxer);
gst_element_link_many (decoder, conv, sink, NULL);
g_signal_connect (parser, "pad-added", G_CALLBACK (new_pad), NULL);
g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added), decoder);
/* Now set to playing and iterate. */
g_print ("Setting to PLAYING\n");
/* note that the demuxer will be linked to the decoder dynamically.
The reason is that Ogg may contain various streams (for example
audio and video). The source pad(s) will be created at run time,
by the demuxer when it detects the amount and nature of streams.
Therefore we connect a callback function which will be executed
when the "pad-added" is emitted.*/
/* Set the pipeline to "playing" state*/
g_print ("Now playing: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
g_print ("Running\n");
/* Iterate */
g_print ("Running...\n");
g_main_loop_run (loop);
/* clean up nicely */
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
@ -228,7 +252,7 @@ main (int argc,
the <quote>filesrc</quote> element with some other element that
reads data from a network, or some other data source element that
is better integrated with your desktop environment. Also, you can
use other decoders and parsers to support other media types. You
use other decoders and parsers/demuxers to support other media types. You
can use another audio sink if you're not running Linux, but Mac OS X,
Windows or FreeBSD, or you can instead use a filesink to write audio
files to disk instead of playing them back. By using an audio card

View file

@ -1,39 +1,148 @@
#FIG 3.2
Landscape
Portrait
Center
Inches
Letter
100.00
Metric
A4
100.000000
Single
-2
1200 2
2 2 0 1 0 7 50 0 -1 0.000 0 0 -1 0 0 5
2100 2775 4050 2775 4050 4425 2100 4425 2100 2775
2 2 0 1 0 6 50 0 20 0.000 0 0 -1 0 0 5
3300 3600 4050 3600 4050 4125 3300 4125 3300 3600
2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2
1 1 1.00 90.00 120.00
4050 3750 4575 3750
2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2
1 1 1.00 90.00 120.00
6525 3750 7125 3750
2 2 0 1 0 7 50 0 -1 0.000 0 0 -1 0 0 5
4575 2775 6525 2775 6525 4425 4575 4425 4575 2775
2 2 0 1 0 6 50 0 20 0.000 0 0 -1 0 0 5
4575 3600 5325 3600 5325 4125 4575 4125 4575 3600
2 2 0 1 0 6 50 0 20 0.000 0 0 -1 0 0 5
5775 3600 6525 3600 6525 4125 5775 4125 5775 3600
2 2 0 1 0 7 50 0 -1 0.000 0 0 -1 0 0 5
7125 2775 9075 2775 9075 4425 7125 4425 7125 2775
2 2 0 1 0 6 50 0 20 0.000 0 0 -1 0 0 5
7125 3600 7875 3600 7875 4125 7125 4125 7125 3600
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
1950 1950 9375 1950 9375 4800 1950 4800 1950 1950
4 0 0 50 0 16 12 0.0000 4 180 660 2175 2250 pipeline\001
4 0 0 50 0 16 12 0.0000 4 105 255 3525 3975 src\001
4 0 0 50 0 16 12 0.0000 4 165 1005 2250 3075 disk_source\001
4 0 0 50 0 16 12 0.0000 4 135 330 4725 3975 sink\001
4 0 0 50 0 16 12 0.0000 4 105 255 6000 3975 src\001
4 0 0 50 0 16 12 0.0000 4 135 690 4725 3075 decoder\001
4 0 0 50 0 16 12 0.0000 4 135 330 7350 3975 sink\001
4 0 0 50 0 16 12 0.0000 4 180 930 7275 3075 play_audio\001
0 32 #ffff00
6 0 0 0 0
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
7559 5196 13653 5196 13653 6566 7559 6566 7559 5196
-6
6 0 0 0 0
4 0 0 0 0 16 11.381102 0.0 6 0.0 0.0 7653 5385 pipeline\001
-6
6 0 0 0 0
2 1 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 2
8645 6215 8754 6215
2 3 0 0 0 0 0 0 20 31.496063 0 0 0 0 0 4
8754 6260 8874 6215 8754 6170 8754 6260
-6
6 0 0 0 0
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
7653 5716 8645 5716 8645 6472 7653 6472 7653 5716
-6
6 0 0 0 0
2 3 0 1 32 32 0 -1 20 31.496063 0 0 0 0 0 5
8220 6094 8645 6094 8645 6336 8220 6336 8220 6094
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
8220 6094 8645 6094 8645 6336 8220 6336 8220 6094
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 8362 6283 src\001
-6
6 0 0 0 0
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
8881 5716 9874 5716 9874 6472 8881 6472 8881 5716
-6
6 0 0 0 0
2 3 0 1 32 32 0 -1 20 31.496063 0 0 0 0 0 5
8881 6094 9307 6094 9307 6336 8881 6336 8881 6094
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
8881 6094 9307 6094 9307 6336 8881 6336 8881 6094
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 8929 6283 sink\001
-6
6 0 0 0 0
2 3 0 1 32 32 0 -1 20 31.496063 0 0 0 0 0 5
9448 6094 9874 6094 9874 6336 9448 6336 9448 6094
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
9448 6094 9874 6094 9874 6336 9448 6336 9448 6094
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 9590 6283 src\001
-6
6 0 0 0 0
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
10110 5716 11102 5716 11102 6472 10110 6472 10110 5716
-6
6 0 0 0 0
2 3 0 1 32 32 0 -1 20 31.496063 0 0 0 0 0 5
10110 6094 10535 6094 10535 6336 10110 6336 10110 6094
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
10110 6094 10535 6094 10535 6336 10110 6336 10110 6094
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 10157 6283 sink\001
-6
6 0 0 0 0
2 3 0 1 32 32 0 -1 20 31.496063 0 0 0 0 0 5
10677 6094 11102 6094 11102 6336 10677 6336 10677 6094
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
10677 6094 11102 6094 11102 6336 10677 6336 10677 6094
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 10818 6283 src\001
-6
6 0 0 0 0
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
11338 5716 12330 5716 12330 6472 11338 6472 11338 5716
-6
6 0 0 0 0
2 3 0 1 32 32 0 -1 20 31.496063 0 0 0 0 0 5
11338 6094 11763 6094 11763 6336 11338 6336 11338 6094
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
11338 6094 11763 6094 11763 6336 11338 6336 11338 6094
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 11385 6283 sink\001
-6
6 0 0 0 0
2 3 0 1 32 32 0 -1 20 31.496063 0 0 0 0 0 5
11905 6094 12330 6094 12330 6336 11905 6336 11905 6094
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
11905 6094 12330 6094 12330 6336 11905 6336 11905 6094
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 12047 6283 src\001
-6
6 0 0 0 0
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
12566 5716 13559 5716 13559 6472 12566 6472 12566 5716
-6
6 0 0 0 0
2 3 0 1 32 32 0 -1 20 31.496063 0 0 0 0 0 5
12566 6094 12992 6094 12992 6336 12566 6336 12566 6094
2 3 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 5
12566 6094 12992 6094 12992 6336 12566 6336 12566 6094
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 12614 6283 sink\001
-6
6 0 0 0 0
2 1 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 2
9874 6215 9982 6215
2 3 0 0 0 0 0 0 20 31.496063 0 0 0 0 0 4
9982 6260 10102 6215 9982 6170 9982 6260
-6
6 0 0 0 0
2 1 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 2
11102 6215 11211 6215
2 3 0 0 0 0 0 0 20 31.496063 0 0 0 0 0 4
11211 6260 11331 6215 11211 6170 11211 6260
-6
6 0 0 0 0
2 1 0 1 0 0 0 0 -1 31.496063 0 0 0 0 0 2
12330 6215 12439 6215
2 3 0 0 0 0 0 0 20 31.496063 0 0 0 0 0 4
12439 6260 12559 6215 12439 6170 12439 6260
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 7700 5905 file-source\001
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 8929 5905 ogg-demuxer\001
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 10157 5905 vorbis-decoder\001
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 11385 5905 converter\001
-6
6 0 0 0 0
4 0 0 0 0 16 8.535827 0.0 6 0.0 0.0 12614 5905 audio-output\001
-6