2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include <stdlib.h> /* exit */
28 pad_added_cb (GstElement * decodebin, GstPad * new_pad, GstElement * pipeline)
33 fakesink = gst_element_factory_make ("fakesink", NULL);
34 gst_bin_add (GST_BIN (pipeline), fakesink);
36 sinkpad = gst_element_get_static_pad (fakesink, "sink");
37 if (GST_PAD_LINK_FAILED (gst_pad_link (new_pad, sinkpad))) {
38 g_warning ("Failed to link %s:%s to %s:%s", GST_DEBUG_PAD_NAME (new_pad),
39 GST_DEBUG_PAD_NAME (sinkpad));
40 gst_bin_remove (GST_BIN (pipeline), fakesink);
42 gst_element_set_state (fakesink, GST_STATE_PAUSED);
47 show_error (const gchar * errmsg, GstBus * bus)
53 msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
55 g_assert (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
57 gst_message_parse_error (msg, &err, &dbg);
60 g_print ("ERROR: %s\n", errmsg);
61 g_print (" %s\n", (err) ? err->message : "");
63 g_print ("\ndebug: %s\n\n", dbg);
72 main (gint argc, gchar * argv[])
74 GstElement *pipeline, *filesrc, *decodebin;
75 GstStateChangeReturn res;
80 gst_init (&argc, &argv);
82 pipeline = gst_pipeline_new ("pipeline");
84 filesrc = gst_element_factory_make ("filesrc", "filesrc");
87 decodebin = gst_element_factory_make ("decodebin", "decodebin");
90 gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
91 gst_element_link (filesrc, decodebin);
94 g_print ("usage: %s <filenames>\n", argv[0]);
98 if (!g_str_has_prefix (argv[1], "file://")) {
99 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
101 g_object_set (G_OBJECT (filesrc), "location", argv[1] + 7, NULL);
104 /* we've got to connect fakesinks to newly decoded pads to make sure
105 * buffers have actually been flowing over those pads and caps have
106 * been set on them. decodebin might insert internal queues and
107 * without fakesinks it's pot-luck what caps we get from the pad, because
108 * it depends on whether the queues have started pushing buffers yet or not.
109 * With fakesinks we make sure that the pipeline doesn't go to PAUSED state
110 * before each fakesink has a buffer queued. */
111 g_signal_connect (decodebin, "pad-added",
112 G_CALLBACK (pad_added_cb), pipeline);
114 bus = gst_element_get_bus (pipeline);
116 g_print ("pause..\n");
117 res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
118 if (res == GST_STATE_CHANGE_FAILURE) {
119 show_error ("Could not go to PAUSED state", bus);
122 g_print ("waiting..\n");
123 res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
124 if (res != GST_STATE_CHANGE_SUCCESS) {
125 show_error ("Failed to complete state change to PAUSED", bus);
128 g_print ("stats..\n");
130 it = gst_element_iterate_src_pads (decodebin);
131 while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) {
132 GstPad *pad = g_value_get_object (&data);
137 g_print ("stream %s:\n", GST_OBJECT_NAME (pad));
139 caps = gst_pad_query_caps (pad, NULL);
140 str = gst_caps_to_string (caps);
141 g_print (" caps: %s\n", str);
143 gst_caps_unref (caps);
145 query = gst_query_new_duration (GST_FORMAT_TIME);
146 if (gst_pad_query (pad, query)) {
149 gst_query_parse_duration (query, NULL, &duration);
151 g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration));
153 gst_query_unref (query);
155 g_value_reset (&data);
157 g_value_unset (&data);
158 gst_iterator_free (it);