1 #include <gst/gst.h>
2 #include <unistd.h>
4 /* threadc.c
5 * this tests if we can make a GstBin and iterate it inside a GThread
6 */
8 #define MAX_IDENTITIES 29
9 #define RUNS_PER_IDENTITY 5
11 gboolean running = FALSE;
12 gboolean done = FALSE;
14 static void
15 construct_pipeline (GstElement * pipeline, gint identities)
16 {
17 GstElement *src, *sink, *identity = NULL;
18 GstElement *from;
19 int i;
21 src = gst_element_factory_make ("fakesrc", NULL);
22 sink = gst_element_factory_make ("fakesink", NULL);
23 g_assert (src);
24 g_assert (sink);
25 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
26 from = src;
28 for (i = 0; i < identities; ++i) {
29 identity = gst_element_factory_make ("identity", NULL);
30 g_assert (identity);
31 gst_bin_add (GST_BIN (pipeline), identity);
32 gst_element_link (from, identity);
33 from = identity;
34 }
35 gst_element_link (identity, sink);
37 g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL);
38 }
40 static void
41 iterator (GstElement * bin)
42 {
43 gst_element_set_state (bin, GST_STATE_PLAYING);
44 while (gst_bin_iterate (GST_BIN (bin)))
45 g_print ("+");
46 gst_element_set_state (bin, GST_STATE_NULL);
47 g_print ("\n");
48 done = TRUE;
49 }
51 int
52 main (gint argc, gchar * argv[])
53 {
54 int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY;
55 int i;
56 GstElement *pipeline;
58 alarm (10);
60 g_thread_init (NULL);
61 gst_init (&argc, &argv);
63 for (i = 0; i < runs; ++i) {
64 pipeline = gst_pipeline_new ("main_pipeline");
65 g_assert (pipeline);
67 /* connect state change signal */
68 construct_pipeline (pipeline, i / RUNS_PER_IDENTITY + 1);
70 done = FALSE;
71 g_thread_create ((GThreadFunc) iterator, pipeline, FALSE, NULL);
72 g_print ("Created GThread\n");
74 g_print ("Waiting for thread PLAYING->PAUSED\n");
75 while (!done) /* do nothing */
76 ;
77 running = FALSE;
78 g_print ("Unreffing pipeline\n");
79 g_object_unref (G_OBJECT (pipeline));
80 }
82 return 0;
83 }