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.
38 #include <gst/interfaces/xoverlay.h>
40 GST_DEBUG_CATEGORY_STATIC (seek_debug);
41 #define GST_CAT_DEFAULT (seek_debug)
45 //#define SOURCE "filesrc"
46 #define SOURCE "gnomevfssrc"
48 #define ASINK "alsasink"
49 //#define ASINK "osssink"
51 #define VSINK "xvimagesink"
52 //#define VSINK "sdlvideosink"
53 //#define VSINK "ximagesink"
54 //#define VSINK "aasink"
55 //#define VSINK "cacasink"
57 #define FILL_INTERVAL 100
58 //#define UPDATE_INTERVAL 500
59 //#define UPDATE_INTERVAL 100
60 #define UPDATE_INTERVAL 10
62 /* number of milliseconds to play for after a seek */
63 #define SCRUB_TIME 100
65 /* timeout for gst_element_get_state() after a seek */
66 #define SEEK_TIMEOUT 40 * GST_MSECOND
68 #define DEFAULT_VIDEO_HEIGHT 300
71 static GList *seekable_pads = NULL;
72 static GList *rate_pads = NULL;
73 static GList *seekable_elements = NULL;
75 static gboolean accurate_seek = FALSE;
76 static gboolean keyframe_seek = FALSE;
77 static gboolean loop_seek = FALSE;
78 static gboolean flush_seek = TRUE;
79 static gboolean scrub = TRUE;
80 static gboolean play_scrub = FALSE;
81 static gboolean skip_seek = FALSE;
82 static gdouble rate = 1.0;
84 static GstElement *pipeline;
85 static gint pipeline_type;
86 static const gchar *pipeline_spec;
87 static gint64 position = -1;
88 static gint64 duration = -1;
89 static GtkAdjustment *adjustment;
90 static GtkWidget *hscale, *statusbar;
91 static guint status_id = 0;
92 static gboolean stats = FALSE;
93 static gboolean elem_seek = FALSE;
94 static gboolean verbose = FALSE;
96 static gboolean is_live = FALSE;
97 static gboolean buffering = FALSE;
98 static GstBufferingMode mode;
99 static gint64 buffering_left;
100 static GstState state = GST_STATE_NULL;
101 static guint update_id = 0;
102 static guint seek_timeout_id = 0;
103 static gulong changed_id;
104 static guint fill_id = 0;
106 static gint n_video = 0, n_audio = 0, n_text = 0;
107 static gboolean need_streams = TRUE;
108 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
109 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
110 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
111 static GtkWidget *skip_checkbox, *video_window;
113 GList *paths = NULL, *l = NULL;
115 /* we keep an array of the visualisation entries so that we can easily switch
116 * with the combo box index. */
119 GstElementFactory *factory;
122 static GArray *vis_entries;
124 static void clear_streams (GstElement * pipeline);
125 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
128 /* pipeline construction */
132 const gchar *padname;
139 gst_element_factory_make_or_warn (gchar * type, gchar * name)
141 GstElement *element = gst_element_factory_make (type, name);
144 g_warning ("Failed to create element %s of type %s", name, type);
151 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
154 dyn_link *connect = (dyn_link *) data;
156 padname = gst_pad_get_name (newpad);
158 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
160 gst_bin_add (GST_BIN (pipeline), connect->bin);
161 gst_pad_link (newpad, connect->target);
163 //seekable_pads = g_list_prepend (seekable_pads, newpad);
164 rate_pads = g_list_prepend (rate_pads, newpad);
170 setup_dynamic_link (GstElement * element, const gchar * padname,
171 GstPad * target, GstElement * bin)
175 connect = g_new0 (dyn_link, 1);
176 connect->padname = g_strdup (padname);
177 connect->target = target;
180 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
185 make_mod_pipeline (const gchar * location)
187 GstElement *pipeline;
188 GstElement *src, *decoder, *audiosink;
191 pipeline = gst_pipeline_new ("app");
193 src = gst_element_factory_make_or_warn (SOURCE, "src");
194 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
195 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
196 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
198 g_object_set (G_OBJECT (src), "location", location, NULL);
200 gst_bin_add (GST_BIN (pipeline), src);
201 gst_bin_add (GST_BIN (pipeline), decoder);
202 gst_bin_add (GST_BIN (pipeline), audiosink);
204 gst_element_link (src, decoder);
205 gst_element_link (decoder, audiosink);
207 seekable = gst_element_get_static_pad (decoder, "src");
208 seekable_pads = g_list_prepend (seekable_pads, seekable);
209 rate_pads = g_list_prepend (rate_pads, seekable);
211 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
217 make_dv_pipeline (const gchar * location)
219 GstElement *pipeline;
220 GstElement *src, *demux, *decoder, *audiosink, *videosink;
221 GstElement *a_queue, *v_queue;
224 pipeline = gst_pipeline_new ("app");
226 src = gst_element_factory_make_or_warn (SOURCE, "src");
227 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
228 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
229 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
230 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
231 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
232 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
234 g_object_set (G_OBJECT (src), "location", location, NULL);
236 gst_bin_add (GST_BIN (pipeline), src);
237 gst_bin_add (GST_BIN (pipeline), demux);
238 gst_bin_add (GST_BIN (pipeline), a_queue);
239 gst_bin_add (GST_BIN (pipeline), audiosink);
240 gst_bin_add (GST_BIN (pipeline), v_queue);
241 gst_bin_add (GST_BIN (pipeline), decoder);
242 gst_bin_add (GST_BIN (pipeline), videosink);
244 gst_element_link (src, demux);
245 gst_element_link (a_queue, audiosink);
246 gst_element_link (v_queue, decoder);
247 gst_element_link (decoder, videosink);
249 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
251 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
254 seekable = gst_element_get_static_pad (decoder, "src");
255 seekable_pads = g_list_prepend (seekable_pads, seekable);
256 rate_pads = g_list_prepend (rate_pads, seekable);
262 make_wav_pipeline (const gchar * location)
264 GstElement *pipeline;
265 GstElement *src, *decoder, *audiosink;
267 pipeline = gst_pipeline_new ("app");
269 src = gst_element_factory_make_or_warn (SOURCE, "src");
270 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
271 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
273 g_object_set (G_OBJECT (src), "location", location, NULL);
275 gst_bin_add (GST_BIN (pipeline), src);
276 gst_bin_add (GST_BIN (pipeline), decoder);
277 gst_bin_add (GST_BIN (pipeline), audiosink);
279 gst_element_link (src, decoder);
281 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
284 seekable_elements = g_list_prepend (seekable_elements, audiosink);
286 /* force element seeking on this pipeline */
293 make_flac_pipeline (const gchar * location)
295 GstElement *pipeline;
296 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 ("flacdec", "decoder");
303 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
304 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
306 g_object_set (G_OBJECT (src), "location", location, NULL);
308 gst_bin_add (GST_BIN (pipeline), src);
309 gst_bin_add (GST_BIN (pipeline), decoder);
310 gst_bin_add (GST_BIN (pipeline), audiosink);
312 gst_element_link (src, decoder);
313 gst_element_link (decoder, audiosink);
315 seekable = gst_element_get_static_pad (decoder, "src");
316 seekable_pads = g_list_prepend (seekable_pads, seekable);
317 rate_pads = g_list_prepend (rate_pads, seekable);
319 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
325 make_sid_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 ("siddec", "decoder");
335 audiosink = gst_element_factory_make_or_warn (ASINK, "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_parse_pipeline (const gchar * location)
359 GstElement *pipeline;
360 GstElement *src, *parser, *fakesink;
363 pipeline = gst_pipeline_new ("app");
365 src = gst_element_factory_make_or_warn (SOURCE, "src");
366 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
367 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
368 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
369 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
371 g_object_set (G_OBJECT (src), "location", location, NULL);
373 gst_bin_add (GST_BIN (pipeline), src);
374 gst_bin_add (GST_BIN (pipeline), parser);
375 gst_bin_add (GST_BIN (pipeline), fakesink);
377 gst_element_link (src, parser);
378 gst_element_link (parser, fakesink);
380 seekable = gst_element_get_static_pad (parser, "src");
381 seekable_pads = g_list_prepend (seekable_pads, seekable);
382 rate_pads = g_list_prepend (rate_pads, seekable);
384 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
390 make_vorbis_pipeline (const gchar * location)
392 GstElement *pipeline, *audio_bin;
393 GstElement *src, *demux, *decoder, *convert, *audiosink;
394 GstPad *pad, *seekable;
396 pipeline = gst_pipeline_new ("app");
398 src = gst_element_factory_make_or_warn (SOURCE, "src");
399 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
400 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
401 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
402 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
403 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
405 g_object_set (G_OBJECT (src), "location", location, NULL);
407 audio_bin = gst_bin_new ("a_decoder_bin");
409 gst_bin_add (GST_BIN (pipeline), src);
410 gst_bin_add (GST_BIN (pipeline), demux);
411 gst_bin_add (GST_BIN (audio_bin), decoder);
412 gst_bin_add (GST_BIN (audio_bin), convert);
413 gst_bin_add (GST_BIN (audio_bin), audiosink);
414 gst_bin_add (GST_BIN (pipeline), audio_bin);
416 gst_element_link (src, demux);
417 gst_element_link (decoder, convert);
418 gst_element_link (convert, audiosink);
420 pad = gst_element_get_static_pad (decoder, "sink");
421 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
422 gst_object_unref (pad);
424 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
427 seekable = gst_element_get_static_pad (decoder, "src");
428 seekable_pads = g_list_prepend (seekable_pads, seekable);
429 rate_pads = g_list_prepend (rate_pads, seekable);
431 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
437 make_theora_pipeline (const gchar * location)
439 GstElement *pipeline, *video_bin;
440 GstElement *src, *demux, *decoder, *convert, *videosink;
441 GstPad *pad, *seekable;
443 pipeline = gst_pipeline_new ("app");
445 src = gst_element_factory_make_or_warn (SOURCE, "src");
446 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
447 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
448 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
449 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
451 g_object_set (G_OBJECT (src), "location", location, NULL);
453 video_bin = gst_bin_new ("v_decoder_bin");
455 gst_bin_add (GST_BIN (pipeline), src);
456 gst_bin_add (GST_BIN (pipeline), demux);
457 gst_bin_add (GST_BIN (video_bin), decoder);
458 gst_bin_add (GST_BIN (video_bin), convert);
459 gst_bin_add (GST_BIN (video_bin), videosink);
460 gst_bin_add (GST_BIN (pipeline), video_bin);
462 gst_element_link (src, demux);
463 gst_element_link (decoder, convert);
464 gst_element_link (convert, videosink);
466 pad = gst_element_get_static_pad (decoder, "sink");
467 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
468 gst_object_unref (pad);
470 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
473 seekable = gst_element_get_static_pad (decoder, "src");
474 seekable_pads = g_list_prepend (seekable_pads, seekable);
475 rate_pads = g_list_prepend (rate_pads, seekable);
477 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
483 make_vorbis_theora_pipeline (const gchar * location)
485 GstElement *pipeline, *audio_bin, *video_bin;
486 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
487 GstElement *audiosink, *videosink;
488 GstElement *a_queue, *v_queue, *v_scale;
492 pipeline = gst_pipeline_new ("app");
494 src = gst_element_factory_make_or_warn (SOURCE, "src");
495 g_object_set (G_OBJECT (src), "location", location, NULL);
497 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
499 gst_bin_add (GST_BIN (pipeline), src);
500 gst_bin_add (GST_BIN (pipeline), demux);
501 gst_element_link (src, demux);
503 audio_bin = gst_bin_new ("a_decoder_bin");
504 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
505 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
506 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
507 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
509 gst_bin_add (GST_BIN (pipeline), audio_bin);
511 gst_bin_add (GST_BIN (audio_bin), a_queue);
512 gst_bin_add (GST_BIN (audio_bin), a_decoder);
513 gst_bin_add (GST_BIN (audio_bin), a_convert);
514 gst_bin_add (GST_BIN (audio_bin), audiosink);
516 gst_element_link (a_queue, a_decoder);
517 gst_element_link (a_decoder, a_convert);
518 gst_element_link (a_convert, audiosink);
520 pad = gst_element_get_static_pad (a_queue, "sink");
521 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
522 gst_object_unref (pad);
524 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
527 video_bin = gst_bin_new ("v_decoder_bin");
528 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
529 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
531 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
532 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
533 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
535 gst_bin_add (GST_BIN (pipeline), video_bin);
537 gst_bin_add (GST_BIN (video_bin), v_queue);
538 gst_bin_add (GST_BIN (video_bin), v_decoder);
539 gst_bin_add (GST_BIN (video_bin), v_convert);
540 gst_bin_add (GST_BIN (video_bin), v_scale);
541 gst_bin_add (GST_BIN (video_bin), videosink);
543 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
546 pad = gst_element_get_static_pad (v_queue, "sink");
547 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
548 gst_object_unref (pad);
550 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
553 seekable = gst_element_get_static_pad (a_decoder, "src");
554 seekable_pads = g_list_prepend (seekable_pads, seekable);
555 rate_pads = g_list_prepend (rate_pads, seekable);
557 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
564 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
566 GstElement *pipeline, *audio_bin, *video_bin;
567 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
568 GstElement *audiosink, *videosink;
569 GstElement *a_queue, *v_queue;
570 GstPad *seekable, *pad;
572 pipeline = gst_pipeline_new ("app");
574 src = gst_element_factory_make_or_warn (SOURCE, "src");
575 g_object_set (G_OBJECT (src), "location", location, NULL);
577 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
579 gst_bin_add (GST_BIN (pipeline), src);
580 gst_bin_add (GST_BIN (pipeline), demux);
581 gst_element_link (src, demux);
583 audio_bin = gst_bin_new ("a_decoder_bin");
584 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
585 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
586 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
587 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
589 gst_bin_add (GST_BIN (audio_bin), a_queue);
590 gst_bin_add (GST_BIN (audio_bin), a_decoder);
591 gst_bin_add (GST_BIN (audio_bin), a_convert);
592 gst_bin_add (GST_BIN (audio_bin), audiosink);
594 gst_element_link (a_queue, a_decoder);
595 gst_element_link (a_decoder, a_convert);
596 gst_element_link (a_convert, audiosink);
598 gst_bin_add (GST_BIN (pipeline), audio_bin);
600 pad = gst_element_get_static_pad (a_queue, "sink");
601 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
602 gst_object_unref (pad);
604 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
607 video_bin = gst_bin_new ("v_decoder_bin");
608 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
609 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
611 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
612 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
614 gst_bin_add (GST_BIN (video_bin), v_queue);
615 gst_bin_add (GST_BIN (video_bin), v_decoder);
616 gst_bin_add (GST_BIN (video_bin), v_convert);
617 gst_bin_add (GST_BIN (video_bin), videosink);
619 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
621 gst_bin_add (GST_BIN (pipeline), video_bin);
623 pad = gst_element_get_static_pad (v_queue, "sink");
624 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
625 gst_object_unref (pad);
627 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
630 seekable = gst_element_get_static_pad (a_decoder, "src");
631 seekable_pads = g_list_prepend (seekable_pads, seekable);
632 rate_pads = g_list_prepend (rate_pads, seekable);
634 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
641 make_mp3_pipeline (const gchar * location)
643 GstElement *pipeline;
644 GstElement *src, *parser, *decoder, *audiosink, *queue;
647 pipeline = gst_pipeline_new ("app");
649 src = gst_element_factory_make_or_warn (SOURCE, "src");
650 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
651 decoder = gst_element_factory_make_or_warn ("mad", "dec");
652 queue = gst_element_factory_make_or_warn ("queue", "queue");
653 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
655 seekable_elements = g_list_prepend (seekable_elements, audiosink);
657 g_object_set (G_OBJECT (src), "location", location, NULL);
658 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
660 gst_bin_add (GST_BIN (pipeline), src);
661 gst_bin_add (GST_BIN (pipeline), parser);
662 gst_bin_add (GST_BIN (pipeline), decoder);
663 gst_bin_add (GST_BIN (pipeline), queue);
664 gst_bin_add (GST_BIN (pipeline), audiosink);
666 gst_element_link (src, parser);
667 gst_element_link (parser, decoder);
668 gst_element_link (decoder, queue);
669 gst_element_link (queue, audiosink);
671 seekable = gst_element_get_static_pad (queue, "src");
672 seekable_pads = g_list_prepend (seekable_pads, seekable);
673 rate_pads = g_list_prepend (rate_pads, seekable);
675 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
681 make_avi_pipeline (const gchar * location)
683 GstElement *pipeline, *audio_bin, *video_bin;
684 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
685 GstElement *a_queue = NULL, *v_queue = NULL;
688 pipeline = gst_pipeline_new ("app");
690 src = gst_element_factory_make_or_warn (SOURCE, "src");
691 g_object_set (G_OBJECT (src), "location", location, NULL);
693 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
694 seekable_elements = g_list_prepend (seekable_elements, demux);
696 gst_bin_add (GST_BIN (pipeline), src);
697 gst_bin_add (GST_BIN (pipeline), demux);
698 gst_element_link (src, demux);
700 audio_bin = gst_bin_new ("a_decoder_bin");
701 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
702 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
703 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
704 gst_element_link (a_decoder, a_queue);
705 gst_element_link (a_queue, audiosink);
706 gst_bin_add (GST_BIN (audio_bin), a_decoder);
707 gst_bin_add (GST_BIN (audio_bin), a_queue);
708 gst_bin_add (GST_BIN (audio_bin), audiosink);
709 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
711 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
714 seekable = gst_element_get_static_pad (a_queue, "src");
715 seekable_pads = g_list_prepend (seekable_pads, seekable);
716 rate_pads = g_list_prepend (rate_pads, seekable);
718 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
721 video_bin = gst_bin_new ("v_decoder_bin");
722 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
723 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
724 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
725 gst_element_link (v_decoder, v_queue);
726 gst_element_link (v_queue, videosink);
727 gst_bin_add (GST_BIN (video_bin), v_decoder);
728 gst_bin_add (GST_BIN (video_bin), v_queue);
729 gst_bin_add (GST_BIN (video_bin), videosink);
731 gst_element_set_state (video_bin, GST_STATE_PAUSED);
733 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
736 seekable = gst_element_get_static_pad (v_queue, "src");
737 seekable_pads = g_list_prepend (seekable_pads, seekable);
738 rate_pads = g_list_prepend (rate_pads, seekable);
740 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
747 make_mpeg_pipeline (const gchar * location)
749 GstElement *pipeline, *audio_bin, *video_bin;
750 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
751 GstElement *audiosink, *videosink;
752 GstElement *a_queue, *v_queue;
756 pipeline = gst_pipeline_new ("app");
758 src = gst_element_factory_make_or_warn (SOURCE, "src");
759 g_object_set (G_OBJECT (src), "location", location, NULL);
761 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
762 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
764 gst_bin_add (GST_BIN (pipeline), src);
765 gst_bin_add (GST_BIN (pipeline), demux);
766 gst_element_link (src, demux);
768 audio_bin = gst_bin_new ("a_decoder_bin");
769 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
770 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
771 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
772 gst_bin_add (GST_BIN (audio_bin), a_decoder);
773 gst_bin_add (GST_BIN (audio_bin), a_queue);
774 gst_bin_add (GST_BIN (audio_bin), audiosink);
776 gst_element_link (a_decoder, a_queue);
777 gst_element_link (a_queue, audiosink);
779 gst_bin_add (GST_BIN (pipeline), audio_bin);
781 pad = gst_element_get_static_pad (a_decoder, "sink");
782 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
783 gst_object_unref (pad);
785 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
788 video_bin = gst_bin_new ("v_decoder_bin");
789 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
790 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
791 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
792 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
794 gst_bin_add (GST_BIN (video_bin), v_decoder);
795 gst_bin_add (GST_BIN (video_bin), v_queue);
796 gst_bin_add (GST_BIN (video_bin), v_filter);
797 gst_bin_add (GST_BIN (video_bin), videosink);
799 gst_element_link (v_decoder, v_queue);
800 gst_element_link (v_queue, v_filter);
801 gst_element_link (v_filter, videosink);
803 gst_bin_add (GST_BIN (pipeline), video_bin);
805 pad = gst_element_get_static_pad (v_decoder, "sink");
806 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
807 gst_object_unref (pad);
809 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
812 seekable = gst_element_get_static_pad (v_filter, "src");
813 seekable_pads = g_list_prepend (seekable_pads, seekable);
814 rate_pads = g_list_prepend (rate_pads, seekable);
816 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
823 make_mpegnt_pipeline (const gchar * location)
825 GstElement *pipeline, *audio_bin, *video_bin;
826 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
827 GstElement *audiosink, *videosink;
831 pipeline = gst_pipeline_new ("app");
833 src = gst_element_factory_make_or_warn (SOURCE, "src");
834 g_object_set (G_OBJECT (src), "location", location, NULL);
836 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
837 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
839 seekable_elements = g_list_prepend (seekable_elements, demux);
841 gst_bin_add (GST_BIN (pipeline), src);
842 gst_bin_add (GST_BIN (pipeline), demux);
843 gst_element_link (src, demux);
845 audio_bin = gst_bin_new ("a_decoder_bin");
846 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
847 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
848 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
849 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
850 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
851 gst_element_link (a_decoder, a_queue);
852 gst_element_link (a_queue, audiosink);
853 gst_bin_add (GST_BIN (audio_bin), a_decoder);
854 gst_bin_add (GST_BIN (audio_bin), a_queue);
855 gst_bin_add (GST_BIN (audio_bin), audiosink);
857 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
860 seekable = gst_element_get_static_pad (a_queue, "src");
861 seekable_pads = g_list_prepend (seekable_pads, seekable);
862 rate_pads = g_list_prepend (rate_pads, seekable);
864 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
867 video_bin = gst_bin_new ("v_decoder_bin");
868 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
869 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
870 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
871 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
873 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
875 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
878 seekable = gst_element_get_static_pad (v_decoder, "src");
879 seekable_pads = g_list_prepend (seekable_pads, seekable);
880 rate_pads = g_list_prepend (rate_pads, seekable);
882 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
889 playerbin_set_uri (GstElement * player, const gchar * location)
893 /* Add "file://" prefix for convenience */
894 if (g_str_has_prefix (location, "/")) {
895 uri = g_strconcat ("file://", location, NULL);
896 g_object_set (G_OBJECT (player), "uri", uri, NULL);
899 g_object_set (G_OBJECT (player), "uri", location, NULL);
904 construct_playerbin (const gchar * name, const gchar * location)
908 player = gst_element_factory_make (name, "player");
911 playerbin_set_uri (player, location);
913 seekable_elements = g_list_prepend (seekable_elements, player);
915 /* force element seeking on this pipeline */
922 make_playerbin_pipeline (const gchar * location)
924 return construct_playerbin ("playbin", location);
928 make_playerbin2_pipeline (const gchar * location)
930 GstElement *pipeline = construct_playerbin ("playbin2", location);
932 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
933 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
938 #ifndef GST_DISABLE_PARSE
940 make_parselaunch_pipeline (const gchar * description)
942 GstElement *pipeline;
943 GError *error = NULL;
945 pipeline = gst_parse_launch (description, &error);
947 seekable_elements = g_list_prepend (seekable_elements, pipeline);
958 GstElement *(*func) (const gchar * location);
962 static Pipeline pipelines[] = {
963 {"mp3", make_mp3_pipeline},
964 {"avi", make_avi_pipeline},
965 {"mpeg1", make_mpeg_pipeline},
966 {"mpegparse", make_parse_pipeline},
967 {"vorbis", make_vorbis_pipeline},
968 {"theora", make_theora_pipeline},
969 {"ogg/v/t", make_vorbis_theora_pipeline},
970 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
971 {"sid", make_sid_pipeline},
972 {"flac", make_flac_pipeline},
973 {"wav", make_wav_pipeline},
974 {"mod", make_mod_pipeline},
975 {"dv", make_dv_pipeline},
976 {"mpeg1nothreads", make_mpegnt_pipeline},
977 {"playerbin", make_playerbin_pipeline},
978 #ifndef GST_DISABLE_PARSE
979 {"parse-launch", make_parselaunch_pipeline},
981 {"playerbin2", make_playerbin2_pipeline},
985 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
987 /* ui callbacks and helpers */
990 format_value (GtkScale * scale, gdouble value)
996 real = value * duration / 100;
997 seconds = (gint64) real / GST_SECOND;
998 subseconds = (gint64) real / (GST_SECOND / 100);
1000 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1001 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1007 const GstFormat format;
1011 static seek_format seek_formats[] = {
1012 {"tim", GST_FORMAT_TIME},
1013 {"byt", GST_FORMAT_BYTES},
1014 {"buf", GST_FORMAT_BUFFERS},
1015 {"def", GST_FORMAT_DEFAULT},
1019 G_GNUC_UNUSED static void
1022 GList *walk = rate_pads;
1025 GstPad *pad = GST_PAD (walk->data);
1028 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1029 while (seek_formats[i].name) {
1033 format = seek_formats[i].format;
1035 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
1037 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1039 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1044 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1046 walk = g_list_next (walk);
1050 G_GNUC_UNUSED static void
1051 query_positions_elems (void)
1053 GList *walk = seekable_elements;
1056 GstElement *element = GST_ELEMENT (walk->data);
1059 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1060 while (seek_formats[i].name) {
1061 gint64 position, total;
1064 format = seek_formats[i].format;
1066 if (gst_element_query_position (element, &format, &position) &&
1067 gst_element_query_duration (element, &format, &total)) {
1068 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1069 seek_formats[i].name, position, total);
1071 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1076 g_print (" %s\n", GST_ELEMENT_NAME (element));
1078 walk = g_list_next (walk);
1082 G_GNUC_UNUSED static void
1083 query_positions_pads (void)
1085 GList *walk = seekable_pads;
1088 GstPad *pad = GST_PAD (walk->data);
1091 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1092 while (seek_formats[i].name) {
1094 gint64 position, total;
1096 format = seek_formats[i].format;
1098 if (gst_pad_query_position (pad, &format, &position) &&
1099 gst_pad_query_duration (pad, &format, &total)) {
1100 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1101 seek_formats[i].name, position, total);
1103 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1109 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1111 walk = g_list_next (walk);
1115 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1116 gpointer user_data);
1117 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1118 gpointer user_data);
1119 static void seek_cb (GtkWidget * widget);
1122 set_scale (gdouble value)
1124 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1126 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1128 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1129 gtk_adjustment_set_value (adjustment, value);
1130 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1132 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1134 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1136 gtk_widget_queue_draw (hscale);
1140 update_fill (gpointer data)
1143 if (seekable_elements) {
1144 GstElement *element = GST_ELEMENT (seekable_elements->data);
1147 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1148 if (gst_element_query (element, query)) {
1155 gst_query_parse_buffering_percent (query, &busy, &percent);
1157 if (buffering && !busy) {
1158 /* if we were buffering but not anymore, start playing */
1159 if (state == GST_STATE_PLAYING && !is_live) {
1160 fprintf (stderr, "setting pipeline to PLAYING ...\n");
1161 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1162 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1163 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id,
1166 state = GST_STATE_PAUSED;
1170 gst_query_parse_buffering_range (query, &format, &start, &stop, NULL);
1172 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1176 fill = 100.0 * stop / GST_FORMAT_PERCENT_MAX;
1180 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1182 gst_query_unref (query);
1189 update_scale (gpointer data)
1191 GstFormat format = GST_FORMAT_TIME;
1197 if (seekable_elements) {
1198 GstElement *element = GST_ELEMENT (seekable_elements->data);
1200 gst_element_query_position (element, &format, &position);
1201 gst_element_query_duration (element, &format, &duration);
1204 if (seekable_pads) {
1205 GstPad *pad = GST_PAD (seekable_pads->data);
1207 gst_pad_query_position (pad, &format, &position);
1208 gst_pad_query_duration (pad, &format, &duration);
1214 query_positions_elems ();
1216 query_positions_pads ();
1220 if (position >= duration)
1221 duration = position;
1224 set_scale (position * 100.0 / duration);
1227 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1228 if (pipeline_type == 16) {
1229 g_object_notify (G_OBJECT (pipeline), "volume");
1235 static void do_seek (GtkWidget * widget);
1236 static void connect_bus_signals (GstElement * pipeline);
1237 static void set_update_scale (gboolean active);
1238 static void set_update_fill (gboolean active);
1241 end_scrub (GtkWidget * widget)
1243 GST_DEBUG ("end scrub, PAUSE");
1244 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1245 seek_timeout_id = 0;
1251 send_event (GstEvent * event)
1253 gboolean res = FALSE;
1256 GList *walk = seekable_pads;
1259 GstPad *seekable = GST_PAD (walk->data);
1261 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1263 gst_event_ref (event);
1264 res = gst_pad_send_event (seekable, event);
1266 walk = g_list_next (walk);
1269 GList *walk = seekable_elements;
1272 GstElement *seekable = GST_ELEMENT (walk->data);
1274 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1276 gst_event_ref (event);
1277 res = gst_element_send_event (seekable, event);
1279 walk = g_list_next (walk);
1282 gst_event_unref (event);
1287 do_seek (GtkWidget * widget)
1290 gboolean res = FALSE;
1294 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
1298 flags |= GST_SEEK_FLAG_FLUSH;
1300 flags |= GST_SEEK_FLAG_ACCURATE;
1302 flags |= GST_SEEK_FLAG_KEY_UNIT;
1304 flags |= GST_SEEK_FLAG_SEGMENT;
1306 flags |= GST_SEEK_FLAG_SKIP;
1309 s_event = gst_event_new_seek (rate,
1310 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1311 GST_CLOCK_TIME_NONE);
1312 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1313 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1315 s_event = gst_event_new_seek (rate,
1316 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1317 GST_SEEK_TYPE_SET, real);
1318 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1319 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1322 res = send_event (s_event);
1326 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1328 set_update_scale (TRUE);
1331 g_print ("seek failed\n");
1332 set_update_scale (TRUE);
1337 seek_cb (GtkWidget * widget)
1339 /* If the timer hasn't expired yet, then the pipeline is running */
1340 if (play_scrub && seek_timeout_id != 0) {
1341 GST_DEBUG ("do scrub seek, PAUSED");
1342 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1345 GST_DEBUG ("do seek");
1349 GST_DEBUG ("do scrub seek, PLAYING");
1350 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1352 if (seek_timeout_id == 0) {
1354 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1360 set_update_fill (gboolean active)
1362 GST_DEBUG ("fill scale is %d", active);
1367 g_timeout_add (FILL_INTERVAL, (GtkFunction) update_fill, pipeline);
1371 g_source_remove (fill_id);
1378 set_update_scale (gboolean active)
1381 GST_DEBUG ("update scale is %d", active);
1384 if (update_id == 0) {
1386 g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
1390 g_source_remove (update_id);
1397 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1399 if (event->type != GDK_BUTTON_PRESS)
1402 set_update_scale (FALSE);
1404 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1405 GST_DEBUG ("start scrub seek, PAUSE");
1406 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1409 if (changed_id == 0 && flush_seek && scrub) {
1410 changed_id = gtk_signal_connect (GTK_OBJECT (hscale),
1411 "value_changed", G_CALLBACK (seek_cb), pipeline);
1418 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1421 g_signal_handler_disconnect (GTK_OBJECT (hscale), changed_id);
1425 if (!flush_seek || !scrub) {
1426 GST_DEBUG ("do final seek");
1430 if (seek_timeout_id != 0) {
1431 g_source_remove (seek_timeout_id);
1432 seek_timeout_id = 0;
1433 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1435 if (state == GST_STATE_PAUSED) {
1436 GST_DEBUG ("stop scrub seek, PAUSED");
1437 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1440 if (state == GST_STATE_PLAYING) {
1441 GST_DEBUG ("stop scrub seek, PLAYING");
1442 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1450 play_cb (GtkButton * button, gpointer data)
1452 GstStateChangeReturn ret;
1454 if (state != GST_STATE_PLAYING) {
1455 g_print ("PLAY pipeline\n");
1456 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1458 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1460 case GST_STATE_CHANGE_FAILURE:
1462 case GST_STATE_CHANGE_NO_PREROLL:
1468 state = GST_STATE_PLAYING;
1469 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1475 g_print ("PLAY failed\n");
1476 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1481 pause_cb (GtkButton * button, gpointer data)
1483 if (state != GST_STATE_PAUSED) {
1484 GstStateChangeReturn ret;
1486 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1487 g_print ("PAUSE pipeline\n");
1488 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1490 case GST_STATE_CHANGE_FAILURE:
1492 case GST_STATE_CHANGE_NO_PREROLL:
1499 state = GST_STATE_PAUSED;
1500 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1506 g_print ("PAUSE failed\n");
1507 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1512 stop_cb (GtkButton * button, gpointer data)
1514 if (state != GST_STATE_READY) {
1515 GstStateChangeReturn ret;
1517 g_print ("READY pipeline\n");
1518 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1520 ret = gst_element_set_state (pipeline, GST_STATE_READY);
1521 if (ret == GST_STATE_CHANGE_FAILURE)
1524 state = GST_STATE_READY;
1525 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1529 set_update_scale (FALSE);
1531 set_update_fill (FALSE);
1533 if (pipeline_type == 16)
1534 clear_streams (pipeline);
1537 /* if one uses parse_launch, play, stop and play again it fails as all the
1538 * pads after the demuxer can't be reconnected
1540 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1541 gst_element_set_state (pipeline, GST_STATE_NULL);
1542 gst_object_unref (pipeline);
1544 g_list_free (seekable_elements);
1545 seekable_elements = NULL;
1546 g_list_free (seekable_pads);
1547 seekable_pads = NULL;
1548 g_list_free (rate_pads);
1551 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1552 g_assert (pipeline);
1553 gst_element_set_state (pipeline, GST_STATE_READY);
1554 connect_bus_signals (pipeline);
1562 g_print ("STOP failed\n");
1563 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1568 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1570 accurate_seek = gtk_toggle_button_get_active (button);
1574 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1576 keyframe_seek = gtk_toggle_button_get_active (button);
1580 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1582 loop_seek = gtk_toggle_button_get_active (button);
1583 if (state == GST_STATE_PLAYING) {
1589 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1591 flush_seek = gtk_toggle_button_get_active (button);
1595 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1597 scrub = gtk_toggle_button_get_active (button);
1601 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1603 play_scrub = gtk_toggle_button_get_active (button);
1607 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1609 skip_seek = gtk_toggle_button_get_active (button);
1610 if (state == GST_STATE_PLAYING) {
1616 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1618 gboolean res = FALSE;
1622 rate = gtk_spin_button_get_value (button);
1626 flags |= GST_SEEK_FLAG_FLUSH;
1628 flags |= GST_SEEK_FLAG_SEGMENT;
1630 flags |= GST_SEEK_FLAG_ACCURATE;
1632 flags |= GST_SEEK_FLAG_KEY_UNIT;
1634 flags |= GST_SEEK_FLAG_SKIP;
1637 s_event = gst_event_new_seek (rate,
1638 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1639 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1641 s_event = gst_event_new_seek (rate,
1642 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1643 GST_SEEK_TYPE_SET, position);
1646 GST_DEBUG ("rate changed to %lf", rate);
1648 res = send_event (s_event);
1652 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1655 g_print ("seek failed\n");
1659 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1663 g_object_get (pipeline, "flags", &flags, NULL);
1665 flags |= (1 << num);
1667 flags &= ~(1 << num);
1668 g_object_set (pipeline, "flags", flags, NULL);
1672 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1676 state = gtk_toggle_button_get_active (button);
1677 update_flag (pipeline, 3, state);
1678 gtk_widget_set_sensitive (vis_combo, state);
1682 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1686 state = gtk_toggle_button_get_active (button);
1687 update_flag (pipeline, 1, state);
1688 gtk_widget_set_sensitive (audio_combo, state);
1692 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1696 state = gtk_toggle_button_get_active (button);
1697 update_flag (pipeline, 0, state);
1698 gtk_widget_set_sensitive (video_combo, state);
1702 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1706 state = gtk_toggle_button_get_active (button);
1707 update_flag (pipeline, 2, state);
1708 gtk_widget_set_sensitive (text_combo, state);
1712 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1716 mute = gtk_toggle_button_get_active (button);
1717 g_object_set (pipeline, "mute", mute, NULL);
1721 clear_streams (GstElement * pipeline)
1725 /* remove previous info */
1726 for (i = 0; i < n_video; i++)
1727 gtk_combo_box_remove_text (GTK_COMBO_BOX (video_combo), 0);
1728 for (i = 0; i < n_audio; i++)
1729 gtk_combo_box_remove_text (GTK_COMBO_BOX (audio_combo), 0);
1730 for (i = 0; i < n_text; i++)
1731 gtk_combo_box_remove_text (GTK_COMBO_BOX (text_combo), 0);
1733 n_audio = n_video = n_text = 0;
1734 gtk_widget_set_sensitive (video_combo, FALSE);
1735 gtk_widget_set_sensitive (audio_combo, FALSE);
1736 gtk_widget_set_sensitive (text_combo, FALSE);
1738 need_streams = TRUE;
1742 update_streams (GstPipeline * pipeline)
1746 if (pipeline_type == 16 && need_streams) {
1752 /* remove previous info */
1753 clear_streams (GST_ELEMENT_CAST (pipeline));
1755 /* here we get and update the different streams detected by playbin2 */
1756 g_object_get (pipeline, "n-video", &n_video, NULL);
1757 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1758 g_object_get (pipeline, "n-text", &n_text, NULL);
1760 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1763 for (i = 0; i < n_video; i++) {
1764 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1766 str = gst_structure_to_string ((GstStructure *) tags);
1767 g_print ("video %d: %s\n", i, str);
1770 /* find good name for the label */
1771 name = g_strdup_printf ("video %d", i + 1);
1772 gtk_combo_box_append_text (GTK_COMBO_BOX (video_combo), name);
1775 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1776 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1777 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1780 for (i = 0; i < n_audio; i++) {
1781 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1783 str = gst_structure_to_string ((GstStructure *) tags);
1784 g_print ("audio %d: %s\n", i, str);
1787 /* find good name for the label */
1788 name = g_strdup_printf ("audio %d", i + 1);
1789 gtk_combo_box_append_text (GTK_COMBO_BOX (audio_combo), name);
1792 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1793 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1794 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1797 for (i = 0; i < n_text; i++) {
1798 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1802 const GValue *value;
1804 str = gst_structure_to_string ((GstStructure *) tags);
1805 g_print ("text %d: %s\n", i, str);
1808 /* get the language code if we can */
1809 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1810 if (value && G_VALUE_HOLDS_STRING (value)) {
1811 name = g_strdup_printf ("text %s", g_value_get_string (value));
1814 /* find good name for the label if we didn't use a tag */
1816 name = g_strdup_printf ("text %d", i + 1);
1818 gtk_combo_box_append_text (GTK_COMBO_BOX (text_combo), name);
1821 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1822 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1823 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1825 need_streams = FALSE;
1830 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1834 active = gtk_combo_box_get_active (combo);
1836 g_print ("setting current video track %d\n", active);
1837 g_object_set (pipeline, "current-video", active, NULL);
1841 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1845 active = gtk_combo_box_get_active (combo);
1847 g_print ("setting current audio track %d\n", active);
1848 g_object_set (pipeline, "current-audio", active, NULL);
1852 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1856 active = gtk_combo_box_get_active (combo);
1858 g_print ("setting current text track %d\n", active);
1859 g_object_set (pipeline, "current-text", active, NULL);
1863 filter_features (GstPluginFeature * feature, gpointer data)
1865 GstElementFactory *f;
1867 if (!GST_IS_ELEMENT_FACTORY (feature))
1869 f = GST_ELEMENT_FACTORY (feature);
1870 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1877 init_visualization_features (void)
1881 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1883 list = gst_registry_feature_filter (gst_registry_get_default (),
1884 filter_features, FALSE, NULL);
1886 for (walk = list; walk; walk = g_list_next (walk)) {
1890 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1891 name = gst_element_factory_get_longname (entry.factory);
1893 g_array_append_val (vis_entries, entry);
1894 gtk_combo_box_append_text (GTK_COMBO_BOX (vis_combo), name);
1896 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1900 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1904 GstElement *element;
1906 /* get the selected index and get the factory for this index */
1907 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1908 if (vis_entries->len > 0) {
1909 entry = &g_array_index (vis_entries, VisEntry, index);
1911 /* create an instance of the element from the factory */
1912 element = gst_element_factory_create (entry->factory, NULL);
1916 /* set vis plugin for playbin2 */
1917 g_object_set (pipeline, "vis-plugin", element, NULL);
1922 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1926 volume = gtk_spin_button_get_value (button);
1928 g_object_set (pipeline, "volume", volume, NULL);
1932 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
1934 gdouble cur_volume, new_volume;
1936 g_object_get (pipeline, "volume", &new_volume, NULL);
1937 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
1938 if (fabs (cur_volume - new_volume) > 0.001) {
1939 g_signal_handlers_block_by_func (volume_spinbutton,
1940 volume_spinbutton_changed_cb, pipeline);
1941 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
1942 g_signal_handlers_unblock_by_func (volume_spinbutton,
1943 volume_spinbutton_changed_cb, pipeline);
1948 shot_cb (GtkButton * button, gpointer data)
1953 /* convert to our desired format (RGB24) */
1954 caps = gst_caps_new_simple ("video/x-raw-rgb",
1955 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
1956 /* Note: we don't ask for a specific width/height here, so that
1957 * videoscale can adjust dimensions from a non-1/1 pixel aspect
1958 * ratio to a 1/1 pixel-aspect-ratio */
1959 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
1960 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
1961 "red_mask", G_TYPE_INT, 0xff0000,
1962 "green_mask", G_TYPE_INT, 0x00ff00,
1963 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
1965 /* convert the latest frame to the requested format */
1966 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
1967 gst_caps_unref (caps);
1975 GError *error = NULL;
1977 /* get the snapshot buffer format now. We set the caps on the appsink so
1978 * that it can only be an rgb buffer. The only thing we have not specified
1979 * on the caps is the height, which is dependant on the pixel-aspect-ratio
1980 * of the source material */
1981 caps = GST_BUFFER_CAPS (buffer);
1983 g_warning ("could not get snapshot format\n");
1986 s = gst_caps_get_structure (caps, 0);
1988 /* we need to get the final caps on the buffer to get the size */
1989 res = gst_structure_get_int (s, "width", &width);
1990 res |= gst_structure_get_int (s, "height", &height);
1992 g_warning ("could not get snapshot dimension\n");
1996 /* create pixmap from buffer and save, gstreamer video buffers have a stride
1997 * that is rounded up to the nearest multiple of 4 */
1998 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
1999 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2000 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2002 /* save the pixbuf */
2003 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2006 gst_buffer_unref (buffer);
2011 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2013 const GstStructure *s;
2015 s = gst_message_get_structure (message);
2016 g_print ("message from \"%s\" (%s): ",
2017 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2018 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2022 sstr = gst_structure_to_string (s);
2023 g_print ("%s\n", sstr);
2026 g_print ("no message details\n");
2031 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2033 GST_DEBUG ("async done");
2034 /* when we get ASYNC_DONE we can query position, duration and other
2036 update_scale (pipeline);
2038 /* update the available streams */
2039 update_streams (pipeline);
2043 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2045 const GstStructure *s;
2047 s = gst_message_get_structure (message);
2049 /* We only care about state changed on the pipeline */
2050 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2051 GstState old, new, pending;
2053 gst_message_parse_state_changed (message, &old, &new, &pending);
2055 /* When state of the pipeline changes to paused or playing we start updating scale */
2056 if (new == GST_STATE_PLAYING) {
2057 set_update_scale (TRUE);
2059 set_update_scale (FALSE);
2065 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2072 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2073 gst_message_parse_segment_done (message, &format, &position);
2074 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2077 /* in the segment-done callback we never flush as this would not make sense
2078 * for seamless playback. */
2080 flags |= GST_SEEK_FLAG_SEGMENT;
2082 flags |= GST_SEEK_FLAG_SKIP;
2084 s_event = gst_event_new_seek (rate,
2085 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2086 GST_SEEK_TYPE_SET, duration);
2088 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2089 rate, GST_TIME_ARGS (duration));
2091 res = send_event (s_event);
2093 g_print ("segment seek failed\n");
2096 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2099 do_stream_buffering (gint percent)
2103 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2104 bufstr = g_strdup_printf ("Buffering...%d", percent);
2105 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2108 if (percent == 100) {
2109 /* a 100% message means buffering is done */
2111 /* if the desired state is playing, go back */
2112 if (state == GST_STATE_PLAYING) {
2113 /* no state management needed for live pipelines */
2115 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2116 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2118 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2119 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2122 /* buffering busy */
2123 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2124 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2126 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2127 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2135 do_download_buffering (gint percent)
2137 if (!buffering && percent < 100) {
2142 bufstr = g_strdup_printf ("Downloading...");
2143 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2146 /* once we get a buffering message, we'll do the fill update */
2147 set_update_fill (TRUE);
2149 if (state == GST_STATE_PLAYING && !is_live) {
2150 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2151 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2157 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2161 gst_message_parse_buffering (message, &percent);
2163 /* get more stats */
2164 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2168 case GST_BUFFERING_DOWNLOAD:
2169 do_download_buffering (percent);
2171 case GST_BUFFERING_LIVE:
2172 case GST_BUFFERING_TIMESHIFT:
2173 case GST_BUFFERING_STREAM:
2174 do_stream_buffering (percent);
2180 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2182 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2184 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2185 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2190 static guint embed_xid = 0;
2192 static GstBusSyncReply
2193 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2195 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
2196 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
2197 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2199 g_print ("got prepare-xwindow-id\n");
2201 embed_xid = GDK_WINDOW_XID (GDK_WINDOW (video_window->window));
2204 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2205 "force-aspect-ratio")) {
2206 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2209 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
2212 return GST_BUS_PASS;
2217 handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
2219 if (state < GST_STATE_PAUSED) {
2220 gdk_draw_rectangle (widget->window, widget->style->black_gc, TRUE,
2221 0, 0, widget->allocation.width, widget->allocation.height);
2228 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2230 message_received (bus, message, data);
2232 /* Set new uri for playerbins and continue playback */
2233 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2234 stop_cb (NULL, NULL);
2235 l = g_list_next (l);
2237 playerbin_set_uri (GST_ELEMENT (data), l->data);
2238 play_cb (NULL, NULL);
2244 connect_bus_signals (GstElement * pipeline)
2246 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2249 /* handle prepare-xwindow-id element message synchronously */
2250 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2254 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2256 g_signal_connect (bus, "message::state-changed",
2257 (GCallback) msg_state_changed, pipeline);
2258 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2260 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2263 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2265 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2267 g_signal_connect (bus, "message::error", (GCallback) message_received,
2269 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2271 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2272 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2274 g_signal_connect (bus, "message::element", (GCallback) message_received,
2276 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2278 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2281 gst_object_unref (bus);
2284 /* Return GList of paths described in location string */
2286 handle_wildcards (const gchar * location)
2289 gchar *path = g_path_get_dirname (location);
2290 gchar *pattern = g_path_get_basename (location);
2291 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2292 GDir *dir = g_dir_open (path, 0, NULL);
2295 g_print ("matching %s from %s\n", pattern, path);
2298 g_print ("opening directory %s failed\n", path);
2302 while ((name = g_dir_read_name (dir)) != NULL) {
2303 if (g_pattern_match_string (pspec, name)) {
2304 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2305 g_print (" found clip %s\n", name);
2311 g_pattern_spec_free (pspec);
2319 delete_event_cb (void)
2321 stop_cb (NULL, NULL);
2326 print_usage (int argc, char **argv)
2330 g_print ("usage: %s <type> <filename>\n", argv[0]);
2331 g_print (" possible types:\n");
2333 for (i = 0; i < NUM_TYPES; i++) {
2334 g_print (" %d = %s\n", i, pipelines[i].name);
2339 main (int argc, char **argv)
2341 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2342 *flagtable, *boxes2;
2343 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2344 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2345 GtkWidget *scrub_checkbox, *play_scrub_checkbox, *rate_spinbutton;
2346 GtkWidget *rate_label, *volume_label;
2348 GOptionEntry options[] = {
2349 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2350 "Show pad stats", NULL},
2351 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2352 "Seek on elements instead of pads", NULL},
2353 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2354 "Verbose properties", NULL},
2357 GOptionContext *ctx;
2360 if (!g_thread_supported ())
2361 g_thread_init (NULL);
2363 ctx = g_option_context_new ("- test seeking in gsteamer");
2364 g_option_context_add_main_entries (ctx, options, NULL);
2365 g_option_context_add_group (ctx, gst_init_get_option_group ());
2366 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2368 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2369 g_print ("Error initializing: %s\n", err->message);
2373 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2376 print_usage (argc, argv);
2380 pipeline_type = atoi (argv[1]);
2382 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2383 print_usage (argc, argv);
2387 pipeline_spec = argv[2];
2389 if (g_strrstr (pipeline_spec, "*") != NULL ||
2390 g_strrstr (pipeline_spec, "?") != NULL) {
2391 paths = handle_wildcards (pipeline_spec);
2393 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2397 g_print ("opening %s failed\n", pipeline_spec);
2403 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2404 g_assert (pipeline);
2406 /* initialize gui elements ... */
2407 tips = gtk_tooltips_new ();
2408 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2409 video_window = gtk_drawing_area_new ();
2410 g_signal_connect (G_OBJECT (video_window), "expose-event",
2411 G_CALLBACK (handle_expose_cb), NULL);
2412 gtk_widget_set_double_buffered (video_window, FALSE);
2413 statusbar = gtk_statusbar_new ();
2414 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2415 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2416 hbox = gtk_hbox_new (FALSE, 0);
2417 vbox = gtk_vbox_new (FALSE, 0);
2418 flagtable = gtk_table_new (4, 2, FALSE);
2419 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2421 /* media controls */
2422 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2423 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2424 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2427 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2428 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2429 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2430 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2431 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2432 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2433 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2434 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2435 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2436 rate_label = gtk_label_new ("Rate");
2438 gtk_tooltips_set_tip (tips, accurate_checkbox,
2439 "accurate position is requested, this might be considerably slower for some formats",
2441 gtk_tooltips_set_tip (tips, key_checkbox,
2442 "seek to the nearest keyframe. This might be faster but less accurate",
2444 gtk_tooltips_set_tip (tips, loop_checkbox, "loop playback", NULL);
2445 gtk_tooltips_set_tip (tips, flush_checkbox, "flush pipeline after seeking",
2447 gtk_tooltips_set_tip (tips, rate_spinbutton, "define the playback rate, "
2448 "negative value trigger reverse playback", NULL);
2449 gtk_tooltips_set_tip (tips, scrub_checkbox, "show images while seeking",
2451 gtk_tooltips_set_tip (tips, play_scrub_checkbox, "play video while seeking",
2453 gtk_tooltips_set_tip (tips, skip_checkbox,
2454 "Skip frames while playing at high frame rates", NULL);
2456 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2457 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2459 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2463 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
2464 hscale = gtk_hscale_new (adjustment);
2465 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2466 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
2467 #if GTK_CHECK_VERSION(2,12,0)
2468 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2469 gtk_range_set_fill_level (GTK_RANGE (hscale), 100.0);
2471 gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);
2473 gtk_signal_connect (GTK_OBJECT (hscale),
2474 "button_press_event", G_CALLBACK (start_seek), pipeline);
2475 gtk_signal_connect (GTK_OBJECT (hscale),
2476 "button_release_event", G_CALLBACK (stop_seek), pipeline);
2477 gtk_signal_connect (GTK_OBJECT (hscale),
2478 "format_value", G_CALLBACK (format_value), pipeline);
2480 if (pipeline_type == 16) {
2481 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2482 panel = gtk_hbox_new (FALSE, 0);
2483 video_combo = gtk_combo_box_new_text ();
2484 audio_combo = gtk_combo_box_new_text ();
2485 text_combo = gtk_combo_box_new_text ();
2486 gtk_widget_set_sensitive (video_combo, FALSE);
2487 gtk_widget_set_sensitive (audio_combo, FALSE);
2488 gtk_widget_set_sensitive (text_combo, FALSE);
2489 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2490 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2491 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2492 g_signal_connect (G_OBJECT (video_combo), "changed",
2493 G_CALLBACK (video_combo_cb), pipeline);
2494 g_signal_connect (G_OBJECT (audio_combo), "changed",
2495 G_CALLBACK (audio_combo_cb), pipeline);
2496 g_signal_connect (G_OBJECT (text_combo), "changed",
2497 G_CALLBACK (text_combo_cb), pipeline);
2498 /* playbin2 panel for flag checkboxes and volume/mute */
2499 boxes = gtk_hbox_new (FALSE, 0);
2500 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2501 video_checkbox = gtk_check_button_new_with_label ("Video");
2502 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2503 text_checkbox = gtk_check_button_new_with_label ("Text");
2504 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2505 volume_label = gtk_label_new ("Volume");
2506 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2507 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2508 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2509 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2510 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2511 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2512 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2513 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
2514 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2515 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2516 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2517 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2518 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2519 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2520 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2521 G_CALLBACK (vis_toggle_cb), pipeline);
2522 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2523 G_CALLBACK (audio_toggle_cb), pipeline);
2524 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2525 G_CALLBACK (video_toggle_cb), pipeline);
2526 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2527 G_CALLBACK (text_toggle_cb), pipeline);
2528 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2529 G_CALLBACK (mute_toggle_cb), pipeline);
2530 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2531 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2532 /* playbin2 panel for snapshot */
2533 boxes2 = gtk_hbox_new (FALSE, 0);
2534 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2535 gtk_tooltips_set_tip (tips, shot_button,
2536 "save a screenshot .png in the current directory", NULL);
2537 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2539 vis_combo = gtk_combo_box_new_text ();
2540 g_signal_connect (G_OBJECT (vis_combo), "changed",
2541 G_CALLBACK (vis_combo_cb), pipeline);
2542 gtk_widget_set_sensitive (vis_combo, FALSE);
2543 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2544 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2546 /* fill the vis combo box and the array of factories */
2547 init_visualization_features ();
2549 panel = boxes = boxes2 = NULL;
2552 /* do the packing stuff ... */
2553 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2554 /* FIXME: can we avoid this for audio only? */
2555 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
2556 DEFAULT_VIDEO_HEIGHT);
2557 gtk_container_add (GTK_CONTAINER (window), vbox);
2558 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
2559 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2560 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2561 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2562 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2563 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2564 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2566 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2567 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2568 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2569 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2570 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2572 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2573 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2574 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2576 if (panel && boxes && boxes2) {
2577 expander = gtk_expander_new ("playbin2 options");
2578 pb2vbox = gtk_vbox_new (FALSE, 0);
2579 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2580 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2581 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2582 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2583 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2585 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
2586 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
2588 /* connect things ... */
2589 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
2591 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
2593 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
2595 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2596 G_CALLBACK (accurate_toggle_cb), pipeline);
2597 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2598 G_CALLBACK (key_toggle_cb), pipeline);
2599 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2600 G_CALLBACK (loop_toggle_cb), pipeline);
2601 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2602 G_CALLBACK (flush_toggle_cb), pipeline);
2603 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2604 G_CALLBACK (scrub_toggle_cb), pipeline);
2605 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2606 G_CALLBACK (play_scrub_toggle_cb), pipeline);
2607 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2608 G_CALLBACK (skip_toggle_cb), pipeline);
2609 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
2610 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
2612 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
2615 gtk_widget_show_all (window);
2618 g_signal_connect (pipeline, "deep_notify",
2619 G_CALLBACK (gst_object_default_deep_notify), NULL);
2622 connect_bus_signals (pipeline);
2625 g_print ("NULL pipeline\n");
2626 gst_element_set_state (pipeline, GST_STATE_NULL);
2628 g_print ("free pipeline\n");
2629 gst_object_unref (pipeline);
2631 g_list_foreach (paths, (GFunc) g_free, NULL);
2632 g_list_free (paths);