*.c: Don't cast to GST_OBJECT when reffing or unreffing. Large source-munging commit!!!
[platform/upstream/gstreamer.git] / testsuite / states / locked.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "unistd.h"
21
22 #include <gst/gst.h>
23
24 static GMainLoop *loop;
25
26 static gboolean
27 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
28 {
29   g_print ("message %p\n", message);
30
31   if (message->type == GST_MESSAGE_EOS) {
32     g_print ("EOS!!\n");
33     if (g_main_loop_is_running (loop))
34       g_main_loop_quit (loop);
35   }
36   gst_message_unref (message);
37
38   return TRUE;
39 }
40
41 gint
42 main (gint argc, gchar * argv[])
43 {
44   GstElement *pipeline;
45   GstElement *fakesrc1, *fakesink1;
46   GstElement *fakesrc2, *fakesink2;
47   GstBus *bus;
48
49   gst_init (&argc, &argv);
50
51   pipeline = gst_pipeline_new ("pipeline");
52
53   loop = g_main_loop_new (NULL, FALSE);
54   bus = gst_element_get_bus (pipeline);
55   gst_bus_add_watch (bus, (GstBusHandler) message_received, pipeline);
56   gst_object_unref (bus);
57
58   fakesrc1 = gst_element_factory_make ("fakesrc", "fakesrc1");
59   g_object_set (G_OBJECT (fakesrc1), "num_buffers", 5, NULL);
60   fakesink1 = gst_element_factory_make ("fakesink", "fakesink1");
61
62   gst_bin_add (GST_BIN (pipeline), fakesrc1);
63   gst_bin_add (GST_BIN (pipeline), fakesink1);
64   gst_pad_link (gst_element_get_pad (fakesrc1, "src"),
65       gst_element_get_pad (fakesink1, "sink"));
66
67   fakesrc2 = gst_element_factory_make ("fakesrc", "fakesrc2");
68   g_object_set (G_OBJECT (fakesrc2), "num_buffers", 5, NULL);
69   fakesink2 = gst_element_factory_make ("fakesink", "fakesink2");
70
71   gst_bin_add (GST_BIN (pipeline), fakesrc2);
72   gst_bin_add (GST_BIN (pipeline), fakesink2);
73   gst_pad_link (gst_element_get_pad (fakesrc2, "src"),
74       gst_element_get_pad (fakesink2, "sink"));
75
76   g_signal_connect (G_OBJECT (pipeline), "deep_notify",
77       G_CALLBACK (gst_object_default_deep_notify), NULL);
78
79   GST_FLAG_SET (fakesrc2, GST_ELEMENT_LOCKED_STATE);
80   GST_FLAG_SET (fakesink2, GST_ELEMENT_LOCKED_STATE);
81
82   g_print ("play..\n");
83   gst_element_set_state (pipeline, GST_STATE_PLAYING);
84
85   g_main_loop_run (loop);
86
87   g_object_set (G_OBJECT (fakesrc1), "num_buffers", 5, NULL);
88
89   gst_element_set_state (pipeline, GST_STATE_READY);
90
91   GST_FLAG_UNSET (fakesrc2, GST_ELEMENT_LOCKED_STATE);
92   GST_FLAG_UNSET (fakesink2, GST_ELEMENT_LOCKED_STATE);
93
94   g_print ("play..\n");
95   gst_element_set_state (pipeline, GST_STATE_PLAYING);
96
97   g_main_loop_run (loop);
98
99   gst_element_set_state (pipeline, GST_STATE_NULL);
100
101   gst_object_unref (pipeline);
102
103   return 0;
104 }