1 #include <stdlib.h>
2 #include <gst/gst.h>
4 gboolean playing;
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");
12 playing = FALSE;
13 }
15 int
16 main (int argc, char *argv[])
17 {
18 GstElement *filesrc, *osssink, *queue, *queue2, *parse, *decode;
19 GstElement *bin;
20 GstElement *thread, *thread2;
22 gst_init (&argc, &argv);
24 if (argc != 2) {
25 g_print ("usage: %s <filename>\n", argv[0]);
26 exit (-1);
27 }
29 /* create a new thread to hold the elements */
30 thread = gst_thread_new ("thread");
31 g_assert (thread != NULL);
32 thread2 = gst_thread_new ("thread2");
33 g_assert (thread2 != NULL);
35 /* create a new bin to hold the elements */
36 bin = gst_bin_new ("bin");
37 g_assert (bin != NULL);
39 /* create a disk reader */
40 filesrc = gst_element_factory_make ("filesrc", "disk_source");
41 g_assert (filesrc != NULL);
42 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
43 g_signal_connect (G_OBJECT (filesrc), "eos", G_CALLBACK (eos), thread);
45 queue = gst_element_factory_make ("queue", "queue");
46 queue2 = gst_element_factory_make ("queue", "queue2");
48 /* and an audio sink */
49 osssink = gst_element_factory_make ("osssink", "play_audio");
50 g_assert (osssink != NULL);
52 parse = gst_element_factory_make ("mp3parse", "parse");
53 decode = gst_element_factory_make ("mpg123", "decode");
55 /* add objects to the main bin */
56 gst_bin_add (GST_BIN (bin), filesrc);
57 gst_bin_add (GST_BIN (bin), queue);
59 gst_bin_add (GST_BIN (thread), parse);
60 gst_bin_add (GST_BIN (thread), decode);
61 gst_bin_add (GST_BIN (thread), queue2);
63 gst_bin_add (GST_BIN (thread2), osssink);
65 gst_element_link_many (filesrc, queue, parse, decode, queue2, osssink, NULL);
67 gst_bin_add (GST_BIN (bin), thread);
68 gst_bin_add (GST_BIN (bin), thread2);
70 /* make it ready */
71 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
72 /* start playing */
73 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
75 playing = TRUE;
77 while (playing) {
78 gst_bin_iterate (GST_BIN (bin));
79 }
81 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
83 exit (0);
84 }