0a2dc07dfa24c890fe2e6bc05bbf4db7b97f19ce
[platform/upstream/gstreamer.git] / tests / old / testsuite / schedulers / 147713.c
1 /* GStreamer
2  * Copyright (C) 2004 Wim Taymanse <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 gint src_handoff = 0;
22
23 static void
24 handoff_src (GstElement * element)
25 {
26   g_print ("src handoff\n");
27   src_handoff++;
28 }
29
30 static void
31 handoff_sink (GstElement * element)
32 {
33   g_print ("sink handoff\n");
34   g_assert (src_handoff == 1);
35 }
36
37 gint
38 main (gint argc, gchar ** argv)
39 {
40   GstElement *pipeline, *src, *sink, *id1, *id2;
41
42   gst_init (&argc, &argv);
43
44   g_print ("setting up...\n");
45   /* setup pipeline */
46   pipeline = gst_element_factory_make ("pipeline", NULL);
47   g_assert (pipeline);
48   src = gst_element_factory_make ("fakesrc", NULL);
49   g_assert (src);
50   g_object_set (G_OBJECT (src), "signal-handoffs", TRUE, NULL);
51   g_signal_connect (G_OBJECT (src), "handoff", (GCallback) handoff_src, NULL);
52   id1 = gst_element_factory_make ("identity", NULL);
53   g_assert (id1);
54
55   id2 = gst_element_factory_make ("identity", NULL);
56   g_assert (id2);
57   g_object_set (G_OBJECT (id2), "loop-based", TRUE, NULL);
58
59   sink = gst_element_factory_make ("fakesink", NULL);
60   g_assert (sink);
61   g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL);
62   g_signal_connect (G_OBJECT (sink), "handoff", (GCallback) handoff_sink, NULL);
63
64   gst_bin_add_many (GST_BIN (pipeline), src, id1, NULL);
65   gst_element_link_pads (src, "src", id1, "sink");
66
67   if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
68     g_assert_not_reached ();
69
70   if (gst_element_set_state (id2, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
71     g_assert_not_reached ();
72   if (gst_element_set_state (sink, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
73     g_assert_not_reached ();
74
75   gst_bin_add_many (GST_BIN (pipeline), sink, NULL);
76   gst_element_link_pads (id2, "src", sink, "sink");
77   gst_element_link_pads (id1, "src", id2, "sink");
78   gst_bin_add_many (GST_BIN (pipeline), id2, NULL);
79
80   gst_bin_iterate (GST_BIN (pipeline));
81   gst_bin_iterate (GST_BIN (pipeline));
82
83   g_print ("cleaning up...\n");
84   gst_object_unref (GST_OBJECT (pipeline));
85   src = id1 = id2 = sink = pipeline = NULL;
86
87   g_print ("done.\n");
88   return 0;
89 }