3c057e498044f2cdaaecabacc758d425cf38586b
[platform/upstream/gstreamer.git] / testsuite / refcounting / sched.c
1 #include <gst/gst.h>
2
3 gint i = 0;
4 GstElement *pipeline;
5 GstPadChainFunction oss_chain;
6
7 static GstElement *
8 make_and_check_element (gchar *type, gchar *name)
9 {
10   GstElement *element = gst_element_factory_make (type, name);
11
12   if (element == NULL) {
13     g_warning ("Could not run test, because element type \"%s\" is not installed. Please retry when it is. Assuming it works for now...", type);
14     exit (0);
15   }
16
17   return element;
18 }
19
20 static void
21 create_pipeline (void)
22 {
23   GstElement *src; 
24   GstElement *sink;
25   GstElement *id;
26   
27   pipeline = gst_pipeline_new ("pipeline");
28   src = make_and_check_element ("sinesrc", "src");
29   /**
30    * You need a sink with a loop-based element in here, if you want to kill opt, too.
31    * Osssink (chain-based) only breaks the basic scheduler.
32    */
33   sink = make_and_check_element ("alsasink", "sink");
34   
35
36   gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
37   gst_element_link (src, sink);
38   
39   /** 
40    * now make the bug appear
41    * I believe it has something to do with 2 chains being created in the scheduler
42    * but I haven't looked at it yet
43    * If you comment out the next 4 lines, everything works fine.
44    * And no, it's not because of identity, you may use any other element.
45    */
46   gst_element_unlink (src, sink);
47   id = make_and_check_element ("identity", "id");
48   gst_bin_add (GST_BIN (pipeline), id);
49   gst_element_link_many (src, id, sink, NULL);
50   
51   /* This pipeline will not be removed properly once we unref it */
52   gst_element_set_state (pipeline, GST_STATE_PLAYING);
53 }  
54
55 gint 
56 main (gint argc, gchar *argv[]) 
57 {
58   gst_init (&argc, &argv);
59   create_pipeline();
60   
61   while (i < 300) {
62     /**
63      * only inc i when it works, so the program hangs when _iterate returns false,
64      * which it does after the first pipeline isn't unref'd properly and the next
65      * osssink refuses to work.
66      */
67     if (gst_bin_iterate (GST_BIN (pipeline)))
68       i++;
69     if (i % 50 == 0) {
70       gst_object_unref (GST_OBJECT (pipeline));
71       create_pipeline ();
72     }
73   }
74   return 0;
75 }