2 * Test three ways of going non-lineairly to PLAYING. Both tests have a
3 * thread containing a fakesrc/sink.
5 * Test1 tests by adding fakesrc/fakesink, setting fakesrc to PLAYING
6 * (which should increment the container state) and then synchronizing
7 * state and see if the bin iterates. This reflects bug #123775.
9 * Test2 does the same, but emits EOS directly. This will (in case of
10 * race conditions) sometimes lead to a state-change before the previous
11 * one succeeded. This bug is not fixed yet (999998).
13 * Test3 tests by adding fakesrc, putting thread to PLAYING, adding
14 * fakesink, syncing state and see if it iterates. The group is sometimes
15 * activated before fakesink is added to the bin, which is a bug in opt
16 * and a race in core that is not fixed yet (999999).
21 static GstElement *pipeline, *fakesrc, *fakesink;
24 cb_timeout (gpointer data)
26 g_assert_not_reached ();
32 cb_quit (gpointer data)
36 g_print ("Quit mainloop\n");
44 cb_eos (gpointer data)
46 g_print ("Received EOS\n");
48 g_idle_add ((GSourceFunc) cb_quit, NULL);
52 cb_data (gpointer data)
54 static gboolean first = TRUE;
56 g_print ("Received data\n");
60 g_idle_add ((GSourceFunc) cb_quit, NULL);
66 cb_state (GstElement * element, GstElementState old_state,
67 GstElementState new_state, gpointer data)
69 g_print ("Changed state from %d to %d\n", old_state, new_state);
73 cb_play (gpointer data)
75 GstElementStateReturn res;
78 g_print ("Setting state on fakesrc\n");
79 gst_element_set_state (fakesrc, GST_STATE_PLAYING);
82 g_print ("Setting state on pipeline w/o fakesink\n");
83 gst_element_set_state (pipeline, GST_STATE_PLAYING);
84 g_print ("Adding fakesink\n");
85 gst_bin_add (GST_BIN (pipeline), fakesink);
88 g_print ("Syncing state in pipeline\n");
89 res = gst_bin_sync_children_state (GST_BIN (data));
90 g_assert (res == GST_STATE_SUCCESS);
91 g_print ("Set to playing correctly: %d\n", GST_STATE (pipeline));
98 main (gint argc, gchar * argv[])
102 gst_init (&argc, &argv);
104 g_print ("Will do a test to see if bug %d is fixed\n", TESTNUM);
106 pipeline = gst_thread_new ("p");
107 g_signal_connect (pipeline, "state-change", G_CALLBACK (cb_state), NULL);
108 fakesrc = gst_element_factory_make ("fakesrc", "src");
109 fakesink = gst_element_factory_make ("fakesink", "sink");
110 #if TESTNUM != 123775
111 g_object_set (G_OBJECT (fakesrc), "num-buffers", 0, NULL);
112 g_signal_connect (pipeline, "eos", G_CALLBACK (cb_eos), NULL);
114 g_object_set (G_OBJECT (fakesink), "signal-handoffs", TRUE, NULL);
115 g_signal_connect (fakesink, "handoff", G_CALLBACK (cb_data), NULL);
118 #if TESTNUM != 999999
119 gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
121 gst_bin_add (GST_BIN (pipeline), fakesrc);
124 gst_element_link (fakesrc, fakesink);
125 g_idle_add ((GSourceFunc) cb_play, pipeline);
128 id = g_timeout_add (5000, (GSourceFunc) cb_timeout, NULL);
129 g_print ("Enter mainloop\n");
131 g_source_remove (id);
133 gst_element_set_state (pipeline, GST_STATE_NULL);
134 gst_object_unref (pipeline);
136 g_print ("Done with test to show bug %d, fixed correctly\n", TESTNUM);