1 #include <gst/gst.h>
3 /*
4 * FIXME:
5 * these tests should have a maximum run length, so that they get killed
6 * if they lock up, which they're bound to do.
7 */
9 void
10 usage (void)
11 {
12 g_print ("compile this test with TESTNUM defined.\n"
13 " available TESTNUMs: \n"
14 " 1: stress test state change \n"
15 " 2: iterate once \n"
16 " 3: iterate twice \n"
17 " 4: state change while running \n"
18 " 5: state change in thread context\n");
19 }
21 static void
22 construct_pipeline (GstElement *pipeline)
23 {
24 GstElement *src, *sink, *queue, *identity, *thread;
26 src = gst_element_factory_make ("fakesrc", NULL);
27 sink = gst_element_factory_make ("fakesink", "sink");
28 identity = gst_element_factory_make ("identity", NULL);
29 queue = gst_element_factory_make ("queue", NULL);
30 thread = gst_element_factory_make ("thread", NULL);
32 gst_element_link_many (src, queue, identity, sink, NULL);
34 gst_bin_add_many (GST_BIN (pipeline), src, queue, thread, NULL);
35 gst_bin_add_many (GST_BIN (thread), identity, sink, NULL);
37 g_object_set (G_OBJECT (src), "num_buffers", 5, NULL);
38 g_object_set (sink, "signal-handoff", TRUE, NULL);
39 }
41 void
42 change_state (GstElement *element, GstBuffer *buf, GstElement *pipeline)
43 {
44 gst_element_set_state (pipeline, GST_STATE_NULL);
45 }
47 int
48 main (gint argc, gchar *argv[])
49 {
50 GstElement *pipeline;
52 gst_init (&argc, &argv);
54 #ifndef TESTNUM
55 usage ();
56 return -1;
57 #endif
59 pipeline = gst_pipeline_new ("main_pipeline");
60 construct_pipeline (pipeline);
62 if (TESTNUM == 1) {
63 g_print ("thread test 1: stress test state changes...\n");
65 g_print ("NULL\n");
66 gst_element_set_state (pipeline, GST_STATE_NULL);
67 g_print ("READY\n");
68 gst_element_set_state (pipeline, GST_STATE_READY);
69 g_print ("NULL\n");
70 gst_element_set_state (pipeline, GST_STATE_NULL);
71 g_print ("PAUSED\n");
72 gst_element_set_state (pipeline, GST_STATE_PAUSED);
73 g_print ("READY\n");
74 gst_element_set_state (pipeline, GST_STATE_READY);
75 g_print ("PAUSED\n");
76 gst_element_set_state (pipeline, GST_STATE_PAUSED);
77 g_print ("PLAYING\n");
78 gst_element_set_state (pipeline, GST_STATE_PLAYING);
79 /* element likely hits EOS and does a state transition to PAUSED */
80 g_print ("READY\n");
81 gst_element_set_state (pipeline, GST_STATE_READY);
82 g_print ("NULL\n");
83 gst_element_set_state (pipeline, GST_STATE_NULL);
84 }
86 if (TESTNUM == 2 || TESTNUM == 3) {
87 gst_element_set_state (pipeline, GST_STATE_PLAYING);
88 g_print ("running ...\n");
89 while (gst_bin_iterate (GST_BIN (pipeline)));
90 gst_element_set_state (pipeline, GST_STATE_NULL);
91 }
92 if (TESTNUM == 3) {
93 gst_element_set_state (pipeline, GST_STATE_PLAYING);
94 g_print ("running ...\n");
95 while (gst_bin_iterate (GST_BIN (pipeline)));
96 gst_element_set_state (pipeline, GST_STATE_NULL);
97 }
98 if (TESTNUM == 4) {
99 gint run;
101 gst_element_set_state (pipeline, GST_STATE_PLAYING);
102 g_print ("running ...\n");
103 for (run = 0; run < 3; run++) {
104 gst_bin_iterate (GST_BIN (pipeline));
105 }
106 gst_element_set_state (pipeline, GST_STATE_NULL);
107 }
108 if (TESTNUM == 5) {
109 /* I don't this test is supposed to work */
110 GstElement *sink;
112 sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
113 g_assert (sink);
115 g_signal_connect (G_OBJECT (sink), "handoff",
116 G_CALLBACK (change_state), pipeline);
117 gst_element_set_state (pipeline, GST_STATE_PLAYING);
118 g_print ("running ...\n");
119 while (gst_bin_iterate (GST_BIN (pipeline)));
120 gst_element_set_state (pipeline, GST_STATE_NULL);
121 }
123 return 0;
124 }