6 g_print ("usage: thread <testnum> \n"
7 " available testnums: \n"
8 " 1: stress test state change \n"
10 " 3: iterate twice \n"
11 " 4: state change while running \n"
12 " 5: state change in thread context\n");
16 construct_pipeline (GstElement *pipeline)
18 GstElement *src, *sink, *queue, *thread;
20 src = gst_elementfactory_make ("fakesrc", "src");
21 sink = gst_elementfactory_make ("fakesink", "sink");
22 queue = gst_elementfactory_make ("queue", "queue");
23 thread = gst_elementfactory_make ("thread", "thread");
25 gst_element_connect (src, "src", queue, "sink");
26 gst_element_connect (queue, "src", sink, "sink");
28 gst_bin_add (GST_BIN (pipeline), src);
29 gst_bin_add (GST_BIN (pipeline), queue);
30 gst_bin_add (GST_BIN (pipeline), thread);
32 gst_bin_add (GST_BIN (thread), sink);
34 g_object_set (G_OBJECT (src), "num_buffers", 5, NULL);
38 change_state (GstElement *element, GstBuffer *buf, GstElement *pipeline)
40 gst_element_set_state (pipeline, GST_STATE_NULL);
44 main (gint argc, gchar *argv[])
49 gst_init (&argc, &argv);
56 testnum = atoi (argv[1]);
58 pipeline = gst_pipeline_new ("main_pipeline");
59 construct_pipeline (pipeline);
62 g_print ("stress test state changes...\n");
64 gst_element_set_state (pipeline, GST_STATE_NULL);
65 gst_element_set_state (pipeline, GST_STATE_READY);
66 gst_element_set_state (pipeline, GST_STATE_NULL);
67 gst_element_set_state (pipeline, GST_STATE_PAUSED);
68 gst_element_set_state (pipeline, GST_STATE_READY);
69 gst_element_set_state (pipeline, GST_STATE_PAUSED);
70 gst_element_set_state (pipeline, GST_STATE_PLAYING);
71 gst_element_set_state (pipeline, GST_STATE_PAUSED);
72 gst_element_set_state (pipeline, GST_STATE_PLAYING);
73 gst_element_set_state (pipeline, GST_STATE_READY);
74 gst_element_set_state (pipeline, GST_STATE_NULL);
77 if (testnum == 2 || testnum == 3) {
78 gst_element_set_state (pipeline, GST_STATE_PLAYING);
79 g_print ("running ...\n");
80 while (gst_bin_iterate (GST_BIN (pipeline)));
81 gst_element_set_state (pipeline, GST_STATE_NULL);
84 gst_element_set_state (pipeline, GST_STATE_PLAYING);
85 g_print ("running2 ...\n");
86 while (gst_bin_iterate (GST_BIN (pipeline)));
87 gst_element_set_state (pipeline, GST_STATE_NULL);
92 gst_element_set_state (pipeline, GST_STATE_PLAYING);
93 g_print ("running3 ...\n");
94 for (run = 0; run < 3; run++) {
95 gst_bin_iterate (GST_BIN (pipeline));
97 gst_element_set_state (pipeline, GST_STATE_NULL);
102 sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
104 g_signal_connect (G_OBJECT (sink), "handoff", change_state, pipeline);
105 gst_element_set_state (pipeline, GST_STATE_PLAYING);
106 g_print ("running3 ...\n");
107 while (gst_bin_iterate (GST_BIN (pipeline)));
108 gst_element_set_state (pipeline, GST_STATE_NULL);