|
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., 59 Temple Place - Suite 330, |
|
17 * Boston, MA 02111-1307, USA. |
|
18 */ |
|
19 #include <unistd.h> |
|
20 #include <stdlib.h> /* exit */ |
|
21 #include <gst/gst.h> |
|
22 |
|
23 static void |
|
24 new_decoded_pad_cb (GstElement * decodebin, GstPad * new_pad, gboolean last, |
|
25 GstElement * pipeline) |
|
26 { |
|
27 GstElement *fakesink; |
|
28 GstPad *sinkpad; |
|
29 |
|
30 fakesink = gst_element_factory_make ("fakesink", NULL); |
|
31 gst_bin_add (GST_BIN (pipeline), fakesink); |
|
32 |
|
33 sinkpad = gst_element_get_pad (fakesink, "sink"); |
|
34 if (GST_PAD_LINK_FAILED (gst_pad_link (new_pad, sinkpad))) { |
|
35 g_warning ("Failed to link %s:%s to %s:%s", GST_DEBUG_PAD_NAME (new_pad), |
|
36 GST_DEBUG_PAD_NAME (sinkpad)); |
|
37 gst_bin_remove (GST_BIN (pipeline), fakesink); |
|
38 } else { |
|
39 gst_element_set_state (fakesink, GST_STATE_PAUSED); |
|
40 } |
|
41 } |
|
42 |
|
43 static void |
|
44 show_error (const gchar * errmsg, GstBus * bus) |
|
45 { |
|
46 GstMessage *msg; |
|
47 GError *err = NULL; |
|
48 gchar *dbg = NULL; |
|
49 |
|
50 msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0); |
|
51 if (msg) { |
|
52 g_assert (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR); |
|
53 |
|
54 gst_message_parse_error (msg, &err, &dbg); |
|
55 } |
|
56 |
|
57 g_print ("ERROR: %s\n", errmsg); |
|
58 g_print (" %s\n", (err) ? err->message : ""); |
|
59 if (dbg) { |
|
60 g_print ("\ndebug: %s\n\n", dbg); |
|
61 g_free (dbg); |
|
62 } |
|
63 |
|
64 if (err) |
|
65 g_error_free (err); |
|
66 } |
|
67 |
|
68 gint |
|
69 main (gint argc, gchar * argv[]) |
|
70 { |
|
71 GstElement *pipeline, *filesrc, *decodebin; |
|
72 GstStateChangeReturn res; |
|
73 GstIterator *it; |
|
74 GstBus *bus; |
|
75 gpointer data; |
|
76 |
|
77 gst_init (&argc, &argv); |
|
78 |
|
79 pipeline = gst_pipeline_new ("pipeline"); |
|
80 |
|
81 filesrc = gst_element_factory_make ("filesrc", "filesrc"); |
|
82 g_assert (filesrc); |
|
83 |
|
84 decodebin = gst_element_factory_make ("decodebin", "decodebin"); |
|
85 g_assert (decodebin); |
|
86 |
|
87 gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL); |
|
88 gst_element_link (filesrc, decodebin); |
|
89 |
|
90 if (argc < 2) { |
|
91 g_print ("usage: %s <filenames>\n", argv[0]); |
|
92 exit (-1); |
|
93 } |
|
94 |
|
95 if (!g_str_has_prefix (argv[1], "file://")) { |
|
96 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); |
|
97 } else { |
|
98 g_object_set (G_OBJECT (filesrc), "location", argv[1] + 7, NULL); |
|
99 } |
|
100 |
|
101 /* we've got to connect fakesinks to newly decoded pads to make sure |
|
102 * buffers have actually been flowing over those pads and caps have |
|
103 * been set on them. decodebin might insert internal queues and |
|
104 * without fakesinks it's pot-luck what caps we get from the pad, because |
|
105 * it depends on whether the queues have started pushing buffers yet or not. |
|
106 * With fakesinks we make sure that the pipeline doesn't go to PAUSED state |
|
107 * before each fakesink has a buffer queued. */ |
|
108 g_signal_connect (decodebin, "new-decoded-pad", |
|
109 G_CALLBACK (new_decoded_pad_cb), pipeline); |
|
110 |
|
111 bus = gst_element_get_bus (pipeline); |
|
112 |
|
113 g_print ("pause..\n"); |
|
114 res = gst_element_set_state (pipeline, GST_STATE_PAUSED); |
|
115 if (res == GST_STATE_CHANGE_FAILURE) { |
|
116 show_error ("Could not go to PAUSED state", bus); |
|
117 exit (-1); |
|
118 } |
|
119 g_print ("waiting..\n"); |
|
120 res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); |
|
121 if (res != GST_STATE_CHANGE_SUCCESS) { |
|
122 show_error ("Failed to complete state change to PAUSED", bus); |
|
123 exit (-1); |
|
124 } |
|
125 g_print ("stats..\n"); |
|
126 |
|
127 it = gst_element_iterate_src_pads (decodebin); |
|
128 while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) { |
|
129 GstPad *pad = GST_PAD (data); |
|
130 GstCaps *caps; |
|
131 gchar *str; |
|
132 GstQuery *query; |
|
133 |
|
134 g_print ("stream %s:\n", GST_OBJECT_NAME (pad)); |
|
135 |
|
136 caps = gst_pad_get_caps (pad); |
|
137 str = gst_caps_to_string (caps); |
|
138 g_print (" caps: %s\n", str); |
|
139 g_free (str); |
|
140 gst_caps_unref (caps); |
|
141 |
|
142 query = gst_query_new_duration (GST_FORMAT_TIME); |
|
143 if (gst_pad_query (pad, query)) { |
|
144 gint64 duration; |
|
145 |
|
146 gst_query_parse_duration (query, NULL, &duration); |
|
147 |
|
148 g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration)); |
|
149 } |
|
150 gst_query_unref (query); |
|
151 |
|
152 gst_object_unref (pad); |
|
153 } |
|
154 gst_iterator_free (it); |
|
155 |
|
156 return 0; |
|
157 } |