gst-indent run on core
[platform/upstream/gstreamer.git] / examples / queue3 / queue3.c
1 #include <stdlib.h>
2 #include <gst/gst.h>
3
4 gboolean playing;
5
6 /* eos will be called when the src element has an end of stream */
7 void
8 eos (GstElement * element, gpointer data)
9 {
10   g_print ("have eos, quitting\n");
11
12   playing = FALSE;
13 }
14
15 int
16 main (int argc, char *argv[])
17 {
18   GstElement *filesrc, *osssink, *queue, *parse, *decode;
19   GstElement *bin;
20   GstElement *thread;
21
22   gst_init (&argc, &argv);
23
24   if (argc != 2) {
25     g_print ("usage: %s <filename>\n", argv[0]);
26     exit (-1);
27   }
28
29   /* create a new thread to hold the elements */
30   thread = gst_thread_new ("thread");
31   g_assert (thread != NULL);
32
33   /* create a new bin to hold the elements */
34   bin = gst_bin_new ("bin");
35   g_assert (bin != NULL);
36
37   /* create a disk reader */
38   filesrc = gst_element_factory_make ("filesrc", "disk_source");
39   g_assert (filesrc != NULL);
40   g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
41   g_signal_connect (G_OBJECT (filesrc), "eos", G_CALLBACK (eos), thread);
42
43   queue = gst_element_factory_make ("queue", "queue");
44
45   /* and an audio sink */
46   osssink = gst_element_factory_make ("osssink", "play_audio");
47   g_assert (osssink != NULL);
48
49   parse = gst_element_factory_make ("mp3parse", "parse");
50   decode = gst_element_factory_make ("mpg123", "decode");
51
52   /* add objects to the main bin */
53   gst_bin_add (GST_BIN (bin), filesrc);
54   gst_bin_add (GST_BIN (bin), queue);
55
56   gst_bin_add (GST_BIN (thread), parse);
57   gst_bin_add (GST_BIN (thread), decode);
58   gst_bin_add (GST_BIN (thread), osssink);
59
60   gst_element_link_many (filesrc, queue, parse, decode, osssink, NULL);
61
62   /* make it ready */
63   gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
64   /* start playing */
65   gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
66
67   playing = TRUE;
68
69   while (playing) {
70     gst_bin_iterate (GST_BIN (bin));
71   }
72
73   gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
74
75   exit (0);
76 }