1 /* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 *
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.
8 *
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.
13 *
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.
18 */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 #ifdef HAVE_UNISTD_H
23 #include <unistd.h>
24 #endif
25 #ifdef HAVE_STDLIB_H
26 #include <stdlib.h> /* exit */
27 #endif
28 #include <gst/gst.h>
29
30 static GMainLoop *loop;
31
32 static void
pad_added_cb(GstElement * element,GstPad * pad,GstElement * sink)33 pad_added_cb (GstElement * element, GstPad * pad, GstElement * sink)
34 {
35 g_print ("New pad...\n");
36 }
37
38 static void
no_more_pads(GstElement * element)39 no_more_pads (GstElement * element)
40 {
41 g_print ("No more pads...\n");
42 g_main_loop_quit (loop);
43 }
44
45 static gboolean
start_finding(GstElement * pipeline)46 start_finding (GstElement * pipeline)
47 {
48 GstStateChangeReturn res;
49
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");
54 exit (-1);
55 }
56 return FALSE;
57 }
58
59 static void
dump_element_stats(GstElement * element)60 dump_element_stats (GstElement * element)
61 {
62 GstIterator *it;
63 GValue data = { 0, };
64
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);
68 GstCaps *caps;
69 gchar *str;
70 GstQuery *query;
71
72 g_print ("stream %s:\n", GST_OBJECT_NAME (pad));
73
74 caps = gst_pad_query_caps (pad, NULL);
75 str = gst_caps_to_string (caps);
76 g_print (" caps: %s\n", str);
77 g_free (str);
78 gst_caps_unref (caps);
79
80 query = gst_query_new_duration (GST_FORMAT_TIME);
81 if (gst_pad_query (pad, query)) {
82 gint64 duration;
83
84 gst_query_parse_duration (query, NULL, &duration);
85
86 g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration));
87 }
88 gst_query_unref (query);
89
90 g_value_reset (&data);
91 }
92 g_value_unset (&data);
93 gst_iterator_free (it);
94 }
95
96 gint
main(gint argc,gchar * argv[])97 main (gint argc, gchar * argv[])
98 {
99 GstElement *pipeline, *filesrc, *decodebin;
100
101 gst_init (&argc, &argv);
102
103 pipeline = gst_pipeline_new ("pipeline");
104
105 filesrc = gst_element_factory_make ("filesrc", "filesrc");
106 g_assert (filesrc);
107
108 decodebin = gst_element_factory_make ("decodebin", "decodebin");
109 g_assert (decodebin);
110
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);
115
116 gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
117 gst_element_link (filesrc, decodebin);
118
119 if (argc < 2) {
120 g_print ("usage: %s <uri>\n", argv[0]);
121 exit (-1);
122 }
123
124 if (!g_str_has_prefix (argv[1], "file://")) {
125 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
126 } else {
127 g_object_set (G_OBJECT (filesrc), "location", argv[1] + 7, NULL);
128 }
129
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);
134
135 dump_element_stats (decodebin);
136
137 return 0;
138 }
139