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.
26 #include <stdlib.h> /* exit */
30 static GMainLoop *loop;
33 pad_added_cb (GstElement * element, GstPad * pad, GstElement * sink)
35 g_print ("New pad...\n");
39 no_more_pads (GstElement * element)
41 g_print ("No more pads...\n");
42 g_main_loop_quit (loop);
46 start_finding (GstElement * pipeline)
48 GstStateChangeReturn res;
50 g_print ("finding caps...\n");
51 res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
52 if (res == GST_STATE_CHANGE_FAILURE) {
53 g_print ("could not pause\n");
60 dump_element_stats (GstElement * element)
65 it = gst_element_iterate_src_pads (element);
66 while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) {
67 GstPad *pad = g_value_get_object (&data);
72 g_print ("stream %s:\n", GST_OBJECT_NAME (pad));
74 caps = gst_pad_query_caps (pad, NULL);
75 str = gst_caps_to_string (caps);
76 g_print (" caps: %s\n", str);
78 gst_caps_unref (caps);
80 query = gst_query_new_duration (GST_FORMAT_TIME);
81 if (gst_pad_query (pad, query)) {
84 gst_query_parse_duration (query, NULL, &duration);
86 g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration));
88 gst_query_unref (query);
90 g_value_reset (&data);
92 g_value_unset (&data);
93 gst_iterator_free (it);
97 main (gint argc, gchar * argv[])
99 GstElement *pipeline, *filesrc, *decodebin;
101 gst_init (&argc, &argv);
103 pipeline = gst_pipeline_new ("pipeline");
105 filesrc = gst_element_factory_make ("filesrc", "filesrc");
108 decodebin = gst_element_factory_make ("decodebin", "decodebin");
109 g_assert (decodebin);
111 g_signal_connect (G_OBJECT (decodebin), "pad-added",
112 G_CALLBACK (pad_added_cb), NULL);
113 g_signal_connect (G_OBJECT (decodebin), "no-more-pads",
114 G_CALLBACK (no_more_pads), NULL);
116 gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
117 gst_element_link (filesrc, decodebin);
120 g_print ("usage: %s <uri>\n", argv[0]);
124 if (!g_str_has_prefix (argv[1], "file://")) {
125 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
127 g_object_set (G_OBJECT (filesrc), "location", argv[1] + 7, NULL);
130 /* event based programming approach */
131 loop = g_main_loop_new (NULL, TRUE);
132 g_idle_add ((GSourceFunc) start_finding, pipeline);
133 g_main_loop_run (loop);
135 dump_element_stats (decodebin);