46b25c792824a712747fc7f4b781962579e868b9
[platform/upstream/gstreamer.git] / tests / sched / dynamic-pipeline.c
1 #include <gst/gst.h>
2
3 /* This test will fail because it tries to allocate two cothread_context's in
4  * one thread. This will cause a segfault. This is a problem with gstreamer's
5  * cothreading that is fixed in the newer cothreads package.
6  */
7
8 int
9 main (int argc, char *argv[])
10 {
11   GstElement *fakesrc, *fakesink1, *fakesink2, *pipe1, *pipe2;
12
13   gst_init (&argc, &argv);
14
15   if (argc != 1) {
16     g_print ("usage: %s\n", argv[0]);
17     exit (-1);
18   }
19
20   fakesrc = gst_element_factory_make ("fakesrc", "fakesrc");
21   fakesink1 = gst_element_factory_make ("fakesink", "fakesink1");
22   fakesink2 = gst_element_factory_make ("fakesink", "fakesink2");
23
24   /* a crucial part of this test (and one that the old cothreads fails on) is
25      having two active pipelines in the same thread. */
26   pipe1 = gst_pipeline_new ("pipe1");
27   pipe2 = gst_pipeline_new ("pipe2");
28
29   /* make the first pipeline */
30   gst_bin_add (GST_BIN (pipe1), fakesrc);
31   gst_bin_add (GST_BIN (pipe1), fakesink1);
32   gst_element_link_pads (fakesrc, "src", fakesink1, "sink");
33
34   /* initialize cothreads */
35   gst_element_set_state (pipe1, GST_STATE_PLAYING);
36   gst_bin_iterate (GST_BIN (pipe1));
37   gst_element_set_state (pipe1, GST_STATE_READY);
38
39   /* destroy the fakesink, but keep fakesrc (its state is GST_STATE_READY) */
40   gst_element_unlink_pads (fakesrc, "src", fakesink1, "sink");
41   gst_object_ref (GST_OBJECT (fakesrc));
42   gst_bin_remove (GST_BIN (pipe1), fakesrc);
43   gst_bin_remove (GST_BIN (pipe1), fakesink1);
44
45   gst_object_unref (GST_OBJECT (pipe1));
46
47   /* make a new pipeline */
48   gst_bin_add (GST_BIN (pipe2), fakesink2);
49
50   /* don't change the new pipeline's state, it should change on the bin_add */
51   gst_bin_add (GST_BIN (pipe2), fakesrc);
52   gst_element_link_pads (fakesrc, "src", fakesink2, "sink");
53
54   /* show the pipeline state */
55   gst_xml_write_file (GST_ELEMENT (pipe2), stdout);
56
57   /* try to iterate the pipeline */
58   gst_element_set_state (pipe2, GST_STATE_PLAYING);
59   gst_bin_iterate (GST_BIN (pipe2));
60   gst_element_set_state (pipe2, GST_STATE_NULL);
61
62   return 0;
63 }