First THREADED backport attempt, focusing on adding locks and making sure the API...
[platform/upstream/gstreamer.git] / tests / old / examples / thread / thread.c
1 #include <stdlib.h>
2 #include <gst/gst.h>
3
4 static GMainLoop *loop;
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   GstThread *thread = GST_THREAD (data);
11
12   g_print ("have eos, quitting\n");
13
14   /* stop the bin */
15   gst_element_set_state (GST_ELEMENT (thread), GST_STATE_NULL);
16
17   g_main_loop_quit (loop);
18   g_main_loop_unref (loop);
19 }
20
21 int
22 main (int argc, char *argv[])
23 {
24   GstElement *filesrc, *osssink;
25   GstElement *pipeline;
26   GstElement *thread;
27
28   gst_init (&argc, &argv);
29
30   if (argc != 2) {
31     g_print ("usage: %s <filename>\n", argv[0]);
32     exit (-1);
33   }
34
35   /* create a new thread to hold the elements */
36   thread = gst_thread_new ("thread");
37   g_assert (thread != NULL);
38
39   /* create a new bin to hold the elements */
40   pipeline = gst_pipeline_new ("pipeline");
41   g_assert (pipeline != NULL);
42
43   /* create a disk reader */
44   filesrc = gst_element_factory_make ("filesrc", "disk_source");
45   g_assert (filesrc != NULL);
46   g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
47   g_signal_connect (G_OBJECT (filesrc), "eos", G_CALLBACK (eos), thread);
48
49   /* and an audio sink */
50   osssink = gst_element_factory_make ("osssink", "play_audio");
51   g_assert (osssink != NULL);
52
53   /* add objects to the main pipeline */
54   /*
55      gst_pipeline_add_src(GST_PIPELINE(pipeline), filesrc);
56      gst_pipeline_add_sink(GST_PIPELINE(pipeline), osssink);
57
58      if (!gst_pipeline_autoplug(GST_PIPELINE(pipeline))) {
59      g_print("unable to handle stream\n");
60      exit(-1);
61      }
62    */
63
64   /*gst_bin_remove(GST_BIN(pipeline), filesrc); */
65
66   /*gst_bin_add(GST_BIN(thread), filesrc); */
67   gst_bin_add (GST_BIN (thread), GST_ELEMENT (pipeline));
68
69   /* make it ready */
70   gst_element_set_state (GST_ELEMENT (thread), GST_STATE_READY);
71   /* start playing */
72   gst_element_set_state (GST_ELEMENT (thread), GST_STATE_PLAYING);
73
74   loop = g_main_loop_new (NULL, FALSE);
75
76   gst_object_unref (GST_OBJECT (thread));
77
78   exit (0);
79 }