*.c: Don't cast to GST_OBJECT when reffing or unreffing. Large source-munging commit!!!
[platform/upstream/gstreamer.git] / tests / old / testsuite / schedulers / 142183-2.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 <gst/gst.h>
20
21 static void
22 handoff_identity (GstElement * element)
23 {
24   GstBin *parent;
25
26   parent = GST_BIN (gst_element_get_parent (element));
27   g_print ("identity handoff\n");
28   /* element is unreffed and destroyed here, which will cause
29    * an assert */
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   g_signal_connect (G_OBJECT (id), "handoff", (GCallback) handoff_identity,
49       NULL);
50   g_object_set (G_OBJECT (id), "loop-based", TRUE, NULL);
51
52   sink = gst_element_factory_make ("fakesink", NULL);
53   g_assert (sink);
54
55   gst_bin_add_many (GST_BIN (pipeline), src, id, sink, NULL);
56   gst_element_link_pads (src, "src", id, "sink");
57   gst_element_link_pads (id, "src", sink, "sink");
58
59   if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
60     g_assert_not_reached ();
61
62   gst_bin_iterate (GST_BIN (pipeline));
63   gst_bin_iterate (GST_BIN (pipeline));
64   g_print ("got past iteration, scheduler refs elements correctly\n");
65
66   g_print ("cleaning up...\n");
67   gst_object_unref (pipeline);
68   src = id = sink = pipeline = NULL;
69
70   g_print ("done.\n");
71   return 0;
72 }