7 static GList *rate_pads = NULL;
8 static GList *seekable_elements = NULL;
10 static GstElement *pipeline;
11 static GtkAdjustment *adjustment;
12 static gboolean stats = FALSE;
13 static guint64 duration;
15 static guint update_id;
17 //#define SOURCE "gnomevfssrc"
18 #define SOURCE "filesrc"
20 #define UPDATE_INTERVAL 500
23 make_spider_pipeline (const gchar * location, gboolean thread)
26 GstElement *src, *decoder, *audiosink, *videosink, *a_thread, *v_thread,
30 pipeline = gst_thread_new ("app");
32 pipeline = gst_pipeline_new ("app");
36 src = gst_element_factory_make (SOURCE, "src");
37 decoder = gst_element_factory_make ("spider", "decoder");
38 a_thread = gst_thread_new ("a_thread");
39 a_queue = gst_element_factory_make ("queue", "a_queue");
40 audiosink = gst_element_factory_make ("osssink", "a_sink");
41 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
43 v_thread = gst_thread_new ("v_thread");
44 v_queue = gst_element_factory_make ("queue", "v_queue");
45 videosink = gst_element_factory_make ("xvideosink", "v_sink");
46 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
48 g_object_set (G_OBJECT (src), "location", location, NULL);
50 gst_bin_add (GST_BIN (pipeline), src);
51 gst_bin_add (GST_BIN (pipeline), decoder);
52 gst_bin_add (GST_BIN (a_thread), a_queue);
53 gst_bin_add (GST_BIN (a_thread), audiosink);
54 gst_bin_add (GST_BIN (v_thread), v_queue);
55 gst_bin_add (GST_BIN (v_thread), videosink);
56 gst_bin_add (GST_BIN (pipeline), a_thread);
57 gst_bin_add (GST_BIN (pipeline), v_thread);
59 gst_element_link (src, decoder);
60 gst_element_link (v_queue, videosink);
61 gst_element_link (decoder, v_queue);
62 gst_element_link (a_queue, audiosink);
63 gst_element_link (decoder, a_queue);
65 seekable_elements = g_list_prepend (seekable_elements, videosink);
66 seekable_elements = g_list_prepend (seekable_elements, audiosink);
68 g_list_prepend (rate_pads, gst_element_get_pad (audiosink, "sink"));
70 g_list_prepend (rate_pads, gst_element_get_pad (videosink, "sink"));
76 format_value (GtkScale * scale, gdouble value)
82 real = value * duration / 100;
83 seconds = (gint64) real / GST_SECOND;
84 subseconds = (gint64) real / (GST_SECOND / 100);
86 return g_strdup_printf ("%02lld:%02lld:%02lld",
87 seconds / 60, seconds % 60, subseconds % 100);
93 const GstFormat format;
96 static seek_format seek_formats[] = {
97 {"tim", GST_FORMAT_TIME},
98 {"byt", GST_FORMAT_BYTES},
99 {"buf", GST_FORMAT_BUFFERS},
100 {"def", GST_FORMAT_DEFAULT},
104 G_GNUC_UNUSED static void
107 GList *walk = rate_pads;
110 GstPad *pad = GST_PAD (walk->data);
113 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
114 while (seek_formats[i].name) {
118 format = seek_formats[i].format;
120 if (gst_pad_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format, &value)) {
121 g_print ("%s %13lld | ", seek_formats[i].name, value);
123 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
128 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
130 walk = g_list_next (walk);
134 G_GNUC_UNUSED static void
137 GList *walk = seekable_elements;
140 GstElement *element = GST_ELEMENT (walk->data);
143 g_print ("durations %8.8s: ", GST_ELEMENT_NAME (element));
144 while (seek_formats[i].name) {
149 format = seek_formats[i].format;
150 res = gst_element_query (element, GST_QUERY_TOTAL, &format, &value);
152 g_print ("%s %13lld | ", seek_formats[i].name, value);
154 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
158 g_print (" %s\n", GST_ELEMENT_NAME (element));
159 walk = g_list_next (walk);
163 G_GNUC_UNUSED static void
166 GList *walk = seekable_elements;
169 GstElement *element = GST_ELEMENT (walk->data);
172 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
173 while (seek_formats[i].name) {
178 format = seek_formats[i].format;
179 res = gst_element_query (element, GST_QUERY_POSITION, &format, &value);
181 g_print ("%s %13lld | ", seek_formats[i].name, value);
183 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
187 g_print (" %s\n", GST_ELEMENT_NAME (element));
188 walk = g_list_next (walk);
193 update_scale (gpointer data)
197 GstFormat format = GST_FORMAT_TIME;
200 clock = gst_bin_get_clock (GST_BIN (pipeline));
202 if (seekable_elements) {
203 GstElement *element = GST_ELEMENT (seekable_elements->data);
205 gst_element_query (element, GST_QUERY_TOTAL, &format, &duration);
207 position = gst_clock_get_time (clock);
210 g_print ("clock: %13llu (%s)\n", position,
211 gst_object_get_name (GST_OBJECT (clock)));
217 gtk_adjustment_set_value (adjustment, position * 100.0 / duration);
224 iterate (gpointer data)
228 res = gst_bin_iterate (GST_BIN (data));
230 gtk_timeout_remove (update_id);
231 g_print ("stopping iterations\n");
237 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
239 gst_element_set_state (pipeline, GST_STATE_PAUSED);
240 gtk_timeout_remove (update_id);
246 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
248 gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
251 GList *walk = seekable_elements;
254 GstElement *seekable = GST_ELEMENT (walk->data);
256 g_print ("seek to %lld on element %s\n", real, GST_ELEMENT_NAME (seekable));
257 s_event = gst_event_new_seek (GST_FORMAT_TIME |
258 GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, real);
260 res = gst_element_send_event (seekable, s_event);
262 walk = g_list_next (walk);
265 gst_element_set_state (pipeline, GST_STATE_PLAYING);
266 if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE))
267 gtk_idle_add ((GtkFunction) iterate, pipeline);
269 gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
275 play_cb (GtkButton * button, gpointer data)
277 if (gst_element_get_state (pipeline) != GST_STATE_PLAYING) {
278 gst_element_set_state (pipeline, GST_STATE_PLAYING);
279 if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE))
280 gtk_idle_add ((GtkFunction) iterate, pipeline);
282 gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
287 pause_cb (GtkButton * button, gpointer data)
289 if (gst_element_get_state (pipeline) != GST_STATE_PAUSED) {
290 gst_element_set_state (pipeline, GST_STATE_PAUSED);
291 gtk_timeout_remove (update_id);
296 stop_cb (GtkButton * button, gpointer data)
298 if (gst_element_get_state (pipeline) != GST_STATE_READY) {
299 gst_element_set_state (pipeline, GST_STATE_READY);
300 gtk_timeout_remove (update_id);
305 main (int argc, char **argv)
307 GtkWidget *window, *hbox, *vbox,
308 *play_button, *pause_button, *stop_button, *hscale;
309 gboolean threaded = FALSE;
310 struct poptOption options[] = {
311 {"threaded", 't', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &threaded, 0,
312 "Run the pipeline in a toplevel thread", NULL},
313 {"stats", 's', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &stats, 0,
314 "Show element stats", NULL},
318 gst_init_with_popt_table (&argc, &argv, options);
319 gtk_init (&argc, &argv);
322 g_print ("usage: %s <filename>\n", argv[0]);
326 pipeline = make_spider_pipeline (argv[1], threaded);
328 /* initialize gui elements ... */
329 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
330 hbox = gtk_hbox_new (FALSE, 0);
331 vbox = gtk_vbox_new (FALSE, 0);
332 play_button = gtk_button_new_with_label ("play");
333 pause_button = gtk_button_new_with_label ("pause");
334 stop_button = gtk_button_new_with_label ("stop");
337 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
338 hscale = gtk_hscale_new (adjustment);
339 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
340 gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);
342 gtk_signal_connect (GTK_OBJECT (hscale),
343 "button_press_event", G_CALLBACK (start_seek), pipeline);
344 gtk_signal_connect (GTK_OBJECT (hscale),
345 "button_release_event", G_CALLBACK (stop_seek), pipeline);
346 gtk_signal_connect (GTK_OBJECT (hscale),
347 "format_value", G_CALLBACK (format_value), pipeline);
349 /* do the packing stuff ... */
350 gtk_window_set_default_size (GTK_WINDOW (window), 96, 96);
351 gtk_container_add (GTK_CONTAINER (window), vbox);
352 gtk_container_add (GTK_CONTAINER (vbox), hbox);
353 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
354 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
355 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
356 gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2);
358 /* connect things ... */
359 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
361 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
363 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
365 g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL);
368 gtk_widget_show_all (window);