3 * seek.c: seeking sample application
5 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
6 * 2006 Stefan Kost <ensonic@users.sf.net>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
27 /* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
28 * with newer GTK versions (>= 3.3.0) */
29 #define GDK_DISABLE_DEPRECATION_WARNINGS
39 #if defined (GDK_WINDOWING_X11)
41 #elif defined (GDK_WINDOWING_WIN32)
42 #include <gdk/gdkwin32.h>
43 #elif defined (GDK_WINDOWING_QUARTZ)
44 #include <gdk/gdkquartzwindow.h>
47 #include <gst/interfaces/xoverlay.h>
48 #include <gst/interfaces/navigation.h>
50 GST_DEBUG_CATEGORY_STATIC (seek_debug);
51 #define GST_CAT_DEFAULT (seek_debug)
55 #define SOURCE "filesrc"
57 static gchar *opt_audiosink_str; /* NULL */
58 static gchar *opt_videosink_str; /* NULL */
60 #define FILL_INTERVAL 100
61 //#define UPDATE_INTERVAL 500
62 //#define UPDATE_INTERVAL 100
63 #define UPDATE_INTERVAL 40
65 /* number of milliseconds to play for after a seek */
66 #define SCRUB_TIME 100
68 /* timeout for gst_element_get_state() after a seek */
69 #define SEEK_TIMEOUT 40 * GST_MSECOND
71 #define DEFAULT_VIDEO_HEIGHT 300
73 /* the state to go to when stop is pressed */
74 #define STOP_STATE GST_STATE_READY
78 static GList *seekable_pads = NULL;
79 static GList *rate_pads = NULL;
80 static GList *seekable_elements = NULL;
82 static gboolean accurate_seek = FALSE;
83 static gboolean keyframe_seek = FALSE;
84 static gboolean loop_seek = FALSE;
85 static gboolean flush_seek = TRUE;
86 static gboolean scrub = TRUE;
87 static gboolean play_scrub = FALSE;
88 static gboolean skip_seek = FALSE;
89 static gdouble rate = 1.0;
91 static GstElement *pipeline;
92 static gint pipeline_type;
93 static const gchar *pipeline_spec;
94 static gint64 position = -1;
95 static gint64 duration = -1;
96 static GtkAdjustment *adjustment;
97 static GtkWidget *hscale, *statusbar;
98 static guint status_id = 0;
99 static gboolean stats = FALSE;
100 static gboolean elem_seek = FALSE;
101 static gboolean verbose = FALSE;
103 static gboolean is_live = FALSE;
104 static gboolean buffering = FALSE;
105 static GstBufferingMode mode;
106 static gint64 buffering_left;
107 static GstState state = GST_STATE_NULL;
108 static guint update_id = 0;
109 static guint seek_timeout_id = 0;
110 static gulong changed_id;
111 static guint fill_id = 0;
113 static gint n_video = 0, n_audio = 0, n_text = 0;
114 static gboolean need_streams = TRUE;
115 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
116 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
117 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
118 static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
119 static GtkWidget *buffer_checkbox, *rate_spinbutton;
121 static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
123 static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
124 static GtkWidget *shuttle_checkbox, *step_button;
125 static GtkWidget *shuttle_hscale;
126 static GtkAdjustment *shuttle_adjustment;
130 GstNavigationCommand cmd;
132 } navigation_buttons[14];
134 static GList *paths = NULL, *l = NULL;
136 /* we keep an array of the visualisation entries so that we can easily switch
137 * with the combo box index. */
140 GstElementFactory *factory;
143 static GArray *vis_entries;
145 static void clear_streams (GstElement * pipeline);
146 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
148 static void find_navigation_element (void);
150 /* pipeline construction */
154 const gchar *padname;
161 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
163 GstElement *element = gst_element_factory_make (type, name);
165 #ifndef GST_DISABLE_PARSE
167 /* Try parsing it as a pipeline description */
168 element = gst_parse_bin_from_description (type, TRUE, NULL);
170 gst_element_set_name (element, name);
176 g_warning ("Failed to create element %s of type %s", name, type);
183 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
186 dyn_link *connect = (dyn_link *) data;
188 padname = gst_pad_get_name (newpad);
190 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
192 gst_bin_add (GST_BIN (pipeline), connect->bin);
193 gst_pad_link (newpad, connect->target);
195 //seekable_pads = g_list_prepend (seekable_pads, newpad);
196 rate_pads = g_list_prepend (rate_pads, newpad);
202 setup_dynamic_link (GstElement * element, const gchar * padname,
203 GstPad * target, GstElement * bin)
207 connect = g_new0 (dyn_link, 1);
208 connect->padname = g_strdup (padname);
209 connect->target = target;
212 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
217 make_mod_pipeline (const gchar * location)
219 GstElement *pipeline;
220 GstElement *src, *decoder, *audiosink;
223 pipeline = gst_pipeline_new ("app");
225 src = gst_element_factory_make_or_warn (SOURCE, "src");
226 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
227 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
228 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
230 g_object_set (G_OBJECT (src), "location", location, NULL);
232 gst_bin_add (GST_BIN (pipeline), src);
233 gst_bin_add (GST_BIN (pipeline), decoder);
234 gst_bin_add (GST_BIN (pipeline), audiosink);
236 gst_element_link (src, decoder);
237 gst_element_link (decoder, audiosink);
239 seekable = gst_element_get_static_pad (decoder, "src");
240 seekable_pads = g_list_prepend (seekable_pads, seekable);
241 rate_pads = g_list_prepend (rate_pads, seekable);
243 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
249 make_dv_pipeline (const gchar * location)
251 GstElement *pipeline;
252 GstElement *src, *demux, *decoder, *audiosink, *videosink;
253 GstElement *a_queue, *v_queue;
256 pipeline = gst_pipeline_new ("app");
258 src = gst_element_factory_make_or_warn (SOURCE, "src");
259 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
260 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
261 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
262 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
263 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
264 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
266 g_object_set (G_OBJECT (src), "location", location, NULL);
268 gst_bin_add (GST_BIN (pipeline), src);
269 gst_bin_add (GST_BIN (pipeline), demux);
270 gst_bin_add (GST_BIN (pipeline), a_queue);
271 gst_bin_add (GST_BIN (pipeline), audiosink);
272 gst_bin_add (GST_BIN (pipeline), v_queue);
273 gst_bin_add (GST_BIN (pipeline), decoder);
274 gst_bin_add (GST_BIN (pipeline), videosink);
276 gst_element_link (src, demux);
277 gst_element_link (a_queue, audiosink);
278 gst_element_link (v_queue, decoder);
279 gst_element_link (decoder, videosink);
281 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
283 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
286 seekable = gst_element_get_static_pad (decoder, "src");
287 seekable_pads = g_list_prepend (seekable_pads, seekable);
288 rate_pads = g_list_prepend (rate_pads, seekable);
294 make_wav_pipeline (const gchar * location)
296 GstElement *pipeline;
297 GstElement *src, *decoder, *audiosink;
299 pipeline = gst_pipeline_new ("app");
301 src = gst_element_factory_make_or_warn (SOURCE, "src");
302 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
303 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
305 g_object_set (G_OBJECT (src), "location", location, NULL);
307 gst_bin_add (GST_BIN (pipeline), src);
308 gst_bin_add (GST_BIN (pipeline), decoder);
309 gst_bin_add (GST_BIN (pipeline), audiosink);
311 gst_element_link (src, decoder);
313 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
316 seekable_elements = g_list_prepend (seekable_elements, audiosink);
318 /* force element seeking on this pipeline */
325 make_flac_pipeline (const gchar * location)
327 GstElement *pipeline;
328 GstElement *src, *decoder, *audiosink;
331 pipeline = gst_pipeline_new ("app");
333 src = gst_element_factory_make_or_warn (SOURCE, "src");
334 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
335 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
336 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
338 g_object_set (G_OBJECT (src), "location", location, NULL);
340 gst_bin_add (GST_BIN (pipeline), src);
341 gst_bin_add (GST_BIN (pipeline), decoder);
342 gst_bin_add (GST_BIN (pipeline), audiosink);
344 gst_element_link (src, decoder);
345 gst_element_link (decoder, audiosink);
347 seekable = gst_element_get_static_pad (decoder, "src");
348 seekable_pads = g_list_prepend (seekable_pads, seekable);
349 rate_pads = g_list_prepend (rate_pads, seekable);
351 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
357 make_sid_pipeline (const gchar * location)
359 GstElement *pipeline;
360 GstElement *src, *decoder, *audiosink;
363 pipeline = gst_pipeline_new ("app");
365 src = gst_element_factory_make_or_warn (SOURCE, "src");
366 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
367 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
368 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
370 g_object_set (G_OBJECT (src), "location", location, NULL);
372 gst_bin_add (GST_BIN (pipeline), src);
373 gst_bin_add (GST_BIN (pipeline), decoder);
374 gst_bin_add (GST_BIN (pipeline), audiosink);
376 gst_element_link (src, decoder);
377 gst_element_link (decoder, audiosink);
379 seekable = gst_element_get_static_pad (decoder, "src");
380 seekable_pads = g_list_prepend (seekable_pads, seekable);
381 rate_pads = g_list_prepend (rate_pads, seekable);
383 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
389 make_parse_pipeline (const gchar * location)
391 GstElement *pipeline;
392 GstElement *src, *parser, *fakesink;
395 pipeline = gst_pipeline_new ("app");
397 src = gst_element_factory_make_or_warn (SOURCE, "src");
398 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
399 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
400 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
401 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
403 g_object_set (G_OBJECT (src), "location", location, NULL);
405 gst_bin_add (GST_BIN (pipeline), src);
406 gst_bin_add (GST_BIN (pipeline), parser);
407 gst_bin_add (GST_BIN (pipeline), fakesink);
409 gst_element_link (src, parser);
410 gst_element_link (parser, fakesink);
412 seekable = gst_element_get_static_pad (parser, "src");
413 seekable_pads = g_list_prepend (seekable_pads, seekable);
414 rate_pads = g_list_prepend (rate_pads, seekable);
416 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
422 make_vorbis_pipeline (const gchar * location)
424 GstElement *pipeline, *audio_bin;
425 GstElement *src, *demux, *decoder, *convert, *audiosink;
426 GstPad *pad, *seekable;
428 pipeline = gst_pipeline_new ("app");
430 src = gst_element_factory_make_or_warn (SOURCE, "src");
431 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
432 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
433 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
434 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
435 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
437 g_object_set (G_OBJECT (src), "location", location, NULL);
439 audio_bin = gst_bin_new ("a_decoder_bin");
441 gst_bin_add (GST_BIN (pipeline), src);
442 gst_bin_add (GST_BIN (pipeline), demux);
443 gst_bin_add (GST_BIN (audio_bin), decoder);
444 gst_bin_add (GST_BIN (audio_bin), convert);
445 gst_bin_add (GST_BIN (audio_bin), audiosink);
446 gst_bin_add (GST_BIN (pipeline), audio_bin);
448 gst_element_link (src, demux);
449 gst_element_link (decoder, convert);
450 gst_element_link (convert, audiosink);
452 pad = gst_element_get_static_pad (decoder, "sink");
453 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
454 gst_object_unref (pad);
456 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
459 seekable = gst_element_get_static_pad (decoder, "src");
460 seekable_pads = g_list_prepend (seekable_pads, seekable);
461 rate_pads = g_list_prepend (rate_pads, seekable);
463 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
469 make_theora_pipeline (const gchar * location)
471 GstElement *pipeline, *video_bin;
472 GstElement *src, *demux, *decoder, *convert, *videosink;
473 GstPad *pad, *seekable;
475 pipeline = gst_pipeline_new ("app");
477 src = gst_element_factory_make_or_warn (SOURCE, "src");
478 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
479 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
480 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
481 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "sink");
483 g_object_set (G_OBJECT (src), "location", location, NULL);
485 video_bin = gst_bin_new ("v_decoder_bin");
487 gst_bin_add (GST_BIN (pipeline), src);
488 gst_bin_add (GST_BIN (pipeline), demux);
489 gst_bin_add (GST_BIN (video_bin), decoder);
490 gst_bin_add (GST_BIN (video_bin), convert);
491 gst_bin_add (GST_BIN (video_bin), videosink);
492 gst_bin_add (GST_BIN (pipeline), video_bin);
494 gst_element_link (src, demux);
495 gst_element_link (decoder, convert);
496 gst_element_link (convert, videosink);
498 pad = gst_element_get_static_pad (decoder, "sink");
499 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
500 gst_object_unref (pad);
502 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
505 seekable = gst_element_get_static_pad (decoder, "src");
506 seekable_pads = g_list_prepend (seekable_pads, seekable);
507 rate_pads = g_list_prepend (rate_pads, seekable);
509 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
515 make_vorbis_theora_pipeline (const gchar * location)
517 GstElement *pipeline, *audio_bin, *video_bin;
518 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
519 GstElement *audiosink, *videosink;
520 GstElement *a_queue, *v_queue, *v_scale;
524 pipeline = gst_pipeline_new ("app");
526 src = gst_element_factory_make_or_warn (SOURCE, "src");
527 g_object_set (G_OBJECT (src), "location", location, NULL);
529 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
531 gst_bin_add (GST_BIN (pipeline), src);
532 gst_bin_add (GST_BIN (pipeline), demux);
533 gst_element_link (src, demux);
535 audio_bin = gst_bin_new ("a_decoder_bin");
536 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
537 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
538 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
539 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
541 gst_bin_add (GST_BIN (pipeline), audio_bin);
543 gst_bin_add (GST_BIN (audio_bin), a_queue);
544 gst_bin_add (GST_BIN (audio_bin), a_decoder);
545 gst_bin_add (GST_BIN (audio_bin), a_convert);
546 gst_bin_add (GST_BIN (audio_bin), audiosink);
548 gst_element_link (a_queue, a_decoder);
549 gst_element_link (a_decoder, a_convert);
550 gst_element_link (a_convert, audiosink);
552 pad = gst_element_get_static_pad (a_queue, "sink");
553 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
554 gst_object_unref (pad);
556 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
559 video_bin = gst_bin_new ("v_decoder_bin");
560 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
561 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
563 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
564 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
565 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
567 gst_bin_add (GST_BIN (pipeline), video_bin);
569 gst_bin_add (GST_BIN (video_bin), v_queue);
570 gst_bin_add (GST_BIN (video_bin), v_decoder);
571 gst_bin_add (GST_BIN (video_bin), v_convert);
572 gst_bin_add (GST_BIN (video_bin), v_scale);
573 gst_bin_add (GST_BIN (video_bin), videosink);
575 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
578 pad = gst_element_get_static_pad (v_queue, "sink");
579 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
580 gst_object_unref (pad);
582 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
585 seekable = gst_element_get_static_pad (a_decoder, "src");
586 seekable_pads = g_list_prepend (seekable_pads, seekable);
587 rate_pads = g_list_prepend (rate_pads, seekable);
589 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
596 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
598 GstElement *pipeline, *audio_bin, *video_bin;
599 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
600 GstElement *audiosink, *videosink;
601 GstElement *a_queue, *v_queue;
602 GstPad *seekable, *pad;
604 pipeline = gst_pipeline_new ("app");
606 src = gst_element_factory_make_or_warn (SOURCE, "src");
607 g_object_set (G_OBJECT (src), "location", location, NULL);
609 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
611 gst_bin_add (GST_BIN (pipeline), src);
612 gst_bin_add (GST_BIN (pipeline), demux);
613 gst_element_link (src, demux);
615 audio_bin = gst_bin_new ("a_decoder_bin");
616 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
617 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
618 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
619 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
621 gst_bin_add (GST_BIN (audio_bin), a_queue);
622 gst_bin_add (GST_BIN (audio_bin), a_decoder);
623 gst_bin_add (GST_BIN (audio_bin), a_convert);
624 gst_bin_add (GST_BIN (audio_bin), audiosink);
626 gst_element_link (a_queue, a_decoder);
627 gst_element_link (a_decoder, a_convert);
628 gst_element_link (a_convert, audiosink);
630 gst_bin_add (GST_BIN (pipeline), audio_bin);
632 pad = gst_element_get_static_pad (a_queue, "sink");
633 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
634 gst_object_unref (pad);
636 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
639 video_bin = gst_bin_new ("v_decoder_bin");
640 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
641 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
643 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
644 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
646 gst_bin_add (GST_BIN (video_bin), v_queue);
647 gst_bin_add (GST_BIN (video_bin), v_decoder);
648 gst_bin_add (GST_BIN (video_bin), v_convert);
649 gst_bin_add (GST_BIN (video_bin), videosink);
651 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
653 gst_bin_add (GST_BIN (pipeline), video_bin);
655 pad = gst_element_get_static_pad (v_queue, "sink");
656 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
657 gst_object_unref (pad);
659 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
662 seekable = gst_element_get_static_pad (a_decoder, "src");
663 seekable_pads = g_list_prepend (seekable_pads, seekable);
664 rate_pads = g_list_prepend (rate_pads, seekable);
666 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
673 make_mp3_pipeline (const gchar * location)
675 GstElement *pipeline;
676 GstElement *src, *parser, *decoder, *audiosink, *queue;
679 pipeline = gst_pipeline_new ("app");
681 src = gst_element_factory_make_or_warn (SOURCE, "src");
682 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
683 decoder = gst_element_factory_make_or_warn ("mad", "dec");
684 queue = gst_element_factory_make_or_warn ("queue", "queue");
685 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
687 seekable_elements = g_list_prepend (seekable_elements, audiosink);
689 g_object_set (G_OBJECT (src), "location", location, NULL);
690 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
692 gst_bin_add (GST_BIN (pipeline), src);
693 gst_bin_add (GST_BIN (pipeline), parser);
694 gst_bin_add (GST_BIN (pipeline), decoder);
695 gst_bin_add (GST_BIN (pipeline), queue);
696 gst_bin_add (GST_BIN (pipeline), audiosink);
698 gst_element_link (src, parser);
699 gst_element_link (parser, decoder);
700 gst_element_link (decoder, queue);
701 gst_element_link (queue, audiosink);
703 seekable = gst_element_get_static_pad (queue, "src");
704 seekable_pads = g_list_prepend (seekable_pads, seekable);
705 rate_pads = g_list_prepend (rate_pads, seekable);
707 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
713 make_avi_pipeline (const gchar * location)
715 GstElement *pipeline, *audio_bin, *video_bin;
716 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
717 GstElement *a_queue = NULL, *v_queue = NULL;
720 pipeline = gst_pipeline_new ("app");
722 src = gst_element_factory_make_or_warn (SOURCE, "src");
723 g_object_set (G_OBJECT (src), "location", location, NULL);
725 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
726 seekable_elements = g_list_prepend (seekable_elements, demux);
728 gst_bin_add (GST_BIN (pipeline), src);
729 gst_bin_add (GST_BIN (pipeline), demux);
730 gst_element_link (src, demux);
732 audio_bin = gst_bin_new ("a_decoder_bin");
733 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
734 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
735 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
736 gst_element_link (a_decoder, a_queue);
737 gst_element_link (a_queue, audiosink);
738 gst_bin_add (GST_BIN (audio_bin), a_decoder);
739 gst_bin_add (GST_BIN (audio_bin), a_queue);
740 gst_bin_add (GST_BIN (audio_bin), audiosink);
741 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
743 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
746 seekable = gst_element_get_static_pad (a_queue, "src");
747 seekable_pads = g_list_prepend (seekable_pads, seekable);
748 rate_pads = g_list_prepend (rate_pads, seekable);
750 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
753 video_bin = gst_bin_new ("v_decoder_bin");
754 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
755 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
756 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
757 gst_element_link (v_decoder, v_queue);
758 gst_element_link (v_queue, videosink);
759 gst_bin_add (GST_BIN (video_bin), v_decoder);
760 gst_bin_add (GST_BIN (video_bin), v_queue);
761 gst_bin_add (GST_BIN (video_bin), videosink);
763 gst_element_set_state (video_bin, GST_STATE_PAUSED);
765 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
768 seekable = gst_element_get_static_pad (v_queue, "src");
769 seekable_pads = g_list_prepend (seekable_pads, seekable);
770 rate_pads = g_list_prepend (rate_pads, seekable);
772 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
779 make_mpeg_pipeline (const gchar * location)
781 GstElement *pipeline, *audio_bin, *video_bin;
782 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
783 GstElement *audiosink, *videosink;
784 GstElement *a_queue, *v_queue;
788 pipeline = gst_pipeline_new ("app");
790 src = gst_element_factory_make_or_warn (SOURCE, "src");
791 g_object_set (G_OBJECT (src), "location", location, NULL);
793 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
794 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
796 gst_bin_add (GST_BIN (pipeline), src);
797 gst_bin_add (GST_BIN (pipeline), demux);
798 gst_element_link (src, demux);
800 audio_bin = gst_bin_new ("a_decoder_bin");
801 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
802 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
803 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
804 gst_bin_add (GST_BIN (audio_bin), a_decoder);
805 gst_bin_add (GST_BIN (audio_bin), a_queue);
806 gst_bin_add (GST_BIN (audio_bin), audiosink);
808 gst_element_link (a_decoder, a_queue);
809 gst_element_link (a_queue, audiosink);
811 gst_bin_add (GST_BIN (pipeline), audio_bin);
813 pad = gst_element_get_static_pad (a_decoder, "sink");
814 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
815 gst_object_unref (pad);
817 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
820 video_bin = gst_bin_new ("v_decoder_bin");
821 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
822 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
823 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
824 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
826 gst_bin_add (GST_BIN (video_bin), v_decoder);
827 gst_bin_add (GST_BIN (video_bin), v_queue);
828 gst_bin_add (GST_BIN (video_bin), v_filter);
829 gst_bin_add (GST_BIN (video_bin), videosink);
831 gst_element_link (v_decoder, v_queue);
832 gst_element_link (v_queue, v_filter);
833 gst_element_link (v_filter, videosink);
835 gst_bin_add (GST_BIN (pipeline), video_bin);
837 pad = gst_element_get_static_pad (v_decoder, "sink");
838 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
839 gst_object_unref (pad);
841 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
844 seekable = gst_element_get_static_pad (v_filter, "src");
845 seekable_pads = g_list_prepend (seekable_pads, seekable);
846 rate_pads = g_list_prepend (rate_pads, seekable);
848 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
855 make_mpegnt_pipeline (const gchar * location)
857 GstElement *pipeline, *audio_bin, *video_bin;
858 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
859 GstElement *audiosink, *videosink;
863 pipeline = gst_pipeline_new ("app");
865 src = gst_element_factory_make_or_warn (SOURCE, "src");
866 g_object_set (G_OBJECT (src), "location", location, NULL);
868 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
869 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
871 seekable_elements = g_list_prepend (seekable_elements, demux);
873 gst_bin_add (GST_BIN (pipeline), src);
874 gst_bin_add (GST_BIN (pipeline), demux);
875 gst_element_link (src, demux);
877 audio_bin = gst_bin_new ("a_decoder_bin");
878 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
879 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
880 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
881 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
882 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
883 gst_element_link (a_decoder, a_queue);
884 gst_element_link (a_queue, audiosink);
885 gst_bin_add (GST_BIN (audio_bin), a_decoder);
886 gst_bin_add (GST_BIN (audio_bin), a_queue);
887 gst_bin_add (GST_BIN (audio_bin), audiosink);
889 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
892 seekable = gst_element_get_static_pad (a_queue, "src");
893 seekable_pads = g_list_prepend (seekable_pads, seekable);
894 rate_pads = g_list_prepend (rate_pads, seekable);
896 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
899 video_bin = gst_bin_new ("v_decoder_bin");
900 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
901 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
902 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
903 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
905 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
907 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
910 seekable = gst_element_get_static_pad (v_decoder, "src");
911 seekable_pads = g_list_prepend (seekable_pads, seekable);
912 rate_pads = g_list_prepend (rate_pads, seekable);
914 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
921 playerbin_set_uri (GstElement * player, const gchar * location)
925 /* Add "file://" prefix for convenience */
926 if (g_str_has_prefix (location, "/") || !gst_uri_is_valid (location)) {
927 uri = gst_filename_to_uri (location, NULL);
928 g_print ("Setting URI: %s\n", uri);
929 g_object_set (G_OBJECT (player), "uri", uri, NULL);
932 g_print ("Setting URI: %s\n", location);
933 g_object_set (G_OBJECT (player), "uri", location, NULL);
938 construct_playerbin (const gchar * name, const gchar * location)
943 player = gst_element_factory_make (name, "player");
946 playerbin_set_uri (player, location);
948 seekable_elements = g_list_prepend (seekable_elements, player);
950 /* force element seeking on this pipeline */
953 avsink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
955 g_object_set (player, "audio-sink", avsink, NULL);
957 avsink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
959 g_object_set (player, "video-sink", avsink, NULL);
965 make_playerbin_pipeline (const gchar * location)
967 return construct_playerbin ("playbin", location);
971 make_playerbin2_pipeline (const gchar * location)
973 GstElement *pipeline = construct_playerbin ("playbin2", location);
975 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
976 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
981 #ifndef GST_DISABLE_PARSE
983 make_parselaunch_pipeline (const gchar * description)
985 GstElement *pipeline;
986 GError *error = NULL;
988 pipeline = gst_parse_launch (description, &error);
990 seekable_elements = g_list_prepend (seekable_elements, pipeline);
1001 GstElement *(*func) (const gchar * location);
1005 static Pipeline pipelines[] = {
1006 {"mp3", make_mp3_pipeline},
1007 {"avi", make_avi_pipeline},
1008 {"mpeg1", make_mpeg_pipeline},
1009 {"mpegparse", make_parse_pipeline},
1010 {"vorbis", make_vorbis_pipeline},
1011 {"theora", make_theora_pipeline},
1012 {"ogg/v/t", make_vorbis_theora_pipeline},
1013 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
1014 {"sid", make_sid_pipeline},
1015 {"flac", make_flac_pipeline},
1016 {"wav", make_wav_pipeline},
1017 {"mod", make_mod_pipeline},
1018 {"dv", make_dv_pipeline},
1019 {"mpeg1nothreads", make_mpegnt_pipeline},
1020 {"playerbin", make_playerbin_pipeline},
1021 #ifndef GST_DISABLE_PARSE
1022 {"parse-launch", make_parselaunch_pipeline},
1024 {"playerbin2", make_playerbin2_pipeline},
1028 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
1030 /* ui callbacks and helpers */
1033 format_value (GtkScale * scale, gdouble value)
1039 real = value * duration / N_GRAD;
1040 seconds = (gint64) real / GST_SECOND;
1041 subseconds = (gint64) real / (GST_SECOND / N_GRAD);
1043 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1044 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1049 shuttle_format_value (GtkScale * scale, gdouble value)
1051 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
1057 const GstFormat format;
1061 static seek_format seek_formats[] = {
1062 {"tim", GST_FORMAT_TIME},
1063 {"byt", GST_FORMAT_BYTES},
1064 {"buf", GST_FORMAT_BUFFERS},
1065 {"def", GST_FORMAT_DEFAULT},
1069 G_GNUC_UNUSED static void
1072 GList *walk = rate_pads;
1075 GstPad *pad = GST_PAD (walk->data);
1078 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1079 while (seek_formats[i].name) {
1083 format = seek_formats[i].format;
1085 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
1087 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1089 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1094 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1096 walk = g_list_next (walk);
1100 G_GNUC_UNUSED static void
1101 query_positions_elems (void)
1103 GList *walk = seekable_elements;
1106 GstElement *element = GST_ELEMENT (walk->data);
1109 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1110 while (seek_formats[i].name) {
1111 gint64 position, total;
1114 format = seek_formats[i].format;
1116 if (gst_element_query_position (element, &format, &position) &&
1117 gst_element_query_duration (element, &format, &total)) {
1118 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1119 seek_formats[i].name, position, total);
1121 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1126 g_print (" %s\n", GST_ELEMENT_NAME (element));
1128 walk = g_list_next (walk);
1132 G_GNUC_UNUSED static void
1133 query_positions_pads (void)
1135 GList *walk = seekable_pads;
1138 GstPad *pad = GST_PAD (walk->data);
1141 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1142 while (seek_formats[i].name) {
1144 gint64 position, total;
1146 format = seek_formats[i].format;
1148 if (gst_pad_query_position (pad, &format, &position) &&
1149 gst_pad_query_duration (pad, &format, &total)) {
1150 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1151 seek_formats[i].name, position, total);
1153 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1159 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1161 walk = g_list_next (walk);
1165 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1166 gpointer user_data);
1167 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1168 gpointer user_data);
1169 static void seek_cb (GtkWidget * widget);
1172 set_scale (gdouble value)
1174 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1176 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1178 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1179 gtk_adjustment_set_value (adjustment, value);
1180 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1182 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1184 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1186 gtk_widget_queue_draw (hscale);
1190 update_fill (gpointer data)
1193 if (seekable_elements) {
1194 GstElement *element = GST_ELEMENT (seekable_elements->data);
1197 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1198 if (gst_element_query (element, query)) {
1199 gint64 start, stop, buffering_total;
1204 GstBufferingMode mode;
1205 gint avg_in, avg_out;
1206 gint64 buffering_left;
1208 gst_query_parse_buffering_percent (query, &busy, &percent);
1209 gst_query_parse_buffering_range (query, &format, &start, &stop,
1211 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
1214 /* note that we could start the playback when buffering_left < remaining
1216 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
1217 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
1218 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1222 fill = N_GRAD * stop / GST_FORMAT_PERCENT_MAX;
1226 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1228 gst_query_unref (query);
1235 update_scale (gpointer data)
1237 GstFormat format = GST_FORMAT_TIME;
1243 if (seekable_elements) {
1244 GstElement *element = GST_ELEMENT (seekable_elements->data);
1246 gst_element_query_position (element, &format, &position);
1247 gst_element_query_duration (element, &format, &duration);
1250 if (seekable_pads) {
1251 GstPad *pad = GST_PAD (seekable_pads->data);
1253 gst_pad_query_position (pad, &format, &position);
1254 gst_pad_query_duration (pad, &format, &duration);
1260 query_positions_elems ();
1262 query_positions_pads ();
1267 if (position >= duration)
1268 duration = position;
1271 set_scale (position * N_GRAD / duration);
1274 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1275 if (pipeline_type == 16) {
1276 g_object_notify (G_OBJECT (pipeline), "volume");
1282 static void do_seek (GtkWidget * widget);
1283 static void connect_bus_signals (GstElement * pipeline);
1284 static void set_update_scale (gboolean active);
1285 static void set_update_fill (gboolean active);
1288 end_scrub (GtkWidget * widget)
1290 GST_DEBUG ("end scrub, PAUSE");
1291 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1292 seek_timeout_id = 0;
1298 send_event (GstEvent * event)
1300 gboolean res = FALSE;
1303 GList *walk = seekable_pads;
1306 GstPad *seekable = GST_PAD (walk->data);
1308 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1310 gst_event_ref (event);
1311 res = gst_pad_send_event (seekable, event);
1313 walk = g_list_next (walk);
1316 GList *walk = seekable_elements;
1319 GstElement *seekable = GST_ELEMENT (walk->data);
1321 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1323 gst_event_ref (event);
1324 res = gst_element_send_event (seekable, event);
1326 walk = g_list_next (walk);
1329 gst_event_unref (event);
1334 do_seek (GtkWidget * widget)
1337 gboolean res = FALSE;
1341 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / N_GRAD;
1343 GST_DEBUG ("value=%f, real=%" G_GINT64_FORMAT,
1344 gtk_range_get_value (GTK_RANGE (widget)), real);
1348 flags |= GST_SEEK_FLAG_FLUSH;
1350 flags |= GST_SEEK_FLAG_ACCURATE;
1352 flags |= GST_SEEK_FLAG_KEY_UNIT;
1354 flags |= GST_SEEK_FLAG_SEGMENT;
1356 flags |= GST_SEEK_FLAG_SKIP;
1359 s_event = gst_event_new_seek (rate,
1360 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1361 GST_CLOCK_TIME_NONE);
1362 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1363 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1365 s_event = gst_event_new_seek (rate,
1366 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1367 GST_SEEK_TYPE_SET, real);
1368 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1369 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1372 res = send_event (s_event);
1376 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1378 set_update_scale (TRUE);
1381 g_print ("seek failed\n");
1382 set_update_scale (TRUE);
1387 seek_cb (GtkWidget * widget)
1389 /* If the timer hasn't expired yet, then the pipeline is running */
1390 if (play_scrub && seek_timeout_id != 0) {
1391 GST_DEBUG ("do scrub seek, PAUSED");
1392 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1395 GST_DEBUG ("do seek");
1399 GST_DEBUG ("do scrub seek, PLAYING");
1400 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1402 if (seek_timeout_id == 0) {
1404 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1410 set_update_fill (gboolean active)
1412 GST_DEBUG ("fill scale is %d", active);
1417 g_timeout_add (FILL_INTERVAL, (GSourceFunc) update_fill, pipeline);
1421 g_source_remove (fill_id);
1428 set_update_scale (gboolean active)
1431 GST_DEBUG ("update scale is %d", active);
1434 if (update_id == 0) {
1436 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, pipeline);
1440 g_source_remove (update_id);
1447 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1449 if (event->type != GDK_BUTTON_PRESS)
1452 set_update_scale (FALSE);
1454 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1455 GST_DEBUG ("start scrub seek, PAUSE");
1456 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1459 if (changed_id == 0 && flush_seek && scrub) {
1461 g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb),
1469 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1472 g_signal_handler_disconnect (hscale, changed_id);
1476 if (!flush_seek || !scrub) {
1477 GST_DEBUG ("do final seek");
1481 if (seek_timeout_id != 0) {
1482 g_source_remove (seek_timeout_id);
1483 seek_timeout_id = 0;
1484 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1486 if (state == GST_STATE_PAUSED) {
1487 GST_DEBUG ("stop scrub seek, PAUSED");
1488 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1491 if (state == GST_STATE_PLAYING) {
1492 GST_DEBUG ("stop scrub seek, PLAYING");
1493 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1501 play_cb (GtkButton * button, gpointer data)
1503 GstStateChangeReturn ret;
1505 if (state != GST_STATE_PLAYING) {
1506 g_print ("PLAY pipeline\n");
1507 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1509 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1511 case GST_STATE_CHANGE_FAILURE:
1513 case GST_STATE_CHANGE_NO_PREROLL:
1519 state = GST_STATE_PLAYING;
1520 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1527 g_print ("PLAY failed\n");
1528 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1533 pause_cb (GtkButton * button, gpointer data)
1535 g_static_mutex_lock (&state_mutex);
1536 if (state != GST_STATE_PAUSED) {
1537 GstStateChangeReturn ret;
1539 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1540 g_print ("PAUSE pipeline\n");
1541 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1543 case GST_STATE_CHANGE_FAILURE:
1545 case GST_STATE_CHANGE_NO_PREROLL:
1552 state = GST_STATE_PAUSED;
1553 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1555 g_static_mutex_unlock (&state_mutex);
1561 g_static_mutex_unlock (&state_mutex);
1562 g_print ("PAUSE failed\n");
1563 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1568 stop_cb (GtkButton * button, gpointer data)
1570 if (state != STOP_STATE) {
1571 GstStateChangeReturn ret;
1574 g_print ("READY pipeline\n");
1575 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1577 g_static_mutex_lock (&state_mutex);
1578 ret = gst_element_set_state (pipeline, STOP_STATE);
1579 if (ret == GST_STATE_CHANGE_FAILURE)
1583 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1584 gtk_widget_queue_draw (video_window);
1588 set_update_scale (FALSE);
1590 set_update_fill (FALSE);
1592 if (pipeline_type == 16)
1593 clear_streams (pipeline);
1594 g_static_mutex_unlock (&state_mutex);
1597 /* if one uses parse_launch, play, stop and play again it fails as all the
1598 * pads after the demuxer can't be reconnected
1600 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1601 gst_element_set_state (pipeline, GST_STATE_NULL);
1602 gst_object_unref (pipeline);
1604 g_list_free (seekable_elements);
1605 seekable_elements = NULL;
1606 g_list_free (seekable_pads);
1607 seekable_pads = NULL;
1608 g_list_free (rate_pads);
1611 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1612 g_assert (pipeline);
1613 gst_element_set_state (pipeline, STOP_STATE);
1614 connect_bus_signals (pipeline);
1617 gtk_widget_set_sensitive (GTK_WIDGET (hscale), TRUE);
1618 for (i = 0; i < G_N_ELEMENTS (navigation_buttons); i++)
1619 gtk_widget_set_sensitive (navigation_buttons[i].button, FALSE);
1625 g_static_mutex_unlock (&state_mutex);
1626 g_print ("STOP failed\n");
1627 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1632 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1634 accurate_seek = gtk_toggle_button_get_active (button);
1638 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1640 keyframe_seek = gtk_toggle_button_get_active (button);
1644 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1646 loop_seek = gtk_toggle_button_get_active (button);
1647 if (state == GST_STATE_PLAYING) {
1653 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1655 flush_seek = gtk_toggle_button_get_active (button);
1659 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1661 scrub = gtk_toggle_button_get_active (button);
1665 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1667 play_scrub = gtk_toggle_button_get_active (button);
1671 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1673 skip_seek = gtk_toggle_button_get_active (button);
1674 if (state == GST_STATE_PLAYING) {
1680 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1682 gboolean res = FALSE;
1686 rate = gtk_spin_button_get_value (button);
1688 GST_DEBUG ("rate changed to %lf", rate);
1692 flags |= GST_SEEK_FLAG_FLUSH;
1694 flags |= GST_SEEK_FLAG_SEGMENT;
1696 flags |= GST_SEEK_FLAG_ACCURATE;
1698 flags |= GST_SEEK_FLAG_KEY_UNIT;
1700 flags |= GST_SEEK_FLAG_SKIP;
1703 s_event = gst_event_new_seek (rate,
1704 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1705 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1707 s_event = gst_event_new_seek (rate,
1708 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1709 GST_SEEK_TYPE_SET, position);
1712 res = send_event (s_event);
1716 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1719 g_print ("seek failed\n");
1723 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1727 g_object_get (pipeline, "flags", &flags, NULL);
1729 flags |= (1 << num);
1731 flags &= ~(1 << num);
1732 g_object_set (pipeline, "flags", flags, NULL);
1736 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1740 state = gtk_toggle_button_get_active (button);
1741 update_flag (pipeline, 3, state);
1742 gtk_widget_set_sensitive (vis_combo, state);
1746 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1750 state = gtk_toggle_button_get_active (button);
1751 update_flag (pipeline, 1, state);
1752 gtk_widget_set_sensitive (audio_combo, state);
1756 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1760 state = gtk_toggle_button_get_active (button);
1761 update_flag (pipeline, 0, state);
1762 gtk_widget_set_sensitive (video_combo, state);
1766 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1770 state = gtk_toggle_button_get_active (button);
1771 update_flag (pipeline, 2, state);
1772 gtk_widget_set_sensitive (text_combo, state);
1776 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1780 mute = gtk_toggle_button_get_active (button);
1781 g_object_set (pipeline, "mute", mute, NULL);
1785 download_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1789 state = gtk_toggle_button_get_active (button);
1790 update_flag (pipeline, 7, state);
1794 buffer_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1798 state = gtk_toggle_button_get_active (button);
1799 update_flag (pipeline, 8, state);
1803 clear_streams (GstElement * pipeline)
1807 /* remove previous info */
1808 for (i = 0; i < n_video; i++)
1809 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (video_combo), 0);
1810 for (i = 0; i < n_audio; i++)
1811 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (audio_combo), 0);
1812 for (i = 0; i < n_text; i++)
1813 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (text_combo), 0);
1815 n_audio = n_video = n_text = 0;
1816 gtk_widget_set_sensitive (video_combo, FALSE);
1817 gtk_widget_set_sensitive (audio_combo, FALSE);
1818 gtk_widget_set_sensitive (text_combo, FALSE);
1820 need_streams = TRUE;
1824 update_streams (GstPipeline * pipeline)
1828 if (pipeline_type == 16 && need_streams) {
1834 /* remove previous info */
1835 clear_streams (GST_ELEMENT_CAST (pipeline));
1837 /* here we get and update the different streams detected by playbin2 */
1838 g_object_get (pipeline, "n-video", &n_video, NULL);
1839 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1840 g_object_get (pipeline, "n-text", &n_text, NULL);
1842 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1845 for (i = 0; i < n_video; i++) {
1846 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1848 str = gst_structure_to_string ((GstStructure *) tags);
1849 g_print ("video %d: %s\n", i, str);
1852 /* find good name for the label */
1853 name = g_strdup_printf ("video %d", i + 1);
1854 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (video_combo), name);
1857 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1858 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1859 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1862 for (i = 0; i < n_audio; i++) {
1863 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1865 str = gst_structure_to_string ((GstStructure *) tags);
1866 g_print ("audio %d: %s\n", i, str);
1869 /* find good name for the label */
1870 name = g_strdup_printf ("audio %d", i + 1);
1871 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (audio_combo), name);
1874 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1875 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1876 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1879 for (i = 0; i < n_text; i++) {
1880 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1884 const GValue *value;
1886 str = gst_structure_to_string ((GstStructure *) tags);
1887 g_print ("text %d: %s\n", i, str);
1890 /* get the language code if we can */
1891 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1892 if (value && G_VALUE_HOLDS_STRING (value)) {
1893 name = g_strdup_printf ("text %s", g_value_get_string (value));
1896 /* find good name for the label if we didn't use a tag */
1898 name = g_strdup_printf ("text %d", i + 1);
1900 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (text_combo), name);
1903 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1904 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1905 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1907 need_streams = FALSE;
1912 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1916 active = gtk_combo_box_get_active (combo);
1918 g_print ("setting current video track %d\n", active);
1919 g_object_set (pipeline, "current-video", active, NULL);
1923 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1927 active = gtk_combo_box_get_active (combo);
1929 g_print ("setting current audio track %d\n", active);
1930 g_object_set (pipeline, "current-audio", active, NULL);
1934 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1938 active = gtk_combo_box_get_active (combo);
1940 g_print ("setting current text track %d\n", active);
1941 g_object_set (pipeline, "current-text", active, NULL);
1945 filter_features (GstPluginFeature * feature, gpointer data)
1947 GstElementFactory *f;
1949 if (!GST_IS_ELEMENT_FACTORY (feature))
1951 f = GST_ELEMENT_FACTORY (feature);
1952 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1959 init_visualization_features (void)
1963 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1965 list = gst_registry_feature_filter (gst_registry_get_default (),
1966 filter_features, FALSE, NULL);
1968 for (walk = list; walk; walk = g_list_next (walk)) {
1972 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1973 name = gst_element_factory_get_longname (entry.factory);
1975 g_array_append_val (vis_entries, entry);
1976 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (vis_combo), name);
1978 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1982 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1986 GstElement *element;
1988 /* get the selected index and get the factory for this index */
1989 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1990 if (vis_entries->len > 0) {
1991 entry = &g_array_index (vis_entries, VisEntry, index);
1993 /* create an instance of the element from the factory */
1994 element = gst_element_factory_create (entry->factory, NULL);
1998 /* set vis plugin for playbin2 */
1999 g_object_set (pipeline, "vis-plugin", element, NULL);
2004 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
2008 volume = gtk_spin_button_get_value (button);
2010 g_object_set (pipeline, "volume", volume, NULL);
2014 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
2016 gdouble cur_volume, new_volume;
2018 g_object_get (pipeline, "volume", &new_volume, NULL);
2019 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
2020 if (fabs (cur_volume - new_volume) > 0.001) {
2021 g_signal_handlers_block_by_func (volume_spinbutton,
2022 volume_spinbutton_changed_cb, pipeline);
2023 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
2024 g_signal_handlers_unblock_by_func (volume_spinbutton,
2025 volume_spinbutton_changed_cb, pipeline);
2030 shot_cb (GtkButton * button, gpointer data)
2035 /* convert to our desired format (RGB24) */
2036 caps = gst_caps_new_simple ("video/x-raw-rgb",
2037 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
2038 /* Note: we don't ask for a specific width/height here, so that
2039 * videoscale can adjust dimensions from a non-1/1 pixel aspect
2040 * ratio to a 1/1 pixel-aspect-ratio */
2041 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
2042 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
2043 "red_mask", G_TYPE_INT, 0xff0000,
2044 "green_mask", G_TYPE_INT, 0x00ff00,
2045 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
2047 /* convert the latest frame to the requested format */
2048 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
2049 gst_caps_unref (caps);
2057 GError *error = NULL;
2059 /* get the snapshot buffer format now. We set the caps on the appsink so
2060 * that it can only be an rgb buffer. The only thing we have not specified
2061 * on the caps is the height, which is dependant on the pixel-aspect-ratio
2062 * of the source material */
2063 caps = GST_BUFFER_CAPS (buffer);
2065 g_warning ("could not get snapshot format\n");
2068 s = gst_caps_get_structure (caps, 0);
2070 /* we need to get the final caps on the buffer to get the size */
2071 res = gst_structure_get_int (s, "width", &width);
2072 res |= gst_structure_get_int (s, "height", &height);
2074 g_warning ("could not get snapshot dimension\n");
2078 /* create pixmap from buffer and save, gstreamer video buffers have a stride
2079 * that is rounded up to the nearest multiple of 4 */
2080 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
2081 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2082 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2084 /* save the pixbuf */
2085 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2088 gst_buffer_unref (buffer);
2092 /* called when the Step button is pressed */
2094 step_cb (GtkButton * button, gpointer data)
2100 gboolean flush, res;
2103 active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo));
2105 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
2106 (step_amount_spinbutton));
2107 rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton));
2112 format = GST_FORMAT_BUFFERS;
2115 format = GST_FORMAT_TIME;
2116 amount *= GST_MSECOND;
2119 format = GST_FORMAT_UNDEFINED;
2123 event = gst_event_new_step (format, amount, rate, flush, FALSE);
2125 res = send_event (event);
2128 g_print ("Sending step event failed\n");
2133 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2135 const GstStructure *s;
2137 switch (GST_MESSAGE_TYPE (message)) {
2138 case GST_MESSAGE_ERROR:
2139 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
2140 GST_DEBUG_GRAPH_SHOW_ALL, "seek.error");
2142 case GST_MESSAGE_WARNING:
2143 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
2144 GST_DEBUG_GRAPH_SHOW_ALL, "seek.warning");
2150 s = gst_message_get_structure (message);
2151 g_print ("message from \"%s\" (%s): ",
2152 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2153 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2157 sstr = gst_structure_to_string (s);
2158 g_print ("%s\n", sstr);
2161 g_print ("no message details\n");
2165 static gboolean shuttling = FALSE;
2166 static gdouble shuttle_rate = 0.0;
2167 static gdouble play_rate = 1.0;
2170 do_shuttle (GstElement * element)
2175 duration = 40 * GST_MSECOND;
2179 gst_element_send_event (element,
2180 gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE,
2185 msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element)
2191 gboolean intermediate;
2195 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
2196 &intermediate, &duration, &eos);
2199 g_print ("stepped till EOS\n");
2203 if (g_static_mutex_trylock (&state_mutex)) {
2205 do_shuttle (element);
2206 g_static_mutex_unlock (&state_mutex);
2208 /* ignore step messages that come while we are doing a state change */
2209 g_print ("state change is busy\n");
2214 shuttle_toggled (GtkToggleButton * button, GstElement * element)
2218 active = gtk_toggle_button_get_active (button);
2220 if (active != shuttling) {
2222 g_print ("shuttling %s\n", shuttling ? "active" : "inactive");
2226 pause_cb (NULL, NULL);
2227 gst_element_get_state (element, NULL, NULL, -1);
2233 shuttle_rate_switch (GstElement * element)
2239 if (state == GST_STATE_PLAYING) {
2240 /* pause when we need to */
2241 pause_cb (NULL, NULL);
2242 gst_element_get_state (element, NULL, NULL, -1);
2245 if (play_rate == 1.0)
2250 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate,
2251 GST_TIME_ARGS (position));
2253 flags = GST_SEEK_FLAG_FLUSH;
2254 flags |= GST_SEEK_FLAG_ACCURATE;
2256 if (play_rate >= 0.0) {
2257 s_event = gst_event_new_seek (play_rate,
2258 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
2259 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
2261 s_event = gst_event_new_seek (play_rate,
2262 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2263 GST_SEEK_TYPE_SET, position);
2265 res = send_event (s_event);
2267 gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT);
2269 g_print ("seek failed\n");
2274 shuttle_value_changed (GtkRange * range, GstElement * element)
2278 rate = gtk_adjustment_get_value (shuttle_adjustment);
2281 g_print ("rate 0.0, pause\n");
2282 pause_cb (NULL, NULL);
2283 gst_element_get_state (element, NULL, NULL, -1);
2285 g_print ("rate changed %0.3g\n", rate);
2287 if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) {
2288 shuttle_rate_switch (element);
2291 shuttle_rate = ABS (rate);
2292 if (state != GST_STATE_PLAYING) {
2293 do_shuttle (element);
2294 play_cb (NULL, NULL);
2300 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2302 GST_DEBUG ("async done");
2303 /* when we get ASYNC_DONE we can query position, duration and other
2305 update_scale (pipeline);
2307 /* update the available streams */
2308 update_streams (pipeline);
2310 find_navigation_element ();
2314 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2316 const GstStructure *s;
2318 s = gst_message_get_structure (message);
2320 /* We only care about state changed on the pipeline */
2321 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2322 GstState old, new, pending;
2324 gst_message_parse_state_changed (message, &old, &new, &pending);
2326 /* When state of the pipeline changes to paused or playing we start updating scale */
2327 if (new == GST_STATE_PLAYING) {
2328 set_update_scale (TRUE);
2330 set_update_scale (FALSE);
2333 /* dump graph for (some) pipeline state changes */
2337 dump_name = g_strdup_printf ("seek.%s_%s",
2338 gst_element_state_get_name (old), gst_element_state_get_name (new));
2340 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
2341 GST_DEBUG_GRAPH_SHOW_ALL, dump_name);
2349 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2356 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2357 gst_message_parse_segment_done (message, &format, &position);
2358 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2361 /* in the segment-done callback we never flush as this would not make sense
2362 * for seamless playback. */
2364 flags |= GST_SEEK_FLAG_SEGMENT;
2366 flags |= GST_SEEK_FLAG_SKIP;
2368 s_event = gst_event_new_seek (rate,
2369 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2370 GST_SEEK_TYPE_SET, duration);
2372 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2373 rate, GST_TIME_ARGS (duration));
2375 res = send_event (s_event);
2377 g_print ("segment seek failed\n");
2380 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2383 do_stream_buffering (gint percent)
2387 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2388 bufstr = g_strdup_printf ("Buffering...%d", percent);
2389 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2392 if (percent == 100) {
2393 /* a 100% message means buffering is done */
2395 /* if the desired state is playing, go back */
2396 if (state == GST_STATE_PLAYING) {
2397 /* no state management needed for live pipelines */
2399 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2400 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2402 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2403 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2406 /* buffering busy */
2407 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2408 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2410 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2411 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2419 do_download_buffering (gint percent)
2421 if (!buffering && percent < 100) {
2426 bufstr = g_strdup_printf ("Downloading...");
2427 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2430 /* once we get a buffering message, we'll do the fill update */
2431 set_update_fill (TRUE);
2433 if (state == GST_STATE_PLAYING && !is_live) {
2434 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2435 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2436 /* user has to manually start the playback */
2437 state = GST_STATE_PAUSED;
2443 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2447 gst_message_parse_buffering (message, &percent);
2449 /* get more stats */
2450 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2454 case GST_BUFFERING_DOWNLOAD:
2455 do_download_buffering (percent);
2457 case GST_BUFFERING_LIVE:
2459 case GST_BUFFERING_TIMESHIFT:
2460 case GST_BUFFERING_STREAM:
2461 do_stream_buffering (percent);
2467 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2469 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2470 if (state == GST_STATE_PLAYING) {
2471 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2472 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2476 static GstElement *navigation_element = NULL;
2479 find_navigation_element (void)
2481 GstElement *video_sink;
2483 g_object_get (pipeline, "video-sink", &video_sink, NULL);
2487 if (navigation_element)
2488 gst_object_unref (navigation_element);
2490 if (GST_IS_NAVIGATION (video_sink)) {
2491 navigation_element = gst_object_ref (video_sink);
2492 } else if (GST_IS_BIN (video_sink)) {
2493 navigation_element =
2494 gst_bin_get_by_interface (GST_BIN (video_sink), GST_TYPE_NAVIGATION);
2496 navigation_element = NULL;
2499 gst_object_unref (video_sink);
2502 /* called when Navigation command button is pressed */
2504 navigation_cmd_cb (GtkButton * button, gpointer data)
2506 GstNavigationCommand cmd = GPOINTER_TO_INT (data);
2508 if (!navigation_element) {
2509 find_navigation_element ();
2510 if (!navigation_element)
2514 gst_navigation_send_command (GST_NAVIGATION (navigation_element), cmd);
2517 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
2519 static GstElement *xoverlay_element = NULL;
2520 static guintptr embed_xid = 0;
2522 /* We set the xid here in response to the prepare-xwindow-id message via a
2523 * bus sync handler because we don't know the actual videosink used from the
2524 * start (as we don't know the pipeline, or bin elements such as autovideosink
2525 * or gconfvideosink may be used which create the actual videosink only once
2526 * the pipeline is started) */
2527 static GstBusSyncReply
2528 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2530 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
2531 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
2532 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2534 if (xoverlay_element)
2535 gst_object_unref (xoverlay_element);
2536 xoverlay_element = GST_ELEMENT (gst_object_ref (element));
2538 g_print ("got prepare-xwindow-id, setting XID %lu\n", embed_xid);
2540 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2541 "force-aspect-ratio")) {
2542 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2545 /* Should have been initialised from main thread before (can't use
2546 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2547 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2548 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2549 * shouldn't be done from a non-GUI thread without explicit locking). */
2550 g_assert (embed_xid != 0);
2552 gst_x_overlay_set_window_handle (GST_X_OVERLAY (element), embed_xid);
2553 gst_x_overlay_handle_events (GST_X_OVERLAY (element), FALSE);
2555 find_navigation_element ();
2557 return GST_BUS_PASS;
2562 draw_cb (GtkWidget * widget, cairo_t * cr, gpointer data)
2564 if (state < GST_STATE_PAUSED) {
2567 width = gtk_widget_get_allocated_width (widget);
2568 height = gtk_widget_get_allocated_height (widget);
2569 cairo_set_source_rgb (cr, 0, 0, 0);
2570 cairo_rectangle (cr, 0, 0, width, height);
2575 if (xoverlay_element)
2576 gst_x_overlay_expose (GST_X_OVERLAY (xoverlay_element));
2582 realize_cb (GtkWidget * widget, gpointer data)
2584 GdkWindow *window = gtk_widget_get_window (widget);
2586 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2588 if (!gdk_window_ensure_native (window))
2589 g_error ("Couldn't create native window needed for GstXOverlay!");
2591 #if defined (GDK_WINDOWING_WIN32)
2592 embed_xid = GDK_WINDOW_HWND (window);
2593 g_print ("Window realize: video window HWND = %lu\n", embed_xid);
2594 #elif defined (GDK_WINDOWING_QUARTZ)
2595 embed_xid = gdk_quartz_window_get_nsview (window);
2596 g_print ("Window realize: video window NSView = %p\n", embed_xid);
2597 #elif defined (GDK_WINDOWING_X11)
2598 embed_xid = GDK_WINDOW_XID (window);
2599 g_print ("Window realize: video window XID = %lu\n", embed_xid);
2604 button_press_cb (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
2606 gtk_widget_grab_focus (widget);
2608 if (navigation_element)
2609 gst_navigation_send_mouse_event (GST_NAVIGATION (navigation_element),
2610 "mouse-button-press", event->button, event->x, event->y);
2616 button_release_cb (GtkWidget * widget, GdkEventButton * event,
2619 if (navigation_element)
2620 gst_navigation_send_mouse_event (GST_NAVIGATION (navigation_element),
2621 "mouse-button-release", event->button, event->x, event->y);
2627 key_press_cb (GtkWidget * widget, GdkEventKey * event, gpointer user_data)
2629 if (navigation_element)
2630 gst_navigation_send_key_event (GST_NAVIGATION (navigation_element),
2631 "key-press", gdk_keyval_name (event->keyval));
2637 key_release_cb (GtkWidget * widget, GdkEventKey * event, gpointer user_data)
2639 if (navigation_element)
2640 gst_navigation_send_key_event (GST_NAVIGATION (navigation_element),
2641 "key-release", gdk_keyval_name (event->keyval));
2647 motion_notify_cb (GtkWidget * widget, GdkEventMotion * event,
2650 if (navigation_element)
2651 gst_navigation_send_mouse_event (GST_NAVIGATION (navigation_element),
2652 "mouse-move", 0, event->x, event->y);
2658 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2660 message_received (bus, message, data);
2662 /* Set new uri for playerbins and continue playback */
2663 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2664 stop_cb (NULL, NULL);
2665 l = g_list_next (l);
2667 playerbin_set_uri (GST_ELEMENT (data), l->data);
2668 play_cb (NULL, NULL);
2674 msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data)
2677 message_received (bus, message, data);
2681 msg (GstBus * bus, GstMessage * message, GstPipeline * data)
2683 GstNavigationMessageType nav_type;
2685 nav_type = gst_navigation_message_get_type (message);
2687 case GST_NAVIGATION_MESSAGE_COMMANDS_CHANGED:{
2691 /* Heuristic to detect if we're dealing with a DVD menu */
2692 query = gst_navigation_query_new_commands ();
2693 res = gst_element_query (GST_ELEMENT (GST_MESSAGE_SRC (message)), query);
2695 for (j = 0; j < G_N_ELEMENTS (navigation_buttons); j++)
2696 gtk_widget_set_sensitive (navigation_buttons[j].button, FALSE);
2699 gboolean is_menu = FALSE;
2702 if (gst_navigation_query_parse_commands_length (query, &n)) {
2703 for (i = 0; i < n; i++) {
2704 GstNavigationCommand cmd;
2706 if (!gst_navigation_query_parse_commands_nth (query, i, &cmd))
2709 is_menu |= (cmd == GST_NAVIGATION_COMMAND_ACTIVATE);
2710 is_menu |= (cmd == GST_NAVIGATION_COMMAND_LEFT);
2711 is_menu |= (cmd == GST_NAVIGATION_COMMAND_RIGHT);
2712 is_menu |= (cmd == GST_NAVIGATION_COMMAND_UP);
2713 is_menu |= (cmd == GST_NAVIGATION_COMMAND_DOWN);
2715 for (j = 0; j < G_N_ELEMENTS (navigation_buttons); j++) {
2716 if (navigation_buttons[j].cmd != cmd)
2719 gtk_widget_set_sensitive (navigation_buttons[j].button, TRUE);
2724 gtk_widget_set_sensitive (GTK_WIDGET (hscale), !is_menu);
2726 g_assert_not_reached ();
2729 gst_query_unref (query);
2738 connect_bus_signals (GstElement * pipeline)
2740 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2742 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
2743 /* handle prepare-xwindow-id element message synchronously */
2744 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2748 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2749 gst_bus_enable_sync_message_emission (bus);
2751 g_signal_connect (bus, "message::state-changed",
2752 (GCallback) msg_state_changed, pipeline);
2753 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2755 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2758 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2760 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2762 g_signal_connect (bus, "message::error", (GCallback) message_received,
2764 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2766 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2767 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2769 g_signal_connect (bus, "message::element", (GCallback) message_received,
2771 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2773 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2775 // g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done,
2777 g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done,
2779 g_signal_connect (bus, "sync-message::step-done",
2780 (GCallback) msg_sync_step_done, pipeline);
2781 g_signal_connect (bus, "message", (GCallback) msg, pipeline);
2783 gst_object_unref (bus);
2786 /* Return GList of paths described in location string */
2788 handle_wildcards (const gchar * location)
2791 gchar *path = g_path_get_dirname (location);
2792 gchar *pattern = g_path_get_basename (location);
2793 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2794 GDir *dir = g_dir_open (path, 0, NULL);
2797 g_print ("matching %s from %s\n", pattern, path);
2800 g_print ("opening directory %s failed\n", path);
2804 while ((name = g_dir_read_name (dir)) != NULL) {
2805 if (g_pattern_match_string (pspec, name)) {
2806 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2807 g_print (" found clip %s\n", name);
2813 g_pattern_spec_free (pspec);
2821 delete_event_cb (void)
2823 stop_cb (NULL, NULL);
2828 print_usage (int argc, char **argv)
2832 g_print ("usage: %s <type> <filename>\n", argv[0]);
2833 g_print (" possible types:\n");
2835 for (i = 0; i < NUM_TYPES; i++) {
2836 g_print (" %d = %s\n", i, pipelines[i].name);
2841 main (int argc, char **argv)
2843 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2844 *flagtable, *boxes2, *step, *navigation;
2845 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2846 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2847 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2848 GtkWidget *rate_label, *volume_label;
2849 GOptionEntry options[] = {
2850 {"audiosink", '\0', 0, G_OPTION_ARG_STRING, &opt_audiosink_str,
2851 "audio sink to use (default: " DEFAULT_AUDIOSINK ")", NULL},
2852 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2853 "Show pad stats", NULL},
2854 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2855 "Seek on elements instead of pads", NULL},
2856 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2857 "Verbose properties", NULL},
2858 {"videosink", '\0', 0, G_OPTION_ARG_STRING, &opt_videosink_str,
2859 "video sink to use (default: " DEFAULT_VIDEOSINK ")", NULL},
2862 GOptionContext *ctx;
2865 #if !GLIB_CHECK_VERSION (2, 31, 0)
2866 if (!g_thread_supported ())
2867 g_thread_init (NULL);
2870 ctx = g_option_context_new ("- test seeking in gsteamer");
2871 g_option_context_add_main_entries (ctx, options, NULL);
2872 g_option_context_add_group (ctx, gst_init_get_option_group ());
2873 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2875 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2876 g_print ("Error initializing: %s\n", err->message);
2880 if (opt_audiosink_str == NULL)
2881 opt_audiosink_str = g_strdup (DEFAULT_AUDIOSINK);
2883 if (opt_videosink_str == NULL)
2884 opt_videosink_str = g_strdup (DEFAULT_VIDEOSINK);
2886 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2889 print_usage (argc, argv);
2893 pipeline_type = atoi (argv[1]);
2895 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2896 print_usage (argc, argv);
2900 pipeline_spec = argv[2];
2902 if (g_path_is_absolute (pipeline_spec) &&
2903 (g_strrstr (pipeline_spec, "*") != NULL ||
2904 g_strrstr (pipeline_spec, "?") != NULL)) {
2905 paths = handle_wildcards (pipeline_spec);
2907 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2911 g_print ("opening %s failed\n", pipeline_spec);
2917 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2918 g_assert (pipeline);
2920 /* initialize gui elements ... */
2921 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2922 video_window = gtk_drawing_area_new ();
2923 g_signal_connect (video_window, "draw", G_CALLBACK (draw_cb), NULL);
2924 g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL);
2925 g_signal_connect (video_window, "button-press-event",
2926 G_CALLBACK (button_press_cb), NULL);
2927 g_signal_connect (video_window, "button-release-event",
2928 G_CALLBACK (button_release_cb), NULL);
2929 g_signal_connect (video_window, "key-press-event", G_CALLBACK (key_press_cb),
2931 g_signal_connect (video_window, "key-release-event",
2932 G_CALLBACK (key_release_cb), NULL);
2933 g_signal_connect (video_window, "motion-notify-event",
2934 G_CALLBACK (motion_notify_cb), NULL);
2935 gtk_widget_set_can_focus (video_window, TRUE);
2936 gtk_widget_set_double_buffered (video_window, FALSE);
2937 gtk_widget_add_events (video_window,
2938 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
2939 | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
2941 statusbar = gtk_statusbar_new ();
2942 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2943 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2944 hbox = gtk_hbox_new (FALSE, 0);
2945 vbox = gtk_vbox_new (FALSE, 0);
2946 flagtable = gtk_table_new (4, 2, FALSE);
2947 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2949 /* media controls */
2950 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2951 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2952 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2955 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2956 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2957 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2958 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2959 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2960 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2961 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2962 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2963 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2964 rate_label = gtk_label_new ("Rate");
2966 gtk_widget_set_tooltip_text (accurate_checkbox,
2967 "accurate position is requested, this might be considerably slower for some formats");
2968 gtk_widget_set_tooltip_text (key_checkbox,
2969 "seek to the nearest keyframe. This might be faster but less accurate");
2970 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2971 gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking");
2972 gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, "
2973 "negative value trigger reverse playback");
2974 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2975 gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking");
2976 gtk_widget_set_tooltip_text (skip_checkbox,
2977 "Skip frames while playing at high frame rates");
2979 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2980 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2982 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2988 step = gtk_expander_new ("step options");
2989 hbox = gtk_hbox_new (FALSE, 0);
2991 format_combo = gtk_combo_box_text_new ();
2992 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2994 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2996 gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0);
2997 gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2);
2999 step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
3000 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0);
3001 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0);
3002 gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE,
3005 step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
3006 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3);
3007 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0);
3008 gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2);
3010 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
3011 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
3012 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
3014 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
3018 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
3019 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
3020 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
3021 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
3024 shuttle_adjustment =
3025 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
3026 shuttle_hscale = gtk_hscale_new (shuttle_adjustment);
3027 gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2);
3028 gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP);
3029 g_signal_connect (shuttle_hscale, "value_changed",
3030 G_CALLBACK (shuttle_value_changed), pipeline);
3031 g_signal_connect (shuttle_hscale, "format_value",
3032 G_CALLBACK (shuttle_format_value), pipeline);
3034 gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2);
3036 gtk_container_add (GTK_CONTAINER (step), hbox);
3039 /* navigation command expander */
3041 GtkWidget *navigation_button;
3045 navigation = gtk_expander_new ("navigation commands");
3046 grid = gtk_grid_new ();
3047 gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
3048 gtk_grid_set_row_homogeneous (GTK_GRID (grid), TRUE);
3049 gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
3050 gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
3052 navigation_button = gtk_button_new_with_label ("Menu 1");
3053 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3054 G_CALLBACK (navigation_cmd_cb),
3055 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_MENU1));
3056 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
3057 gtk_widget_set_sensitive (navigation_button, FALSE);
3058 gtk_widget_set_tooltip_text (navigation_button, "DVD Menu");
3059 navigation_buttons[i].button = navigation_button;
3060 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU1;
3062 navigation_button = gtk_button_new_with_label ("Menu 2");
3063 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3064 G_CALLBACK (navigation_cmd_cb),
3065 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_MENU2));
3066 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
3067 gtk_widget_set_sensitive (navigation_button, FALSE);
3068 gtk_widget_set_tooltip_text (navigation_button, "DVD Title Menu");
3069 navigation_buttons[i].button = navigation_button;
3070 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU2;
3072 navigation_button = gtk_button_new_with_label ("Menu 3");
3073 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3074 G_CALLBACK (navigation_cmd_cb),
3075 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_MENU3));
3076 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
3077 gtk_widget_set_sensitive (navigation_button, FALSE);
3078 gtk_widget_set_tooltip_text (navigation_button, "DVD Root Menu");
3079 navigation_buttons[i].button = navigation_button;
3080 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU3;
3082 navigation_button = gtk_button_new_with_label ("Menu 4");
3083 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3084 G_CALLBACK (navigation_cmd_cb),
3085 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_MENU4));
3086 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
3087 gtk_widget_set_sensitive (navigation_button, FALSE);
3088 gtk_widget_set_tooltip_text (navigation_button, "DVD Subpicture Menu");
3089 navigation_buttons[i].button = navigation_button;
3090 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU4;
3092 navigation_button = gtk_button_new_with_label ("Menu 5");
3093 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3094 G_CALLBACK (navigation_cmd_cb),
3095 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_MENU5));
3096 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
3097 gtk_widget_set_sensitive (navigation_button, FALSE);
3098 gtk_widget_set_tooltip_text (navigation_button, "DVD Audio Menu");
3099 navigation_buttons[i].button = navigation_button;
3100 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU5;
3102 navigation_button = gtk_button_new_with_label ("Menu 6");
3103 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3104 G_CALLBACK (navigation_cmd_cb),
3105 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_MENU6));
3106 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
3107 gtk_widget_set_sensitive (navigation_button, FALSE);
3108 gtk_widget_set_tooltip_text (navigation_button, "DVD Angle Menu");
3109 navigation_buttons[i].button = navigation_button;
3110 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU6;
3112 navigation_button = gtk_button_new_with_label ("Menu 7");
3113 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3114 G_CALLBACK (navigation_cmd_cb),
3115 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_MENU7));
3116 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
3117 gtk_widget_set_sensitive (navigation_button, FALSE);
3118 gtk_widget_set_tooltip_text (navigation_button, "DVD Chapter Menu");
3119 navigation_buttons[i].button = navigation_button;
3120 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU7;
3122 navigation_button = gtk_button_new_with_label ("Left");
3123 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3124 G_CALLBACK (navigation_cmd_cb),
3125 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_LEFT));
3126 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
3127 gtk_widget_set_sensitive (navigation_button, FALSE);
3128 navigation_buttons[i].button = navigation_button;
3129 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_LEFT;
3131 navigation_button = gtk_button_new_with_label ("Right");
3132 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3133 G_CALLBACK (navigation_cmd_cb),
3134 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_RIGHT));
3135 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
3136 gtk_widget_set_sensitive (navigation_button, FALSE);
3137 navigation_buttons[i].button = navigation_button;
3138 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_RIGHT;
3140 navigation_button = gtk_button_new_with_label ("Up");
3141 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3142 G_CALLBACK (navigation_cmd_cb),
3143 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_UP));
3144 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
3145 gtk_widget_set_sensitive (navigation_button, FALSE);
3146 navigation_buttons[i].button = navigation_button;
3147 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_UP;
3149 navigation_button = gtk_button_new_with_label ("Down");
3150 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3151 G_CALLBACK (navigation_cmd_cb),
3152 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_DOWN));
3153 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
3154 gtk_widget_set_sensitive (navigation_button, FALSE);
3155 navigation_buttons[i].button = navigation_button;
3156 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_DOWN;
3158 navigation_button = gtk_button_new_with_label ("Activate");
3159 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3160 G_CALLBACK (navigation_cmd_cb),
3161 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_ACTIVATE));
3162 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
3163 gtk_widget_set_sensitive (navigation_button, FALSE);
3164 navigation_buttons[i].button = navigation_button;
3165 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_ACTIVATE;
3167 navigation_button = gtk_button_new_with_label ("Prev. Angle");
3168 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3169 G_CALLBACK (navigation_cmd_cb),
3170 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_PREV_ANGLE));
3171 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
3172 gtk_widget_set_sensitive (navigation_button, FALSE);
3173 navigation_buttons[i].button = navigation_button;
3174 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_PREV_ANGLE;
3176 navigation_button = gtk_button_new_with_label ("Next. Angle");
3177 g_signal_connect (G_OBJECT (navigation_button), "clicked",
3178 G_CALLBACK (navigation_cmd_cb),
3179 GINT_TO_POINTER (GST_NAVIGATION_COMMAND_NEXT_ANGLE));
3180 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
3181 gtk_widget_set_sensitive (navigation_button, FALSE);
3182 navigation_buttons[i].button = navigation_button;
3183 navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_NEXT_ANGLE;
3185 gtk_container_add (GTK_CONTAINER (navigation), grid);
3190 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, N_GRAD, 0.1, 1.0, 1.0));
3191 hscale = gtk_hscale_new (adjustment);
3192 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
3193 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
3194 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
3195 gtk_range_set_fill_level (GTK_RANGE (hscale), N_GRAD);
3197 g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek),
3199 g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek),
3201 g_signal_connect (hscale, "format_value", G_CALLBACK (format_value),
3204 if (pipeline_type == 16) {
3205 /* the playbin2 panel controls for the video/audio/subtitle tracks */
3206 panel = gtk_hbox_new (FALSE, 0);
3207 video_combo = gtk_combo_box_text_new ();
3208 audio_combo = gtk_combo_box_text_new ();
3209 text_combo = gtk_combo_box_text_new ();
3210 gtk_widget_set_sensitive (video_combo, FALSE);
3211 gtk_widget_set_sensitive (audio_combo, FALSE);
3212 gtk_widget_set_sensitive (text_combo, FALSE);
3213 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
3214 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
3215 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
3216 g_signal_connect (G_OBJECT (video_combo), "changed",
3217 G_CALLBACK (video_combo_cb), pipeline);
3218 g_signal_connect (G_OBJECT (audio_combo), "changed",
3219 G_CALLBACK (audio_combo_cb), pipeline);
3220 g_signal_connect (G_OBJECT (text_combo), "changed",
3221 G_CALLBACK (text_combo_cb), pipeline);
3222 /* playbin2 panel for flag checkboxes and volume/mute */
3223 boxes = gtk_hbox_new (FALSE, 0);
3224 vis_checkbox = gtk_check_button_new_with_label ("Vis");
3225 video_checkbox = gtk_check_button_new_with_label ("Video");
3226 audio_checkbox = gtk_check_button_new_with_label ("Audio");
3227 text_checkbox = gtk_check_button_new_with_label ("Text");
3228 mute_checkbox = gtk_check_button_new_with_label ("Mute");
3229 download_checkbox = gtk_check_button_new_with_label ("Download");
3230 buffer_checkbox = gtk_check_button_new_with_label ("Buffer");
3231 volume_label = gtk_label_new ("Volume");
3232 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
3233 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
3234 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
3235 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
3236 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
3237 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
3238 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
3239 gtk_box_pack_start (GTK_BOX (boxes), download_checkbox, TRUE, TRUE, 2);
3240 gtk_box_pack_start (GTK_BOX (boxes), buffer_checkbox, TRUE, TRUE, 2);
3241 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
3242 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
3243 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
3244 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
3245 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
3246 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
3247 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
3248 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
3249 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffer_checkbox), FALSE);
3250 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
3251 G_CALLBACK (vis_toggle_cb), pipeline);
3252 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
3253 G_CALLBACK (audio_toggle_cb), pipeline);
3254 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
3255 G_CALLBACK (video_toggle_cb), pipeline);
3256 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
3257 G_CALLBACK (text_toggle_cb), pipeline);
3258 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
3259 G_CALLBACK (mute_toggle_cb), pipeline);
3260 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
3261 G_CALLBACK (download_toggle_cb), pipeline);
3262 g_signal_connect (G_OBJECT (buffer_checkbox), "toggled",
3263 G_CALLBACK (buffer_toggle_cb), pipeline);
3264 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
3265 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
3266 /* playbin2 panel for snapshot */
3267 boxes2 = gtk_hbox_new (FALSE, 0);
3268 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
3269 gtk_widget_set_tooltip_text (shot_button,
3270 "save a screenshot .png in the current directory");
3271 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
3273 vis_combo = gtk_combo_box_text_new ();
3274 g_signal_connect (G_OBJECT (vis_combo), "changed",
3275 G_CALLBACK (vis_combo_cb), pipeline);
3276 gtk_widget_set_sensitive (vis_combo, FALSE);
3277 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
3278 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
3280 /* fill the vis combo box and the array of factories */
3281 init_visualization_features ();
3283 panel = boxes = boxes2 = NULL;
3286 /* do the packing stuff ... */
3287 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
3288 /* FIXME: can we avoid this for audio only? */
3289 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
3290 DEFAULT_VIDEO_HEIGHT);
3291 gtk_container_add (GTK_CONTAINER (window), vbox);
3292 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
3293 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
3294 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
3295 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
3296 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
3297 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
3298 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
3300 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
3301 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
3302 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
3303 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
3304 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
3306 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
3307 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
3308 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
3310 if (panel && boxes && boxes2) {
3311 expander = gtk_expander_new ("playbin2 options");
3312 pb2vbox = gtk_vbox_new (FALSE, 0);
3313 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
3314 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
3315 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
3316 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
3317 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
3319 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
3320 gtk_box_pack_start (GTK_BOX (vbox), navigation, FALSE, FALSE, 2);
3321 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
3322 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
3324 /* connect things ... */
3325 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
3327 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
3329 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
3331 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
3332 G_CALLBACK (accurate_toggle_cb), pipeline);
3333 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
3334 G_CALLBACK (key_toggle_cb), pipeline);
3335 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
3336 G_CALLBACK (loop_toggle_cb), pipeline);
3337 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
3338 G_CALLBACK (flush_toggle_cb), pipeline);
3339 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
3340 G_CALLBACK (scrub_toggle_cb), pipeline);
3341 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
3342 G_CALLBACK (play_scrub_toggle_cb), pipeline);
3343 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
3344 G_CALLBACK (skip_toggle_cb), pipeline);
3345 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
3346 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
3348 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
3351 gtk_widget_show_all (window);
3353 /* realize window now so that the video window gets created and we can
3354 * obtain its XID before the pipeline is started up and the videosink
3355 * asks for the XID of the window to render onto */
3356 gtk_widget_realize (window);
3358 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
3359 /* we should have the XID now */
3360 g_assert (embed_xid != 0);
3364 g_signal_connect (pipeline, "deep_notify",
3365 G_CALLBACK (gst_object_default_deep_notify), NULL);
3368 connect_bus_signals (pipeline);
3371 g_print ("NULL pipeline\n");
3372 gst_element_set_state (pipeline, GST_STATE_NULL);
3374 if (xoverlay_element)
3375 gst_object_unref (xoverlay_element);
3376 if (navigation_element)
3377 gst_object_unref (navigation_element);
3379 g_print ("free pipeline\n");
3380 gst_object_unref (pipeline);
3382 g_list_foreach (paths, (GFunc) g_free, NULL);
3383 g_list_free (paths);