2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
27 static GMainLoop *loop;
30 gen_video_element (void)
37 element = gst_bin_new ("vbin");
38 conv = gst_element_factory_make ("ffmpegcolorspace", "conv");
39 sink = gst_element_factory_make (DEFAULT_VIDEOSINK, "sink");
41 gst_bin_add (GST_BIN (element), conv);
42 gst_bin_add (GST_BIN (element), sink);
43 gst_element_link_pads (conv, "src", sink, "sink");
45 pad = gst_element_get_static_pad (conv, "sink");
46 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
47 gst_object_unref (pad);
53 gen_audio_element (void)
60 element = gst_bin_new ("abin");
61 conv = gst_element_factory_make ("audioconvert", "conv");
62 sink = gst_element_factory_make (DEFAULT_AUDIOSINK, "sink");
64 gst_bin_add (GST_BIN (element), conv);
65 gst_bin_add (GST_BIN (element), sink);
66 gst_element_link_pads (conv, "src", sink, "sink");
68 pad = gst_element_get_static_pad (conv, "sink");
69 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
70 gst_object_unref (pad);
76 cb_newpad (GstElement * decodebin, GstPad * pad, gboolean last, gpointer data)
84 GstStateChangeReturn ret;
85 GstPadLinkReturn lret;
87 /* check media type */
88 caps = gst_pad_get_caps (pad);
89 str = gst_caps_get_structure (caps, 0);
91 name = gst_structure_get_name (str);
92 g_print ("name: %s\n", name);
94 if (g_strrstr (name, "audio")) {
95 sink = gen_audio_element ();
96 } else if (g_strrstr (name, "video")) {
97 sink = gen_video_element ();
101 gst_caps_unref (caps);
104 pipeline = GST_ELEMENT_CAST (data);
106 /* add new sink to the pipeline */
107 gst_bin_add (GST_BIN_CAST (pipeline), sink);
109 /* set the new sink tp PAUSED as well */
110 ret = gst_element_set_state (sink, GST_STATE_PAUSED);
111 if (ret == GST_STATE_CHANGE_FAILURE)
114 /* get the ghostpad of the sink bin */
115 sinkpad = gst_element_get_static_pad (sink, "sink");
118 lret = gst_pad_link (pad, sinkpad);
119 if (lret != GST_PAD_LINK_OK)
122 gst_object_unref (sinkpad);
129 gst_bin_remove (GST_BIN_CAST (pipeline), sink);
130 g_warning ("could not change state of new sink (%d)", ret);
135 g_warning ("could not link pad and sink (%d)", lret);
141 main (gint argc, gchar * argv[])
143 GstElement *pipeline, *filesrc, *decodebin;
144 GstStateChangeReturn res;
146 gst_init (&argc, &argv);
148 pipeline = gst_pipeline_new ("pipeline");
150 filesrc = gst_element_factory_make ("filesrc", "filesrc");
152 decodebin = gst_element_factory_make ("decodebin", "decodebin");
153 g_assert (decodebin);
155 g_signal_connect (G_OBJECT (decodebin), "new-decoded-pad",
156 G_CALLBACK (cb_newpad), pipeline);
158 gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
159 gst_element_link (filesrc, decodebin);
162 g_print ("usage: %s <uri>\n", argv[0]);
165 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
167 /* set to paused, decodebin will autoplug and signal new_pad callbacks */
168 res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
169 if (res == GST_STATE_CHANGE_FAILURE) {
170 g_print ("could not pause\n");
173 /* wait for paused to complete */
174 res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
175 if (res == GST_STATE_CHANGE_FAILURE) {
176 g_print ("could not pause\n");
180 /* play, now all the sinks are added to the pipeline and are prerolled and
182 res = gst_element_set_state (pipeline, GST_STATE_PLAYING);
183 if (res == GST_STATE_CHANGE_FAILURE) {
184 g_print ("could not play\n");
188 /* go in the mainloop now */
189 loop = g_main_loop_new (NULL, TRUE);
190 g_main_loop_run (loop);