2 * Copyright (C) 2003 Julien Moutte <julien@moutte.net>
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.
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.
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.
26 static GMainLoop *loop = NULL;
31 got_eos (GstElement *pipeline)
33 g_main_loop_quit (loop);
37 idle_iterate (GstElement *pipeline)
39 gst_bin_iterate (GST_BIN (pipeline));
40 return (GST_STATE (GST_ELEMENT (pipeline)) == GST_STATE_PLAYING);
44 switch_timer (GstElement *video_switch)
46 gint nb_sources, active_source;
48 g_object_get (G_OBJECT (video_switch), "nb_sources", &nb_sources, NULL);
49 g_object_get (G_OBJECT (video_switch), "active_source",
50 &active_source, NULL);
54 if (active_source > nb_sources - 1)
57 g_object_set (G_OBJECT (video_switch), "active_source",
60 g_message ("current number of sources : %d, active source %d",
61 nb_sources, active_source);
63 return (GST_STATE (GST_ELEMENT (video_switch)) == GST_STATE_PLAYING);
67 main (int argc, char *argv[])
69 GstElement *pipeline, *src1, *src2, *video_switch, *video_sink;
71 /* Initing GStreamer library */
72 gst_init (&argc, &argv);
74 loop = g_main_loop_new (NULL, FALSE);
76 pipeline = gst_pipeline_new ("pipeline");
77 src1 = gst_element_factory_make ("videotestsrc", "src1");
78 g_object_set (G_OBJECT (src1), "pattern", 0, NULL);
79 src2 = gst_element_factory_make ("videotestsrc", "src2");
80 g_object_set (G_OBJECT (src2), "pattern", 1, NULL);
81 video_switch = gst_element_factory_make ("switch", "video_switch");
82 video_sink = gst_element_factory_make ("ximagesink", "video_sink");
84 gst_bin_add_many (GST_BIN (pipeline), src1, src2, video_switch,
87 gst_element_link (src1, video_switch);
88 gst_element_link (src2, video_switch);
89 gst_element_link (video_switch, video_sink);
91 g_signal_connect (G_OBJECT (pipeline), "eos",
92 G_CALLBACK (got_eos), NULL);
94 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
96 g_idle_add ((GSourceFunc) idle_iterate, pipeline);
97 g_timeout_add (2000, (GSourceFunc) switch_timer, video_switch);
99 g_main_loop_run (loop);
101 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY);
104 gst_object_unref (GST_OBJECT (pipeline));