4cd7721dbbc9f7b0f4c61afa2b9b910151997271
[platform/upstream/gstreamer.git] / examples / thread / thread.c
1 #include <gst/gst.h>
2
3 /* eos will be called when the src element has an end of stream */
4 void eos(GstSrc *src, gpointer data) 
5 {
6   GstThread *thread = GST_THREAD(data);
7   g_print("have eos, quitting\n");
8
9   /* stop the bin */
10   gst_element_set_state(GST_ELEMENT(thread), GST_STATE_NULL);
11
12   gst_main_quit();
13 }
14
15 int main(int argc,char *argv[]) 
16 {
17   GstElement *disksrc, *audiosink;
18   GstElement *pipeline;
19   GstElement *thread;
20
21   if (argc != 2) {
22     g_print("usage: %s <filename>\n", argv[0]);
23     exit(-1);
24   }
25
26   gst_init(&argc,&argv);
27
28   /* create a new thread to hold the elements */
29   thread = gst_thread_new("thread");
30   g_assert(thread != NULL);
31
32   /* create a new bin to hold the elements */
33   pipeline = gst_pipeline_new("pipeline");
34   g_assert(pipeline != NULL);
35
36   /* create a disk reader */
37   disksrc = gst_elementfactory_make("disksrc", "disk_source");
38   g_assert(disksrc != NULL);
39   gtk_object_set(GTK_OBJECT(disksrc),"location", argv[1],NULL);
40   gtk_signal_connect(GTK_OBJECT(disksrc),"eos",
41                      GTK_SIGNAL_FUNC(eos), thread);
42
43   /* and an audio sink */
44   audiosink = gst_elementfactory_make("audiosink", "play_audio");
45   g_assert(audiosink != NULL);
46
47   /* add objects to the main pipeline */
48   gst_pipeline_add_src(GST_PIPELINE(pipeline), disksrc);
49   gst_pipeline_add_sink(GST_PIPELINE(pipeline), audiosink);
50
51   if (!gst_pipeline_autoplug(GST_PIPELINE(pipeline))) {
52     g_print("unable to handle stream\n");
53     exit(-1);
54   }
55
56   //gst_bin_remove(GST_BIN(pipeline), disksrc);
57
58   //gst_bin_add(GST_BIN(thread), disksrc);
59   gst_bin_add(GST_BIN(thread), GST_ELEMENT(pipeline));
60
61   /* make it ready */
62   gst_element_set_state(GST_ELEMENT(thread), GST_STATE_READY);
63   /* start playing */
64   gst_element_set_state(GST_ELEMENT(thread), GST_STATE_PLAYING);
65
66   gst_main();
67
68   gst_pipeline_destroy(thread);
69
70   exit(0);
71 }
72