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;
112 static GtkWidget *rate_spinbutton;
114 static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
116 static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
117 static GtkWidget *shuttle_checkbox, *step_button;
118 static GtkWidget *shuttle_hscale;
119 static GtkAdjustment *shuttle_adjustment;
121 static GList *paths = NULL, *l = NULL;
123 /* we keep an array of the visualisation entries so that we can easily switch
124 * with the combo box index. */
127 GstElementFactory *factory;
130 static GArray *vis_entries;
132 static void clear_streams (GstElement * pipeline);
133 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
136 /* pipeline construction */
140 const gchar *padname;
147 gst_element_factory_make_or_warn (gchar * type, gchar * name)
149 GstElement *element = gst_element_factory_make (type, name);
152 g_warning ("Failed to create element %s of type %s", name, type);
159 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
162 dyn_link *connect = (dyn_link *) data;
164 padname = gst_pad_get_name (newpad);
166 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
168 gst_bin_add (GST_BIN (pipeline), connect->bin);
169 gst_pad_link (newpad, connect->target);
171 //seekable_pads = g_list_prepend (seekable_pads, newpad);
172 rate_pads = g_list_prepend (rate_pads, newpad);
178 setup_dynamic_link (GstElement * element, const gchar * padname,
179 GstPad * target, GstElement * bin)
183 connect = g_new0 (dyn_link, 1);
184 connect->padname = g_strdup (padname);
185 connect->target = target;
188 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
193 make_mod_pipeline (const gchar * location)
195 GstElement *pipeline;
196 GstElement *src, *decoder, *audiosink;
199 pipeline = gst_pipeline_new ("app");
201 src = gst_element_factory_make_or_warn (SOURCE, "src");
202 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
203 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
204 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
206 g_object_set (G_OBJECT (src), "location", location, NULL);
208 gst_bin_add (GST_BIN (pipeline), src);
209 gst_bin_add (GST_BIN (pipeline), decoder);
210 gst_bin_add (GST_BIN (pipeline), audiosink);
212 gst_element_link (src, decoder);
213 gst_element_link (decoder, audiosink);
215 seekable = gst_element_get_static_pad (decoder, "src");
216 seekable_pads = g_list_prepend (seekable_pads, seekable);
217 rate_pads = g_list_prepend (rate_pads, seekable);
219 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
225 make_dv_pipeline (const gchar * location)
227 GstElement *pipeline;
228 GstElement *src, *demux, *decoder, *audiosink, *videosink;
229 GstElement *a_queue, *v_queue;
232 pipeline = gst_pipeline_new ("app");
234 src = gst_element_factory_make_or_warn (SOURCE, "src");
235 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
236 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
237 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
238 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
239 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
240 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
242 g_object_set (G_OBJECT (src), "location", location, NULL);
244 gst_bin_add (GST_BIN (pipeline), src);
245 gst_bin_add (GST_BIN (pipeline), demux);
246 gst_bin_add (GST_BIN (pipeline), a_queue);
247 gst_bin_add (GST_BIN (pipeline), audiosink);
248 gst_bin_add (GST_BIN (pipeline), v_queue);
249 gst_bin_add (GST_BIN (pipeline), decoder);
250 gst_bin_add (GST_BIN (pipeline), videosink);
252 gst_element_link (src, demux);
253 gst_element_link (a_queue, audiosink);
254 gst_element_link (v_queue, decoder);
255 gst_element_link (decoder, videosink);
257 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
259 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
262 seekable = gst_element_get_static_pad (decoder, "src");
263 seekable_pads = g_list_prepend (seekable_pads, seekable);
264 rate_pads = g_list_prepend (rate_pads, seekable);
270 make_wav_pipeline (const gchar * location)
272 GstElement *pipeline;
273 GstElement *src, *decoder, *audiosink;
275 pipeline = gst_pipeline_new ("app");
277 src = gst_element_factory_make_or_warn (SOURCE, "src");
278 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
279 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
281 g_object_set (G_OBJECT (src), "location", location, NULL);
283 gst_bin_add (GST_BIN (pipeline), src);
284 gst_bin_add (GST_BIN (pipeline), decoder);
285 gst_bin_add (GST_BIN (pipeline), audiosink);
287 gst_element_link (src, decoder);
289 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
292 seekable_elements = g_list_prepend (seekable_elements, audiosink);
294 /* force element seeking on this pipeline */
301 make_flac_pipeline (const gchar * location)
303 GstElement *pipeline;
304 GstElement *src, *decoder, *audiosink;
307 pipeline = gst_pipeline_new ("app");
309 src = gst_element_factory_make_or_warn (SOURCE, "src");
310 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
311 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
312 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
314 g_object_set (G_OBJECT (src), "location", location, NULL);
316 gst_bin_add (GST_BIN (pipeline), src);
317 gst_bin_add (GST_BIN (pipeline), decoder);
318 gst_bin_add (GST_BIN (pipeline), audiosink);
320 gst_element_link (src, decoder);
321 gst_element_link (decoder, audiosink);
323 seekable = gst_element_get_static_pad (decoder, "src");
324 seekable_pads = g_list_prepend (seekable_pads, seekable);
325 rate_pads = g_list_prepend (rate_pads, seekable);
327 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
333 make_sid_pipeline (const gchar * location)
335 GstElement *pipeline;
336 GstElement *src, *decoder, *audiosink;
339 pipeline = gst_pipeline_new ("app");
341 src = gst_element_factory_make_or_warn (SOURCE, "src");
342 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
343 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
344 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
346 g_object_set (G_OBJECT (src), "location", location, NULL);
348 gst_bin_add (GST_BIN (pipeline), src);
349 gst_bin_add (GST_BIN (pipeline), decoder);
350 gst_bin_add (GST_BIN (pipeline), audiosink);
352 gst_element_link (src, decoder);
353 gst_element_link (decoder, audiosink);
355 seekable = gst_element_get_static_pad (decoder, "src");
356 seekable_pads = g_list_prepend (seekable_pads, seekable);
357 rate_pads = g_list_prepend (rate_pads, seekable);
359 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
365 make_parse_pipeline (const gchar * location)
367 GstElement *pipeline;
368 GstElement *src, *parser, *fakesink;
371 pipeline = gst_pipeline_new ("app");
373 src = gst_element_factory_make_or_warn (SOURCE, "src");
374 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
375 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
376 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
377 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
379 g_object_set (G_OBJECT (src), "location", location, NULL);
381 gst_bin_add (GST_BIN (pipeline), src);
382 gst_bin_add (GST_BIN (pipeline), parser);
383 gst_bin_add (GST_BIN (pipeline), fakesink);
385 gst_element_link (src, parser);
386 gst_element_link (parser, fakesink);
388 seekable = gst_element_get_static_pad (parser, "src");
389 seekable_pads = g_list_prepend (seekable_pads, seekable);
390 rate_pads = g_list_prepend (rate_pads, seekable);
392 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
398 make_vorbis_pipeline (const gchar * location)
400 GstElement *pipeline, *audio_bin;
401 GstElement *src, *demux, *decoder, *convert, *audiosink;
402 GstPad *pad, *seekable;
404 pipeline = gst_pipeline_new ("app");
406 src = gst_element_factory_make_or_warn (SOURCE, "src");
407 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
408 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
409 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
410 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
411 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
413 g_object_set (G_OBJECT (src), "location", location, NULL);
415 audio_bin = gst_bin_new ("a_decoder_bin");
417 gst_bin_add (GST_BIN (pipeline), src);
418 gst_bin_add (GST_BIN (pipeline), demux);
419 gst_bin_add (GST_BIN (audio_bin), decoder);
420 gst_bin_add (GST_BIN (audio_bin), convert);
421 gst_bin_add (GST_BIN (audio_bin), audiosink);
422 gst_bin_add (GST_BIN (pipeline), audio_bin);
424 gst_element_link (src, demux);
425 gst_element_link (decoder, convert);
426 gst_element_link (convert, audiosink);
428 pad = gst_element_get_static_pad (decoder, "sink");
429 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
430 gst_object_unref (pad);
432 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
435 seekable = gst_element_get_static_pad (decoder, "src");
436 seekable_pads = g_list_prepend (seekable_pads, seekable);
437 rate_pads = g_list_prepend (rate_pads, seekable);
439 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
445 make_theora_pipeline (const gchar * location)
447 GstElement *pipeline, *video_bin;
448 GstElement *src, *demux, *decoder, *convert, *videosink;
449 GstPad *pad, *seekable;
451 pipeline = gst_pipeline_new ("app");
453 src = gst_element_factory_make_or_warn (SOURCE, "src");
454 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
455 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
456 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
457 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
459 g_object_set (G_OBJECT (src), "location", location, NULL);
461 video_bin = gst_bin_new ("v_decoder_bin");
463 gst_bin_add (GST_BIN (pipeline), src);
464 gst_bin_add (GST_BIN (pipeline), demux);
465 gst_bin_add (GST_BIN (video_bin), decoder);
466 gst_bin_add (GST_BIN (video_bin), convert);
467 gst_bin_add (GST_BIN (video_bin), videosink);
468 gst_bin_add (GST_BIN (pipeline), video_bin);
470 gst_element_link (src, demux);
471 gst_element_link (decoder, convert);
472 gst_element_link (convert, videosink);
474 pad = gst_element_get_static_pad (decoder, "sink");
475 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
476 gst_object_unref (pad);
478 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
481 seekable = gst_element_get_static_pad (decoder, "src");
482 seekable_pads = g_list_prepend (seekable_pads, seekable);
483 rate_pads = g_list_prepend (rate_pads, seekable);
485 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
491 make_vorbis_theora_pipeline (const gchar * location)
493 GstElement *pipeline, *audio_bin, *video_bin;
494 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
495 GstElement *audiosink, *videosink;
496 GstElement *a_queue, *v_queue, *v_scale;
500 pipeline = gst_pipeline_new ("app");
502 src = gst_element_factory_make_or_warn (SOURCE, "src");
503 g_object_set (G_OBJECT (src), "location", location, NULL);
505 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
507 gst_bin_add (GST_BIN (pipeline), src);
508 gst_bin_add (GST_BIN (pipeline), demux);
509 gst_element_link (src, demux);
511 audio_bin = gst_bin_new ("a_decoder_bin");
512 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
513 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
514 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
515 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
517 gst_bin_add (GST_BIN (pipeline), audio_bin);
519 gst_bin_add (GST_BIN (audio_bin), a_queue);
520 gst_bin_add (GST_BIN (audio_bin), a_decoder);
521 gst_bin_add (GST_BIN (audio_bin), a_convert);
522 gst_bin_add (GST_BIN (audio_bin), audiosink);
524 gst_element_link (a_queue, a_decoder);
525 gst_element_link (a_decoder, a_convert);
526 gst_element_link (a_convert, audiosink);
528 pad = gst_element_get_static_pad (a_queue, "sink");
529 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
530 gst_object_unref (pad);
532 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
535 video_bin = gst_bin_new ("v_decoder_bin");
536 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
537 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
539 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
540 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
541 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
543 gst_bin_add (GST_BIN (pipeline), video_bin);
545 gst_bin_add (GST_BIN (video_bin), v_queue);
546 gst_bin_add (GST_BIN (video_bin), v_decoder);
547 gst_bin_add (GST_BIN (video_bin), v_convert);
548 gst_bin_add (GST_BIN (video_bin), v_scale);
549 gst_bin_add (GST_BIN (video_bin), videosink);
551 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
554 pad = gst_element_get_static_pad (v_queue, "sink");
555 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
556 gst_object_unref (pad);
558 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
561 seekable = gst_element_get_static_pad (a_decoder, "src");
562 seekable_pads = g_list_prepend (seekable_pads, seekable);
563 rate_pads = g_list_prepend (rate_pads, seekable);
565 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
572 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
574 GstElement *pipeline, *audio_bin, *video_bin;
575 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
576 GstElement *audiosink, *videosink;
577 GstElement *a_queue, *v_queue;
578 GstPad *seekable, *pad;
580 pipeline = gst_pipeline_new ("app");
582 src = gst_element_factory_make_or_warn (SOURCE, "src");
583 g_object_set (G_OBJECT (src), "location", location, NULL);
585 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
587 gst_bin_add (GST_BIN (pipeline), src);
588 gst_bin_add (GST_BIN (pipeline), demux);
589 gst_element_link (src, demux);
591 audio_bin = gst_bin_new ("a_decoder_bin");
592 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
593 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
594 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
595 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
597 gst_bin_add (GST_BIN (audio_bin), a_queue);
598 gst_bin_add (GST_BIN (audio_bin), a_decoder);
599 gst_bin_add (GST_BIN (audio_bin), a_convert);
600 gst_bin_add (GST_BIN (audio_bin), audiosink);
602 gst_element_link (a_queue, a_decoder);
603 gst_element_link (a_decoder, a_convert);
604 gst_element_link (a_convert, audiosink);
606 gst_bin_add (GST_BIN (pipeline), audio_bin);
608 pad = gst_element_get_static_pad (a_queue, "sink");
609 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
610 gst_object_unref (pad);
612 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
615 video_bin = gst_bin_new ("v_decoder_bin");
616 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
617 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
619 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
620 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
622 gst_bin_add (GST_BIN (video_bin), v_queue);
623 gst_bin_add (GST_BIN (video_bin), v_decoder);
624 gst_bin_add (GST_BIN (video_bin), v_convert);
625 gst_bin_add (GST_BIN (video_bin), videosink);
627 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
629 gst_bin_add (GST_BIN (pipeline), video_bin);
631 pad = gst_element_get_static_pad (v_queue, "sink");
632 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
633 gst_object_unref (pad);
635 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
638 seekable = gst_element_get_static_pad (a_decoder, "src");
639 seekable_pads = g_list_prepend (seekable_pads, seekable);
640 rate_pads = g_list_prepend (rate_pads, seekable);
642 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
649 make_mp3_pipeline (const gchar * location)
651 GstElement *pipeline;
652 GstElement *src, *parser, *decoder, *audiosink, *queue;
655 pipeline = gst_pipeline_new ("app");
657 src = gst_element_factory_make_or_warn (SOURCE, "src");
658 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
659 decoder = gst_element_factory_make_or_warn ("mad", "dec");
660 queue = gst_element_factory_make_or_warn ("queue", "queue");
661 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
663 seekable_elements = g_list_prepend (seekable_elements, audiosink);
665 g_object_set (G_OBJECT (src), "location", location, NULL);
666 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
668 gst_bin_add (GST_BIN (pipeline), src);
669 gst_bin_add (GST_BIN (pipeline), parser);
670 gst_bin_add (GST_BIN (pipeline), decoder);
671 gst_bin_add (GST_BIN (pipeline), queue);
672 gst_bin_add (GST_BIN (pipeline), audiosink);
674 gst_element_link (src, parser);
675 gst_element_link (parser, decoder);
676 gst_element_link (decoder, queue);
677 gst_element_link (queue, audiosink);
679 seekable = gst_element_get_static_pad (queue, "src");
680 seekable_pads = g_list_prepend (seekable_pads, seekable);
681 rate_pads = g_list_prepend (rate_pads, seekable);
683 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
689 make_avi_pipeline (const gchar * location)
691 GstElement *pipeline, *audio_bin, *video_bin;
692 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
693 GstElement *a_queue = NULL, *v_queue = NULL;
696 pipeline = gst_pipeline_new ("app");
698 src = gst_element_factory_make_or_warn (SOURCE, "src");
699 g_object_set (G_OBJECT (src), "location", location, NULL);
701 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
702 seekable_elements = g_list_prepend (seekable_elements, demux);
704 gst_bin_add (GST_BIN (pipeline), src);
705 gst_bin_add (GST_BIN (pipeline), demux);
706 gst_element_link (src, demux);
708 audio_bin = gst_bin_new ("a_decoder_bin");
709 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
710 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
711 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
712 gst_element_link (a_decoder, a_queue);
713 gst_element_link (a_queue, audiosink);
714 gst_bin_add (GST_BIN (audio_bin), a_decoder);
715 gst_bin_add (GST_BIN (audio_bin), a_queue);
716 gst_bin_add (GST_BIN (audio_bin), audiosink);
717 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
719 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
722 seekable = gst_element_get_static_pad (a_queue, "src");
723 seekable_pads = g_list_prepend (seekable_pads, seekable);
724 rate_pads = g_list_prepend (rate_pads, seekable);
726 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
729 video_bin = gst_bin_new ("v_decoder_bin");
730 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
731 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
732 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
733 gst_element_link (v_decoder, v_queue);
734 gst_element_link (v_queue, videosink);
735 gst_bin_add (GST_BIN (video_bin), v_decoder);
736 gst_bin_add (GST_BIN (video_bin), v_queue);
737 gst_bin_add (GST_BIN (video_bin), videosink);
739 gst_element_set_state (video_bin, GST_STATE_PAUSED);
741 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
744 seekable = gst_element_get_static_pad (v_queue, "src");
745 seekable_pads = g_list_prepend (seekable_pads, seekable);
746 rate_pads = g_list_prepend (rate_pads, seekable);
748 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
755 make_mpeg_pipeline (const gchar * location)
757 GstElement *pipeline, *audio_bin, *video_bin;
758 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
759 GstElement *audiosink, *videosink;
760 GstElement *a_queue, *v_queue;
764 pipeline = gst_pipeline_new ("app");
766 src = gst_element_factory_make_or_warn (SOURCE, "src");
767 g_object_set (G_OBJECT (src), "location", location, NULL);
769 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
770 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
772 gst_bin_add (GST_BIN (pipeline), src);
773 gst_bin_add (GST_BIN (pipeline), demux);
774 gst_element_link (src, demux);
776 audio_bin = gst_bin_new ("a_decoder_bin");
777 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
778 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
779 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
780 gst_bin_add (GST_BIN (audio_bin), a_decoder);
781 gst_bin_add (GST_BIN (audio_bin), a_queue);
782 gst_bin_add (GST_BIN (audio_bin), audiosink);
784 gst_element_link (a_decoder, a_queue);
785 gst_element_link (a_queue, audiosink);
787 gst_bin_add (GST_BIN (pipeline), audio_bin);
789 pad = gst_element_get_static_pad (a_decoder, "sink");
790 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
791 gst_object_unref (pad);
793 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
796 video_bin = gst_bin_new ("v_decoder_bin");
797 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
798 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
799 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
800 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
802 gst_bin_add (GST_BIN (video_bin), v_decoder);
803 gst_bin_add (GST_BIN (video_bin), v_queue);
804 gst_bin_add (GST_BIN (video_bin), v_filter);
805 gst_bin_add (GST_BIN (video_bin), videosink);
807 gst_element_link (v_decoder, v_queue);
808 gst_element_link (v_queue, v_filter);
809 gst_element_link (v_filter, videosink);
811 gst_bin_add (GST_BIN (pipeline), video_bin);
813 pad = gst_element_get_static_pad (v_decoder, "sink");
814 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
815 gst_object_unref (pad);
817 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
820 seekable = gst_element_get_static_pad (v_filter, "src");
821 seekable_pads = g_list_prepend (seekable_pads, seekable);
822 rate_pads = g_list_prepend (rate_pads, seekable);
824 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
831 make_mpegnt_pipeline (const gchar * location)
833 GstElement *pipeline, *audio_bin, *video_bin;
834 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
835 GstElement *audiosink, *videosink;
839 pipeline = gst_pipeline_new ("app");
841 src = gst_element_factory_make_or_warn (SOURCE, "src");
842 g_object_set (G_OBJECT (src), "location", location, NULL);
844 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
845 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
847 seekable_elements = g_list_prepend (seekable_elements, demux);
849 gst_bin_add (GST_BIN (pipeline), src);
850 gst_bin_add (GST_BIN (pipeline), demux);
851 gst_element_link (src, demux);
853 audio_bin = gst_bin_new ("a_decoder_bin");
854 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
855 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
856 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
857 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
858 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
859 gst_element_link (a_decoder, a_queue);
860 gst_element_link (a_queue, audiosink);
861 gst_bin_add (GST_BIN (audio_bin), a_decoder);
862 gst_bin_add (GST_BIN (audio_bin), a_queue);
863 gst_bin_add (GST_BIN (audio_bin), audiosink);
865 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
868 seekable = gst_element_get_static_pad (a_queue, "src");
869 seekable_pads = g_list_prepend (seekable_pads, seekable);
870 rate_pads = g_list_prepend (rate_pads, seekable);
872 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
875 video_bin = gst_bin_new ("v_decoder_bin");
876 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
877 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
878 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
879 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
881 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
883 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
886 seekable = gst_element_get_static_pad (v_decoder, "src");
887 seekable_pads = g_list_prepend (seekable_pads, seekable);
888 rate_pads = g_list_prepend (rate_pads, seekable);
890 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
897 playerbin_set_uri (GstElement * player, const gchar * location)
901 /* Add "file://" prefix for convenience */
902 if (g_str_has_prefix (location, "/")) {
903 uri = g_strconcat ("file://", location, NULL);
904 g_object_set (G_OBJECT (player), "uri", uri, NULL);
907 g_object_set (G_OBJECT (player), "uri", location, NULL);
912 construct_playerbin (const gchar * name, const gchar * location)
916 player = gst_element_factory_make (name, "player");
919 playerbin_set_uri (player, location);
921 seekable_elements = g_list_prepend (seekable_elements, player);
923 /* force element seeking on this pipeline */
930 make_playerbin_pipeline (const gchar * location)
932 return construct_playerbin ("playbin", location);
936 make_playerbin2_pipeline (const gchar * location)
938 GstElement *pipeline = construct_playerbin ("playbin2", location);
940 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
941 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
946 #ifndef GST_DISABLE_PARSE
948 make_parselaunch_pipeline (const gchar * description)
950 GstElement *pipeline;
951 GError *error = NULL;
953 pipeline = gst_parse_launch (description, &error);
955 seekable_elements = g_list_prepend (seekable_elements, pipeline);
966 GstElement *(*func) (const gchar * location);
970 static Pipeline pipelines[] = {
971 {"mp3", make_mp3_pipeline},
972 {"avi", make_avi_pipeline},
973 {"mpeg1", make_mpeg_pipeline},
974 {"mpegparse", make_parse_pipeline},
975 {"vorbis", make_vorbis_pipeline},
976 {"theora", make_theora_pipeline},
977 {"ogg/v/t", make_vorbis_theora_pipeline},
978 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
979 {"sid", make_sid_pipeline},
980 {"flac", make_flac_pipeline},
981 {"wav", make_wav_pipeline},
982 {"mod", make_mod_pipeline},
983 {"dv", make_dv_pipeline},
984 {"mpeg1nothreads", make_mpegnt_pipeline},
985 {"playerbin", make_playerbin_pipeline},
986 #ifndef GST_DISABLE_PARSE
987 {"parse-launch", make_parselaunch_pipeline},
989 {"playerbin2", make_playerbin2_pipeline},
993 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
995 /* ui callbacks and helpers */
998 format_value (GtkScale * scale, gdouble value)
1004 real = value * duration / 100;
1005 seconds = (gint64) real / GST_SECOND;
1006 subseconds = (gint64) real / (GST_SECOND / 100);
1008 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1009 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1014 shuttle_format_value (GtkScale * scale, gdouble value)
1016 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
1022 const GstFormat format;
1026 static seek_format seek_formats[] = {
1027 {"tim", GST_FORMAT_TIME},
1028 {"byt", GST_FORMAT_BYTES},
1029 {"buf", GST_FORMAT_BUFFERS},
1030 {"def", GST_FORMAT_DEFAULT},
1034 G_GNUC_UNUSED static void
1037 GList *walk = rate_pads;
1040 GstPad *pad = GST_PAD (walk->data);
1043 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1044 while (seek_formats[i].name) {
1048 format = seek_formats[i].format;
1050 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
1052 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1054 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1059 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1061 walk = g_list_next (walk);
1065 G_GNUC_UNUSED static void
1066 query_positions_elems (void)
1068 GList *walk = seekable_elements;
1071 GstElement *element = GST_ELEMENT (walk->data);
1074 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1075 while (seek_formats[i].name) {
1076 gint64 position, total;
1079 format = seek_formats[i].format;
1081 if (gst_element_query_position (element, &format, &position) &&
1082 gst_element_query_duration (element, &format, &total)) {
1083 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1084 seek_formats[i].name, position, total);
1086 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1091 g_print (" %s\n", GST_ELEMENT_NAME (element));
1093 walk = g_list_next (walk);
1097 G_GNUC_UNUSED static void
1098 query_positions_pads (void)
1100 GList *walk = seekable_pads;
1103 GstPad *pad = GST_PAD (walk->data);
1106 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1107 while (seek_formats[i].name) {
1109 gint64 position, total;
1111 format = seek_formats[i].format;
1113 if (gst_pad_query_position (pad, &format, &position) &&
1114 gst_pad_query_duration (pad, &format, &total)) {
1115 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1116 seek_formats[i].name, position, total);
1118 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1124 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1126 walk = g_list_next (walk);
1130 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1131 gpointer user_data);
1132 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1133 gpointer user_data);
1134 static void seek_cb (GtkWidget * widget);
1137 set_scale (gdouble value)
1139 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1141 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1143 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1144 gtk_adjustment_set_value (adjustment, value);
1145 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1147 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1149 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1151 gtk_widget_queue_draw (hscale);
1155 update_fill (gpointer data)
1158 if (seekable_elements) {
1159 GstElement *element = GST_ELEMENT (seekable_elements->data);
1162 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1163 if (gst_element_query (element, query)) {
1170 gst_query_parse_buffering_percent (query, &busy, &percent);
1172 if (buffering && !busy) {
1173 /* if we were buffering but not anymore, start playing */
1174 if (state == GST_STATE_PLAYING && !is_live) {
1175 fprintf (stderr, "setting pipeline to PLAYING ...\n");
1176 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1177 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1178 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id,
1181 state = GST_STATE_PAUSED;
1185 gst_query_parse_buffering_range (query, &format, &start, &stop, NULL);
1187 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1191 fill = 100.0 * stop / GST_FORMAT_PERCENT_MAX;
1195 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1197 gst_query_unref (query);
1204 update_scale (gpointer data)
1206 GstFormat format = GST_FORMAT_TIME;
1212 if (seekable_elements) {
1213 GstElement *element = GST_ELEMENT (seekable_elements->data);
1215 gst_element_query_position (element, &format, &position);
1216 gst_element_query_duration (element, &format, &duration);
1219 if (seekable_pads) {
1220 GstPad *pad = GST_PAD (seekable_pads->data);
1222 gst_pad_query_position (pad, &format, &position);
1223 gst_pad_query_duration (pad, &format, &duration);
1229 query_positions_elems ();
1231 query_positions_pads ();
1236 if (position >= duration)
1237 duration = position;
1240 set_scale (position * 100.0 / duration);
1243 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1244 if (pipeline_type == 16) {
1245 g_object_notify (G_OBJECT (pipeline), "volume");
1251 static void do_seek (GtkWidget * widget);
1252 static void connect_bus_signals (GstElement * pipeline);
1253 static void set_update_scale (gboolean active);
1254 static void set_update_fill (gboolean active);
1257 end_scrub (GtkWidget * widget)
1259 GST_DEBUG ("end scrub, PAUSE");
1260 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1261 seek_timeout_id = 0;
1267 send_event (GstEvent * event)
1269 gboolean res = FALSE;
1272 GList *walk = seekable_pads;
1275 GstPad *seekable = GST_PAD (walk->data);
1277 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1279 gst_event_ref (event);
1280 res = gst_pad_send_event (seekable, event);
1282 walk = g_list_next (walk);
1285 GList *walk = seekable_elements;
1288 GstElement *seekable = GST_ELEMENT (walk->data);
1290 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1292 gst_event_ref (event);
1293 res = gst_element_send_event (seekable, event);
1295 walk = g_list_next (walk);
1298 gst_event_unref (event);
1303 do_seek (GtkWidget * widget)
1306 gboolean res = FALSE;
1310 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
1314 flags |= GST_SEEK_FLAG_FLUSH;
1316 flags |= GST_SEEK_FLAG_ACCURATE;
1318 flags |= GST_SEEK_FLAG_KEY_UNIT;
1320 flags |= GST_SEEK_FLAG_SEGMENT;
1322 flags |= GST_SEEK_FLAG_SKIP;
1325 s_event = gst_event_new_seek (rate,
1326 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1327 GST_CLOCK_TIME_NONE);
1328 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1329 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1331 s_event = gst_event_new_seek (rate,
1332 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1333 GST_SEEK_TYPE_SET, real);
1334 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1335 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1338 res = send_event (s_event);
1342 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1344 set_update_scale (TRUE);
1347 g_print ("seek failed\n");
1348 set_update_scale (TRUE);
1353 seek_cb (GtkWidget * widget)
1355 /* If the timer hasn't expired yet, then the pipeline is running */
1356 if (play_scrub && seek_timeout_id != 0) {
1357 GST_DEBUG ("do scrub seek, PAUSED");
1358 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1361 GST_DEBUG ("do seek");
1365 GST_DEBUG ("do scrub seek, PLAYING");
1366 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1368 if (seek_timeout_id == 0) {
1370 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1376 set_update_fill (gboolean active)
1378 GST_DEBUG ("fill scale is %d", active);
1383 g_timeout_add (FILL_INTERVAL, (GtkFunction) update_fill, pipeline);
1387 g_source_remove (fill_id);
1394 set_update_scale (gboolean active)
1397 GST_DEBUG ("update scale is %d", active);
1400 if (update_id == 0) {
1402 g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
1406 g_source_remove (update_id);
1413 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1415 if (event->type != GDK_BUTTON_PRESS)
1418 set_update_scale (FALSE);
1420 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1421 GST_DEBUG ("start scrub seek, PAUSE");
1422 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1425 if (changed_id == 0 && flush_seek && scrub) {
1426 changed_id = gtk_signal_connect (GTK_OBJECT (hscale),
1427 "value_changed", G_CALLBACK (seek_cb), pipeline);
1434 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1437 g_signal_handler_disconnect (GTK_OBJECT (hscale), changed_id);
1441 if (!flush_seek || !scrub) {
1442 GST_DEBUG ("do final seek");
1446 if (seek_timeout_id != 0) {
1447 g_source_remove (seek_timeout_id);
1448 seek_timeout_id = 0;
1449 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1451 if (state == GST_STATE_PAUSED) {
1452 GST_DEBUG ("stop scrub seek, PAUSED");
1453 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1456 if (state == GST_STATE_PLAYING) {
1457 GST_DEBUG ("stop scrub seek, PLAYING");
1458 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1466 play_cb (GtkButton * button, gpointer data)
1468 GstStateChangeReturn ret;
1470 if (state != GST_STATE_PLAYING) {
1471 g_print ("PLAY pipeline\n");
1472 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1474 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1476 case GST_STATE_CHANGE_FAILURE:
1478 case GST_STATE_CHANGE_NO_PREROLL:
1484 state = GST_STATE_PLAYING;
1485 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1492 g_print ("PLAY failed\n");
1493 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1498 pause_cb (GtkButton * button, gpointer data)
1500 g_static_mutex_lock (&state_mutex);
1501 if (state != GST_STATE_PAUSED) {
1502 GstStateChangeReturn ret;
1504 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1505 g_print ("PAUSE pipeline\n");
1506 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1508 case GST_STATE_CHANGE_FAILURE:
1510 case GST_STATE_CHANGE_NO_PREROLL:
1517 state = GST_STATE_PAUSED;
1518 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1520 g_static_mutex_unlock (&state_mutex);
1526 g_static_mutex_unlock (&state_mutex);
1527 g_print ("PAUSE failed\n");
1528 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1533 stop_cb (GtkButton * button, gpointer data)
1535 if (state != GST_STATE_READY) {
1536 GstStateChangeReturn ret;
1538 g_print ("READY pipeline\n");
1539 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1541 g_static_mutex_lock (&state_mutex);
1542 ret = gst_element_set_state (pipeline, GST_STATE_READY);
1543 if (ret == GST_STATE_CHANGE_FAILURE)
1546 state = GST_STATE_READY;
1547 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1551 set_update_scale (FALSE);
1553 set_update_fill (FALSE);
1555 if (pipeline_type == 16)
1556 clear_streams (pipeline);
1557 g_static_mutex_unlock (&state_mutex);
1560 /* if one uses parse_launch, play, stop and play again it fails as all the
1561 * pads after the demuxer can't be reconnected
1563 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1564 gst_element_set_state (pipeline, GST_STATE_NULL);
1565 gst_object_unref (pipeline);
1567 g_list_free (seekable_elements);
1568 seekable_elements = NULL;
1569 g_list_free (seekable_pads);
1570 seekable_pads = NULL;
1571 g_list_free (rate_pads);
1574 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1575 g_assert (pipeline);
1576 gst_element_set_state (pipeline, GST_STATE_READY);
1577 connect_bus_signals (pipeline);
1585 g_static_mutex_unlock (&state_mutex);
1586 g_print ("STOP failed\n");
1587 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1592 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1594 accurate_seek = gtk_toggle_button_get_active (button);
1598 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1600 keyframe_seek = gtk_toggle_button_get_active (button);
1604 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1606 loop_seek = gtk_toggle_button_get_active (button);
1607 if (state == GST_STATE_PLAYING) {
1613 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1615 flush_seek = gtk_toggle_button_get_active (button);
1619 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1621 scrub = gtk_toggle_button_get_active (button);
1625 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1627 play_scrub = gtk_toggle_button_get_active (button);
1631 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1633 skip_seek = gtk_toggle_button_get_active (button);
1634 if (state == GST_STATE_PLAYING) {
1640 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1642 gboolean res = FALSE;
1646 rate = gtk_spin_button_get_value (button);
1648 GST_DEBUG ("rate changed to %lf", rate);
1652 flags |= GST_SEEK_FLAG_FLUSH;
1654 flags |= GST_SEEK_FLAG_SEGMENT;
1656 flags |= GST_SEEK_FLAG_ACCURATE;
1658 flags |= GST_SEEK_FLAG_KEY_UNIT;
1660 flags |= GST_SEEK_FLAG_SKIP;
1663 s_event = gst_event_new_seek (rate,
1664 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1665 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1667 s_event = gst_event_new_seek (rate,
1668 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1669 GST_SEEK_TYPE_SET, position);
1672 res = send_event (s_event);
1676 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1679 g_print ("seek failed\n");
1683 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1687 g_object_get (pipeline, "flags", &flags, NULL);
1689 flags |= (1 << num);
1691 flags &= ~(1 << num);
1692 g_object_set (pipeline, "flags", flags, NULL);
1696 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1700 state = gtk_toggle_button_get_active (button);
1701 update_flag (pipeline, 3, state);
1702 gtk_widget_set_sensitive (vis_combo, state);
1706 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1710 state = gtk_toggle_button_get_active (button);
1711 update_flag (pipeline, 1, state);
1712 gtk_widget_set_sensitive (audio_combo, state);
1716 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1720 state = gtk_toggle_button_get_active (button);
1721 update_flag (pipeline, 0, state);
1722 gtk_widget_set_sensitive (video_combo, state);
1726 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1730 state = gtk_toggle_button_get_active (button);
1731 update_flag (pipeline, 2, state);
1732 gtk_widget_set_sensitive (text_combo, state);
1736 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1740 mute = gtk_toggle_button_get_active (button);
1741 g_object_set (pipeline, "mute", mute, NULL);
1745 clear_streams (GstElement * pipeline)
1749 /* remove previous info */
1750 for (i = 0; i < n_video; i++)
1751 gtk_combo_box_remove_text (GTK_COMBO_BOX (video_combo), 0);
1752 for (i = 0; i < n_audio; i++)
1753 gtk_combo_box_remove_text (GTK_COMBO_BOX (audio_combo), 0);
1754 for (i = 0; i < n_text; i++)
1755 gtk_combo_box_remove_text (GTK_COMBO_BOX (text_combo), 0);
1757 n_audio = n_video = n_text = 0;
1758 gtk_widget_set_sensitive (video_combo, FALSE);
1759 gtk_widget_set_sensitive (audio_combo, FALSE);
1760 gtk_widget_set_sensitive (text_combo, FALSE);
1762 need_streams = TRUE;
1766 update_streams (GstPipeline * pipeline)
1770 if (pipeline_type == 16 && need_streams) {
1776 /* remove previous info */
1777 clear_streams (GST_ELEMENT_CAST (pipeline));
1779 /* here we get and update the different streams detected by playbin2 */
1780 g_object_get (pipeline, "n-video", &n_video, NULL);
1781 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1782 g_object_get (pipeline, "n-text", &n_text, NULL);
1784 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1787 for (i = 0; i < n_video; i++) {
1788 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1790 str = gst_structure_to_string ((GstStructure *) tags);
1791 g_print ("video %d: %s\n", i, str);
1794 /* find good name for the label */
1795 name = g_strdup_printf ("video %d", i + 1);
1796 gtk_combo_box_append_text (GTK_COMBO_BOX (video_combo), name);
1799 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1800 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1801 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1804 for (i = 0; i < n_audio; i++) {
1805 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1807 str = gst_structure_to_string ((GstStructure *) tags);
1808 g_print ("audio %d: %s\n", i, str);
1811 /* find good name for the label */
1812 name = g_strdup_printf ("audio %d", i + 1);
1813 gtk_combo_box_append_text (GTK_COMBO_BOX (audio_combo), name);
1816 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1817 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1818 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1821 for (i = 0; i < n_text; i++) {
1822 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1826 const GValue *value;
1828 str = gst_structure_to_string ((GstStructure *) tags);
1829 g_print ("text %d: %s\n", i, str);
1832 /* get the language code if we can */
1833 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1834 if (value && G_VALUE_HOLDS_STRING (value)) {
1835 name = g_strdup_printf ("text %s", g_value_get_string (value));
1838 /* find good name for the label if we didn't use a tag */
1840 name = g_strdup_printf ("text %d", i + 1);
1842 gtk_combo_box_append_text (GTK_COMBO_BOX (text_combo), name);
1845 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1846 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1847 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1849 need_streams = FALSE;
1854 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1858 active = gtk_combo_box_get_active (combo);
1860 g_print ("setting current video track %d\n", active);
1861 g_object_set (pipeline, "current-video", active, NULL);
1865 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1869 active = gtk_combo_box_get_active (combo);
1871 g_print ("setting current audio track %d\n", active);
1872 g_object_set (pipeline, "current-audio", active, NULL);
1876 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1880 active = gtk_combo_box_get_active (combo);
1882 g_print ("setting current text track %d\n", active);
1883 g_object_set (pipeline, "current-text", active, NULL);
1887 filter_features (GstPluginFeature * feature, gpointer data)
1889 GstElementFactory *f;
1891 if (!GST_IS_ELEMENT_FACTORY (feature))
1893 f = GST_ELEMENT_FACTORY (feature);
1894 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1901 init_visualization_features (void)
1905 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1907 list = gst_registry_feature_filter (gst_registry_get_default (),
1908 filter_features, FALSE, NULL);
1910 for (walk = list; walk; walk = g_list_next (walk)) {
1914 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1915 name = gst_element_factory_get_longname (entry.factory);
1917 g_array_append_val (vis_entries, entry);
1918 gtk_combo_box_append_text (GTK_COMBO_BOX (vis_combo), name);
1920 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1924 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1928 GstElement *element;
1930 /* get the selected index and get the factory for this index */
1931 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1932 if (vis_entries->len > 0) {
1933 entry = &g_array_index (vis_entries, VisEntry, index);
1935 /* create an instance of the element from the factory */
1936 element = gst_element_factory_create (entry->factory, NULL);
1940 /* set vis plugin for playbin2 */
1941 g_object_set (pipeline, "vis-plugin", element, NULL);
1946 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1950 volume = gtk_spin_button_get_value (button);
1952 g_object_set (pipeline, "volume", volume, NULL);
1956 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
1958 gdouble cur_volume, new_volume;
1960 g_object_get (pipeline, "volume", &new_volume, NULL);
1961 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
1962 if (fabs (cur_volume - new_volume) > 0.001) {
1963 g_signal_handlers_block_by_func (volume_spinbutton,
1964 volume_spinbutton_changed_cb, pipeline);
1965 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
1966 g_signal_handlers_unblock_by_func (volume_spinbutton,
1967 volume_spinbutton_changed_cb, pipeline);
1972 shot_cb (GtkButton * button, gpointer data)
1977 /* convert to our desired format (RGB24) */
1978 caps = gst_caps_new_simple ("video/x-raw-rgb",
1979 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
1980 /* Note: we don't ask for a specific width/height here, so that
1981 * videoscale can adjust dimensions from a non-1/1 pixel aspect
1982 * ratio to a 1/1 pixel-aspect-ratio */
1983 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
1984 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
1985 "red_mask", G_TYPE_INT, 0xff0000,
1986 "green_mask", G_TYPE_INT, 0x00ff00,
1987 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
1989 /* convert the latest frame to the requested format */
1990 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
1991 gst_caps_unref (caps);
1999 GError *error = NULL;
2001 /* get the snapshot buffer format now. We set the caps on the appsink so
2002 * that it can only be an rgb buffer. The only thing we have not specified
2003 * on the caps is the height, which is dependant on the pixel-aspect-ratio
2004 * of the source material */
2005 caps = GST_BUFFER_CAPS (buffer);
2007 g_warning ("could not get snapshot format\n");
2010 s = gst_caps_get_structure (caps, 0);
2012 /* we need to get the final caps on the buffer to get the size */
2013 res = gst_structure_get_int (s, "width", &width);
2014 res |= gst_structure_get_int (s, "height", &height);
2016 g_warning ("could not get snapshot dimension\n");
2020 /* create pixmap from buffer and save, gstreamer video buffers have a stride
2021 * that is rounded up to the nearest multiple of 4 */
2022 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
2023 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2024 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2026 /* save the pixbuf */
2027 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2030 gst_buffer_unref (buffer);
2034 /* called when the Step button is pressed */
2036 step_cb (GtkButton * button, gpointer data)
2042 gboolean flush, res;
2045 active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo));
2047 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
2048 (step_amount_spinbutton));
2049 rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton));
2054 format = GST_FORMAT_BUFFERS;
2057 format = GST_FORMAT_TIME;
2058 amount *= GST_MSECOND;
2061 format = GST_FORMAT_UNDEFINED;
2065 event = gst_event_new_step (format, amount, rate, flush, FALSE);
2067 res = send_event (event);
2071 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2073 const GstStructure *s;
2075 s = gst_message_get_structure (message);
2076 g_print ("message from \"%s\" (%s): ",
2077 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2078 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2082 sstr = gst_structure_to_string (s);
2083 g_print ("%s\n", sstr);
2086 g_print ("no message details\n");
2090 static gboolean shuttling = FALSE;
2091 static gdouble shuttle_rate = 0.0;
2092 static gdouble play_rate = 1.0;
2095 do_shuttle (GstElement * element)
2100 duration = 40 * GST_MSECOND;
2104 gst_element_send_event (element,
2105 gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE,
2110 msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element)
2116 gboolean intermediate;
2120 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
2121 &intermediate, &duration, &eos);
2124 g_print ("stepped till EOS\n");
2128 if (g_static_mutex_trylock (&state_mutex)) {
2130 do_shuttle (element);
2131 g_static_mutex_unlock (&state_mutex);
2133 /* ignore step messages that come while we are doing a state change */
2134 g_print ("state change is busy\n");
2139 shuttle_toggled (GtkToggleButton * button, GstElement * element)
2143 active = gtk_toggle_button_get_active (button);
2145 if (active != shuttling) {
2147 g_print ("shuttling %s\n", shuttling ? "active" : "inactive");
2151 pause_cb (NULL, NULL);
2152 gst_element_get_state (element, NULL, NULL, -1);
2158 shuttle_rate_switch (GstElement * element)
2164 if (state == GST_STATE_PLAYING) {
2165 /* pause when we need to */
2166 pause_cb (NULL, NULL);
2167 gst_element_get_state (element, NULL, NULL, -1);
2170 if (play_rate == 1.0)
2175 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate,
2176 GST_TIME_ARGS (position));
2178 flags = GST_SEEK_FLAG_FLUSH;
2179 flags |= GST_SEEK_FLAG_ACCURATE;
2181 if (play_rate >= 0.0) {
2182 s_event = gst_event_new_seek (play_rate,
2183 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
2184 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
2186 s_event = gst_event_new_seek (play_rate,
2187 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2188 GST_SEEK_TYPE_SET, position);
2190 res = send_event (s_event);
2192 gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT);
2194 g_print ("seek failed\n");
2199 shuttle_value_changed (GtkRange * range, GstElement * element)
2203 rate = gtk_adjustment_get_value (shuttle_adjustment);
2206 g_print ("rate 0.0, pause\n");
2207 pause_cb (NULL, NULL);
2208 gst_element_get_state (element, NULL, NULL, -1);
2210 g_print ("rate changed %0.3g\n", rate);
2212 if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) {
2213 shuttle_rate_switch (element);
2216 shuttle_rate = ABS (rate);
2217 if (state != GST_STATE_PLAYING) {
2218 do_shuttle (element);
2219 play_cb (NULL, NULL);
2225 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2227 GST_DEBUG ("async done");
2228 /* when we get ASYNC_DONE we can query position, duration and other
2230 update_scale (pipeline);
2232 /* update the available streams */
2233 update_streams (pipeline);
2237 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2239 const GstStructure *s;
2241 s = gst_message_get_structure (message);
2243 /* We only care about state changed on the pipeline */
2244 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2245 GstState old, new, pending;
2247 gst_message_parse_state_changed (message, &old, &new, &pending);
2249 /* When state of the pipeline changes to paused or playing we start updating scale */
2250 if (new == GST_STATE_PLAYING) {
2251 set_update_scale (TRUE);
2253 set_update_scale (FALSE);
2259 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2266 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2267 gst_message_parse_segment_done (message, &format, &position);
2268 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2271 /* in the segment-done callback we never flush as this would not make sense
2272 * for seamless playback. */
2274 flags |= GST_SEEK_FLAG_SEGMENT;
2276 flags |= GST_SEEK_FLAG_SKIP;
2278 s_event = gst_event_new_seek (rate,
2279 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2280 GST_SEEK_TYPE_SET, duration);
2282 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2283 rate, GST_TIME_ARGS (duration));
2285 res = send_event (s_event);
2287 g_print ("segment seek failed\n");
2290 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2293 do_stream_buffering (gint percent)
2297 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2298 bufstr = g_strdup_printf ("Buffering...%d", percent);
2299 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2302 if (percent == 100) {
2303 /* a 100% message means buffering is done */
2305 /* if the desired state is playing, go back */
2306 if (state == GST_STATE_PLAYING) {
2307 /* no state management needed for live pipelines */
2309 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2310 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2312 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2313 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2316 /* buffering busy */
2317 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2318 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2320 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2321 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2329 do_download_buffering (gint percent)
2331 if (!buffering && percent < 100) {
2336 bufstr = g_strdup_printf ("Downloading...");
2337 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2340 /* once we get a buffering message, we'll do the fill update */
2341 set_update_fill (TRUE);
2343 if (state == GST_STATE_PLAYING && !is_live) {
2344 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2345 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2351 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2355 gst_message_parse_buffering (message, &percent);
2357 /* get more stats */
2358 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2362 case GST_BUFFERING_DOWNLOAD:
2363 do_download_buffering (percent);
2365 case GST_BUFFERING_LIVE:
2366 case GST_BUFFERING_TIMESHIFT:
2367 case GST_BUFFERING_STREAM:
2368 do_stream_buffering (percent);
2374 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2376 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2378 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2379 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2384 static guint embed_xid = 0;
2386 static GstBusSyncReply
2387 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2389 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
2390 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
2391 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2393 g_print ("got prepare-xwindow-id\n");
2395 embed_xid = GDK_WINDOW_XID (GDK_WINDOW (video_window->window));
2398 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2399 "force-aspect-ratio")) {
2400 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2403 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
2406 return GST_BUS_PASS;
2411 handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
2413 if (state < GST_STATE_PAUSED) {
2414 gdk_draw_rectangle (widget->window, widget->style->black_gc, TRUE,
2415 0, 0, widget->allocation.width, widget->allocation.height);
2422 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2424 message_received (bus, message, data);
2426 /* Set new uri for playerbins and continue playback */
2427 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2428 stop_cb (NULL, NULL);
2429 l = g_list_next (l);
2431 playerbin_set_uri (GST_ELEMENT (data), l->data);
2432 play_cb (NULL, NULL);
2438 msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data)
2441 message_received (bus, message, data);
2445 connect_bus_signals (GstElement * pipeline)
2447 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2450 /* handle prepare-xwindow-id element message synchronously */
2451 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2455 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2456 gst_bus_enable_sync_message_emission (bus);
2458 g_signal_connect (bus, "message::state-changed",
2459 (GCallback) msg_state_changed, pipeline);
2460 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2462 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2465 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2467 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2469 g_signal_connect (bus, "message::error", (GCallback) message_received,
2471 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2473 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2474 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2476 g_signal_connect (bus, "message::element", (GCallback) message_received,
2478 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2480 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2482 // g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done,
2484 g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done,
2486 g_signal_connect (bus, "sync-message::step-done",
2487 (GCallback) msg_sync_step_done, pipeline);
2489 gst_object_unref (bus);
2492 /* Return GList of paths described in location string */
2494 handle_wildcards (const gchar * location)
2497 gchar *path = g_path_get_dirname (location);
2498 gchar *pattern = g_path_get_basename (location);
2499 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2500 GDir *dir = g_dir_open (path, 0, NULL);
2503 g_print ("matching %s from %s\n", pattern, path);
2506 g_print ("opening directory %s failed\n", path);
2510 while ((name = g_dir_read_name (dir)) != NULL) {
2511 if (g_pattern_match_string (pspec, name)) {
2512 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2513 g_print (" found clip %s\n", name);
2519 g_pattern_spec_free (pspec);
2527 delete_event_cb (void)
2529 stop_cb (NULL, NULL);
2534 print_usage (int argc, char **argv)
2538 g_print ("usage: %s <type> <filename>\n", argv[0]);
2539 g_print (" possible types:\n");
2541 for (i = 0; i < NUM_TYPES; i++) {
2542 g_print (" %d = %s\n", i, pipelines[i].name);
2547 main (int argc, char **argv)
2549 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2550 *flagtable, *boxes2, *step;
2551 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2552 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2553 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2554 GtkWidget *rate_label, *volume_label;
2556 GOptionEntry options[] = {
2557 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2558 "Show pad stats", NULL},
2559 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2560 "Seek on elements instead of pads", NULL},
2561 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2562 "Verbose properties", NULL},
2565 GOptionContext *ctx;
2568 if (!g_thread_supported ())
2569 g_thread_init (NULL);
2571 ctx = g_option_context_new ("- test seeking in gsteamer");
2572 g_option_context_add_main_entries (ctx, options, NULL);
2573 g_option_context_add_group (ctx, gst_init_get_option_group ());
2574 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2576 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2577 g_print ("Error initializing: %s\n", err->message);
2581 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2584 print_usage (argc, argv);
2588 pipeline_type = atoi (argv[1]);
2590 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2591 print_usage (argc, argv);
2595 pipeline_spec = argv[2];
2597 if (g_strrstr (pipeline_spec, "*") != NULL ||
2598 g_strrstr (pipeline_spec, "?") != NULL) {
2599 paths = handle_wildcards (pipeline_spec);
2601 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2605 g_print ("opening %s failed\n", pipeline_spec);
2611 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2612 g_assert (pipeline);
2614 /* initialize gui elements ... */
2615 tips = gtk_tooltips_new ();
2616 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2617 video_window = gtk_drawing_area_new ();
2618 g_signal_connect (G_OBJECT (video_window), "expose-event",
2619 G_CALLBACK (handle_expose_cb), NULL);
2620 gtk_widget_set_double_buffered (video_window, FALSE);
2621 statusbar = gtk_statusbar_new ();
2622 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2623 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2624 hbox = gtk_hbox_new (FALSE, 0);
2625 vbox = gtk_vbox_new (FALSE, 0);
2626 flagtable = gtk_table_new (4, 2, FALSE);
2627 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2629 /* media controls */
2630 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2631 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2632 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2635 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2636 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2637 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2638 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2639 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2640 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2641 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2642 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2643 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2644 rate_label = gtk_label_new ("Rate");
2646 gtk_tooltips_set_tip (tips, accurate_checkbox,
2647 "accurate position is requested, this might be considerably slower for some formats",
2649 gtk_tooltips_set_tip (tips, key_checkbox,
2650 "seek to the nearest keyframe. This might be faster but less accurate",
2652 gtk_tooltips_set_tip (tips, loop_checkbox, "loop playback", NULL);
2653 gtk_tooltips_set_tip (tips, flush_checkbox, "flush pipeline after seeking",
2655 gtk_tooltips_set_tip (tips, rate_spinbutton, "define the playback rate, "
2656 "negative value trigger reverse playback", NULL);
2657 gtk_tooltips_set_tip (tips, scrub_checkbox, "show images while seeking",
2659 gtk_tooltips_set_tip (tips, play_scrub_checkbox, "play video while seeking",
2661 gtk_tooltips_set_tip (tips, skip_checkbox,
2662 "Skip frames while playing at high frame rates", NULL);
2664 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2665 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2667 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2673 step = gtk_expander_new ("step options");
2674 hbox = gtk_hbox_new (FALSE, 0);
2676 format_combo = gtk_combo_box_new_text ();
2677 gtk_combo_box_append_text (GTK_COMBO_BOX (format_combo), "frames");
2678 gtk_combo_box_append_text (GTK_COMBO_BOX (format_combo), "time (ms)");
2679 gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0);
2680 gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2);
2682 step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2683 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0);
2684 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0);
2685 gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE,
2688 step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2689 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3);
2690 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0);
2691 gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2);
2693 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2694 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2695 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2697 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2701 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2702 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2703 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2704 gtk_signal_connect (GTK_OBJECT (shuttle_checkbox),
2705 "toggled", G_CALLBACK (shuttle_toggled), pipeline);
2707 shuttle_adjustment =
2708 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2709 shuttle_hscale = gtk_hscale_new (shuttle_adjustment);
2710 gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2);
2711 gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP);
2712 gtk_range_set_update_policy (GTK_RANGE (shuttle_hscale),
2713 GTK_UPDATE_CONTINUOUS);
2714 gtk_signal_connect (GTK_OBJECT (shuttle_hscale), "value_changed",
2715 G_CALLBACK (shuttle_value_changed), pipeline);
2716 gtk_signal_connect (GTK_OBJECT (shuttle_hscale), "format_value",
2717 G_CALLBACK (shuttle_format_value), pipeline);
2719 gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2);
2721 gtk_container_add (GTK_CONTAINER (step), hbox);
2726 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
2727 hscale = gtk_hscale_new (adjustment);
2728 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2729 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
2730 #if GTK_CHECK_VERSION(2,12,0)
2731 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2732 gtk_range_set_fill_level (GTK_RANGE (hscale), 100.0);
2734 gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);
2736 gtk_signal_connect (GTK_OBJECT (hscale),
2737 "button_press_event", G_CALLBACK (start_seek), pipeline);
2738 gtk_signal_connect (GTK_OBJECT (hscale),
2739 "button_release_event", G_CALLBACK (stop_seek), pipeline);
2740 gtk_signal_connect (GTK_OBJECT (hscale),
2741 "format_value", G_CALLBACK (format_value), pipeline);
2743 if (pipeline_type == 16) {
2744 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2745 panel = gtk_hbox_new (FALSE, 0);
2746 video_combo = gtk_combo_box_new_text ();
2747 audio_combo = gtk_combo_box_new_text ();
2748 text_combo = gtk_combo_box_new_text ();
2749 gtk_widget_set_sensitive (video_combo, FALSE);
2750 gtk_widget_set_sensitive (audio_combo, FALSE);
2751 gtk_widget_set_sensitive (text_combo, FALSE);
2752 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2753 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2754 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2755 g_signal_connect (G_OBJECT (video_combo), "changed",
2756 G_CALLBACK (video_combo_cb), pipeline);
2757 g_signal_connect (G_OBJECT (audio_combo), "changed",
2758 G_CALLBACK (audio_combo_cb), pipeline);
2759 g_signal_connect (G_OBJECT (text_combo), "changed",
2760 G_CALLBACK (text_combo_cb), pipeline);
2761 /* playbin2 panel for flag checkboxes and volume/mute */
2762 boxes = gtk_hbox_new (FALSE, 0);
2763 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2764 video_checkbox = gtk_check_button_new_with_label ("Video");
2765 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2766 text_checkbox = gtk_check_button_new_with_label ("Text");
2767 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2768 volume_label = gtk_label_new ("Volume");
2769 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2770 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2771 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2772 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2773 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2774 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2775 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2776 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
2777 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2778 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2779 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2780 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2781 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2782 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2783 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2784 G_CALLBACK (vis_toggle_cb), pipeline);
2785 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2786 G_CALLBACK (audio_toggle_cb), pipeline);
2787 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2788 G_CALLBACK (video_toggle_cb), pipeline);
2789 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2790 G_CALLBACK (text_toggle_cb), pipeline);
2791 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2792 G_CALLBACK (mute_toggle_cb), pipeline);
2793 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2794 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2795 /* playbin2 panel for snapshot */
2796 boxes2 = gtk_hbox_new (FALSE, 0);
2797 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2798 gtk_tooltips_set_tip (tips, shot_button,
2799 "save a screenshot .png in the current directory", NULL);
2800 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2802 vis_combo = gtk_combo_box_new_text ();
2803 g_signal_connect (G_OBJECT (vis_combo), "changed",
2804 G_CALLBACK (vis_combo_cb), pipeline);
2805 gtk_widget_set_sensitive (vis_combo, FALSE);
2806 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2807 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2809 /* fill the vis combo box and the array of factories */
2810 init_visualization_features ();
2812 panel = boxes = boxes2 = NULL;
2815 /* do the packing stuff ... */
2816 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2817 /* FIXME: can we avoid this for audio only? */
2818 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
2819 DEFAULT_VIDEO_HEIGHT);
2820 gtk_container_add (GTK_CONTAINER (window), vbox);
2821 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
2822 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2823 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2824 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2825 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2826 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2827 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2829 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2830 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2831 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2832 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2833 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2835 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2836 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2837 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2839 if (panel && boxes && boxes2) {
2840 expander = gtk_expander_new ("playbin2 options");
2841 pb2vbox = gtk_vbox_new (FALSE, 0);
2842 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2843 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2844 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2845 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2846 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2848 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2849 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
2850 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
2852 /* connect things ... */
2853 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
2855 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
2857 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
2859 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2860 G_CALLBACK (accurate_toggle_cb), pipeline);
2861 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2862 G_CALLBACK (key_toggle_cb), pipeline);
2863 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2864 G_CALLBACK (loop_toggle_cb), pipeline);
2865 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2866 G_CALLBACK (flush_toggle_cb), pipeline);
2867 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2868 G_CALLBACK (scrub_toggle_cb), pipeline);
2869 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2870 G_CALLBACK (play_scrub_toggle_cb), pipeline);
2871 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2872 G_CALLBACK (skip_toggle_cb), pipeline);
2873 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
2874 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
2876 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
2879 gtk_widget_show_all (window);
2882 g_signal_connect (pipeline, "deep_notify",
2883 G_CALLBACK (gst_object_default_deep_notify), NULL);
2886 connect_bus_signals (pipeline);
2889 g_print ("NULL pipeline\n");
2890 gst_element_set_state (pipeline, GST_STATE_NULL);
2892 g_print ("free pipeline\n");
2893 gst_object_unref (pipeline);
2895 g_list_foreach (paths, (GFunc) g_free, NULL);
2896 g_list_free (paths);