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)
30 identity = gst_element_factory_make ("identity", NULL);
32 gst_bin_add (GST_BIN (pipeline), identity);
33 gst_element_link (from, identity);
36 gst_element_link (identity, sink);
38 g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL);
42 state_changed (GstElement *el, gint arg1, gint arg2, gpointer user_data)
44 GstElementState state = gst_element_get_state (el);
46 g_print ("element %s has changed state to %s\n",
47 GST_ELEMENT_NAME (el),
48 gst_element_state_get_name (state));
49 if (state == GST_STATE_PLAYING) running = TRUE;
50 /* if we move from PLAYING to PAUSED, we're done */
51 if (state == GST_STATE_PAUSED && running)
56 main (gint argc, gchar *argv[])
58 int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY;
65 gst_init (&argc, &argv);
67 for (i = 0; i < runs; ++i)
69 thread = gst_thread_new ("main_thread");
72 /* connect state change signal */
73 id = g_signal_connect (G_OBJECT (thread), "state_change",
74 G_CALLBACK (state_changed), NULL);
75 construct_pipeline (thread, i / RUNS_PER_IDENTITY + 1);
77 g_print ("Setting thread to play with %d identities\n",
78 i / RUNS_PER_IDENTITY + 1);
80 if (gst_element_set_state (thread, GST_STATE_PLAYING) == GST_STATE_FAILURE) {
81 g_warning ("failed to go to PLAYING");
84 g_print ("Waiting for thread PLAYING->PAUSED\n");
85 while (!done) /* do nothing */;
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));