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 */
27 static GMainLoop *loop;
30 pad_added_cb (GstElement * element, GstPad * pad, GstElement * sink)
32 g_print ("New pad...\n");
36 no_more_pads (GstElement * element)
38 g_print ("No more pads...\n");
39 g_main_loop_quit (loop);
43 start_finding (GstElement * pipeline)
45 GstStateChangeReturn res;
47 g_print ("finding caps...\n");
48 res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
49 if (res == GST_STATE_CHANGE_FAILURE) {
50 g_print ("could not pause\n");
57 dump_element_stats (GstElement * element)
62 it = gst_element_iterate_src_pads (element);
63 while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) {
64 GstPad *pad = g_value_get_object (&data);
69 g_print ("stream %s:\n", GST_OBJECT_NAME (pad));
71 caps = gst_pad_query_caps (pad, NULL);
72 str = gst_caps_to_string (caps);
73 g_print (" caps: %s\n", str);
75 gst_caps_unref (caps);
77 query = gst_query_new_duration (GST_FORMAT_TIME);
78 if (gst_pad_query (pad, query)) {
81 gst_query_parse_duration (query, NULL, &duration);
83 g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration));
85 gst_query_unref (query);
87 g_value_reset (&data);
89 g_value_unset (&data);
90 gst_iterator_free (it);
94 main (gint argc, gchar * argv[])
96 GstElement *pipeline, *filesrc, *decodebin;
98 gst_init (&argc, &argv);
100 pipeline = gst_pipeline_new ("pipeline");
102 filesrc = gst_element_factory_make ("filesrc", "filesrc");
105 decodebin = gst_element_factory_make ("decodebin", "decodebin");
106 g_assert (decodebin);
108 g_signal_connect (G_OBJECT (decodebin), "pad-added",
109 G_CALLBACK (pad_added_cb), NULL);
110 g_signal_connect (G_OBJECT (decodebin), "no-more-pads",
111 G_CALLBACK (no_more_pads), NULL);
113 gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
114 gst_element_link (filesrc, decodebin);
117 g_print ("usage: %s <uri>\n", argv[0]);
121 if (!g_str_has_prefix (argv[1], "file://")) {
122 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
124 g_object_set (G_OBJECT (filesrc), "location", argv[1] + 7, NULL);
127 /* event based programming approach */
128 loop = g_main_loop_new (NULL, TRUE);
129 g_idle_add ((GSourceFunc) start_finding, pipeline);
130 g_main_loop_run (loop);
132 dump_element_stats (decodebin);