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 40
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
70 /* the state to go to when stop is pressed */
71 #define STOP_STATE GST_STATE_READY
74 static GList *seekable_pads = NULL;
75 static GList *rate_pads = NULL;
76 static GList *seekable_elements = NULL;
78 static gboolean accurate_seek = FALSE;
79 static gboolean keyframe_seek = FALSE;
80 static gboolean loop_seek = FALSE;
81 static gboolean flush_seek = TRUE;
82 static gboolean scrub = TRUE;
83 static gboolean play_scrub = FALSE;
84 static gboolean skip_seek = FALSE;
85 static gdouble rate = 1.0;
87 static GstElement *pipeline;
88 static gint pipeline_type;
89 static const gchar *pipeline_spec;
90 static gint64 position = -1;
91 static gint64 duration = -1;
92 static GtkAdjustment *adjustment;
93 static GtkWidget *hscale, *statusbar;
94 static guint status_id = 0;
95 static gboolean stats = FALSE;
96 static gboolean elem_seek = FALSE;
97 static gboolean verbose = FALSE;
99 static gboolean is_live = FALSE;
100 static gboolean buffering = FALSE;
101 static GstBufferingMode mode;
102 static gint64 buffering_left;
103 static GstState state = GST_STATE_NULL;
104 static guint update_id = 0;
105 static guint seek_timeout_id = 0;
106 static gulong changed_id;
107 static guint fill_id = 0;
109 static gint n_video = 0, n_audio = 0, n_text = 0;
110 static gboolean need_streams = TRUE;
111 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
112 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
113 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
114 static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
115 static GtkWidget *buffer_checkbox, *rate_spinbutton;
117 static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
119 static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
120 static GtkWidget *shuttle_checkbox, *step_button;
121 static GtkWidget *shuttle_hscale;
122 static GtkAdjustment *shuttle_adjustment;
124 static GList *paths = NULL, *l = NULL;
126 /* we keep an array of the visualisation entries so that we can easily switch
127 * with the combo box index. */
130 GstElementFactory *factory;
133 static GArray *vis_entries;
135 static void clear_streams (GstElement * pipeline);
136 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
139 /* pipeline construction */
143 const gchar *padname;
150 gst_element_factory_make_or_warn (gchar * type, gchar * name)
152 GstElement *element = gst_element_factory_make (type, name);
155 g_warning ("Failed to create element %s of type %s", name, type);
162 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
165 dyn_link *connect = (dyn_link *) data;
167 padname = gst_pad_get_name (newpad);
169 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
171 gst_bin_add (GST_BIN (pipeline), connect->bin);
172 gst_pad_link (newpad, connect->target);
174 //seekable_pads = g_list_prepend (seekable_pads, newpad);
175 rate_pads = g_list_prepend (rate_pads, newpad);
181 setup_dynamic_link (GstElement * element, const gchar * padname,
182 GstPad * target, GstElement * bin)
186 connect = g_new0 (dyn_link, 1);
187 connect->padname = g_strdup (padname);
188 connect->target = target;
191 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
196 make_mod_pipeline (const gchar * location)
198 GstElement *pipeline;
199 GstElement *src, *decoder, *audiosink;
202 pipeline = gst_pipeline_new ("app");
204 src = gst_element_factory_make_or_warn (SOURCE, "src");
205 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
206 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
207 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
209 g_object_set (G_OBJECT (src), "location", location, NULL);
211 gst_bin_add (GST_BIN (pipeline), src);
212 gst_bin_add (GST_BIN (pipeline), decoder);
213 gst_bin_add (GST_BIN (pipeline), audiosink);
215 gst_element_link (src, decoder);
216 gst_element_link (decoder, audiosink);
218 seekable = gst_element_get_static_pad (decoder, "src");
219 seekable_pads = g_list_prepend (seekable_pads, seekable);
220 rate_pads = g_list_prepend (rate_pads, seekable);
222 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
228 make_dv_pipeline (const gchar * location)
230 GstElement *pipeline;
231 GstElement *src, *demux, *decoder, *audiosink, *videosink;
232 GstElement *a_queue, *v_queue;
235 pipeline = gst_pipeline_new ("app");
237 src = gst_element_factory_make_or_warn (SOURCE, "src");
238 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
239 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
240 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
241 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
242 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
243 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
245 g_object_set (G_OBJECT (src), "location", location, NULL);
247 gst_bin_add (GST_BIN (pipeline), src);
248 gst_bin_add (GST_BIN (pipeline), demux);
249 gst_bin_add (GST_BIN (pipeline), a_queue);
250 gst_bin_add (GST_BIN (pipeline), audiosink);
251 gst_bin_add (GST_BIN (pipeline), v_queue);
252 gst_bin_add (GST_BIN (pipeline), decoder);
253 gst_bin_add (GST_BIN (pipeline), videosink);
255 gst_element_link (src, demux);
256 gst_element_link (a_queue, audiosink);
257 gst_element_link (v_queue, decoder);
258 gst_element_link (decoder, videosink);
260 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
262 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
265 seekable = gst_element_get_static_pad (decoder, "src");
266 seekable_pads = g_list_prepend (seekable_pads, seekable);
267 rate_pads = g_list_prepend (rate_pads, seekable);
273 make_wav_pipeline (const gchar * location)
275 GstElement *pipeline;
276 GstElement *src, *decoder, *audiosink;
278 pipeline = gst_pipeline_new ("app");
280 src = gst_element_factory_make_or_warn (SOURCE, "src");
281 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
282 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
284 g_object_set (G_OBJECT (src), "location", location, NULL);
286 gst_bin_add (GST_BIN (pipeline), src);
287 gst_bin_add (GST_BIN (pipeline), decoder);
288 gst_bin_add (GST_BIN (pipeline), audiosink);
290 gst_element_link (src, decoder);
292 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
295 seekable_elements = g_list_prepend (seekable_elements, audiosink);
297 /* force element seeking on this pipeline */
304 make_flac_pipeline (const gchar * location)
306 GstElement *pipeline;
307 GstElement *src, *decoder, *audiosink;
310 pipeline = gst_pipeline_new ("app");
312 src = gst_element_factory_make_or_warn (SOURCE, "src");
313 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
314 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
315 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
317 g_object_set (G_OBJECT (src), "location", location, NULL);
319 gst_bin_add (GST_BIN (pipeline), src);
320 gst_bin_add (GST_BIN (pipeline), decoder);
321 gst_bin_add (GST_BIN (pipeline), audiosink);
323 gst_element_link (src, decoder);
324 gst_element_link (decoder, audiosink);
326 seekable = gst_element_get_static_pad (decoder, "src");
327 seekable_pads = g_list_prepend (seekable_pads, seekable);
328 rate_pads = g_list_prepend (rate_pads, seekable);
330 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
336 make_sid_pipeline (const gchar * location)
338 GstElement *pipeline;
339 GstElement *src, *decoder, *audiosink;
342 pipeline = gst_pipeline_new ("app");
344 src = gst_element_factory_make_or_warn (SOURCE, "src");
345 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
346 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
347 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
349 g_object_set (G_OBJECT (src), "location", location, NULL);
351 gst_bin_add (GST_BIN (pipeline), src);
352 gst_bin_add (GST_BIN (pipeline), decoder);
353 gst_bin_add (GST_BIN (pipeline), audiosink);
355 gst_element_link (src, decoder);
356 gst_element_link (decoder, audiosink);
358 seekable = gst_element_get_static_pad (decoder, "src");
359 seekable_pads = g_list_prepend (seekable_pads, seekable);
360 rate_pads = g_list_prepend (rate_pads, seekable);
362 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
368 make_parse_pipeline (const gchar * location)
370 GstElement *pipeline;
371 GstElement *src, *parser, *fakesink;
374 pipeline = gst_pipeline_new ("app");
376 src = gst_element_factory_make_or_warn (SOURCE, "src");
377 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
378 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
379 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
380 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
382 g_object_set (G_OBJECT (src), "location", location, NULL);
384 gst_bin_add (GST_BIN (pipeline), src);
385 gst_bin_add (GST_BIN (pipeline), parser);
386 gst_bin_add (GST_BIN (pipeline), fakesink);
388 gst_element_link (src, parser);
389 gst_element_link (parser, fakesink);
391 seekable = gst_element_get_static_pad (parser, "src");
392 seekable_pads = g_list_prepend (seekable_pads, seekable);
393 rate_pads = g_list_prepend (rate_pads, seekable);
395 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
401 make_vorbis_pipeline (const gchar * location)
403 GstElement *pipeline, *audio_bin;
404 GstElement *src, *demux, *decoder, *convert, *audiosink;
405 GstPad *pad, *seekable;
407 pipeline = gst_pipeline_new ("app");
409 src = gst_element_factory_make_or_warn (SOURCE, "src");
410 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
411 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
412 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
413 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
414 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
416 g_object_set (G_OBJECT (src), "location", location, NULL);
418 audio_bin = gst_bin_new ("a_decoder_bin");
420 gst_bin_add (GST_BIN (pipeline), src);
421 gst_bin_add (GST_BIN (pipeline), demux);
422 gst_bin_add (GST_BIN (audio_bin), decoder);
423 gst_bin_add (GST_BIN (audio_bin), convert);
424 gst_bin_add (GST_BIN (audio_bin), audiosink);
425 gst_bin_add (GST_BIN (pipeline), audio_bin);
427 gst_element_link (src, demux);
428 gst_element_link (decoder, convert);
429 gst_element_link (convert, audiosink);
431 pad = gst_element_get_static_pad (decoder, "sink");
432 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
433 gst_object_unref (pad);
435 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
438 seekable = gst_element_get_static_pad (decoder, "src");
439 seekable_pads = g_list_prepend (seekable_pads, seekable);
440 rate_pads = g_list_prepend (rate_pads, seekable);
442 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
448 make_theora_pipeline (const gchar * location)
450 GstElement *pipeline, *video_bin;
451 GstElement *src, *demux, *decoder, *convert, *videosink;
452 GstPad *pad, *seekable;
454 pipeline = gst_pipeline_new ("app");
456 src = gst_element_factory_make_or_warn (SOURCE, "src");
457 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
458 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
459 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
460 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
462 g_object_set (G_OBJECT (src), "location", location, NULL);
464 video_bin = gst_bin_new ("v_decoder_bin");
466 gst_bin_add (GST_BIN (pipeline), src);
467 gst_bin_add (GST_BIN (pipeline), demux);
468 gst_bin_add (GST_BIN (video_bin), decoder);
469 gst_bin_add (GST_BIN (video_bin), convert);
470 gst_bin_add (GST_BIN (video_bin), videosink);
471 gst_bin_add (GST_BIN (pipeline), video_bin);
473 gst_element_link (src, demux);
474 gst_element_link (decoder, convert);
475 gst_element_link (convert, videosink);
477 pad = gst_element_get_static_pad (decoder, "sink");
478 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
479 gst_object_unref (pad);
481 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
484 seekable = gst_element_get_static_pad (decoder, "src");
485 seekable_pads = g_list_prepend (seekable_pads, seekable);
486 rate_pads = g_list_prepend (rate_pads, seekable);
488 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
494 make_vorbis_theora_pipeline (const gchar * location)
496 GstElement *pipeline, *audio_bin, *video_bin;
497 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
498 GstElement *audiosink, *videosink;
499 GstElement *a_queue, *v_queue, *v_scale;
503 pipeline = gst_pipeline_new ("app");
505 src = gst_element_factory_make_or_warn (SOURCE, "src");
506 g_object_set (G_OBJECT (src), "location", location, NULL);
508 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
510 gst_bin_add (GST_BIN (pipeline), src);
511 gst_bin_add (GST_BIN (pipeline), demux);
512 gst_element_link (src, demux);
514 audio_bin = gst_bin_new ("a_decoder_bin");
515 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
516 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
517 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
518 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
520 gst_bin_add (GST_BIN (pipeline), audio_bin);
522 gst_bin_add (GST_BIN (audio_bin), a_queue);
523 gst_bin_add (GST_BIN (audio_bin), a_decoder);
524 gst_bin_add (GST_BIN (audio_bin), a_convert);
525 gst_bin_add (GST_BIN (audio_bin), audiosink);
527 gst_element_link (a_queue, a_decoder);
528 gst_element_link (a_decoder, a_convert);
529 gst_element_link (a_convert, audiosink);
531 pad = gst_element_get_static_pad (a_queue, "sink");
532 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
533 gst_object_unref (pad);
535 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
538 video_bin = gst_bin_new ("v_decoder_bin");
539 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
540 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
542 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
543 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
544 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
546 gst_bin_add (GST_BIN (pipeline), video_bin);
548 gst_bin_add (GST_BIN (video_bin), v_queue);
549 gst_bin_add (GST_BIN (video_bin), v_decoder);
550 gst_bin_add (GST_BIN (video_bin), v_convert);
551 gst_bin_add (GST_BIN (video_bin), v_scale);
552 gst_bin_add (GST_BIN (video_bin), videosink);
554 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
557 pad = gst_element_get_static_pad (v_queue, "sink");
558 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
559 gst_object_unref (pad);
561 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
564 seekable = gst_element_get_static_pad (a_decoder, "src");
565 seekable_pads = g_list_prepend (seekable_pads, seekable);
566 rate_pads = g_list_prepend (rate_pads, seekable);
568 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
575 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
577 GstElement *pipeline, *audio_bin, *video_bin;
578 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
579 GstElement *audiosink, *videosink;
580 GstElement *a_queue, *v_queue;
581 GstPad *seekable, *pad;
583 pipeline = gst_pipeline_new ("app");
585 src = gst_element_factory_make_or_warn (SOURCE, "src");
586 g_object_set (G_OBJECT (src), "location", location, NULL);
588 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
590 gst_bin_add (GST_BIN (pipeline), src);
591 gst_bin_add (GST_BIN (pipeline), demux);
592 gst_element_link (src, demux);
594 audio_bin = gst_bin_new ("a_decoder_bin");
595 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
596 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
597 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
598 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
600 gst_bin_add (GST_BIN (audio_bin), a_queue);
601 gst_bin_add (GST_BIN (audio_bin), a_decoder);
602 gst_bin_add (GST_BIN (audio_bin), a_convert);
603 gst_bin_add (GST_BIN (audio_bin), audiosink);
605 gst_element_link (a_queue, a_decoder);
606 gst_element_link (a_decoder, a_convert);
607 gst_element_link (a_convert, audiosink);
609 gst_bin_add (GST_BIN (pipeline), audio_bin);
611 pad = gst_element_get_static_pad (a_queue, "sink");
612 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
613 gst_object_unref (pad);
615 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
618 video_bin = gst_bin_new ("v_decoder_bin");
619 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
620 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
622 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
623 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
625 gst_bin_add (GST_BIN (video_bin), v_queue);
626 gst_bin_add (GST_BIN (video_bin), v_decoder);
627 gst_bin_add (GST_BIN (video_bin), v_convert);
628 gst_bin_add (GST_BIN (video_bin), videosink);
630 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
632 gst_bin_add (GST_BIN (pipeline), video_bin);
634 pad = gst_element_get_static_pad (v_queue, "sink");
635 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
636 gst_object_unref (pad);
638 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
641 seekable = gst_element_get_static_pad (a_decoder, "src");
642 seekable_pads = g_list_prepend (seekable_pads, seekable);
643 rate_pads = g_list_prepend (rate_pads, seekable);
645 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
652 make_mp3_pipeline (const gchar * location)
654 GstElement *pipeline;
655 GstElement *src, *parser, *decoder, *audiosink, *queue;
658 pipeline = gst_pipeline_new ("app");
660 src = gst_element_factory_make_or_warn (SOURCE, "src");
661 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
662 decoder = gst_element_factory_make_or_warn ("mad", "dec");
663 queue = gst_element_factory_make_or_warn ("queue", "queue");
664 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
666 seekable_elements = g_list_prepend (seekable_elements, audiosink);
668 g_object_set (G_OBJECT (src), "location", location, NULL);
669 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
671 gst_bin_add (GST_BIN (pipeline), src);
672 gst_bin_add (GST_BIN (pipeline), parser);
673 gst_bin_add (GST_BIN (pipeline), decoder);
674 gst_bin_add (GST_BIN (pipeline), queue);
675 gst_bin_add (GST_BIN (pipeline), audiosink);
677 gst_element_link (src, parser);
678 gst_element_link (parser, decoder);
679 gst_element_link (decoder, queue);
680 gst_element_link (queue, audiosink);
682 seekable = gst_element_get_static_pad (queue, "src");
683 seekable_pads = g_list_prepend (seekable_pads, seekable);
684 rate_pads = g_list_prepend (rate_pads, seekable);
686 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
692 make_avi_pipeline (const gchar * location)
694 GstElement *pipeline, *audio_bin, *video_bin;
695 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
696 GstElement *a_queue = NULL, *v_queue = NULL;
699 pipeline = gst_pipeline_new ("app");
701 src = gst_element_factory_make_or_warn (SOURCE, "src");
702 g_object_set (G_OBJECT (src), "location", location, NULL);
704 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
705 seekable_elements = g_list_prepend (seekable_elements, demux);
707 gst_bin_add (GST_BIN (pipeline), src);
708 gst_bin_add (GST_BIN (pipeline), demux);
709 gst_element_link (src, demux);
711 audio_bin = gst_bin_new ("a_decoder_bin");
712 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
713 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
714 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
715 gst_element_link (a_decoder, a_queue);
716 gst_element_link (a_queue, audiosink);
717 gst_bin_add (GST_BIN (audio_bin), a_decoder);
718 gst_bin_add (GST_BIN (audio_bin), a_queue);
719 gst_bin_add (GST_BIN (audio_bin), audiosink);
720 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
722 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
725 seekable = gst_element_get_static_pad (a_queue, "src");
726 seekable_pads = g_list_prepend (seekable_pads, seekable);
727 rate_pads = g_list_prepend (rate_pads, seekable);
729 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
732 video_bin = gst_bin_new ("v_decoder_bin");
733 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
734 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
735 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
736 gst_element_link (v_decoder, v_queue);
737 gst_element_link (v_queue, videosink);
738 gst_bin_add (GST_BIN (video_bin), v_decoder);
739 gst_bin_add (GST_BIN (video_bin), v_queue);
740 gst_bin_add (GST_BIN (video_bin), videosink);
742 gst_element_set_state (video_bin, GST_STATE_PAUSED);
744 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
747 seekable = gst_element_get_static_pad (v_queue, "src");
748 seekable_pads = g_list_prepend (seekable_pads, seekable);
749 rate_pads = g_list_prepend (rate_pads, seekable);
751 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
758 make_mpeg_pipeline (const gchar * location)
760 GstElement *pipeline, *audio_bin, *video_bin;
761 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
762 GstElement *audiosink, *videosink;
763 GstElement *a_queue, *v_queue;
767 pipeline = gst_pipeline_new ("app");
769 src = gst_element_factory_make_or_warn (SOURCE, "src");
770 g_object_set (G_OBJECT (src), "location", location, NULL);
772 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
773 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
775 gst_bin_add (GST_BIN (pipeline), src);
776 gst_bin_add (GST_BIN (pipeline), demux);
777 gst_element_link (src, demux);
779 audio_bin = gst_bin_new ("a_decoder_bin");
780 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
781 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
782 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
783 gst_bin_add (GST_BIN (audio_bin), a_decoder);
784 gst_bin_add (GST_BIN (audio_bin), a_queue);
785 gst_bin_add (GST_BIN (audio_bin), audiosink);
787 gst_element_link (a_decoder, a_queue);
788 gst_element_link (a_queue, audiosink);
790 gst_bin_add (GST_BIN (pipeline), audio_bin);
792 pad = gst_element_get_static_pad (a_decoder, "sink");
793 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
794 gst_object_unref (pad);
796 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
799 video_bin = gst_bin_new ("v_decoder_bin");
800 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
801 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
802 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
803 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
805 gst_bin_add (GST_BIN (video_bin), v_decoder);
806 gst_bin_add (GST_BIN (video_bin), v_queue);
807 gst_bin_add (GST_BIN (video_bin), v_filter);
808 gst_bin_add (GST_BIN (video_bin), videosink);
810 gst_element_link (v_decoder, v_queue);
811 gst_element_link (v_queue, v_filter);
812 gst_element_link (v_filter, videosink);
814 gst_bin_add (GST_BIN (pipeline), video_bin);
816 pad = gst_element_get_static_pad (v_decoder, "sink");
817 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
818 gst_object_unref (pad);
820 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
823 seekable = gst_element_get_static_pad (v_filter, "src");
824 seekable_pads = g_list_prepend (seekable_pads, seekable);
825 rate_pads = g_list_prepend (rate_pads, seekable);
827 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
834 make_mpegnt_pipeline (const gchar * location)
836 GstElement *pipeline, *audio_bin, *video_bin;
837 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
838 GstElement *audiosink, *videosink;
842 pipeline = gst_pipeline_new ("app");
844 src = gst_element_factory_make_or_warn (SOURCE, "src");
845 g_object_set (G_OBJECT (src), "location", location, NULL);
847 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
848 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
850 seekable_elements = g_list_prepend (seekable_elements, demux);
852 gst_bin_add (GST_BIN (pipeline), src);
853 gst_bin_add (GST_BIN (pipeline), demux);
854 gst_element_link (src, demux);
856 audio_bin = gst_bin_new ("a_decoder_bin");
857 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
858 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
859 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
860 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
861 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
862 gst_element_link (a_decoder, a_queue);
863 gst_element_link (a_queue, audiosink);
864 gst_bin_add (GST_BIN (audio_bin), a_decoder);
865 gst_bin_add (GST_BIN (audio_bin), a_queue);
866 gst_bin_add (GST_BIN (audio_bin), audiosink);
868 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
871 seekable = gst_element_get_static_pad (a_queue, "src");
872 seekable_pads = g_list_prepend (seekable_pads, seekable);
873 rate_pads = g_list_prepend (rate_pads, seekable);
875 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
878 video_bin = gst_bin_new ("v_decoder_bin");
879 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
880 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
881 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
882 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
884 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
886 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
889 seekable = gst_element_get_static_pad (v_decoder, "src");
890 seekable_pads = g_list_prepend (seekable_pads, seekable);
891 rate_pads = g_list_prepend (rate_pads, seekable);
893 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
900 playerbin_set_uri (GstElement * player, const gchar * location)
904 /* Add "file://" prefix for convenience */
905 if (g_str_has_prefix (location, "/")) {
906 uri = g_strconcat ("file://", location, NULL);
907 g_object_set (G_OBJECT (player), "uri", uri, NULL);
910 g_object_set (G_OBJECT (player), "uri", location, NULL);
915 construct_playerbin (const gchar * name, const gchar * location)
919 player = gst_element_factory_make (name, "player");
922 playerbin_set_uri (player, location);
924 seekable_elements = g_list_prepend (seekable_elements, player);
926 /* force element seeking on this pipeline */
933 make_playerbin_pipeline (const gchar * location)
935 return construct_playerbin ("playbin", location);
939 make_playerbin2_pipeline (const gchar * location)
941 GstElement *pipeline = construct_playerbin ("playbin2", location);
943 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
944 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
949 #ifndef GST_DISABLE_PARSE
951 make_parselaunch_pipeline (const gchar * description)
953 GstElement *pipeline;
954 GError *error = NULL;
956 pipeline = gst_parse_launch (description, &error);
958 seekable_elements = g_list_prepend (seekable_elements, pipeline);
969 GstElement *(*func) (const gchar * location);
973 static Pipeline pipelines[] = {
974 {"mp3", make_mp3_pipeline},
975 {"avi", make_avi_pipeline},
976 {"mpeg1", make_mpeg_pipeline},
977 {"mpegparse", make_parse_pipeline},
978 {"vorbis", make_vorbis_pipeline},
979 {"theora", make_theora_pipeline},
980 {"ogg/v/t", make_vorbis_theora_pipeline},
981 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
982 {"sid", make_sid_pipeline},
983 {"flac", make_flac_pipeline},
984 {"wav", make_wav_pipeline},
985 {"mod", make_mod_pipeline},
986 {"dv", make_dv_pipeline},
987 {"mpeg1nothreads", make_mpegnt_pipeline},
988 {"playerbin", make_playerbin_pipeline},
989 #ifndef GST_DISABLE_PARSE
990 {"parse-launch", make_parselaunch_pipeline},
992 {"playerbin2", make_playerbin2_pipeline},
996 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
998 /* ui callbacks and helpers */
1001 format_value (GtkScale * scale, gdouble value)
1007 real = value * duration / 100;
1008 seconds = (gint64) real / GST_SECOND;
1009 subseconds = (gint64) real / (GST_SECOND / 100);
1011 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1012 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1017 shuttle_format_value (GtkScale * scale, gdouble value)
1019 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
1025 const GstFormat format;
1029 static seek_format seek_formats[] = {
1030 {"tim", GST_FORMAT_TIME},
1031 {"byt", GST_FORMAT_BYTES},
1032 {"buf", GST_FORMAT_BUFFERS},
1033 {"def", GST_FORMAT_DEFAULT},
1037 G_GNUC_UNUSED static void
1040 GList *walk = rate_pads;
1043 GstPad *pad = GST_PAD (walk->data);
1046 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1047 while (seek_formats[i].name) {
1051 format = seek_formats[i].format;
1053 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
1055 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1057 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1062 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1064 walk = g_list_next (walk);
1068 G_GNUC_UNUSED static void
1069 query_positions_elems (void)
1071 GList *walk = seekable_elements;
1074 GstElement *element = GST_ELEMENT (walk->data);
1077 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1078 while (seek_formats[i].name) {
1079 gint64 position, total;
1082 format = seek_formats[i].format;
1084 if (gst_element_query_position (element, &format, &position) &&
1085 gst_element_query_duration (element, &format, &total)) {
1086 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1087 seek_formats[i].name, position, total);
1089 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1094 g_print (" %s\n", GST_ELEMENT_NAME (element));
1096 walk = g_list_next (walk);
1100 G_GNUC_UNUSED static void
1101 query_positions_pads (void)
1103 GList *walk = seekable_pads;
1106 GstPad *pad = GST_PAD (walk->data);
1109 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1110 while (seek_formats[i].name) {
1112 gint64 position, total;
1114 format = seek_formats[i].format;
1116 if (gst_pad_query_position (pad, &format, &position) &&
1117 gst_pad_query_duration (pad, &format, &total)) {
1118 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1119 seek_formats[i].name, position, total);
1121 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1127 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1129 walk = g_list_next (walk);
1133 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1134 gpointer user_data);
1135 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1136 gpointer user_data);
1137 static void seek_cb (GtkWidget * widget);
1140 set_scale (gdouble value)
1142 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1144 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1146 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1147 gtk_adjustment_set_value (adjustment, value);
1148 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1150 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1152 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1154 gtk_widget_queue_draw (hscale);
1158 update_fill (gpointer data)
1161 if (seekable_elements) {
1162 GstElement *element = GST_ELEMENT (seekable_elements->data);
1165 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1166 if (gst_element_query (element, query)) {
1173 gst_query_parse_buffering_percent (query, &busy, &percent);
1174 gst_query_parse_buffering_range (query, &format, &start, &stop, NULL);
1176 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1180 fill = 100.0 * stop / GST_FORMAT_PERCENT_MAX;
1184 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1186 gst_query_unref (query);
1193 update_scale (gpointer data)
1195 GstFormat format = GST_FORMAT_TIME;
1201 if (seekable_elements) {
1202 GstElement *element = GST_ELEMENT (seekable_elements->data);
1204 gst_element_query_position (element, &format, &position);
1205 gst_element_query_duration (element, &format, &duration);
1208 if (seekable_pads) {
1209 GstPad *pad = GST_PAD (seekable_pads->data);
1211 gst_pad_query_position (pad, &format, &position);
1212 gst_pad_query_duration (pad, &format, &duration);
1218 query_positions_elems ();
1220 query_positions_pads ();
1225 if (position >= duration)
1226 duration = position;
1229 set_scale (position * 100.0 / duration);
1232 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1233 if (pipeline_type == 16) {
1234 g_object_notify (G_OBJECT (pipeline), "volume");
1240 static void do_seek (GtkWidget * widget);
1241 static void connect_bus_signals (GstElement * pipeline);
1242 static void set_update_scale (gboolean active);
1243 static void set_update_fill (gboolean active);
1246 end_scrub (GtkWidget * widget)
1248 GST_DEBUG ("end scrub, PAUSE");
1249 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1250 seek_timeout_id = 0;
1256 send_event (GstEvent * event)
1258 gboolean res = FALSE;
1261 GList *walk = seekable_pads;
1264 GstPad *seekable = GST_PAD (walk->data);
1266 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1268 gst_event_ref (event);
1269 res = gst_pad_send_event (seekable, event);
1271 walk = g_list_next (walk);
1274 GList *walk = seekable_elements;
1277 GstElement *seekable = GST_ELEMENT (walk->data);
1279 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1281 gst_event_ref (event);
1282 res = gst_element_send_event (seekable, event);
1284 walk = g_list_next (walk);
1287 gst_event_unref (event);
1292 do_seek (GtkWidget * widget)
1295 gboolean res = FALSE;
1299 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
1303 flags |= GST_SEEK_FLAG_FLUSH;
1305 flags |= GST_SEEK_FLAG_ACCURATE;
1307 flags |= GST_SEEK_FLAG_KEY_UNIT;
1309 flags |= GST_SEEK_FLAG_SEGMENT;
1311 flags |= GST_SEEK_FLAG_SKIP;
1314 s_event = gst_event_new_seek (rate,
1315 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1316 GST_CLOCK_TIME_NONE);
1317 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1318 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1320 s_event = gst_event_new_seek (rate,
1321 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1322 GST_SEEK_TYPE_SET, real);
1323 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1324 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1327 res = send_event (s_event);
1331 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1333 set_update_scale (TRUE);
1336 g_print ("seek failed\n");
1337 set_update_scale (TRUE);
1342 seek_cb (GtkWidget * widget)
1344 /* If the timer hasn't expired yet, then the pipeline is running */
1345 if (play_scrub && seek_timeout_id != 0) {
1346 GST_DEBUG ("do scrub seek, PAUSED");
1347 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1350 GST_DEBUG ("do seek");
1354 GST_DEBUG ("do scrub seek, PLAYING");
1355 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1357 if (seek_timeout_id == 0) {
1359 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1365 set_update_fill (gboolean active)
1367 GST_DEBUG ("fill scale is %d", active);
1372 g_timeout_add (FILL_INTERVAL, (GtkFunction) update_fill, pipeline);
1376 g_source_remove (fill_id);
1383 set_update_scale (gboolean active)
1386 GST_DEBUG ("update scale is %d", active);
1389 if (update_id == 0) {
1391 g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
1395 g_source_remove (update_id);
1402 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1404 if (event->type != GDK_BUTTON_PRESS)
1407 set_update_scale (FALSE);
1409 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1410 GST_DEBUG ("start scrub seek, PAUSE");
1411 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1414 if (changed_id == 0 && flush_seek && scrub) {
1416 g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb),
1424 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1427 g_signal_handler_disconnect (hscale, changed_id);
1431 if (!flush_seek || !scrub) {
1432 GST_DEBUG ("do final seek");
1436 if (seek_timeout_id != 0) {
1437 g_source_remove (seek_timeout_id);
1438 seek_timeout_id = 0;
1439 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1441 if (state == GST_STATE_PAUSED) {
1442 GST_DEBUG ("stop scrub seek, PAUSED");
1443 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1446 if (state == GST_STATE_PLAYING) {
1447 GST_DEBUG ("stop scrub seek, PLAYING");
1448 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1456 play_cb (GtkButton * button, gpointer data)
1458 GstStateChangeReturn ret;
1460 if (state != GST_STATE_PLAYING) {
1461 g_print ("PLAY pipeline\n");
1462 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1464 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1466 case GST_STATE_CHANGE_FAILURE:
1468 case GST_STATE_CHANGE_NO_PREROLL:
1474 state = GST_STATE_PLAYING;
1475 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1482 g_print ("PLAY failed\n");
1483 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1488 pause_cb (GtkButton * button, gpointer data)
1490 g_static_mutex_lock (&state_mutex);
1491 if (state != GST_STATE_PAUSED) {
1492 GstStateChangeReturn ret;
1494 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1495 g_print ("PAUSE pipeline\n");
1496 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1498 case GST_STATE_CHANGE_FAILURE:
1500 case GST_STATE_CHANGE_NO_PREROLL:
1507 state = GST_STATE_PAUSED;
1508 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1510 g_static_mutex_unlock (&state_mutex);
1516 g_static_mutex_unlock (&state_mutex);
1517 g_print ("PAUSE failed\n");
1518 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1523 stop_cb (GtkButton * button, gpointer data)
1525 if (state != STOP_STATE) {
1526 GstStateChangeReturn ret;
1528 g_print ("READY pipeline\n");
1529 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1531 g_static_mutex_lock (&state_mutex);
1532 ret = gst_element_set_state (pipeline, STOP_STATE);
1533 if (ret == GST_STATE_CHANGE_FAILURE)
1537 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1541 set_update_scale (FALSE);
1543 set_update_fill (FALSE);
1545 if (pipeline_type == 16)
1546 clear_streams (pipeline);
1547 g_static_mutex_unlock (&state_mutex);
1550 /* if one uses parse_launch, play, stop and play again it fails as all the
1551 * pads after the demuxer can't be reconnected
1553 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1554 gst_element_set_state (pipeline, GST_STATE_NULL);
1555 gst_object_unref (pipeline);
1557 g_list_free (seekable_elements);
1558 seekable_elements = NULL;
1559 g_list_free (seekable_pads);
1560 seekable_pads = NULL;
1561 g_list_free (rate_pads);
1564 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1565 g_assert (pipeline);
1566 gst_element_set_state (pipeline, STOP_STATE);
1567 connect_bus_signals (pipeline);
1575 g_static_mutex_unlock (&state_mutex);
1576 g_print ("STOP failed\n");
1577 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1582 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1584 accurate_seek = gtk_toggle_button_get_active (button);
1588 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1590 keyframe_seek = gtk_toggle_button_get_active (button);
1594 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1596 loop_seek = gtk_toggle_button_get_active (button);
1597 if (state == GST_STATE_PLAYING) {
1603 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1605 flush_seek = gtk_toggle_button_get_active (button);
1609 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1611 scrub = gtk_toggle_button_get_active (button);
1615 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1617 play_scrub = gtk_toggle_button_get_active (button);
1621 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1623 skip_seek = gtk_toggle_button_get_active (button);
1624 if (state == GST_STATE_PLAYING) {
1630 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1632 gboolean res = FALSE;
1636 rate = gtk_spin_button_get_value (button);
1638 GST_DEBUG ("rate changed to %lf", rate);
1642 flags |= GST_SEEK_FLAG_FLUSH;
1644 flags |= GST_SEEK_FLAG_SEGMENT;
1646 flags |= GST_SEEK_FLAG_ACCURATE;
1648 flags |= GST_SEEK_FLAG_KEY_UNIT;
1650 flags |= GST_SEEK_FLAG_SKIP;
1653 s_event = gst_event_new_seek (rate,
1654 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1655 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1657 s_event = gst_event_new_seek (rate,
1658 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1659 GST_SEEK_TYPE_SET, position);
1662 res = send_event (s_event);
1666 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1669 g_print ("seek failed\n");
1673 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1677 g_object_get (pipeline, "flags", &flags, NULL);
1679 flags |= (1 << num);
1681 flags &= ~(1 << num);
1682 g_object_set (pipeline, "flags", flags, NULL);
1686 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1690 state = gtk_toggle_button_get_active (button);
1691 update_flag (pipeline, 3, state);
1692 gtk_widget_set_sensitive (vis_combo, state);
1696 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1700 state = gtk_toggle_button_get_active (button);
1701 update_flag (pipeline, 1, state);
1702 gtk_widget_set_sensitive (audio_combo, state);
1706 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1710 state = gtk_toggle_button_get_active (button);
1711 update_flag (pipeline, 0, state);
1712 gtk_widget_set_sensitive (video_combo, state);
1716 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1720 state = gtk_toggle_button_get_active (button);
1721 update_flag (pipeline, 2, state);
1722 gtk_widget_set_sensitive (text_combo, state);
1726 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1730 mute = gtk_toggle_button_get_active (button);
1731 g_object_set (pipeline, "mute", mute, NULL);
1735 download_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1739 state = gtk_toggle_button_get_active (button);
1740 update_flag (pipeline, 7, state);
1744 buffer_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1748 state = gtk_toggle_button_get_active (button);
1749 update_flag (pipeline, 8, state);
1753 clear_streams (GstElement * pipeline)
1757 /* remove previous info */
1758 for (i = 0; i < n_video; i++)
1759 gtk_combo_box_remove_text (GTK_COMBO_BOX (video_combo), 0);
1760 for (i = 0; i < n_audio; i++)
1761 gtk_combo_box_remove_text (GTK_COMBO_BOX (audio_combo), 0);
1762 for (i = 0; i < n_text; i++)
1763 gtk_combo_box_remove_text (GTK_COMBO_BOX (text_combo), 0);
1765 n_audio = n_video = n_text = 0;
1766 gtk_widget_set_sensitive (video_combo, FALSE);
1767 gtk_widget_set_sensitive (audio_combo, FALSE);
1768 gtk_widget_set_sensitive (text_combo, FALSE);
1770 need_streams = TRUE;
1774 update_streams (GstPipeline * pipeline)
1778 if (pipeline_type == 16 && need_streams) {
1784 /* remove previous info */
1785 clear_streams (GST_ELEMENT_CAST (pipeline));
1787 /* here we get and update the different streams detected by playbin2 */
1788 g_object_get (pipeline, "n-video", &n_video, NULL);
1789 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1790 g_object_get (pipeline, "n-text", &n_text, NULL);
1792 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1795 for (i = 0; i < n_video; i++) {
1796 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1798 str = gst_structure_to_string ((GstStructure *) tags);
1799 g_print ("video %d: %s\n", i, str);
1802 /* find good name for the label */
1803 name = g_strdup_printf ("video %d", i + 1);
1804 gtk_combo_box_append_text (GTK_COMBO_BOX (video_combo), name);
1807 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1808 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1809 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1812 for (i = 0; i < n_audio; i++) {
1813 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1815 str = gst_structure_to_string ((GstStructure *) tags);
1816 g_print ("audio %d: %s\n", i, str);
1819 /* find good name for the label */
1820 name = g_strdup_printf ("audio %d", i + 1);
1821 gtk_combo_box_append_text (GTK_COMBO_BOX (audio_combo), name);
1824 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1825 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1826 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1829 for (i = 0; i < n_text; i++) {
1830 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1834 const GValue *value;
1836 str = gst_structure_to_string ((GstStructure *) tags);
1837 g_print ("text %d: %s\n", i, str);
1840 /* get the language code if we can */
1841 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1842 if (value && G_VALUE_HOLDS_STRING (value)) {
1843 name = g_strdup_printf ("text %s", g_value_get_string (value));
1846 /* find good name for the label if we didn't use a tag */
1848 name = g_strdup_printf ("text %d", i + 1);
1850 gtk_combo_box_append_text (GTK_COMBO_BOX (text_combo), name);
1853 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1854 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1855 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1857 need_streams = FALSE;
1862 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1866 active = gtk_combo_box_get_active (combo);
1868 g_print ("setting current video track %d\n", active);
1869 g_object_set (pipeline, "current-video", active, NULL);
1873 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1877 active = gtk_combo_box_get_active (combo);
1879 g_print ("setting current audio track %d\n", active);
1880 g_object_set (pipeline, "current-audio", active, NULL);
1884 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1888 active = gtk_combo_box_get_active (combo);
1890 g_print ("setting current text track %d\n", active);
1891 g_object_set (pipeline, "current-text", active, NULL);
1895 filter_features (GstPluginFeature * feature, gpointer data)
1897 GstElementFactory *f;
1899 if (!GST_IS_ELEMENT_FACTORY (feature))
1901 f = GST_ELEMENT_FACTORY (feature);
1902 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1909 init_visualization_features (void)
1913 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1915 list = gst_registry_feature_filter (gst_registry_get_default (),
1916 filter_features, FALSE, NULL);
1918 for (walk = list; walk; walk = g_list_next (walk)) {
1922 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1923 name = gst_element_factory_get_longname (entry.factory);
1925 g_array_append_val (vis_entries, entry);
1926 gtk_combo_box_append_text (GTK_COMBO_BOX (vis_combo), name);
1928 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1932 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1936 GstElement *element;
1938 /* get the selected index and get the factory for this index */
1939 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1940 if (vis_entries->len > 0) {
1941 entry = &g_array_index (vis_entries, VisEntry, index);
1943 /* create an instance of the element from the factory */
1944 element = gst_element_factory_create (entry->factory, NULL);
1948 /* set vis plugin for playbin2 */
1949 g_object_set (pipeline, "vis-plugin", element, NULL);
1954 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1958 volume = gtk_spin_button_get_value (button);
1960 g_object_set (pipeline, "volume", volume, NULL);
1964 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
1966 gdouble cur_volume, new_volume;
1968 g_object_get (pipeline, "volume", &new_volume, NULL);
1969 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
1970 if (fabs (cur_volume - new_volume) > 0.001) {
1971 g_signal_handlers_block_by_func (volume_spinbutton,
1972 volume_spinbutton_changed_cb, pipeline);
1973 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
1974 g_signal_handlers_unblock_by_func (volume_spinbutton,
1975 volume_spinbutton_changed_cb, pipeline);
1980 shot_cb (GtkButton * button, gpointer data)
1985 /* convert to our desired format (RGB24) */
1986 caps = gst_caps_new_simple ("video/x-raw-rgb",
1987 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
1988 /* Note: we don't ask for a specific width/height here, so that
1989 * videoscale can adjust dimensions from a non-1/1 pixel aspect
1990 * ratio to a 1/1 pixel-aspect-ratio */
1991 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
1992 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
1993 "red_mask", G_TYPE_INT, 0xff0000,
1994 "green_mask", G_TYPE_INT, 0x00ff00,
1995 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
1997 /* convert the latest frame to the requested format */
1998 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
1999 gst_caps_unref (caps);
2007 GError *error = NULL;
2009 /* get the snapshot buffer format now. We set the caps on the appsink so
2010 * that it can only be an rgb buffer. The only thing we have not specified
2011 * on the caps is the height, which is dependant on the pixel-aspect-ratio
2012 * of the source material */
2013 caps = GST_BUFFER_CAPS (buffer);
2015 g_warning ("could not get snapshot format\n");
2018 s = gst_caps_get_structure (caps, 0);
2020 /* we need to get the final caps on the buffer to get the size */
2021 res = gst_structure_get_int (s, "width", &width);
2022 res |= gst_structure_get_int (s, "height", &height);
2024 g_warning ("could not get snapshot dimension\n");
2028 /* create pixmap from buffer and save, gstreamer video buffers have a stride
2029 * that is rounded up to the nearest multiple of 4 */
2030 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
2031 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2032 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2034 /* save the pixbuf */
2035 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2038 gst_buffer_unref (buffer);
2042 /* called when the Step button is pressed */
2044 step_cb (GtkButton * button, gpointer data)
2050 gboolean flush, res;
2053 active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo));
2055 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
2056 (step_amount_spinbutton));
2057 rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton));
2062 format = GST_FORMAT_BUFFERS;
2065 format = GST_FORMAT_TIME;
2066 amount *= GST_MSECOND;
2069 format = GST_FORMAT_UNDEFINED;
2073 event = gst_event_new_step (format, amount, rate, flush, FALSE);
2075 res = send_event (event);
2079 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2081 const GstStructure *s;
2083 s = gst_message_get_structure (message);
2084 g_print ("message from \"%s\" (%s): ",
2085 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2086 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2090 sstr = gst_structure_to_string (s);
2091 g_print ("%s\n", sstr);
2094 g_print ("no message details\n");
2098 static gboolean shuttling = FALSE;
2099 static gdouble shuttle_rate = 0.0;
2100 static gdouble play_rate = 1.0;
2103 do_shuttle (GstElement * element)
2108 duration = 40 * GST_MSECOND;
2112 gst_element_send_event (element,
2113 gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE,
2118 msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element)
2124 gboolean intermediate;
2128 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
2129 &intermediate, &duration, &eos);
2132 g_print ("stepped till EOS\n");
2136 if (g_static_mutex_trylock (&state_mutex)) {
2138 do_shuttle (element);
2139 g_static_mutex_unlock (&state_mutex);
2141 /* ignore step messages that come while we are doing a state change */
2142 g_print ("state change is busy\n");
2147 shuttle_toggled (GtkToggleButton * button, GstElement * element)
2151 active = gtk_toggle_button_get_active (button);
2153 if (active != shuttling) {
2155 g_print ("shuttling %s\n", shuttling ? "active" : "inactive");
2159 pause_cb (NULL, NULL);
2160 gst_element_get_state (element, NULL, NULL, -1);
2166 shuttle_rate_switch (GstElement * element)
2172 if (state == GST_STATE_PLAYING) {
2173 /* pause when we need to */
2174 pause_cb (NULL, NULL);
2175 gst_element_get_state (element, NULL, NULL, -1);
2178 if (play_rate == 1.0)
2183 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate,
2184 GST_TIME_ARGS (position));
2186 flags = GST_SEEK_FLAG_FLUSH;
2187 flags |= GST_SEEK_FLAG_ACCURATE;
2189 if (play_rate >= 0.0) {
2190 s_event = gst_event_new_seek (play_rate,
2191 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
2192 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
2194 s_event = gst_event_new_seek (play_rate,
2195 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2196 GST_SEEK_TYPE_SET, position);
2198 res = send_event (s_event);
2200 gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT);
2202 g_print ("seek failed\n");
2207 shuttle_value_changed (GtkRange * range, GstElement * element)
2211 rate = gtk_adjustment_get_value (shuttle_adjustment);
2214 g_print ("rate 0.0, pause\n");
2215 pause_cb (NULL, NULL);
2216 gst_element_get_state (element, NULL, NULL, -1);
2218 g_print ("rate changed %0.3g\n", rate);
2220 if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) {
2221 shuttle_rate_switch (element);
2224 shuttle_rate = ABS (rate);
2225 if (state != GST_STATE_PLAYING) {
2226 do_shuttle (element);
2227 play_cb (NULL, NULL);
2233 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2235 GST_DEBUG ("async done");
2236 /* when we get ASYNC_DONE we can query position, duration and other
2238 update_scale (pipeline);
2240 /* update the available streams */
2241 update_streams (pipeline);
2245 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2247 const GstStructure *s;
2249 s = gst_message_get_structure (message);
2251 /* We only care about state changed on the pipeline */
2252 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2253 GstState old, new, pending;
2255 gst_message_parse_state_changed (message, &old, &new, &pending);
2257 /* When state of the pipeline changes to paused or playing we start updating scale */
2258 if (new == GST_STATE_PLAYING) {
2259 set_update_scale (TRUE);
2261 set_update_scale (FALSE);
2267 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2274 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2275 gst_message_parse_segment_done (message, &format, &position);
2276 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2279 /* in the segment-done callback we never flush as this would not make sense
2280 * for seamless playback. */
2282 flags |= GST_SEEK_FLAG_SEGMENT;
2284 flags |= GST_SEEK_FLAG_SKIP;
2286 s_event = gst_event_new_seek (rate,
2287 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2288 GST_SEEK_TYPE_SET, duration);
2290 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2291 rate, GST_TIME_ARGS (duration));
2293 res = send_event (s_event);
2295 g_print ("segment seek failed\n");
2298 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2301 do_stream_buffering (gint percent)
2305 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2306 bufstr = g_strdup_printf ("Buffering...%d", percent);
2307 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2310 if (percent == 100) {
2311 /* a 100% message means buffering is done */
2313 /* if the desired state is playing, go back */
2314 if (state == GST_STATE_PLAYING) {
2315 /* no state management needed for live pipelines */
2317 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2318 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2320 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2321 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2324 /* buffering busy */
2325 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2326 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2328 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2329 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2337 do_download_buffering (gint percent)
2339 if (!buffering && percent < 100) {
2344 bufstr = g_strdup_printf ("Downloading...");
2345 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2348 /* once we get a buffering message, we'll do the fill update */
2349 set_update_fill (TRUE);
2351 if (state == GST_STATE_PLAYING && !is_live) {
2352 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2353 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2354 /* user has to manually start the playback */
2355 state = GST_STATE_PAUSED;
2361 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2365 gst_message_parse_buffering (message, &percent);
2367 /* get more stats */
2368 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2372 case GST_BUFFERING_DOWNLOAD:
2373 do_download_buffering (percent);
2375 case GST_BUFFERING_LIVE:
2376 case GST_BUFFERING_TIMESHIFT:
2377 case GST_BUFFERING_STREAM:
2378 do_stream_buffering (percent);
2384 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2386 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2388 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2389 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2394 static gulong embed_xid = 0;
2396 /* We set the xid here in response to the prepare-xwindow-id message via a
2397 * bus sync handler because we don't know the actual videosink used from the
2398 * start (as we don't know the pipeline, or bin elements such as autovideosink
2399 * or gconfvideosink may be used which create the actual videosink only once
2400 * the pipeline is started) */
2401 static GstBusSyncReply
2402 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2404 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
2405 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
2406 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2408 g_print ("got prepare-xwindow-id, setting XID %lu\n", embed_xid);
2410 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2411 "force-aspect-ratio")) {
2412 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2415 /* Should have been initialised from main thread before (can't use
2416 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2417 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2418 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2419 * shouldn't be done from a non-GUI thread without explicit locking). */
2420 g_assert (embed_xid != 0);
2422 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (element), embed_xid);
2424 return GST_BUS_PASS;
2429 handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
2431 if (state < GST_STATE_PAUSED) {
2432 gdk_draw_rectangle (widget->window, widget->style->black_gc, TRUE,
2433 0, 0, widget->allocation.width, widget->allocation.height);
2439 realize_cb (GtkWidget * widget, gpointer data)
2441 #if GTK_CHECK_VERSION(2,18,0)
2442 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2444 if (!gdk_window_ensure_native (widget->window))
2445 g_error ("Couldn't create native window needed for GstXOverlay!");
2449 embed_xid = GDK_WINDOW_XID (video_window->window);
2450 g_print ("Window realize: video window XID = %lu\n", embed_xid);
2455 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2457 message_received (bus, message, data);
2459 /* Set new uri for playerbins and continue playback */
2460 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2461 stop_cb (NULL, NULL);
2462 l = g_list_next (l);
2464 playerbin_set_uri (GST_ELEMENT (data), l->data);
2465 play_cb (NULL, NULL);
2471 msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data)
2474 message_received (bus, message, data);
2478 connect_bus_signals (GstElement * pipeline)
2480 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2483 /* handle prepare-xwindow-id element message synchronously */
2484 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2488 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2489 gst_bus_enable_sync_message_emission (bus);
2491 g_signal_connect (bus, "message::state-changed",
2492 (GCallback) msg_state_changed, pipeline);
2493 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2495 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2498 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2500 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2502 g_signal_connect (bus, "message::error", (GCallback) message_received,
2504 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2506 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2507 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2509 g_signal_connect (bus, "message::element", (GCallback) message_received,
2511 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2513 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2515 // g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done,
2517 g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done,
2519 g_signal_connect (bus, "sync-message::step-done",
2520 (GCallback) msg_sync_step_done, pipeline);
2522 gst_object_unref (bus);
2525 /* Return GList of paths described in location string */
2527 handle_wildcards (const gchar * location)
2530 gchar *path = g_path_get_dirname (location);
2531 gchar *pattern = g_path_get_basename (location);
2532 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2533 GDir *dir = g_dir_open (path, 0, NULL);
2536 g_print ("matching %s from %s\n", pattern, path);
2539 g_print ("opening directory %s failed\n", path);
2543 while ((name = g_dir_read_name (dir)) != NULL) {
2544 if (g_pattern_match_string (pspec, name)) {
2545 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2546 g_print (" found clip %s\n", name);
2552 g_pattern_spec_free (pspec);
2560 delete_event_cb (void)
2562 stop_cb (NULL, NULL);
2567 print_usage (int argc, char **argv)
2571 g_print ("usage: %s <type> <filename>\n", argv[0]);
2572 g_print (" possible types:\n");
2574 for (i = 0; i < NUM_TYPES; i++) {
2575 g_print (" %d = %s\n", i, pipelines[i].name);
2580 main (int argc, char **argv)
2582 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2583 *flagtable, *boxes2, *step;
2584 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2585 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2586 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2587 GtkWidget *rate_label, *volume_label;
2588 GOptionEntry options[] = {
2589 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2590 "Show pad stats", NULL},
2591 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2592 "Seek on elements instead of pads", NULL},
2593 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2594 "Verbose properties", NULL},
2597 GOptionContext *ctx;
2600 if (!g_thread_supported ())
2601 g_thread_init (NULL);
2603 ctx = g_option_context_new ("- test seeking in gsteamer");
2604 g_option_context_add_main_entries (ctx, options, NULL);
2605 g_option_context_add_group (ctx, gst_init_get_option_group ());
2606 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2608 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2609 g_print ("Error initializing: %s\n", err->message);
2613 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2616 print_usage (argc, argv);
2620 pipeline_type = atoi (argv[1]);
2622 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2623 print_usage (argc, argv);
2627 pipeline_spec = argv[2];
2629 if (g_strrstr (pipeline_spec, "*") != NULL ||
2630 g_strrstr (pipeline_spec, "?") != NULL) {
2631 paths = handle_wildcards (pipeline_spec);
2633 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2637 g_print ("opening %s failed\n", pipeline_spec);
2643 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2644 g_assert (pipeline);
2646 /* initialize gui elements ... */
2647 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2648 video_window = gtk_drawing_area_new ();
2649 g_signal_connect (video_window, "expose-event",
2650 G_CALLBACK (handle_expose_cb), NULL);
2651 g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL);
2652 gtk_widget_set_double_buffered (video_window, FALSE);
2654 statusbar = gtk_statusbar_new ();
2655 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2656 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2657 hbox = gtk_hbox_new (FALSE, 0);
2658 vbox = gtk_vbox_new (FALSE, 0);
2659 flagtable = gtk_table_new (4, 2, FALSE);
2660 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2662 /* media controls */
2663 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2664 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2665 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2668 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2669 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2670 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2671 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2672 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2673 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2674 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2675 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2676 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2677 rate_label = gtk_label_new ("Rate");
2679 gtk_widget_set_tooltip_text (accurate_checkbox,
2680 "accurate position is requested, this might be considerably slower for some formats");
2681 gtk_widget_set_tooltip_text (key_checkbox,
2682 "seek to the nearest keyframe. This might be faster but less accurate");
2683 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2684 gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking");
2685 gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, "
2686 "negative value trigger reverse playback");
2687 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2688 gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking");
2689 gtk_widget_set_tooltip_text (skip_checkbox,
2690 "Skip frames while playing at high frame rates");
2692 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2693 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2695 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2701 step = gtk_expander_new ("step options");
2702 hbox = gtk_hbox_new (FALSE, 0);
2704 format_combo = gtk_combo_box_new_text ();
2705 gtk_combo_box_append_text (GTK_COMBO_BOX (format_combo), "frames");
2706 gtk_combo_box_append_text (GTK_COMBO_BOX (format_combo), "time (ms)");
2707 gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0);
2708 gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2);
2710 step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2711 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0);
2712 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0);
2713 gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE,
2716 step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2717 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3);
2718 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0);
2719 gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2);
2721 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2722 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2723 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2725 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2729 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2730 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2731 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2732 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2735 shuttle_adjustment =
2736 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2737 shuttle_hscale = gtk_hscale_new (shuttle_adjustment);
2738 gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2);
2739 gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP);
2740 gtk_range_set_update_policy (GTK_RANGE (shuttle_hscale),
2741 GTK_UPDATE_CONTINUOUS);
2742 g_signal_connect (shuttle_hscale, "value_changed",
2743 G_CALLBACK (shuttle_value_changed), pipeline);
2744 g_signal_connect (shuttle_hscale, "format_value",
2745 G_CALLBACK (shuttle_format_value), pipeline);
2747 gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2);
2749 gtk_container_add (GTK_CONTAINER (step), hbox);
2754 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
2755 hscale = gtk_hscale_new (adjustment);
2756 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2757 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
2758 #if GTK_CHECK_VERSION(2,12,0)
2759 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2760 gtk_range_set_fill_level (GTK_RANGE (hscale), 100.0);
2762 gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);
2764 g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek),
2766 g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek),
2768 g_signal_connect (hscale, "format_value", G_CALLBACK (format_value),
2771 if (pipeline_type == 16) {
2772 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2773 panel = gtk_hbox_new (FALSE, 0);
2774 video_combo = gtk_combo_box_new_text ();
2775 audio_combo = gtk_combo_box_new_text ();
2776 text_combo = gtk_combo_box_new_text ();
2777 gtk_widget_set_sensitive (video_combo, FALSE);
2778 gtk_widget_set_sensitive (audio_combo, FALSE);
2779 gtk_widget_set_sensitive (text_combo, FALSE);
2780 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2781 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2782 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2783 g_signal_connect (G_OBJECT (video_combo), "changed",
2784 G_CALLBACK (video_combo_cb), pipeline);
2785 g_signal_connect (G_OBJECT (audio_combo), "changed",
2786 G_CALLBACK (audio_combo_cb), pipeline);
2787 g_signal_connect (G_OBJECT (text_combo), "changed",
2788 G_CALLBACK (text_combo_cb), pipeline);
2789 /* playbin2 panel for flag checkboxes and volume/mute */
2790 boxes = gtk_hbox_new (FALSE, 0);
2791 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2792 video_checkbox = gtk_check_button_new_with_label ("Video");
2793 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2794 text_checkbox = gtk_check_button_new_with_label ("Text");
2795 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2796 download_checkbox = gtk_check_button_new_with_label ("Download");
2797 buffer_checkbox = gtk_check_button_new_with_label ("Buffer");
2798 volume_label = gtk_label_new ("Volume");
2799 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2800 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2801 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2802 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2803 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2804 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2805 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2806 gtk_box_pack_start (GTK_BOX (boxes), download_checkbox, TRUE, TRUE, 2);
2807 gtk_box_pack_start (GTK_BOX (boxes), buffer_checkbox, TRUE, TRUE, 2);
2808 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
2809 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2810 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2811 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2812 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2813 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2814 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2815 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
2816 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffer_checkbox), FALSE);
2817 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2818 G_CALLBACK (vis_toggle_cb), pipeline);
2819 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2820 G_CALLBACK (audio_toggle_cb), pipeline);
2821 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2822 G_CALLBACK (video_toggle_cb), pipeline);
2823 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2824 G_CALLBACK (text_toggle_cb), pipeline);
2825 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2826 G_CALLBACK (mute_toggle_cb), pipeline);
2827 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
2828 G_CALLBACK (download_toggle_cb), pipeline);
2829 g_signal_connect (G_OBJECT (buffer_checkbox), "toggled",
2830 G_CALLBACK (buffer_toggle_cb), pipeline);
2831 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2832 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2833 /* playbin2 panel for snapshot */
2834 boxes2 = gtk_hbox_new (FALSE, 0);
2835 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2836 gtk_widget_set_tooltip_text (shot_button,
2837 "save a screenshot .png in the current directory");
2838 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2840 vis_combo = gtk_combo_box_new_text ();
2841 g_signal_connect (G_OBJECT (vis_combo), "changed",
2842 G_CALLBACK (vis_combo_cb), pipeline);
2843 gtk_widget_set_sensitive (vis_combo, FALSE);
2844 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2845 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2847 /* fill the vis combo box and the array of factories */
2848 init_visualization_features ();
2850 panel = boxes = boxes2 = NULL;
2853 /* do the packing stuff ... */
2854 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2855 /* FIXME: can we avoid this for audio only? */
2856 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
2857 DEFAULT_VIDEO_HEIGHT);
2858 gtk_container_add (GTK_CONTAINER (window), vbox);
2859 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
2860 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2861 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2862 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2863 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2864 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2865 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2867 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2868 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2869 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2870 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2871 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2873 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2874 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2875 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2877 if (panel && boxes && boxes2) {
2878 expander = gtk_expander_new ("playbin2 options");
2879 pb2vbox = gtk_vbox_new (FALSE, 0);
2880 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2881 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2882 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2883 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2884 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2886 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2887 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
2888 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
2890 /* connect things ... */
2891 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
2893 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
2895 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
2897 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2898 G_CALLBACK (accurate_toggle_cb), pipeline);
2899 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2900 G_CALLBACK (key_toggle_cb), pipeline);
2901 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2902 G_CALLBACK (loop_toggle_cb), pipeline);
2903 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2904 G_CALLBACK (flush_toggle_cb), pipeline);
2905 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2906 G_CALLBACK (scrub_toggle_cb), pipeline);
2907 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2908 G_CALLBACK (play_scrub_toggle_cb), pipeline);
2909 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2910 G_CALLBACK (skip_toggle_cb), pipeline);
2911 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
2912 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
2914 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
2917 gtk_widget_show_all (window);
2919 /* realize window now so that the video window gets created and we can
2920 * obtain its XID before the pipeline is started up and the videosink
2921 * asks for the XID of the window to render onto */
2922 gtk_widget_realize (window);
2924 /* we should have the XID now */
2925 g_assert (embed_xid != 0);
2928 g_signal_connect (pipeline, "deep_notify",
2929 G_CALLBACK (gst_object_default_deep_notify), NULL);
2932 connect_bus_signals (pipeline);
2935 g_print ("NULL pipeline\n");
2936 gst_element_set_state (pipeline, GST_STATE_NULL);
2938 g_print ("free pipeline\n");
2939 gst_object_unref (pipeline);
2941 g_list_foreach (paths, (GFunc) g_free, NULL);
2942 g_list_free (paths);