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", &active_source, NULL);
53 if (active_source > nb_sources - 1)
56 g_object_set (G_OBJECT (video_switch), "active_source", active_source, NULL);
58 g_message ("current number of sources : %d, active source %d",
59 nb_sources, active_source);
61 return (GST_STATE (GST_ELEMENT (video_switch)) == GST_STATE_PLAYING);
65 main (int argc, char *argv[])
67 GstElement *pipeline, *src1, *src2, *video_switch, *video_sink;
69 /* Initing GStreamer library */
70 gst_init (&argc, &argv);
72 loop = g_main_loop_new (NULL, FALSE);
74 pipeline = gst_pipeline_new ("pipeline");
75 src1 = gst_element_factory_make ("videotestsrc", "src1");
76 g_object_set (G_OBJECT (src1), "pattern", 0, NULL);
77 src2 = gst_element_factory_make ("videotestsrc", "src2");
78 g_object_set (G_OBJECT (src2), "pattern", 1, NULL);
79 video_switch = gst_element_factory_make ("switch", "video_switch");
80 video_sink = gst_element_factory_make ("ximagesink", "video_sink");
82 gst_bin_add_many (GST_BIN (pipeline), src1, src2, video_switch,
85 gst_element_link (src1, video_switch);
86 gst_element_link (src2, video_switch);
87 gst_element_link (video_switch, video_sink);
89 g_signal_connect (G_OBJECT (pipeline), "eos", G_CALLBACK (got_eos), NULL);
91 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
93 g_idle_add ((GSourceFunc) idle_iterate, pipeline);
94 g_timeout_add (2000, (GSourceFunc) switch_timer, video_switch);
96 g_main_loop_run (loop);
98 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY);
101 gst_object_unref (GST_OBJECT (pipeline));