mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 10:11:08 +00:00
code cleanup and make it work
Original commit message from CVS: code cleanup and make it work
This commit is contained in:
parent
a15c1a4af2
commit
0bb8c8b7f7
2 changed files with 42 additions and 58 deletions
|
@ -79,8 +79,13 @@
|
|||
</para>
|
||||
|
||||
<programlisting>
|
||||
/* example-begin threads.c */
|
||||
#include <gst/gst.h>
|
||||
|
||||
/* we set this to TRUE right before gst_main (), but there could still
|
||||
be a race condition between setting it and entering the function */
|
||||
gboolean can_quit = FALSE;
|
||||
|
||||
/* eos will be called when the src element has an end of stream */
|
||||
void
|
||||
eos (GstElement *src, gpointer data)
|
||||
|
@ -91,18 +96,18 @@ eos (GstElement *src, gpointer data)
|
|||
/* stop the bin */
|
||||
gst_element_set_state (GST_ELEMENT (thread), GST_STATE_NULL);
|
||||
|
||||
while (!can_quit) /* waste cycles */ ;
|
||||
gst_main_quit ();
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstElement *filesrc, *audiosink;
|
||||
GstElement *pipeline;
|
||||
GstElement *filesrc, *decoder, *audiosink;
|
||||
GstElement *thread;
|
||||
|
||||
if (argc != 2) {
|
||||
g_print ("usage: %s <filename>\n", argv[0]);
|
||||
if (argc < 2) {
|
||||
g_print ("usage: %s <Ogg/Vorbis filename>\n", argv[0]);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
|
@ -112,10 +117,6 @@ main (int argc, char *argv[])
|
|||
thread = gst_thread_new ("thread");
|
||||
g_assert (thread != NULL);
|
||||
|
||||
/* create a new bin to hold the elements */
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
g_assert (pipeline != NULL);
|
||||
|
||||
/* create a disk reader */
|
||||
filesrc = gst_element_factory_make ("filesrc", "disk_source");
|
||||
g_assert (filesrc != NULL);
|
||||
|
@ -123,42 +124,33 @@ main (int argc, char *argv[])
|
|||
g_signal_connect (G_OBJECT (filesrc), "eos",
|
||||
G_CALLBACK (eos), thread);
|
||||
|
||||
/* create an ogg decoder */
|
||||
decoder = gst_element_factory_make ("vorbisfile", "decoder");
|
||||
g_assert (decoder != NULL);
|
||||
|
||||
/* and an audio sink */
|
||||
audiosink = gst_element_factory_make ("audiosink", "play_audio");
|
||||
audiosink = gst_element_factory_make ("osssink", "play_audio");
|
||||
g_assert (audiosink != NULL);
|
||||
|
||||
/* add objects to the main pipeline */
|
||||
gst_bin_add (GST_BIN (pipeline), filesrc);
|
||||
gst_bin_add (GST_BIN (pipeline), audiosink);
|
||||
|
||||
/* automatically setup the pipeline */
|
||||
if (!gst_pipeline_autoplug (GST_PIPELINE (pipeline))) {
|
||||
g_print ("unable to handle stream\n");
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* remove the source element from the pipeline */
|
||||
gst_bin_remove (GST_BIN (pipeline), filesrc);
|
||||
|
||||
/* insert the source element in the thread, remember a thread needs at
|
||||
least one source or connection element */
|
||||
gst_bin_add (GST_BIN (thread), filesrc);
|
||||
|
||||
/* add the pipeline to the thread too */
|
||||
gst_bin_add (GST_BIN (thread), GST_ELEMENT (pipeline));
|
||||
/* add objects to the thread */
|
||||
gst_bin_add_many (GST_BIN (thread), filesrc, decoder, audiosink, NULL);
|
||||
/* connect them in the logical order */
|
||||
gst_element_connect_many (filesrc, decoder, audiosink, NULL);
|
||||
|
||||
/* start playing */
|
||||
gst_element_set_state (GST_ELEMENT (thread), GST_STATE_PLAYING);
|
||||
|
||||
/* do whatever you want here, the thread will be playing */
|
||||
...
|
||||
g_print ("thread is playing\n");
|
||||
|
||||
can_quit = TRUE;
|
||||
gst_main ();
|
||||
|
||||
gst_pipeline_destroy (thread);
|
||||
|
||||
exit (0);
|
||||
}
|
||||
/* example-end threads.c */
|
||||
</programlisting>
|
||||
|
||||
</chapter>
|
||||
|
|
|
@ -79,8 +79,13 @@
|
|||
</para>
|
||||
|
||||
<programlisting>
|
||||
/* example-begin threads.c */
|
||||
#include <gst/gst.h>
|
||||
|
||||
/* we set this to TRUE right before gst_main (), but there could still
|
||||
be a race condition between setting it and entering the function */
|
||||
gboolean can_quit = FALSE;
|
||||
|
||||
/* eos will be called when the src element has an end of stream */
|
||||
void
|
||||
eos (GstElement *src, gpointer data)
|
||||
|
@ -91,18 +96,18 @@ eos (GstElement *src, gpointer data)
|
|||
/* stop the bin */
|
||||
gst_element_set_state (GST_ELEMENT (thread), GST_STATE_NULL);
|
||||
|
||||
while (!can_quit) /* waste cycles */ ;
|
||||
gst_main_quit ();
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstElement *filesrc, *audiosink;
|
||||
GstElement *pipeline;
|
||||
GstElement *filesrc, *decoder, *audiosink;
|
||||
GstElement *thread;
|
||||
|
||||
if (argc != 2) {
|
||||
g_print ("usage: %s <filename>\n", argv[0]);
|
||||
if (argc < 2) {
|
||||
g_print ("usage: %s <Ogg/Vorbis filename>\n", argv[0]);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
|
@ -112,10 +117,6 @@ main (int argc, char *argv[])
|
|||
thread = gst_thread_new ("thread");
|
||||
g_assert (thread != NULL);
|
||||
|
||||
/* create a new bin to hold the elements */
|
||||
pipeline = gst_pipeline_new ("pipeline");
|
||||
g_assert (pipeline != NULL);
|
||||
|
||||
/* create a disk reader */
|
||||
filesrc = gst_element_factory_make ("filesrc", "disk_source");
|
||||
g_assert (filesrc != NULL);
|
||||
|
@ -123,42 +124,33 @@ main (int argc, char *argv[])
|
|||
g_signal_connect (G_OBJECT (filesrc), "eos",
|
||||
G_CALLBACK (eos), thread);
|
||||
|
||||
/* create an ogg decoder */
|
||||
decoder = gst_element_factory_make ("vorbisfile", "decoder");
|
||||
g_assert (decoder != NULL);
|
||||
|
||||
/* and an audio sink */
|
||||
audiosink = gst_element_factory_make ("audiosink", "play_audio");
|
||||
audiosink = gst_element_factory_make ("osssink", "play_audio");
|
||||
g_assert (audiosink != NULL);
|
||||
|
||||
/* add objects to the main pipeline */
|
||||
gst_bin_add (GST_BIN (pipeline), filesrc);
|
||||
gst_bin_add (GST_BIN (pipeline), audiosink);
|
||||
|
||||
/* automatically setup the pipeline */
|
||||
if (!gst_pipeline_autoplug (GST_PIPELINE (pipeline))) {
|
||||
g_print ("unable to handle stream\n");
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* remove the source element from the pipeline */
|
||||
gst_bin_remove (GST_BIN (pipeline), filesrc);
|
||||
|
||||
/* insert the source element in the thread, remember a thread needs at
|
||||
least one source or connection element */
|
||||
gst_bin_add (GST_BIN (thread), filesrc);
|
||||
|
||||
/* add the pipeline to the thread too */
|
||||
gst_bin_add (GST_BIN (thread), GST_ELEMENT (pipeline));
|
||||
/* add objects to the thread */
|
||||
gst_bin_add_many (GST_BIN (thread), filesrc, decoder, audiosink, NULL);
|
||||
/* connect them in the logical order */
|
||||
gst_element_connect_many (filesrc, decoder, audiosink, NULL);
|
||||
|
||||
/* start playing */
|
||||
gst_element_set_state (GST_ELEMENT (thread), GST_STATE_PLAYING);
|
||||
|
||||
/* do whatever you want here, the thread will be playing */
|
||||
...
|
||||
g_print ("thread is playing\n");
|
||||
|
||||
can_quit = TRUE;
|
||||
gst_main ();
|
||||
|
||||
gst_pipeline_destroy (thread);
|
||||
|
||||
exit (0);
|
||||
}
|
||||
/* example-end threads.c */
|
||||
</programlisting>
|
||||
|
||||
</chapter>
|
||||
|
|
Loading…
Reference in a new issue