543620a7acd6db5831e17c7338c5db9ab9a84a3d
[platform/upstream/gstreamer.git] / tests / old / testsuite / schedulers / unref.c
1 /* GStreamer
2  * Copyright (C) 2004 Benjamin Otte <in7y118@public.uni-hamburg.de>
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 GstElement *pipeline, *src, *sink;
22
23 static void
24 cb_handoff (GstElement * element, GstBuffer * buffer, GstPad * pad,
25     gpointer unused)
26 {
27   if (pipeline) {
28     g_print ("unreffing...\n");
29     gst_object_unref (GST_OBJECT (pipeline));
30     pipeline = NULL;
31   }
32 }
33
34 gint
35 main (gint argc, gchar ** argv)
36 {
37   gst_init (&argc, &argv);
38
39   g_print ("setting up...\n");
40   /* setup pipeline */
41   pipeline = gst_element_factory_make ("pipeline", NULL);
42   g_assert (pipeline);
43   src = gst_element_factory_make ("fakesrc", NULL);
44   g_assert (src);
45   sink = gst_element_factory_make ("fakesink", NULL);
46   g_assert (sink);
47   gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
48   gst_element_link (src, sink);
49   /* setup special stuff */
50   g_object_set (ELEMENT, "signal-handoffs", TRUE, NULL);
51   g_signal_connect (ELEMENT, "handoff", (GCallback) cb_handoff, NULL);
52
53   /* run pipeline */
54   g_print ("running...\n");
55   if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
56     g_assert_not_reached ();
57   while (pipeline && gst_bin_iterate (GST_BIN (pipeline)));
58
59   g_print ("done.\n");
60   return 0;
61 }