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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include <stdlib.h> /* exit */
31 new_decoded_pad_cb (GstElement * decodebin, GstPad * new_pad, gboolean last,
32 GstElement * pipeline)
37 fakesink = gst_element_factory_make ("fakesink", NULL);
38 gst_bin_add (GST_BIN (pipeline), fakesink);
40 sinkpad = gst_element_get_static_pad (fakesink, "sink");
41 if (GST_PAD_LINK_FAILED (gst_pad_link (new_pad, sinkpad))) {
42 g_warning ("Failed to link %s:%s to %s:%s", GST_DEBUG_PAD_NAME (new_pad),
43 GST_DEBUG_PAD_NAME (sinkpad));
44 gst_bin_remove (GST_BIN (pipeline), fakesink);
46 gst_element_set_state (fakesink, GST_STATE_PAUSED);
51 show_error (const gchar * errmsg, GstBus * bus)
57 msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
59 g_assert (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
61 gst_message_parse_error (msg, &err, &dbg);
64 g_print ("ERROR: %s\n", errmsg);
65 g_print (" %s\n", (err) ? err->message : "");
67 g_print ("\ndebug: %s\n\n", dbg);
76 main (gint argc, gchar * argv[])
78 GstElement *pipeline, *filesrc, *decodebin;
79 GstStateChangeReturn res;
84 gst_init (&argc, &argv);
86 pipeline = gst_pipeline_new ("pipeline");
88 filesrc = gst_element_factory_make ("filesrc", "filesrc");
91 decodebin = gst_element_factory_make ("decodebin", "decodebin");
94 gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
95 gst_element_link (filesrc, decodebin);
98 g_print ("usage: %s <filenames>\n", argv[0]);
102 if (!g_str_has_prefix (argv[1], "file://")) {
103 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
105 g_object_set (G_OBJECT (filesrc), "location", argv[1] + 7, NULL);
108 /* we've got to connect fakesinks to newly decoded pads to make sure
109 * buffers have actually been flowing over those pads and caps have
110 * been set on them. decodebin might insert internal queues and
111 * without fakesinks it's pot-luck what caps we get from the pad, because
112 * it depends on whether the queues have started pushing buffers yet or not.
113 * With fakesinks we make sure that the pipeline doesn't go to PAUSED state
114 * before each fakesink has a buffer queued. */
115 g_signal_connect (decodebin, "new-decoded-pad",
116 G_CALLBACK (new_decoded_pad_cb), pipeline);
118 bus = gst_element_get_bus (pipeline);
120 g_print ("pause..\n");
121 res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
122 if (res == GST_STATE_CHANGE_FAILURE) {
123 show_error ("Could not go to PAUSED state", bus);
126 g_print ("waiting..\n");
127 res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
128 if (res != GST_STATE_CHANGE_SUCCESS) {
129 show_error ("Failed to complete state change to PAUSED", bus);
132 g_print ("stats..\n");
134 it = gst_element_iterate_src_pads (decodebin);
135 while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) {
136 GstPad *pad = GST_PAD (data);
141 g_print ("stream %s:\n", GST_OBJECT_NAME (pad));
143 caps = gst_pad_get_caps (pad);
144 str = gst_caps_to_string (caps);
145 g_print (" caps: %s\n", str);
147 gst_caps_unref (caps);
149 query = gst_query_new_duration (GST_FORMAT_TIME);
150 if (gst_pad_query (pad, query)) {
153 gst_query_parse_duration (query, NULL, &duration);
155 g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration));
157 gst_query_unref (query);
159 gst_object_unref (pad);
161 gst_iterator_free (it);