1 #include <gst/gst.h>
3 /* threadc.c
4 * this tests if we can make a GstThread, with enough cothreads to stress it
5 */
7 gboolean running = FALSE;
8 gboolean can_quit = FALSE;
10 static void
11 construct_pipeline (GstElement *pipeline, gint identities)
12 {
13 GstElement *src, *sink;
14 GstElement *identity = NULL;
15 GstElement *from;
16 int i;
18 identity = NULL;
19 src = gst_element_factory_make ("fakesrc", NULL);
20 sink = gst_element_factory_make ("fakesink", NULL);
21 g_assert (src);
22 g_assert (sink);
23 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
24 from = src;
26 for (i = 0; i < identities; ++i)
27 {
28 identity = gst_element_factory_make ("identity", NULL);
29 g_assert (identity);
30 gst_bin_add (GST_BIN (pipeline), identity);
31 gst_element_link (from, identity);
32 from = identity;
33 }
34 gst_element_link (identity, sink);
36 g_object_set (G_OBJECT (src), "num_buffers", 1, "sizetype", 3, NULL);
37 }
39 void
40 state_changed (GstElement *el, gint arg1, gint arg2, gpointer user_data)
41 {
42 GstElementState state = gst_element_get_state (el);
44 g_print ("element %s has changed state to %s\n",
45 GST_ELEMENT_NAME (el),
46 gst_element_state_get_name (state));
47 if (state == GST_STATE_PLAYING) running = TRUE;
48 /* if we move from PLAYING to PAUSED, we're done */
49 if (state == GST_STATE_PAUSED && running)
50 {
51 while (!can_quit) ;
52 can_quit = FALSE;
53 g_print ("quitting main loop\n");
54 gst_main_quit ();
55 }
56 }
58 int
59 main (gint argc, gchar *argv[])
60 {
61 int runs = 290;
62 int i;
63 gulong id;
64 GstElement *thread;
66 gst_init (&argc, &argv);
68 for (i = 90; i < runs; ++i)
69 {
70 thread = gst_thread_new ("main_thread");
71 g_assert (thread);
73 /* connect state change signal */
74 id = g_signal_connect (G_OBJECT (thread), "state_change",
75 G_CALLBACK (state_changed), NULL);
76 construct_pipeline (thread, i / 10 + 1);
78 g_print ("Setting thread to play with %d identities\n", i / 10 + 1);
79 if (gst_element_set_state (thread, GST_STATE_PLAYING) == GST_STATE_FAILURE) {
80 g_error ("Failed setting thread to play\n");
81 }
82 else {
83 g_print ("Going into the main GStreamer loop\n");
84 can_quit = TRUE; /* we don't want gst_main_quit called before gst_main */
85 gst_main ();
86 }
87 running = FALSE;
88 g_print ("Coming out of the main GStreamer loop\n");
89 g_signal_handler_disconnect (G_OBJECT (thread), id);
90 gst_element_set_state (thread, GST_STATE_NULL);
91 g_print ("Unreffing thread\n");
92 g_object_unref (G_OBJECT (thread));
93 }
95 return 0;
96 }