3a0c7131383167dae725dc5720a3040f14e59133
[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(GstElement *element, 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, *osssink;
18   GstElement *pipeline;
19   GstElement *thread;
20
21   gst_init(&argc,&argv);
22
23   if (argc != 2) {
24     g_print("usage: %s <filename>\n", argv[0]);
25     exit(-1);
26   }
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   g_object_set(G_OBJECT(disksrc),"location", argv[1],NULL);
40   g_signal_connect(G_OBJECT(disksrc),"eos",
41                      G_CALLBACK(eos), thread);
42
43   /* and an audio sink */
44   osssink = gst_elementfactory_make("osssink", "play_audio");
45   g_assert(osssink != NULL);
46
47   /* add objects to the main pipeline */
48   /*
49   gst_pipeline_add_src(GST_PIPELINE(pipeline), disksrc);
50   gst_pipeline_add_sink(GST_PIPELINE(pipeline), osssink);
51
52   if (!gst_pipeline_autoplug(GST_PIPELINE(pipeline))) {
53     g_print("unable to handle stream\n");
54     exit(-1);
55   }
56   */
57
58   //gst_bin_remove(GST_BIN(pipeline), disksrc);
59
60   //gst_bin_add(GST_BIN(thread), disksrc);
61   gst_bin_add(GST_BIN(thread), GST_ELEMENT(pipeline));
62
63   /* make it ready */
64   gst_element_set_state(GST_ELEMENT(thread), GST_STATE_READY);
65   /* start playing */
66   gst_element_set_state(GST_ELEMENT(thread), GST_STATE_PLAYING);
67
68   gst_main();
69
70   gst_pipeline_destroy(thread);
71
72   exit(0);
73 }
74