5 * this tests if we can make a GstThread, with enough cothreads to stress it
8 #define MAX_IDENTITIES 29
9 #define RUNS_PER_IDENTITY 5
11 gboolean running = FALSE;
12 gboolean done = FALSE;
15 construct_pipeline (GstElement * pipeline, gint identities)
17 GstElement *src, *sink, *identity = NULL;
21 src = gst_element_factory_make ("fakesrc", NULL);
22 sink = gst_element_factory_make ("fakesink", NULL);
25 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
28 for (i = 0; i < identities; ++i) {
29 identity = gst_element_factory_make ("identity", NULL);
31 gst_bin_add (GST_BIN (pipeline), identity);
32 gst_element_link (from, identity);
35 gst_element_link (identity, sink);
37 g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL);
41 state_changed (GstElement * el, gint arg1, gint arg2, gpointer user_data)
43 GstElementState state = gst_element_get_state (el);
45 g_print ("element %s has changed state to %s\n",
46 GST_ELEMENT_NAME (el), gst_element_state_get_name (state));
47 if (state == GST_STATE_PLAYING)
49 /* if we move from PLAYING to PAUSED, we're done */
50 if (state == GST_STATE_PAUSED && running)
55 main (gint argc, gchar * argv[])
57 int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY;
64 gst_init (&argc, &argv);
66 for (i = 0; i < runs; ++i) {
67 thread = gst_thread_new ("main_thread");
70 /* connect state change signal */
71 id = g_signal_connect (G_OBJECT (thread), "state_change",
72 G_CALLBACK (state_changed), NULL);
73 construct_pipeline (thread, i / RUNS_PER_IDENTITY + 1);
75 g_print ("Setting thread to play with %d identities\n",
76 i / RUNS_PER_IDENTITY + 1);
78 if (gst_element_set_state (thread, GST_STATE_PLAYING) == GST_STATE_FAILURE) {
79 g_warning ("failed to go to PLAYING");
81 g_print ("Waiting for thread PLAYING->PAUSED\n");
82 while (!done) /* do nothing */
86 g_print ("Coming out of the main GStreamer loop\n");
87 g_signal_handler_disconnect (G_OBJECT (thread), id);
88 gst_element_set_state (thread, GST_STATE_NULL);
89 g_print ("Unreffing thread\n");
90 g_object_unref (G_OBJECT (thread));