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.
36 #if defined (GDK_WINDOWING_X11)
38 #elif defined (GDK_WINDOWING_WIN32)
39 #include <gdk/gdkwin32.h>
42 #include <gst/interfaces/xoverlay.h>
44 #if (!GTK_CHECK_VERSION(2, 23, 0) || GTK_CHECK_VERSION(2, 90, 0)) && !GTK_CHECK_VERSION(2, 91, 1)
45 #define gtk_combo_box_text_new gtk_combo_box_new_text
46 #define gtk_combo_box_text_append_text gtk_combo_box_append_text
47 #define gtk_combo_box_text_remove gtk_combo_box_remove_text
48 #define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX
51 GST_DEBUG_CATEGORY_STATIC (seek_debug);
52 #define GST_CAT_DEFAULT (seek_debug)
54 #if !GTK_CHECK_VERSION (2, 17, 7)
56 gtk_widget_get_allocation (GtkWidget * w, GtkAllocation * a)
64 #define SOURCE "filesrc"
66 static gchar *opt_audiosink_str; /* NULL */
67 static gchar *opt_videosink_str; /* NULL */
69 #define FILL_INTERVAL 100
70 //#define UPDATE_INTERVAL 500
71 //#define UPDATE_INTERVAL 100
72 #define UPDATE_INTERVAL 40
74 /* number of milliseconds to play for after a seek */
75 #define SCRUB_TIME 100
77 /* timeout for gst_element_get_state() after a seek */
78 #define SEEK_TIMEOUT 40 * GST_MSECOND
80 #define DEFAULT_VIDEO_HEIGHT 300
82 /* the state to go to when stop is pressed */
83 #define STOP_STATE GST_STATE_READY
87 static GList *seekable_pads = NULL;
88 static GList *rate_pads = NULL;
89 static GList *seekable_elements = NULL;
91 static gboolean accurate_seek = FALSE;
92 static gboolean keyframe_seek = FALSE;
93 static gboolean loop_seek = FALSE;
94 static gboolean flush_seek = TRUE;
95 static gboolean scrub = TRUE;
96 static gboolean play_scrub = FALSE;
97 static gboolean skip_seek = FALSE;
98 static gdouble rate = 1.0;
100 static GstElement *pipeline;
101 static gint pipeline_type;
102 static const gchar *pipeline_spec;
103 static gint64 position = -1;
104 static gint64 duration = -1;
105 static GtkAdjustment *adjustment;
106 static GtkWidget *hscale, *statusbar;
107 static guint status_id = 0;
108 static gboolean stats = FALSE;
109 static gboolean elem_seek = FALSE;
110 static gboolean verbose = FALSE;
112 static gboolean is_live = FALSE;
113 static gboolean buffering = FALSE;
114 static GstBufferingMode mode;
115 static gint64 buffering_left;
116 static GstState state = GST_STATE_NULL;
117 static guint update_id = 0;
118 static guint seek_timeout_id = 0;
119 static gulong changed_id;
120 static guint fill_id = 0;
122 static gint n_video = 0, n_audio = 0, n_text = 0;
123 static gboolean need_streams = TRUE;
124 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
125 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
126 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
127 static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
128 static GtkWidget *buffer_checkbox, *rate_spinbutton;
130 static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
132 static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
133 static GtkWidget *shuttle_checkbox, *step_button;
134 static GtkWidget *shuttle_hscale;
135 static GtkAdjustment *shuttle_adjustment;
137 static GList *paths = NULL, *l = NULL;
139 /* we keep an array of the visualisation entries so that we can easily switch
140 * with the combo box index. */
143 GstElementFactory *factory;
146 static GArray *vis_entries;
148 static void clear_streams (GstElement * pipeline);
149 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
152 /* pipeline construction */
156 const gchar *padname;
163 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
165 GstElement *element = gst_element_factory_make (type, name);
167 #ifndef GST_DISABLE_PARSE
169 /* Try parsing it as a pipeline description */
170 element = gst_parse_bin_from_description (type, TRUE, NULL);
172 gst_element_set_name (element, name);
178 g_warning ("Failed to create element %s of type %s", name, type);
185 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
188 dyn_link *connect = (dyn_link *) data;
190 padname = gst_pad_get_name (newpad);
192 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
194 gst_bin_add (GST_BIN (pipeline), connect->bin);
195 gst_pad_link (newpad, connect->target);
197 //seekable_pads = g_list_prepend (seekable_pads, newpad);
198 rate_pads = g_list_prepend (rate_pads, newpad);
204 setup_dynamic_link (GstElement * element, const gchar * padname,
205 GstPad * target, GstElement * bin)
209 connect = g_new0 (dyn_link, 1);
210 connect->padname = g_strdup (padname);
211 connect->target = target;
214 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
219 make_mod_pipeline (const gchar * location)
221 GstElement *pipeline;
222 GstElement *src, *decoder, *audiosink;
225 pipeline = gst_pipeline_new ("app");
227 src = gst_element_factory_make_or_warn (SOURCE, "src");
228 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
229 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
230 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
232 g_object_set (G_OBJECT (src), "location", location, NULL);
234 gst_bin_add (GST_BIN (pipeline), src);
235 gst_bin_add (GST_BIN (pipeline), decoder);
236 gst_bin_add (GST_BIN (pipeline), audiosink);
238 gst_element_link (src, decoder);
239 gst_element_link (decoder, audiosink);
241 seekable = gst_element_get_static_pad (decoder, "src");
242 seekable_pads = g_list_prepend (seekable_pads, seekable);
243 rate_pads = g_list_prepend (rate_pads, seekable);
245 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
251 make_dv_pipeline (const gchar * location)
253 GstElement *pipeline;
254 GstElement *src, *demux, *decoder, *audiosink, *videosink;
255 GstElement *a_queue, *v_queue;
258 pipeline = gst_pipeline_new ("app");
260 src = gst_element_factory_make_or_warn (SOURCE, "src");
261 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
262 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
263 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
264 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
265 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
266 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
268 g_object_set (G_OBJECT (src), "location", location, NULL);
270 gst_bin_add (GST_BIN (pipeline), src);
271 gst_bin_add (GST_BIN (pipeline), demux);
272 gst_bin_add (GST_BIN (pipeline), a_queue);
273 gst_bin_add (GST_BIN (pipeline), audiosink);
274 gst_bin_add (GST_BIN (pipeline), v_queue);
275 gst_bin_add (GST_BIN (pipeline), decoder);
276 gst_bin_add (GST_BIN (pipeline), videosink);
278 gst_element_link (src, demux);
279 gst_element_link (a_queue, audiosink);
280 gst_element_link (v_queue, decoder);
281 gst_element_link (decoder, videosink);
283 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
285 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
288 seekable = gst_element_get_static_pad (decoder, "src");
289 seekable_pads = g_list_prepend (seekable_pads, seekable);
290 rate_pads = g_list_prepend (rate_pads, seekable);
296 make_wav_pipeline (const gchar * location)
298 GstElement *pipeline;
299 GstElement *src, *decoder, *audiosink;
301 pipeline = gst_pipeline_new ("app");
303 src = gst_element_factory_make_or_warn (SOURCE, "src");
304 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
305 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
307 g_object_set (G_OBJECT (src), "location", location, NULL);
309 gst_bin_add (GST_BIN (pipeline), src);
310 gst_bin_add (GST_BIN (pipeline), decoder);
311 gst_bin_add (GST_BIN (pipeline), audiosink);
313 gst_element_link (src, decoder);
315 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
318 seekable_elements = g_list_prepend (seekable_elements, audiosink);
320 /* force element seeking on this pipeline */
327 make_flac_pipeline (const gchar * location)
329 GstElement *pipeline;
330 GstElement *src, *decoder, *audiosink;
333 pipeline = gst_pipeline_new ("app");
335 src = gst_element_factory_make_or_warn (SOURCE, "src");
336 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
337 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
338 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
340 g_object_set (G_OBJECT (src), "location", location, NULL);
342 gst_bin_add (GST_BIN (pipeline), src);
343 gst_bin_add (GST_BIN (pipeline), decoder);
344 gst_bin_add (GST_BIN (pipeline), audiosink);
346 gst_element_link (src, decoder);
347 gst_element_link (decoder, audiosink);
349 seekable = gst_element_get_static_pad (decoder, "src");
350 seekable_pads = g_list_prepend (seekable_pads, seekable);
351 rate_pads = g_list_prepend (rate_pads, seekable);
353 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
359 make_sid_pipeline (const gchar * location)
361 GstElement *pipeline;
362 GstElement *src, *decoder, *audiosink;
365 pipeline = gst_pipeline_new ("app");
367 src = gst_element_factory_make_or_warn (SOURCE, "src");
368 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
369 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
370 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
372 g_object_set (G_OBJECT (src), "location", location, NULL);
374 gst_bin_add (GST_BIN (pipeline), src);
375 gst_bin_add (GST_BIN (pipeline), decoder);
376 gst_bin_add (GST_BIN (pipeline), audiosink);
378 gst_element_link (src, decoder);
379 gst_element_link (decoder, audiosink);
381 seekable = gst_element_get_static_pad (decoder, "src");
382 seekable_pads = g_list_prepend (seekable_pads, seekable);
383 rate_pads = g_list_prepend (rate_pads, seekable);
385 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
391 make_parse_pipeline (const gchar * location)
393 GstElement *pipeline;
394 GstElement *src, *parser, *fakesink;
397 pipeline = gst_pipeline_new ("app");
399 src = gst_element_factory_make_or_warn (SOURCE, "src");
400 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
401 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
402 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
403 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
405 g_object_set (G_OBJECT (src), "location", location, NULL);
407 gst_bin_add (GST_BIN (pipeline), src);
408 gst_bin_add (GST_BIN (pipeline), parser);
409 gst_bin_add (GST_BIN (pipeline), fakesink);
411 gst_element_link (src, parser);
412 gst_element_link (parser, fakesink);
414 seekable = gst_element_get_static_pad (parser, "src");
415 seekable_pads = g_list_prepend (seekable_pads, seekable);
416 rate_pads = g_list_prepend (rate_pads, seekable);
418 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
424 make_vorbis_pipeline (const gchar * location)
426 GstElement *pipeline, *audio_bin;
427 GstElement *src, *demux, *decoder, *convert, *audiosink;
428 GstPad *pad, *seekable;
430 pipeline = gst_pipeline_new ("app");
432 src = gst_element_factory_make_or_warn (SOURCE, "src");
433 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
434 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
435 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
436 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
437 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
439 g_object_set (G_OBJECT (src), "location", location, NULL);
441 audio_bin = gst_bin_new ("a_decoder_bin");
443 gst_bin_add (GST_BIN (pipeline), src);
444 gst_bin_add (GST_BIN (pipeline), demux);
445 gst_bin_add (GST_BIN (audio_bin), decoder);
446 gst_bin_add (GST_BIN (audio_bin), convert);
447 gst_bin_add (GST_BIN (audio_bin), audiosink);
448 gst_bin_add (GST_BIN (pipeline), audio_bin);
450 gst_element_link (src, demux);
451 gst_element_link (decoder, convert);
452 gst_element_link (convert, audiosink);
454 pad = gst_element_get_static_pad (decoder, "sink");
455 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
456 gst_object_unref (pad);
458 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
461 seekable = gst_element_get_static_pad (decoder, "src");
462 seekable_pads = g_list_prepend (seekable_pads, seekable);
463 rate_pads = g_list_prepend (rate_pads, seekable);
465 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
471 make_theora_pipeline (const gchar * location)
473 GstElement *pipeline, *video_bin;
474 GstElement *src, *demux, *decoder, *convert, *videosink;
475 GstPad *pad, *seekable;
477 pipeline = gst_pipeline_new ("app");
479 src = gst_element_factory_make_or_warn (SOURCE, "src");
480 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
481 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
482 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
483 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "sink");
485 g_object_set (G_OBJECT (src), "location", location, NULL);
487 video_bin = gst_bin_new ("v_decoder_bin");
489 gst_bin_add (GST_BIN (pipeline), src);
490 gst_bin_add (GST_BIN (pipeline), demux);
491 gst_bin_add (GST_BIN (video_bin), decoder);
492 gst_bin_add (GST_BIN (video_bin), convert);
493 gst_bin_add (GST_BIN (video_bin), videosink);
494 gst_bin_add (GST_BIN (pipeline), video_bin);
496 gst_element_link (src, demux);
497 gst_element_link (decoder, convert);
498 gst_element_link (convert, videosink);
500 pad = gst_element_get_static_pad (decoder, "sink");
501 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
502 gst_object_unref (pad);
504 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
507 seekable = gst_element_get_static_pad (decoder, "src");
508 seekable_pads = g_list_prepend (seekable_pads, seekable);
509 rate_pads = g_list_prepend (rate_pads, seekable);
511 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
517 make_vorbis_theora_pipeline (const gchar * location)
519 GstElement *pipeline, *audio_bin, *video_bin;
520 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
521 GstElement *audiosink, *videosink;
522 GstElement *a_queue, *v_queue, *v_scale;
526 pipeline = gst_pipeline_new ("app");
528 src = gst_element_factory_make_or_warn (SOURCE, "src");
529 g_object_set (G_OBJECT (src), "location", location, NULL);
531 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
533 gst_bin_add (GST_BIN (pipeline), src);
534 gst_bin_add (GST_BIN (pipeline), demux);
535 gst_element_link (src, demux);
537 audio_bin = gst_bin_new ("a_decoder_bin");
538 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
539 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
540 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
541 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
543 gst_bin_add (GST_BIN (pipeline), audio_bin);
545 gst_bin_add (GST_BIN (audio_bin), a_queue);
546 gst_bin_add (GST_BIN (audio_bin), a_decoder);
547 gst_bin_add (GST_BIN (audio_bin), a_convert);
548 gst_bin_add (GST_BIN (audio_bin), audiosink);
550 gst_element_link (a_queue, a_decoder);
551 gst_element_link (a_decoder, a_convert);
552 gst_element_link (a_convert, audiosink);
554 pad = gst_element_get_static_pad (a_queue, "sink");
555 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
556 gst_object_unref (pad);
558 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
561 video_bin = gst_bin_new ("v_decoder_bin");
562 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
563 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
565 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
566 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
567 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
569 gst_bin_add (GST_BIN (pipeline), video_bin);
571 gst_bin_add (GST_BIN (video_bin), v_queue);
572 gst_bin_add (GST_BIN (video_bin), v_decoder);
573 gst_bin_add (GST_BIN (video_bin), v_convert);
574 gst_bin_add (GST_BIN (video_bin), v_scale);
575 gst_bin_add (GST_BIN (video_bin), videosink);
577 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
580 pad = gst_element_get_static_pad (v_queue, "sink");
581 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
582 gst_object_unref (pad);
584 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
587 seekable = gst_element_get_static_pad (a_decoder, "src");
588 seekable_pads = g_list_prepend (seekable_pads, seekable);
589 rate_pads = g_list_prepend (rate_pads, seekable);
591 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
598 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
600 GstElement *pipeline, *audio_bin, *video_bin;
601 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
602 GstElement *audiosink, *videosink;
603 GstElement *a_queue, *v_queue;
604 GstPad *seekable, *pad;
606 pipeline = gst_pipeline_new ("app");
608 src = gst_element_factory_make_or_warn (SOURCE, "src");
609 g_object_set (G_OBJECT (src), "location", location, NULL);
611 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
613 gst_bin_add (GST_BIN (pipeline), src);
614 gst_bin_add (GST_BIN (pipeline), demux);
615 gst_element_link (src, demux);
617 audio_bin = gst_bin_new ("a_decoder_bin");
618 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
619 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
620 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
621 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
623 gst_bin_add (GST_BIN (audio_bin), a_queue);
624 gst_bin_add (GST_BIN (audio_bin), a_decoder);
625 gst_bin_add (GST_BIN (audio_bin), a_convert);
626 gst_bin_add (GST_BIN (audio_bin), audiosink);
628 gst_element_link (a_queue, a_decoder);
629 gst_element_link (a_decoder, a_convert);
630 gst_element_link (a_convert, audiosink);
632 gst_bin_add (GST_BIN (pipeline), audio_bin);
634 pad = gst_element_get_static_pad (a_queue, "sink");
635 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
636 gst_object_unref (pad);
638 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
641 video_bin = gst_bin_new ("v_decoder_bin");
642 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
643 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
645 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
646 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
648 gst_bin_add (GST_BIN (video_bin), v_queue);
649 gst_bin_add (GST_BIN (video_bin), v_decoder);
650 gst_bin_add (GST_BIN (video_bin), v_convert);
651 gst_bin_add (GST_BIN (video_bin), videosink);
653 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
655 gst_bin_add (GST_BIN (pipeline), video_bin);
657 pad = gst_element_get_static_pad (v_queue, "sink");
658 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
659 gst_object_unref (pad);
661 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
664 seekable = gst_element_get_static_pad (a_decoder, "src");
665 seekable_pads = g_list_prepend (seekable_pads, seekable);
666 rate_pads = g_list_prepend (rate_pads, seekable);
668 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
675 make_mp3_pipeline (const gchar * location)
677 GstElement *pipeline;
678 GstElement *src, *parser, *decoder, *audiosink, *queue;
681 pipeline = gst_pipeline_new ("app");
683 src = gst_element_factory_make_or_warn (SOURCE, "src");
684 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
685 decoder = gst_element_factory_make_or_warn ("mad", "dec");
686 queue = gst_element_factory_make_or_warn ("queue", "queue");
687 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
689 seekable_elements = g_list_prepend (seekable_elements, audiosink);
691 g_object_set (G_OBJECT (src), "location", location, NULL);
692 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
694 gst_bin_add (GST_BIN (pipeline), src);
695 gst_bin_add (GST_BIN (pipeline), parser);
696 gst_bin_add (GST_BIN (pipeline), decoder);
697 gst_bin_add (GST_BIN (pipeline), queue);
698 gst_bin_add (GST_BIN (pipeline), audiosink);
700 gst_element_link (src, parser);
701 gst_element_link (parser, decoder);
702 gst_element_link (decoder, queue);
703 gst_element_link (queue, audiosink);
705 seekable = gst_element_get_static_pad (queue, "src");
706 seekable_pads = g_list_prepend (seekable_pads, seekable);
707 rate_pads = g_list_prepend (rate_pads, seekable);
709 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
715 make_avi_pipeline (const gchar * location)
717 GstElement *pipeline, *audio_bin, *video_bin;
718 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
719 GstElement *a_queue = NULL, *v_queue = NULL;
722 pipeline = gst_pipeline_new ("app");
724 src = gst_element_factory_make_or_warn (SOURCE, "src");
725 g_object_set (G_OBJECT (src), "location", location, NULL);
727 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
728 seekable_elements = g_list_prepend (seekable_elements, demux);
730 gst_bin_add (GST_BIN (pipeline), src);
731 gst_bin_add (GST_BIN (pipeline), demux);
732 gst_element_link (src, demux);
734 audio_bin = gst_bin_new ("a_decoder_bin");
735 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
736 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
737 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
738 gst_element_link (a_decoder, a_queue);
739 gst_element_link (a_queue, audiosink);
740 gst_bin_add (GST_BIN (audio_bin), a_decoder);
741 gst_bin_add (GST_BIN (audio_bin), a_queue);
742 gst_bin_add (GST_BIN (audio_bin), audiosink);
743 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
745 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
748 seekable = gst_element_get_static_pad (a_queue, "src");
749 seekable_pads = g_list_prepend (seekable_pads, seekable);
750 rate_pads = g_list_prepend (rate_pads, seekable);
752 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
755 video_bin = gst_bin_new ("v_decoder_bin");
756 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
757 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
758 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
759 gst_element_link (v_decoder, v_queue);
760 gst_element_link (v_queue, videosink);
761 gst_bin_add (GST_BIN (video_bin), v_decoder);
762 gst_bin_add (GST_BIN (video_bin), v_queue);
763 gst_bin_add (GST_BIN (video_bin), videosink);
765 gst_element_set_state (video_bin, GST_STATE_PAUSED);
767 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
770 seekable = gst_element_get_static_pad (v_queue, "src");
771 seekable_pads = g_list_prepend (seekable_pads, seekable);
772 rate_pads = g_list_prepend (rate_pads, seekable);
774 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
781 make_mpeg_pipeline (const gchar * location)
783 GstElement *pipeline, *audio_bin, *video_bin;
784 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
785 GstElement *audiosink, *videosink;
786 GstElement *a_queue, *v_queue;
790 pipeline = gst_pipeline_new ("app");
792 src = gst_element_factory_make_or_warn (SOURCE, "src");
793 g_object_set (G_OBJECT (src), "location", location, NULL);
795 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
796 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
798 gst_bin_add (GST_BIN (pipeline), src);
799 gst_bin_add (GST_BIN (pipeline), demux);
800 gst_element_link (src, demux);
802 audio_bin = gst_bin_new ("a_decoder_bin");
803 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
804 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
805 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
806 gst_bin_add (GST_BIN (audio_bin), a_decoder);
807 gst_bin_add (GST_BIN (audio_bin), a_queue);
808 gst_bin_add (GST_BIN (audio_bin), audiosink);
810 gst_element_link (a_decoder, a_queue);
811 gst_element_link (a_queue, audiosink);
813 gst_bin_add (GST_BIN (pipeline), audio_bin);
815 pad = gst_element_get_static_pad (a_decoder, "sink");
816 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
817 gst_object_unref (pad);
819 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
822 video_bin = gst_bin_new ("v_decoder_bin");
823 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
824 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
825 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
826 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
828 gst_bin_add (GST_BIN (video_bin), v_decoder);
829 gst_bin_add (GST_BIN (video_bin), v_queue);
830 gst_bin_add (GST_BIN (video_bin), v_filter);
831 gst_bin_add (GST_BIN (video_bin), videosink);
833 gst_element_link (v_decoder, v_queue);
834 gst_element_link (v_queue, v_filter);
835 gst_element_link (v_filter, videosink);
837 gst_bin_add (GST_BIN (pipeline), video_bin);
839 pad = gst_element_get_static_pad (v_decoder, "sink");
840 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
841 gst_object_unref (pad);
843 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
846 seekable = gst_element_get_static_pad (v_filter, "src");
847 seekable_pads = g_list_prepend (seekable_pads, seekable);
848 rate_pads = g_list_prepend (rate_pads, seekable);
850 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
857 make_mpegnt_pipeline (const gchar * location)
859 GstElement *pipeline, *audio_bin, *video_bin;
860 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
861 GstElement *audiosink, *videosink;
865 pipeline = gst_pipeline_new ("app");
867 src = gst_element_factory_make_or_warn (SOURCE, "src");
868 g_object_set (G_OBJECT (src), "location", location, NULL);
870 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
871 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
873 seekable_elements = g_list_prepend (seekable_elements, demux);
875 gst_bin_add (GST_BIN (pipeline), src);
876 gst_bin_add (GST_BIN (pipeline), demux);
877 gst_element_link (src, demux);
879 audio_bin = gst_bin_new ("a_decoder_bin");
880 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
881 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
882 audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
883 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
884 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
885 gst_element_link (a_decoder, a_queue);
886 gst_element_link (a_queue, audiosink);
887 gst_bin_add (GST_BIN (audio_bin), a_decoder);
888 gst_bin_add (GST_BIN (audio_bin), a_queue);
889 gst_bin_add (GST_BIN (audio_bin), audiosink);
891 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
894 seekable = gst_element_get_static_pad (a_queue, "src");
895 seekable_pads = g_list_prepend (seekable_pads, seekable);
896 rate_pads = g_list_prepend (rate_pads, seekable);
898 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
901 video_bin = gst_bin_new ("v_decoder_bin");
902 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
903 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
904 videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
905 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
907 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
909 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
912 seekable = gst_element_get_static_pad (v_decoder, "src");
913 seekable_pads = g_list_prepend (seekable_pads, seekable);
914 rate_pads = g_list_prepend (rate_pads, seekable);
916 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
923 playerbin_set_uri (GstElement * player, const gchar * location)
927 /* Add "file://" prefix for convenience */
928 if (g_str_has_prefix (location, "/") || !gst_uri_is_valid (location)) {
929 uri = gst_filename_to_uri (location, NULL);
930 g_print ("Setting URI: %s\n", uri);
931 g_object_set (G_OBJECT (player), "uri", uri, NULL);
934 g_print ("Setting URI: %s\n", location);
935 g_object_set (G_OBJECT (player), "uri", location, NULL);
940 construct_playerbin (const gchar * name, const gchar * location)
945 player = gst_element_factory_make (name, "player");
948 playerbin_set_uri (player, location);
950 seekable_elements = g_list_prepend (seekable_elements, player);
952 /* force element seeking on this pipeline */
955 avsink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
957 g_object_set (player, "audio-sink", avsink, NULL);
959 avsink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
961 g_object_set (player, "video-sink", avsink, NULL);
967 make_playerbin_pipeline (const gchar * location)
969 return construct_playerbin ("playbin", location);
973 make_playerbin2_pipeline (const gchar * location)
975 GstElement *pipeline = construct_playerbin ("playbin2", location);
977 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
978 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
983 #ifndef GST_DISABLE_PARSE
985 make_parselaunch_pipeline (const gchar * description)
987 GstElement *pipeline;
988 GError *error = NULL;
990 pipeline = gst_parse_launch (description, &error);
992 seekable_elements = g_list_prepend (seekable_elements, pipeline);
1003 GstElement *(*func) (const gchar * location);
1007 static Pipeline pipelines[] = {
1008 {"mp3", make_mp3_pipeline},
1009 {"avi", make_avi_pipeline},
1010 {"mpeg1", make_mpeg_pipeline},
1011 {"mpegparse", make_parse_pipeline},
1012 {"vorbis", make_vorbis_pipeline},
1013 {"theora", make_theora_pipeline},
1014 {"ogg/v/t", make_vorbis_theora_pipeline},
1015 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
1016 {"sid", make_sid_pipeline},
1017 {"flac", make_flac_pipeline},
1018 {"wav", make_wav_pipeline},
1019 {"mod", make_mod_pipeline},
1020 {"dv", make_dv_pipeline},
1021 {"mpeg1nothreads", make_mpegnt_pipeline},
1022 {"playerbin", make_playerbin_pipeline},
1023 #ifndef GST_DISABLE_PARSE
1024 {"parse-launch", make_parselaunch_pipeline},
1026 {"playerbin2", make_playerbin2_pipeline},
1030 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
1032 /* ui callbacks and helpers */
1035 format_value (GtkScale * scale, gdouble value)
1041 real = value * duration / N_GRAD;
1042 seconds = (gint64) real / GST_SECOND;
1043 subseconds = (gint64) real / (GST_SECOND / N_GRAD);
1045 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1046 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1051 shuttle_format_value (GtkScale * scale, gdouble value)
1053 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
1059 const GstFormat format;
1063 static seek_format seek_formats[] = {
1064 {"tim", GST_FORMAT_TIME},
1065 {"byt", GST_FORMAT_BYTES},
1066 {"buf", GST_FORMAT_BUFFERS},
1067 {"def", GST_FORMAT_DEFAULT},
1071 G_GNUC_UNUSED static void
1074 GList *walk = rate_pads;
1077 GstPad *pad = GST_PAD (walk->data);
1080 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1081 while (seek_formats[i].name) {
1085 format = seek_formats[i].format;
1087 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
1089 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1091 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1096 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1098 walk = g_list_next (walk);
1102 G_GNUC_UNUSED static void
1103 query_positions_elems (void)
1105 GList *walk = seekable_elements;
1108 GstElement *element = GST_ELEMENT (walk->data);
1111 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1112 while (seek_formats[i].name) {
1113 gint64 position, total;
1116 format = seek_formats[i].format;
1118 if (gst_element_query_position (element, &format, &position) &&
1119 gst_element_query_duration (element, &format, &total)) {
1120 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1121 seek_formats[i].name, position, total);
1123 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1128 g_print (" %s\n", GST_ELEMENT_NAME (element));
1130 walk = g_list_next (walk);
1134 G_GNUC_UNUSED static void
1135 query_positions_pads (void)
1137 GList *walk = seekable_pads;
1140 GstPad *pad = GST_PAD (walk->data);
1143 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1144 while (seek_formats[i].name) {
1146 gint64 position, total;
1148 format = seek_formats[i].format;
1150 if (gst_pad_query_position (pad, &format, &position) &&
1151 gst_pad_query_duration (pad, &format, &total)) {
1152 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1153 seek_formats[i].name, position, total);
1155 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1161 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1163 walk = g_list_next (walk);
1167 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1168 gpointer user_data);
1169 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1170 gpointer user_data);
1171 static void seek_cb (GtkWidget * widget);
1174 set_scale (gdouble value)
1176 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1178 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1180 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1181 gtk_adjustment_set_value (adjustment, value);
1182 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1184 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1186 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1188 gtk_widget_queue_draw (hscale);
1192 update_fill (gpointer data)
1195 if (seekable_elements) {
1196 GstElement *element = GST_ELEMENT (seekable_elements->data);
1199 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1200 if (gst_element_query (element, query)) {
1201 gint64 start, stop, buffering_total;
1206 GstBufferingMode mode;
1207 gint avg_in, avg_out;
1208 gint64 buffering_left;
1210 gst_query_parse_buffering_percent (query, &busy, &percent);
1211 gst_query_parse_buffering_range (query, &format, &start, &stop,
1213 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
1216 /* note that we could start the playback when buffering_left < remaining
1218 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
1219 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
1220 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1224 fill = N_GRAD * stop / GST_FORMAT_PERCENT_MAX;
1228 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1230 gst_query_unref (query);
1237 update_scale (gpointer data)
1239 GstFormat format = GST_FORMAT_TIME;
1245 if (seekable_elements) {
1246 GstElement *element = GST_ELEMENT (seekable_elements->data);
1248 gst_element_query_position (element, &format, &position);
1249 gst_element_query_duration (element, &format, &duration);
1252 if (seekable_pads) {
1253 GstPad *pad = GST_PAD (seekable_pads->data);
1255 gst_pad_query_position (pad, &format, &position);
1256 gst_pad_query_duration (pad, &format, &duration);
1262 query_positions_elems ();
1264 query_positions_pads ();
1269 if (position >= duration)
1270 duration = position;
1273 set_scale (position * N_GRAD / duration);
1276 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1277 if (pipeline_type == 16) {
1278 g_object_notify (G_OBJECT (pipeline), "volume");
1284 static void do_seek (GtkWidget * widget);
1285 static void connect_bus_signals (GstElement * pipeline);
1286 static void set_update_scale (gboolean active);
1287 static void set_update_fill (gboolean active);
1290 end_scrub (GtkWidget * widget)
1292 GST_DEBUG ("end scrub, PAUSE");
1293 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1294 seek_timeout_id = 0;
1300 send_event (GstEvent * event)
1302 gboolean res = FALSE;
1305 GList *walk = seekable_pads;
1308 GstPad *seekable = GST_PAD (walk->data);
1310 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1312 gst_event_ref (event);
1313 res = gst_pad_send_event (seekable, event);
1315 walk = g_list_next (walk);
1318 GList *walk = seekable_elements;
1321 GstElement *seekable = GST_ELEMENT (walk->data);
1323 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1325 gst_event_ref (event);
1326 res = gst_element_send_event (seekable, event);
1328 walk = g_list_next (walk);
1331 gst_event_unref (event);
1336 do_seek (GtkWidget * widget)
1339 gboolean res = FALSE;
1343 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / N_GRAD;
1345 GST_DEBUG ("value=%f, real=%" G_GINT64_FORMAT,
1346 gtk_range_get_value (GTK_RANGE (widget)), real);
1350 flags |= GST_SEEK_FLAG_FLUSH;
1352 flags |= GST_SEEK_FLAG_ACCURATE;
1354 flags |= GST_SEEK_FLAG_KEY_UNIT;
1356 flags |= GST_SEEK_FLAG_SEGMENT;
1358 flags |= GST_SEEK_FLAG_SKIP;
1361 s_event = gst_event_new_seek (rate,
1362 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1363 GST_CLOCK_TIME_NONE);
1364 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1365 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1367 s_event = gst_event_new_seek (rate,
1368 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1369 GST_SEEK_TYPE_SET, real);
1370 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1371 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1374 res = send_event (s_event);
1378 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1380 set_update_scale (TRUE);
1383 g_print ("seek failed\n");
1384 set_update_scale (TRUE);
1389 seek_cb (GtkWidget * widget)
1391 /* If the timer hasn't expired yet, then the pipeline is running */
1392 if (play_scrub && seek_timeout_id != 0) {
1393 GST_DEBUG ("do scrub seek, PAUSED");
1394 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1397 GST_DEBUG ("do seek");
1401 GST_DEBUG ("do scrub seek, PLAYING");
1402 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1404 if (seek_timeout_id == 0) {
1406 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1412 set_update_fill (gboolean active)
1414 GST_DEBUG ("fill scale is %d", active);
1419 g_timeout_add (FILL_INTERVAL, (GSourceFunc) update_fill, pipeline);
1423 g_source_remove (fill_id);
1430 set_update_scale (gboolean active)
1433 GST_DEBUG ("update scale is %d", active);
1436 if (update_id == 0) {
1438 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, pipeline);
1442 g_source_remove (update_id);
1449 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1451 if (event->type != GDK_BUTTON_PRESS)
1454 set_update_scale (FALSE);
1456 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1457 GST_DEBUG ("start scrub seek, PAUSE");
1458 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1461 if (changed_id == 0 && flush_seek && scrub) {
1463 g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb),
1471 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1474 g_signal_handler_disconnect (hscale, changed_id);
1478 if (!flush_seek || !scrub) {
1479 GST_DEBUG ("do final seek");
1483 if (seek_timeout_id != 0) {
1484 g_source_remove (seek_timeout_id);
1485 seek_timeout_id = 0;
1486 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1488 if (state == GST_STATE_PAUSED) {
1489 GST_DEBUG ("stop scrub seek, PAUSED");
1490 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1493 if (state == GST_STATE_PLAYING) {
1494 GST_DEBUG ("stop scrub seek, PLAYING");
1495 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1503 play_cb (GtkButton * button, gpointer data)
1505 GstStateChangeReturn ret;
1507 if (state != GST_STATE_PLAYING) {
1508 g_print ("PLAY pipeline\n");
1509 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1511 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1513 case GST_STATE_CHANGE_FAILURE:
1515 case GST_STATE_CHANGE_NO_PREROLL:
1521 state = GST_STATE_PLAYING;
1522 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1529 g_print ("PLAY failed\n");
1530 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1535 pause_cb (GtkButton * button, gpointer data)
1537 g_static_mutex_lock (&state_mutex);
1538 if (state != GST_STATE_PAUSED) {
1539 GstStateChangeReturn ret;
1541 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1542 g_print ("PAUSE pipeline\n");
1543 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1545 case GST_STATE_CHANGE_FAILURE:
1547 case GST_STATE_CHANGE_NO_PREROLL:
1554 state = GST_STATE_PAUSED;
1555 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1557 g_static_mutex_unlock (&state_mutex);
1563 g_static_mutex_unlock (&state_mutex);
1564 g_print ("PAUSE failed\n");
1565 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1570 stop_cb (GtkButton * button, gpointer data)
1572 if (state != STOP_STATE) {
1573 GstStateChangeReturn ret;
1575 g_print ("READY pipeline\n");
1576 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1578 g_static_mutex_lock (&state_mutex);
1579 ret = gst_element_set_state (pipeline, STOP_STATE);
1580 if (ret == GST_STATE_CHANGE_FAILURE)
1584 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
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);
1622 g_static_mutex_unlock (&state_mutex);
1623 g_print ("STOP failed\n");
1624 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1629 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1631 accurate_seek = gtk_toggle_button_get_active (button);
1635 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1637 keyframe_seek = gtk_toggle_button_get_active (button);
1641 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1643 loop_seek = gtk_toggle_button_get_active (button);
1644 if (state == GST_STATE_PLAYING) {
1650 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1652 flush_seek = gtk_toggle_button_get_active (button);
1656 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1658 scrub = gtk_toggle_button_get_active (button);
1662 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1664 play_scrub = gtk_toggle_button_get_active (button);
1668 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1670 skip_seek = gtk_toggle_button_get_active (button);
1671 if (state == GST_STATE_PLAYING) {
1677 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1679 gboolean res = FALSE;
1683 rate = gtk_spin_button_get_value (button);
1685 GST_DEBUG ("rate changed to %lf", rate);
1689 flags |= GST_SEEK_FLAG_FLUSH;
1691 flags |= GST_SEEK_FLAG_SEGMENT;
1693 flags |= GST_SEEK_FLAG_ACCURATE;
1695 flags |= GST_SEEK_FLAG_KEY_UNIT;
1697 flags |= GST_SEEK_FLAG_SKIP;
1700 s_event = gst_event_new_seek (rate,
1701 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1702 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1704 s_event = gst_event_new_seek (rate,
1705 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1706 GST_SEEK_TYPE_SET, position);
1709 res = send_event (s_event);
1713 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1716 g_print ("seek failed\n");
1720 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1724 g_object_get (pipeline, "flags", &flags, NULL);
1726 flags |= (1 << num);
1728 flags &= ~(1 << num);
1729 g_object_set (pipeline, "flags", flags, NULL);
1733 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1737 state = gtk_toggle_button_get_active (button);
1738 update_flag (pipeline, 3, state);
1739 gtk_widget_set_sensitive (vis_combo, state);
1743 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1747 state = gtk_toggle_button_get_active (button);
1748 update_flag (pipeline, 1, state);
1749 gtk_widget_set_sensitive (audio_combo, state);
1753 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1757 state = gtk_toggle_button_get_active (button);
1758 update_flag (pipeline, 0, state);
1759 gtk_widget_set_sensitive (video_combo, state);
1763 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1767 state = gtk_toggle_button_get_active (button);
1768 update_flag (pipeline, 2, state);
1769 gtk_widget_set_sensitive (text_combo, state);
1773 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1777 mute = gtk_toggle_button_get_active (button);
1778 g_object_set (pipeline, "mute", mute, NULL);
1782 download_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1786 state = gtk_toggle_button_get_active (button);
1787 update_flag (pipeline, 7, state);
1791 buffer_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1795 state = gtk_toggle_button_get_active (button);
1796 update_flag (pipeline, 8, state);
1800 clear_streams (GstElement * pipeline)
1804 /* remove previous info */
1805 for (i = 0; i < n_video; i++)
1806 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (video_combo), 0);
1807 for (i = 0; i < n_audio; i++)
1808 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (audio_combo), 0);
1809 for (i = 0; i < n_text; i++)
1810 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (text_combo), 0);
1812 n_audio = n_video = n_text = 0;
1813 gtk_widget_set_sensitive (video_combo, FALSE);
1814 gtk_widget_set_sensitive (audio_combo, FALSE);
1815 gtk_widget_set_sensitive (text_combo, FALSE);
1817 need_streams = TRUE;
1821 update_streams (GstPipeline * pipeline)
1825 if (pipeline_type == 16 && need_streams) {
1831 /* remove previous info */
1832 clear_streams (GST_ELEMENT_CAST (pipeline));
1834 /* here we get and update the different streams detected by playbin2 */
1835 g_object_get (pipeline, "n-video", &n_video, NULL);
1836 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1837 g_object_get (pipeline, "n-text", &n_text, NULL);
1839 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1842 for (i = 0; i < n_video; i++) {
1843 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1845 str = gst_structure_to_string ((GstStructure *) tags);
1846 g_print ("video %d: %s\n", i, str);
1849 /* find good name for the label */
1850 name = g_strdup_printf ("video %d", i + 1);
1851 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (video_combo), name);
1854 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1855 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1856 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1859 for (i = 0; i < n_audio; i++) {
1860 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1862 str = gst_structure_to_string ((GstStructure *) tags);
1863 g_print ("audio %d: %s\n", i, str);
1866 /* find good name for the label */
1867 name = g_strdup_printf ("audio %d", i + 1);
1868 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (audio_combo), name);
1871 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1872 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1873 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1876 for (i = 0; i < n_text; i++) {
1877 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1881 const GValue *value;
1883 str = gst_structure_to_string ((GstStructure *) tags);
1884 g_print ("text %d: %s\n", i, str);
1887 /* get the language code if we can */
1888 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1889 if (value && G_VALUE_HOLDS_STRING (value)) {
1890 name = g_strdup_printf ("text %s", g_value_get_string (value));
1893 /* find good name for the label if we didn't use a tag */
1895 name = g_strdup_printf ("text %d", i + 1);
1897 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (text_combo), name);
1900 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1901 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1902 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1904 need_streams = FALSE;
1909 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1913 active = gtk_combo_box_get_active (combo);
1915 g_print ("setting current video track %d\n", active);
1916 g_object_set (pipeline, "current-video", active, NULL);
1920 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1924 active = gtk_combo_box_get_active (combo);
1926 g_print ("setting current audio track %d\n", active);
1927 g_object_set (pipeline, "current-audio", active, NULL);
1931 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1935 active = gtk_combo_box_get_active (combo);
1937 g_print ("setting current text track %d\n", active);
1938 g_object_set (pipeline, "current-text", active, NULL);
1942 filter_features (GstPluginFeature * feature, gpointer data)
1944 GstElementFactory *f;
1946 if (!GST_IS_ELEMENT_FACTORY (feature))
1948 f = GST_ELEMENT_FACTORY (feature);
1949 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1956 init_visualization_features (void)
1960 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1962 list = gst_registry_feature_filter (gst_registry_get_default (),
1963 filter_features, FALSE, NULL);
1965 for (walk = list; walk; walk = g_list_next (walk)) {
1969 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1970 name = gst_element_factory_get_longname (entry.factory);
1972 g_array_append_val (vis_entries, entry);
1973 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (vis_combo), name);
1975 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1979 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1983 GstElement *element;
1985 /* get the selected index and get the factory for this index */
1986 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1987 if (vis_entries->len > 0) {
1988 entry = &g_array_index (vis_entries, VisEntry, index);
1990 /* create an instance of the element from the factory */
1991 element = gst_element_factory_create (entry->factory, NULL);
1995 /* set vis plugin for playbin2 */
1996 g_object_set (pipeline, "vis-plugin", element, NULL);
2001 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
2005 volume = gtk_spin_button_get_value (button);
2007 g_object_set (pipeline, "volume", volume, NULL);
2011 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
2013 gdouble cur_volume, new_volume;
2015 g_object_get (pipeline, "volume", &new_volume, NULL);
2016 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
2017 if (fabs (cur_volume - new_volume) > 0.001) {
2018 g_signal_handlers_block_by_func (volume_spinbutton,
2019 volume_spinbutton_changed_cb, pipeline);
2020 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
2021 g_signal_handlers_unblock_by_func (volume_spinbutton,
2022 volume_spinbutton_changed_cb, pipeline);
2027 shot_cb (GtkButton * button, gpointer data)
2032 /* convert to our desired format (RGB24) */
2033 caps = gst_caps_new_simple ("video/x-raw-rgb",
2034 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
2035 /* Note: we don't ask for a specific width/height here, so that
2036 * videoscale can adjust dimensions from a non-1/1 pixel aspect
2037 * ratio to a 1/1 pixel-aspect-ratio */
2038 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
2039 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
2040 "red_mask", G_TYPE_INT, 0xff0000,
2041 "green_mask", G_TYPE_INT, 0x00ff00,
2042 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
2044 /* convert the latest frame to the requested format */
2045 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
2046 gst_caps_unref (caps);
2054 GError *error = NULL;
2056 /* get the snapshot buffer format now. We set the caps on the appsink so
2057 * that it can only be an rgb buffer. The only thing we have not specified
2058 * on the caps is the height, which is dependant on the pixel-aspect-ratio
2059 * of the source material */
2060 caps = GST_BUFFER_CAPS (buffer);
2062 g_warning ("could not get snapshot format\n");
2065 s = gst_caps_get_structure (caps, 0);
2067 /* we need to get the final caps on the buffer to get the size */
2068 res = gst_structure_get_int (s, "width", &width);
2069 res |= gst_structure_get_int (s, "height", &height);
2071 g_warning ("could not get snapshot dimension\n");
2075 /* create pixmap from buffer and save, gstreamer video buffers have a stride
2076 * that is rounded up to the nearest multiple of 4 */
2077 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
2078 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2079 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2081 /* save the pixbuf */
2082 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2085 gst_buffer_unref (buffer);
2089 /* called when the Step button is pressed */
2091 step_cb (GtkButton * button, gpointer data)
2097 gboolean flush, res;
2100 active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo));
2102 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
2103 (step_amount_spinbutton));
2104 rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton));
2109 format = GST_FORMAT_BUFFERS;
2112 format = GST_FORMAT_TIME;
2113 amount *= GST_MSECOND;
2116 format = GST_FORMAT_UNDEFINED;
2120 event = gst_event_new_step (format, amount, rate, flush, FALSE);
2122 res = send_event (event);
2125 g_print ("Sending step event failed\n");
2130 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2132 const GstStructure *s;
2134 switch (GST_MESSAGE_TYPE (message)) {
2135 case GST_MESSAGE_ERROR:
2136 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
2137 GST_DEBUG_GRAPH_SHOW_ALL, "seek.error");
2139 case GST_MESSAGE_WARNING:
2140 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
2141 GST_DEBUG_GRAPH_SHOW_ALL, "seek.warning");
2147 s = gst_message_get_structure (message);
2148 g_print ("message from \"%s\" (%s): ",
2149 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2150 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2154 sstr = gst_structure_to_string (s);
2155 g_print ("%s\n", sstr);
2158 g_print ("no message details\n");
2162 static gboolean shuttling = FALSE;
2163 static gdouble shuttle_rate = 0.0;
2164 static gdouble play_rate = 1.0;
2167 do_shuttle (GstElement * element)
2172 duration = 40 * GST_MSECOND;
2176 gst_element_send_event (element,
2177 gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE,
2182 msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element)
2188 gboolean intermediate;
2192 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
2193 &intermediate, &duration, &eos);
2196 g_print ("stepped till EOS\n");
2200 if (g_static_mutex_trylock (&state_mutex)) {
2202 do_shuttle (element);
2203 g_static_mutex_unlock (&state_mutex);
2205 /* ignore step messages that come while we are doing a state change */
2206 g_print ("state change is busy\n");
2211 shuttle_toggled (GtkToggleButton * button, GstElement * element)
2215 active = gtk_toggle_button_get_active (button);
2217 if (active != shuttling) {
2219 g_print ("shuttling %s\n", shuttling ? "active" : "inactive");
2223 pause_cb (NULL, NULL);
2224 gst_element_get_state (element, NULL, NULL, -1);
2230 shuttle_rate_switch (GstElement * element)
2236 if (state == GST_STATE_PLAYING) {
2237 /* pause when we need to */
2238 pause_cb (NULL, NULL);
2239 gst_element_get_state (element, NULL, NULL, -1);
2242 if (play_rate == 1.0)
2247 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate,
2248 GST_TIME_ARGS (position));
2250 flags = GST_SEEK_FLAG_FLUSH;
2251 flags |= GST_SEEK_FLAG_ACCURATE;
2253 if (play_rate >= 0.0) {
2254 s_event = gst_event_new_seek (play_rate,
2255 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
2256 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
2258 s_event = gst_event_new_seek (play_rate,
2259 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2260 GST_SEEK_TYPE_SET, position);
2262 res = send_event (s_event);
2264 gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT);
2266 g_print ("seek failed\n");
2271 shuttle_value_changed (GtkRange * range, GstElement * element)
2275 rate = gtk_adjustment_get_value (shuttle_adjustment);
2278 g_print ("rate 0.0, pause\n");
2279 pause_cb (NULL, NULL);
2280 gst_element_get_state (element, NULL, NULL, -1);
2282 g_print ("rate changed %0.3g\n", rate);
2284 if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) {
2285 shuttle_rate_switch (element);
2288 shuttle_rate = ABS (rate);
2289 if (state != GST_STATE_PLAYING) {
2290 do_shuttle (element);
2291 play_cb (NULL, NULL);
2297 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2299 GST_DEBUG ("async done");
2300 /* when we get ASYNC_DONE we can query position, duration and other
2302 update_scale (pipeline);
2304 /* update the available streams */
2305 update_streams (pipeline);
2309 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2311 const GstStructure *s;
2313 s = gst_message_get_structure (message);
2315 /* We only care about state changed on the pipeline */
2316 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2317 GstState old, new, pending;
2319 gst_message_parse_state_changed (message, &old, &new, &pending);
2321 /* When state of the pipeline changes to paused or playing we start updating scale */
2322 if (new == GST_STATE_PLAYING) {
2323 set_update_scale (TRUE);
2325 set_update_scale (FALSE);
2328 /* dump graph for (some) pipeline state changes */
2332 dump_name = g_strdup_printf ("seek.%s_%s",
2333 gst_element_state_get_name (old), gst_element_state_get_name (new));
2335 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
2336 GST_DEBUG_GRAPH_SHOW_ALL, dump_name);
2344 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2351 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2352 gst_message_parse_segment_done (message, &format, &position);
2353 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2356 /* in the segment-done callback we never flush as this would not make sense
2357 * for seamless playback. */
2359 flags |= GST_SEEK_FLAG_SEGMENT;
2361 flags |= GST_SEEK_FLAG_SKIP;
2363 s_event = gst_event_new_seek (rate,
2364 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2365 GST_SEEK_TYPE_SET, duration);
2367 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2368 rate, GST_TIME_ARGS (duration));
2370 res = send_event (s_event);
2372 g_print ("segment seek failed\n");
2375 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2378 do_stream_buffering (gint percent)
2382 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2383 bufstr = g_strdup_printf ("Buffering...%d", percent);
2384 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2387 if (percent == 100) {
2388 /* a 100% message means buffering is done */
2390 /* if the desired state is playing, go back */
2391 if (state == GST_STATE_PLAYING) {
2392 /* no state management needed for live pipelines */
2394 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2395 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2397 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2398 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2401 /* buffering busy */
2402 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2403 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2405 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2406 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2414 do_download_buffering (gint percent)
2416 if (!buffering && percent < 100) {
2421 bufstr = g_strdup_printf ("Downloading...");
2422 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2425 /* once we get a buffering message, we'll do the fill update */
2426 set_update_fill (TRUE);
2428 if (state == GST_STATE_PLAYING && !is_live) {
2429 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2430 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2431 /* user has to manually start the playback */
2432 state = GST_STATE_PAUSED;
2438 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2442 gst_message_parse_buffering (message, &percent);
2444 /* get more stats */
2445 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2449 case GST_BUFFERING_DOWNLOAD:
2450 do_download_buffering (percent);
2452 case GST_BUFFERING_LIVE:
2454 case GST_BUFFERING_TIMESHIFT:
2455 case GST_BUFFERING_STREAM:
2456 do_stream_buffering (percent);
2462 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2464 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2465 if (state == GST_STATE_PLAYING) {
2466 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2467 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2471 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32)
2473 static gulong embed_xid = 0;
2475 /* We set the xid here in response to the prepare-xwindow-id message via a
2476 * bus sync handler because we don't know the actual videosink used from the
2477 * start (as we don't know the pipeline, or bin elements such as autovideosink
2478 * or gconfvideosink may be used which create the actual videosink only once
2479 * the pipeline is started) */
2480 static GstBusSyncReply
2481 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2483 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
2484 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
2485 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2487 g_print ("got prepare-xwindow-id, setting XID %lu\n", embed_xid);
2489 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2490 "force-aspect-ratio")) {
2491 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2494 /* Should have been initialised from main thread before (can't use
2495 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2496 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2497 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2498 * shouldn't be done from a non-GUI thread without explicit locking). */
2499 g_assert (embed_xid != 0);
2501 gst_x_overlay_set_window_handle (GST_X_OVERLAY (element), embed_xid);
2503 return GST_BUS_PASS;
2508 handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
2510 if (state < GST_STATE_PAUSED) {
2511 GtkAllocation allocation;
2512 GdkWindow *window = gtk_widget_get_window (widget);
2515 gtk_widget_get_allocation (widget, &allocation);
2516 cr = gdk_cairo_create (window);
2517 cairo_set_source_rgb (cr, 0, 0, 0);
2518 cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
2526 realize_cb (GtkWidget * widget, gpointer data)
2528 #if GTK_CHECK_VERSION(2,18,0)
2530 GdkWindow *window = gtk_widget_get_window (widget);
2532 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2534 if (!gdk_window_ensure_native (window))
2535 g_error ("Couldn't create native window needed for GstXOverlay!");
2539 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32)
2541 GdkWindow *window = gtk_widget_get_window (video_window);
2543 #if defined (GDK_WINDOWING_WIN32)
2544 embed_xid = GDK_WINDOW_HWND (window);
2546 embed_xid = GDK_WINDOW_XID (window);
2548 g_print ("Window realize: video window XID = %lu\n", embed_xid);
2554 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2556 message_received (bus, message, data);
2558 /* Set new uri for playerbins and continue playback */
2559 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2560 stop_cb (NULL, NULL);
2561 l = g_list_next (l);
2563 playerbin_set_uri (GST_ELEMENT (data), l->data);
2564 play_cb (NULL, NULL);
2570 msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data)
2573 message_received (bus, message, data);
2577 connect_bus_signals (GstElement * pipeline)
2579 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2581 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32)
2582 /* handle prepare-xwindow-id element message synchronously */
2583 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2587 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2588 gst_bus_enable_sync_message_emission (bus);
2590 g_signal_connect (bus, "message::state-changed",
2591 (GCallback) msg_state_changed, pipeline);
2592 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2594 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2597 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2599 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2601 g_signal_connect (bus, "message::error", (GCallback) message_received,
2603 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2605 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2606 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2608 g_signal_connect (bus, "message::element", (GCallback) message_received,
2610 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2612 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2614 // g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done,
2616 g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done,
2618 g_signal_connect (bus, "sync-message::step-done",
2619 (GCallback) msg_sync_step_done, pipeline);
2621 gst_object_unref (bus);
2624 /* Return GList of paths described in location string */
2626 handle_wildcards (const gchar * location)
2629 gchar *path = g_path_get_dirname (location);
2630 gchar *pattern = g_path_get_basename (location);
2631 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2632 GDir *dir = g_dir_open (path, 0, NULL);
2635 g_print ("matching %s from %s\n", pattern, path);
2638 g_print ("opening directory %s failed\n", path);
2642 while ((name = g_dir_read_name (dir)) != NULL) {
2643 if (g_pattern_match_string (pspec, name)) {
2644 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2645 g_print (" found clip %s\n", name);
2651 g_pattern_spec_free (pspec);
2659 delete_event_cb (void)
2661 stop_cb (NULL, NULL);
2666 print_usage (int argc, char **argv)
2670 g_print ("usage: %s <type> <filename>\n", argv[0]);
2671 g_print (" possible types:\n");
2673 for (i = 0; i < NUM_TYPES; i++) {
2674 g_print (" %d = %s\n", i, pipelines[i].name);
2679 main (int argc, char **argv)
2681 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2682 *flagtable, *boxes2, *step;
2683 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2684 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2685 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2686 GtkWidget *rate_label, *volume_label;
2687 GOptionEntry options[] = {
2688 {"audiosink", '\0', 0, G_OPTION_ARG_STRING, &opt_audiosink_str,
2689 "audio sink to use (default: " DEFAULT_AUDIOSINK ")", NULL},
2690 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2691 "Show pad stats", NULL},
2692 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2693 "Seek on elements instead of pads", NULL},
2694 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2695 "Verbose properties", NULL},
2696 {"videosink", '\0', 0, G_OPTION_ARG_STRING, &opt_videosink_str,
2697 "video sink to use (default: " DEFAULT_VIDEOSINK ")", NULL},
2700 GOptionContext *ctx;
2703 if (!g_thread_supported ())
2704 g_thread_init (NULL);
2706 ctx = g_option_context_new ("- test seeking in gsteamer");
2707 g_option_context_add_main_entries (ctx, options, NULL);
2708 g_option_context_add_group (ctx, gst_init_get_option_group ());
2709 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2711 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2712 g_print ("Error initializing: %s\n", err->message);
2716 if (opt_audiosink_str == NULL)
2717 opt_audiosink_str = g_strdup (DEFAULT_AUDIOSINK);
2719 if (opt_videosink_str == NULL)
2720 opt_videosink_str = g_strdup (DEFAULT_VIDEOSINK);
2722 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2725 print_usage (argc, argv);
2729 pipeline_type = atoi (argv[1]);
2731 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2732 print_usage (argc, argv);
2736 pipeline_spec = argv[2];
2738 if (g_path_is_absolute (pipeline_spec) &&
2739 (g_strrstr (pipeline_spec, "*") != NULL ||
2740 g_strrstr (pipeline_spec, "?") != NULL)) {
2741 paths = handle_wildcards (pipeline_spec);
2743 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2747 g_print ("opening %s failed\n", pipeline_spec);
2753 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2754 g_assert (pipeline);
2756 /* initialize gui elements ... */
2757 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2758 video_window = gtk_drawing_area_new ();
2759 g_signal_connect (video_window, "expose-event",
2760 G_CALLBACK (handle_expose_cb), NULL);
2761 g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL);
2762 gtk_widget_set_double_buffered (video_window, FALSE);
2764 statusbar = gtk_statusbar_new ();
2765 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2766 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2767 hbox = gtk_hbox_new (FALSE, 0);
2768 vbox = gtk_vbox_new (FALSE, 0);
2769 flagtable = gtk_table_new (4, 2, FALSE);
2770 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2772 /* media controls */
2773 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2774 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2775 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2778 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2779 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2780 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2781 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2782 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2783 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2784 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2785 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2786 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2787 rate_label = gtk_label_new ("Rate");
2789 gtk_widget_set_tooltip_text (accurate_checkbox,
2790 "accurate position is requested, this might be considerably slower for some formats");
2791 gtk_widget_set_tooltip_text (key_checkbox,
2792 "seek to the nearest keyframe. This might be faster but less accurate");
2793 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2794 gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking");
2795 gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, "
2796 "negative value trigger reverse playback");
2797 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2798 gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking");
2799 gtk_widget_set_tooltip_text (skip_checkbox,
2800 "Skip frames while playing at high frame rates");
2802 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2803 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2805 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2811 step = gtk_expander_new ("step options");
2812 hbox = gtk_hbox_new (FALSE, 0);
2814 format_combo = gtk_combo_box_text_new ();
2815 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2817 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2819 gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0);
2820 gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2);
2822 step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2823 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0);
2824 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0);
2825 gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE,
2828 step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2829 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3);
2830 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0);
2831 gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2);
2833 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2834 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2835 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2837 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2841 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2842 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2843 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2844 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2847 shuttle_adjustment =
2848 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2849 shuttle_hscale = gtk_hscale_new (shuttle_adjustment);
2850 gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2);
2851 gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP);
2852 g_signal_connect (shuttle_hscale, "value_changed",
2853 G_CALLBACK (shuttle_value_changed), pipeline);
2854 g_signal_connect (shuttle_hscale, "format_value",
2855 G_CALLBACK (shuttle_format_value), pipeline);
2857 gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2);
2859 gtk_container_add (GTK_CONTAINER (step), hbox);
2864 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, N_GRAD, 0.1, 1.0, 1.0));
2865 hscale = gtk_hscale_new (adjustment);
2866 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2867 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
2868 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2869 gtk_range_set_fill_level (GTK_RANGE (hscale), N_GRAD);
2871 g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek),
2873 g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek),
2875 g_signal_connect (hscale, "format_value", G_CALLBACK (format_value),
2878 if (pipeline_type == 16) {
2879 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2880 panel = gtk_hbox_new (FALSE, 0);
2881 video_combo = gtk_combo_box_text_new ();
2882 audio_combo = gtk_combo_box_text_new ();
2883 text_combo = gtk_combo_box_text_new ();
2884 gtk_widget_set_sensitive (video_combo, FALSE);
2885 gtk_widget_set_sensitive (audio_combo, FALSE);
2886 gtk_widget_set_sensitive (text_combo, FALSE);
2887 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2888 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2889 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2890 g_signal_connect (G_OBJECT (video_combo), "changed",
2891 G_CALLBACK (video_combo_cb), pipeline);
2892 g_signal_connect (G_OBJECT (audio_combo), "changed",
2893 G_CALLBACK (audio_combo_cb), pipeline);
2894 g_signal_connect (G_OBJECT (text_combo), "changed",
2895 G_CALLBACK (text_combo_cb), pipeline);
2896 /* playbin2 panel for flag checkboxes and volume/mute */
2897 boxes = gtk_hbox_new (FALSE, 0);
2898 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2899 video_checkbox = gtk_check_button_new_with_label ("Video");
2900 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2901 text_checkbox = gtk_check_button_new_with_label ("Text");
2902 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2903 download_checkbox = gtk_check_button_new_with_label ("Download");
2904 buffer_checkbox = gtk_check_button_new_with_label ("Buffer");
2905 volume_label = gtk_label_new ("Volume");
2906 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2907 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2908 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2909 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2910 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2911 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2912 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2913 gtk_box_pack_start (GTK_BOX (boxes), download_checkbox, TRUE, TRUE, 2);
2914 gtk_box_pack_start (GTK_BOX (boxes), buffer_checkbox, TRUE, TRUE, 2);
2915 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
2916 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2917 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2918 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2919 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2920 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2921 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2922 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
2923 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffer_checkbox), FALSE);
2924 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2925 G_CALLBACK (vis_toggle_cb), pipeline);
2926 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2927 G_CALLBACK (audio_toggle_cb), pipeline);
2928 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2929 G_CALLBACK (video_toggle_cb), pipeline);
2930 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2931 G_CALLBACK (text_toggle_cb), pipeline);
2932 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2933 G_CALLBACK (mute_toggle_cb), pipeline);
2934 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
2935 G_CALLBACK (download_toggle_cb), pipeline);
2936 g_signal_connect (G_OBJECT (buffer_checkbox), "toggled",
2937 G_CALLBACK (buffer_toggle_cb), pipeline);
2938 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2939 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2940 /* playbin2 panel for snapshot */
2941 boxes2 = gtk_hbox_new (FALSE, 0);
2942 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2943 gtk_widget_set_tooltip_text (shot_button,
2944 "save a screenshot .png in the current directory");
2945 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2947 vis_combo = gtk_combo_box_text_new ();
2948 g_signal_connect (G_OBJECT (vis_combo), "changed",
2949 G_CALLBACK (vis_combo_cb), pipeline);
2950 gtk_widget_set_sensitive (vis_combo, FALSE);
2951 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2952 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2954 /* fill the vis combo box and the array of factories */
2955 init_visualization_features ();
2957 panel = boxes = boxes2 = NULL;
2960 /* do the packing stuff ... */
2961 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2962 /* FIXME: can we avoid this for audio only? */
2963 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
2964 DEFAULT_VIDEO_HEIGHT);
2965 gtk_container_add (GTK_CONTAINER (window), vbox);
2966 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
2967 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2968 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2969 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2970 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2971 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2972 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2974 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2975 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2976 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2977 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2978 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2980 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2981 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2982 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2984 if (panel && boxes && boxes2) {
2985 expander = gtk_expander_new ("playbin2 options");
2986 pb2vbox = gtk_vbox_new (FALSE, 0);
2987 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2988 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2989 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2990 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2991 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2993 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2994 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
2995 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
2997 /* connect things ... */
2998 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
3000 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
3002 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
3004 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
3005 G_CALLBACK (accurate_toggle_cb), pipeline);
3006 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
3007 G_CALLBACK (key_toggle_cb), pipeline);
3008 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
3009 G_CALLBACK (loop_toggle_cb), pipeline);
3010 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
3011 G_CALLBACK (flush_toggle_cb), pipeline);
3012 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
3013 G_CALLBACK (scrub_toggle_cb), pipeline);
3014 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
3015 G_CALLBACK (play_scrub_toggle_cb), pipeline);
3016 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
3017 G_CALLBACK (skip_toggle_cb), pipeline);
3018 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
3019 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
3021 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
3024 gtk_widget_show_all (window);
3026 /* realize window now so that the video window gets created and we can
3027 * obtain its XID before the pipeline is started up and the videosink
3028 * asks for the XID of the window to render onto */
3029 gtk_widget_realize (window);
3031 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32)
3032 /* we should have the XID now */
3033 g_assert (embed_xid != 0);
3037 g_signal_connect (pipeline, "deep_notify",
3038 G_CALLBACK (gst_object_default_deep_notify), NULL);
3041 connect_bus_signals (pipeline);
3044 g_print ("NULL pipeline\n");
3045 gst_element_set_state (pipeline, GST_STATE_NULL);
3047 g_print ("free pipeline\n");
3048 gst_object_unref (pipeline);
3050 g_list_foreach (paths, (GFunc) g_free, NULL);
3051 g_list_free (paths);