*.c: Don't cast to GST_OBJECT when reffing or unreffing. Large source-munging commit!!!
[platform/upstream/gstreamer.git] / testsuite / schedulers / 142183.c
1 /* GStreamer
2  * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <unistd.h>
20
21 #include <gst/gst.h>
22
23 static void
24 handoff_identity (GstElement * element)
25 {
26   GstBin *parent;
27
28   parent = GST_BIN (gst_element_get_parent (element));
29   g_print ("identity handoff\n");
30   gst_bin_remove (parent, element);
31 }
32
33 gint
34 main (gint argc, gchar ** argv)
35 {
36   GstElement *pipeline, *src, *sink, *id;
37
38   gst_init (&argc, &argv);
39
40   g_print ("setting up...\n");
41   /* setup pipeline */
42   pipeline = gst_element_factory_make ("pipeline", NULL);
43   g_assert (pipeline);
44   src = gst_element_factory_make ("fakesrc", NULL);
45   g_assert (src);
46   id = gst_element_factory_make ("identity", NULL);
47   g_assert (id);
48   /* ref object here as it will be unparented and destroyed in the
49    * handoff signal, normally the scheduler should keep a ref to the
50    * currently scheduled elements but that's another bug displayed in
51    * 142183-2.c */
52   gst_object_ref (id);
53   g_signal_connect (G_OBJECT (id), "handoff", (GCallback) handoff_identity,
54       NULL);
55   g_object_set (G_OBJECT (id), "loop-based", TRUE, NULL);
56
57   sink = gst_element_factory_make ("fakesink", NULL);
58   g_assert (sink);
59
60   gst_bin_add_many (GST_BIN (pipeline), src, id, sink, NULL);
61   /* this is what triggers the bug */
62   gst_element_enable_threadsafe_properties (GST_ELEMENT (src));
63   gst_element_enable_threadsafe_properties (GST_ELEMENT (id));
64   gst_element_enable_threadsafe_properties (GST_ELEMENT (sink));
65
66   gst_element_link_pads (src, "src", id, "sink");
67   gst_element_link_pads (id, "src", sink, "sink");
68
69   if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
70     g_assert_not_reached ();
71
72   gst_bin_iterate (GST_BIN (pipeline));
73   gst_bin_iterate (GST_BIN (pipeline));
74
75   /* 'cause we're going into deadlock mode */
76   alarm (5);
77
78   g_print ("adding identity back...\n");
79   /* add identity back in */
80   gst_bin_add_many (GST_BIN (pipeline), id, NULL);
81
82   g_print ("going into possible deadlock... alarm at 5 seconds\n");
83   gst_bin_iterate (GST_BIN (pipeline));
84   gst_bin_iterate (GST_BIN (pipeline));
85   g_print ("ok, no deadlock. bug 142183 fixed!\n");
86
87   g_print ("cleaning up...\n");
88   gst_object_unref (pipeline);
89   gst_object_unref (id);
90   src = id = sink = pipeline = NULL;
91
92   g_print ("done.\n");
93   return 0;
94 }