1 #include <gst/gst.h>
3 /* threadb.c
4 * this tests if we can make a GstThread, put some stuff in it,
5 * dispatch it, and let it run from a main gst loop
6 * we repeat the main loop a hundred times to test thread reuse
7 * underneath GstThread
8 */
10 gboolean running = FALSE;
12 static void
13 construct_pipeline (GstElement * pipeline)
14 {
15 GstElement *src, *sink, *identity;
17 src = gst_element_factory_make ("fakesrc", NULL);
18 identity = gst_element_factory_make ("identity", NULL);
19 sink = gst_element_factory_make ("fakesink", NULL);
20 g_assert (src);
21 g_assert (identity);
22 g_assert (sink);
24 gst_element_link_many (src, identity, sink, NULL);
26 gst_bin_add_many (GST_BIN (pipeline), src, identity, sink, NULL);
28 g_object_set (G_OBJECT (src), "num_buffers", 5, NULL);
29 }
31 void
32 state_changed (GstElement * el, gint arg1, gint arg2, gpointer user_data)
33 {
34 GstElementState state = gst_element_get_state (el);
36 g_print ("element %s has changed state to %s\n",
37 GST_ELEMENT_NAME (el), gst_element_state_get_name (state));
38 if (state == GST_STATE_PLAYING)
39 running = TRUE;
40 /* if we move from PLAYING to PAUSED, we're done */
41 if (state == GST_STATE_PAUSED && running) {
42 running = FALSE;
43 gst_main_quit ();
44 }
45 }
47 int
48 main (gint argc, gchar * argv[])
49 {
50 int runs = 100;
51 int i;
52 gulong id;
53 GstElement *thread;
55 gst_init (&argc, &argv);
57 for (i = 0; i < runs; ++i) {
58 thread = gst_thread_new ("main_thread");
59 g_assert (thread);
61 /* connect state change signal */
62 id = g_signal_connect (G_OBJECT (thread), "state_change",
63 G_CALLBACK (state_changed), NULL);
64 construct_pipeline (thread);
66 g_print ("Setting thread to play\n");
67 gst_element_set_state (thread, GST_STATE_PLAYING);
69 g_print ("Going into the main GStreamer loop\n");
70 gst_main ();
71 g_print ("Coming out of the main GStreamer loop\n");
72 g_signal_handler_disconnect (G_OBJECT (thread), id);
73 gst_element_set_state (thread, GST_STATE_NULL);
74 g_print ("Unreffing thread\n");
75 g_object_unref (G_OBJECT (thread));
76 running = FALSE;
77 }
79 return 0;
80 }