4 * this tests if we can make a GstThread, with enough cothreads to stress it
7 #define MAX_IDENTITIES 29
8 #define RUNS_PER_IDENTITY 5
10 gboolean running = FALSE;
11 gboolean done = FALSE;
14 construct_pipeline (GstElement *pipeline, gint identities)
16 GstElement *src, *sink, *identity;
20 src = gst_element_factory_make ("fakesrc", NULL);
21 sink = gst_element_factory_make ("fakesink", NULL);
24 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
27 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_connect (from, identity);
35 gst_element_connect (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),
47 gst_element_state_get_name (state));
48 if (state == GST_STATE_PLAYING) running = TRUE;
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;
62 gst_init (&argc, &argv);
64 for (i = 0; i < runs; ++i)
66 thread = gst_thread_new ("main_thread");
69 /* connect state change signal */
70 id = g_signal_connect (G_OBJECT (thread), "state_change",
71 G_CALLBACK (state_changed), NULL);
72 construct_pipeline (thread, i / RUNS_PER_IDENTITY + 1);
74 g_print ("Setting thread to play with %d identities\n",
75 i / RUNS_PER_IDENTITY + 1);
77 gst_element_set_state (thread, GST_STATE_PLAYING);
79 g_print ("Waiting for thread PLAYING->PAUSED\n");
80 while (!done) /* do nothing */;
82 g_print ("Coming out of the main GStreamer loop\n");
83 g_signal_handler_disconnect (G_OBJECT (thread), id);
84 gst_element_set_state (thread, GST_STATE_NULL);
85 g_print ("Unreffing thread\n");
86 g_object_unref (G_OBJECT (thread));