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.
29 #include <glib/gstdio.h>
42 #include <linux/input.h>
43 #include <linux/joystick.h>
48 #include <gst/interfaces/xoverlay.h>
50 GST_DEBUG_CATEGORY_STATIC (seek_debug);
51 #define GST_CAT_DEFAULT (seek_debug)
53 #if (!GTK_CHECK_VERSION(2, 23, 0) || GTK_CHECK_VERSION(2, 90, 0)) && !GTK_CHECK_VERSION(2, 91, 1)
54 #define gtk_combo_box_text_new gtk_combo_box_new_text
55 #define gtk_combo_box_text_append_text gtk_combo_box_append_text
56 #define gtk_combo_box_text_remove gtk_combo_box_remove_text
57 #define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX
60 #if !GTK_CHECK_VERSION (2, 17, 7)
62 gtk_widget_get_allocation (GtkWidget * w, GtkAllocation * a)
70 //#define SOURCE "filesrc"
71 #define SOURCE "gnomevfssrc"
73 #define ASINK "alsasink"
74 //#define ASINK "osssink"
76 #define VSINK "xvimagesink"
77 //#define VSINK "sdlvideosink"
78 //#define VSINK "ximagesink"
79 //#define VSINK "aasink"
80 //#define VSINK "cacasink"
82 #define FILL_INTERVAL 100
83 //#define UPDATE_INTERVAL 500
84 //#define UPDATE_INTERVAL 100
85 //#define UPDATE_INTERVAL 10
86 #define UPDATE_INTERVAL 40
88 /* number of milliseconds to play for after a seek */
89 #define SCRUB_TIME 100
91 /* timeout for gst_element_get_state() after a seek */
92 #define SEEK_TIMEOUT 40 * GST_MSECOND
94 #define DEFAULT_VIDEO_HEIGHT 300
96 /* the state to go to when stop is pressed */
97 #define STOP_STATE GST_STATE_READY
100 static GList *seekable_pads = NULL;
101 static GList *rate_pads = NULL;
102 static GList *seekable_elements = NULL;
104 static gboolean accurate_seek = FALSE;
105 static gboolean keyframe_seek = FALSE;
106 static gboolean loop_seek = FALSE;
107 static gboolean flush_seek = TRUE;
108 static gboolean scrub = TRUE;
109 static gboolean play_scrub = FALSE;
110 static gboolean skip_seek = FALSE;
111 static gdouble rate = 1.0;
113 static GstElement *pipeline;
114 static gint pipeline_type;
115 static const gchar *pipeline_spec;
116 static gint64 position = -1;
117 static gint64 duration = -1;
118 static GtkAdjustment *adjustment;
119 static GtkWidget *hscale, *statusbar;
120 static guint status_id = 0;
121 static gboolean stats = FALSE;
122 static gboolean elem_seek = FALSE;
123 static gboolean verbose = FALSE;
124 static gchar *js_device = NULL;
126 static gboolean is_live = FALSE;
127 static gboolean buffering = FALSE;
128 static GstBufferingMode mode;
129 static gint64 buffering_left;
130 static GstState state = GST_STATE_NULL;
131 static guint update_id = 0;
132 static guint seek_timeout_id = 0;
133 static gulong changed_id;
134 static guint fill_id = 0;
136 static gint n_video = 0, n_audio = 0, n_text = 0;
137 static gboolean need_streams = TRUE;
138 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
139 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
140 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
141 static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
142 static GtkWidget *buffer_checkbox, *rate_spinbutton;
144 static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
146 static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
147 static GtkWidget *shuttle_checkbox, *step_button;
148 static GtkWidget *shuttle_hscale;
149 static GtkAdjustment *shuttle_adjustment;
151 static GList *paths = NULL, *l = NULL;
155 /* we keep an array of the visualisation entries so that we can easily switch
156 * with the combo box index. */
159 GstElementFactory *factory;
162 static GArray *vis_entries;
164 static void clear_streams (GstElement * pipeline);
165 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
168 /* pipeline construction */
172 const gchar *padname;
179 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
181 GstElement *element = gst_element_factory_make (type, name);
184 g_warning ("Failed to create element %s of type %s", name, type);
191 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
194 dyn_link *connect = (dyn_link *) data;
196 padname = gst_pad_get_name (newpad);
198 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
200 gst_bin_add (GST_BIN (pipeline), connect->bin);
201 gst_pad_link (newpad, connect->target);
203 //seekable_pads = g_list_prepend (seekable_pads, newpad);
204 rate_pads = g_list_prepend (rate_pads, newpad);
210 setup_dynamic_link (GstElement * element, const gchar * padname,
211 GstPad * target, GstElement * bin)
215 connect = g_new0 (dyn_link, 1);
216 connect->padname = g_strdup (padname);
217 connect->target = target;
220 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
225 make_mod_pipeline (const gchar * location)
227 GstElement *pipeline;
228 GstElement *src, *decoder, *audiosink;
231 pipeline = gst_pipeline_new ("app");
233 src = gst_element_factory_make_or_warn (SOURCE, "src");
234 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
235 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
236 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
238 g_object_set (G_OBJECT (src), "location", location, NULL);
240 gst_bin_add (GST_BIN (pipeline), src);
241 gst_bin_add (GST_BIN (pipeline), decoder);
242 gst_bin_add (GST_BIN (pipeline), audiosink);
244 gst_element_link (src, decoder);
245 gst_element_link (decoder, audiosink);
247 seekable = gst_element_get_static_pad (decoder, "src");
248 seekable_pads = g_list_prepend (seekable_pads, seekable);
249 rate_pads = g_list_prepend (rate_pads, seekable);
251 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
257 make_dv_pipeline (const gchar * location)
259 GstElement *pipeline;
260 GstElement *src, *demux, *decoder, *audiosink, *videosink;
261 GstElement *a_queue, *v_queue;
264 pipeline = gst_pipeline_new ("app");
266 src = gst_element_factory_make_or_warn (SOURCE, "src");
267 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
268 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
269 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
270 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
271 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
272 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
274 g_object_set (G_OBJECT (src), "location", location, NULL);
276 gst_bin_add (GST_BIN (pipeline), src);
277 gst_bin_add (GST_BIN (pipeline), demux);
278 gst_bin_add (GST_BIN (pipeline), a_queue);
279 gst_bin_add (GST_BIN (pipeline), audiosink);
280 gst_bin_add (GST_BIN (pipeline), v_queue);
281 gst_bin_add (GST_BIN (pipeline), decoder);
282 gst_bin_add (GST_BIN (pipeline), videosink);
284 gst_element_link (src, demux);
285 gst_element_link (a_queue, audiosink);
286 gst_element_link (v_queue, decoder);
287 gst_element_link (decoder, videosink);
289 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
291 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
294 seekable = gst_element_get_static_pad (decoder, "src");
295 seekable_pads = g_list_prepend (seekable_pads, seekable);
296 rate_pads = g_list_prepend (rate_pads, seekable);
302 make_wav_pipeline (const gchar * location)
304 GstElement *pipeline;
305 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 ("wavparse", "decoder");
311 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
313 g_object_set (G_OBJECT (src), "location", location, NULL);
315 gst_bin_add (GST_BIN (pipeline), src);
316 gst_bin_add (GST_BIN (pipeline), decoder);
317 gst_bin_add (GST_BIN (pipeline), audiosink);
319 gst_element_link (src, decoder);
321 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
324 seekable_elements = g_list_prepend (seekable_elements, audiosink);
326 /* force element seeking on this pipeline */
333 make_flac_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 ("flacdec", "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_sid_pipeline (const gchar * location)
367 GstElement *pipeline;
368 GstElement *src, *decoder, *audiosink;
371 pipeline = gst_pipeline_new ("app");
373 src = gst_element_factory_make_or_warn (SOURCE, "src");
374 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
375 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
376 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
378 g_object_set (G_OBJECT (src), "location", location, NULL);
380 gst_bin_add (GST_BIN (pipeline), src);
381 gst_bin_add (GST_BIN (pipeline), decoder);
382 gst_bin_add (GST_BIN (pipeline), audiosink);
384 gst_element_link (src, decoder);
385 gst_element_link (decoder, audiosink);
387 seekable = gst_element_get_static_pad (decoder, "src");
388 seekable_pads = g_list_prepend (seekable_pads, seekable);
389 rate_pads = g_list_prepend (rate_pads, seekable);
391 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
397 make_parse_pipeline (const gchar * location)
399 GstElement *pipeline;
400 GstElement *src, *parser, *fakesink;
403 pipeline = gst_pipeline_new ("app");
405 src = gst_element_factory_make_or_warn (SOURCE, "src");
406 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
407 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
408 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
409 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
411 g_object_set (G_OBJECT (src), "location", location, NULL);
413 gst_bin_add (GST_BIN (pipeline), src);
414 gst_bin_add (GST_BIN (pipeline), parser);
415 gst_bin_add (GST_BIN (pipeline), fakesink);
417 gst_element_link (src, parser);
418 gst_element_link (parser, fakesink);
420 seekable = gst_element_get_static_pad (parser, "src");
421 seekable_pads = g_list_prepend (seekable_pads, seekable);
422 rate_pads = g_list_prepend (rate_pads, seekable);
424 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
430 make_vorbis_pipeline (const gchar * location)
432 GstElement *pipeline, *audio_bin;
433 GstElement *src, *demux, *decoder, *convert, *audiosink;
434 GstPad *pad, *seekable;
436 pipeline = gst_pipeline_new ("app");
438 src = gst_element_factory_make_or_warn (SOURCE, "src");
439 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
440 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
441 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
442 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
443 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
445 g_object_set (G_OBJECT (src), "location", location, NULL);
447 audio_bin = gst_bin_new ("a_decoder_bin");
449 gst_bin_add (GST_BIN (pipeline), src);
450 gst_bin_add (GST_BIN (pipeline), demux);
451 gst_bin_add (GST_BIN (audio_bin), decoder);
452 gst_bin_add (GST_BIN (audio_bin), convert);
453 gst_bin_add (GST_BIN (audio_bin), audiosink);
454 gst_bin_add (GST_BIN (pipeline), audio_bin);
456 gst_element_link (src, demux);
457 gst_element_link (decoder, convert);
458 gst_element_link (convert, audiosink);
460 pad = gst_element_get_static_pad (decoder, "sink");
461 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
462 gst_object_unref (pad);
464 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
467 seekable = gst_element_get_static_pad (decoder, "src");
468 seekable_pads = g_list_prepend (seekable_pads, seekable);
469 rate_pads = g_list_prepend (rate_pads, seekable);
471 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
477 make_theora_pipeline (const gchar * location)
479 GstElement *pipeline, *video_bin;
480 GstElement *src, *demux, *decoder, *convert, *videosink;
481 GstPad *pad, *seekable;
483 pipeline = gst_pipeline_new ("app");
485 src = gst_element_factory_make_or_warn (SOURCE, "src");
486 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
487 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
488 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
489 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
491 g_object_set (G_OBJECT (src), "location", location, NULL);
493 video_bin = gst_bin_new ("v_decoder_bin");
495 gst_bin_add (GST_BIN (pipeline), src);
496 gst_bin_add (GST_BIN (pipeline), demux);
497 gst_bin_add (GST_BIN (video_bin), decoder);
498 gst_bin_add (GST_BIN (video_bin), convert);
499 gst_bin_add (GST_BIN (video_bin), videosink);
500 gst_bin_add (GST_BIN (pipeline), video_bin);
502 gst_element_link (src, demux);
503 gst_element_link (decoder, convert);
504 gst_element_link (convert, videosink);
506 pad = gst_element_get_static_pad (decoder, "sink");
507 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
508 gst_object_unref (pad);
510 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
513 seekable = gst_element_get_static_pad (decoder, "src");
514 seekable_pads = g_list_prepend (seekable_pads, seekable);
515 rate_pads = g_list_prepend (rate_pads, seekable);
517 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
523 make_vorbis_theora_pipeline (const gchar * location)
525 GstElement *pipeline, *audio_bin, *video_bin;
526 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
527 GstElement *audiosink, *videosink;
528 GstElement *a_queue, *v_queue, *v_scale;
532 pipeline = gst_pipeline_new ("app");
534 src = gst_element_factory_make_or_warn (SOURCE, "src");
535 g_object_set (G_OBJECT (src), "location", location, NULL);
537 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
539 gst_bin_add (GST_BIN (pipeline), src);
540 gst_bin_add (GST_BIN (pipeline), demux);
541 gst_element_link (src, demux);
543 audio_bin = gst_bin_new ("a_decoder_bin");
544 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
545 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
546 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
547 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
549 gst_bin_add (GST_BIN (pipeline), audio_bin);
551 gst_bin_add (GST_BIN (audio_bin), a_queue);
552 gst_bin_add (GST_BIN (audio_bin), a_decoder);
553 gst_bin_add (GST_BIN (audio_bin), a_convert);
554 gst_bin_add (GST_BIN (audio_bin), audiosink);
556 gst_element_link (a_queue, a_decoder);
557 gst_element_link (a_decoder, a_convert);
558 gst_element_link (a_convert, audiosink);
560 pad = gst_element_get_static_pad (a_queue, "sink");
561 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
562 gst_object_unref (pad);
564 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
567 video_bin = gst_bin_new ("v_decoder_bin");
568 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
569 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
571 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
572 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
573 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
575 gst_bin_add (GST_BIN (pipeline), video_bin);
577 gst_bin_add (GST_BIN (video_bin), v_queue);
578 gst_bin_add (GST_BIN (video_bin), v_decoder);
579 gst_bin_add (GST_BIN (video_bin), v_convert);
580 gst_bin_add (GST_BIN (video_bin), v_scale);
581 gst_bin_add (GST_BIN (video_bin), videosink);
583 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
586 pad = gst_element_get_static_pad (v_queue, "sink");
587 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
588 gst_object_unref (pad);
590 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
593 seekable = gst_element_get_static_pad (a_decoder, "src");
594 seekable_pads = g_list_prepend (seekable_pads, seekable);
595 rate_pads = g_list_prepend (rate_pads, seekable);
597 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
604 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
606 GstElement *pipeline, *audio_bin, *video_bin;
607 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
608 GstElement *audiosink, *videosink;
609 GstElement *a_queue, *v_queue;
610 GstPad *seekable, *pad;
612 pipeline = gst_pipeline_new ("app");
614 src = gst_element_factory_make_or_warn (SOURCE, "src");
615 g_object_set (G_OBJECT (src), "location", location, NULL);
617 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
619 gst_bin_add (GST_BIN (pipeline), src);
620 gst_bin_add (GST_BIN (pipeline), demux);
621 gst_element_link (src, demux);
623 audio_bin = gst_bin_new ("a_decoder_bin");
624 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
625 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
626 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
627 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
629 gst_bin_add (GST_BIN (audio_bin), a_queue);
630 gst_bin_add (GST_BIN (audio_bin), a_decoder);
631 gst_bin_add (GST_BIN (audio_bin), a_convert);
632 gst_bin_add (GST_BIN (audio_bin), audiosink);
634 gst_element_link (a_queue, a_decoder);
635 gst_element_link (a_decoder, a_convert);
636 gst_element_link (a_convert, audiosink);
638 gst_bin_add (GST_BIN (pipeline), audio_bin);
640 pad = gst_element_get_static_pad (a_queue, "sink");
641 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
642 gst_object_unref (pad);
644 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
647 video_bin = gst_bin_new ("v_decoder_bin");
648 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
649 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
651 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
652 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
654 gst_bin_add (GST_BIN (video_bin), v_queue);
655 gst_bin_add (GST_BIN (video_bin), v_decoder);
656 gst_bin_add (GST_BIN (video_bin), v_convert);
657 gst_bin_add (GST_BIN (video_bin), videosink);
659 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
661 gst_bin_add (GST_BIN (pipeline), video_bin);
663 pad = gst_element_get_static_pad (v_queue, "sink");
664 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
665 gst_object_unref (pad);
667 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
670 seekable = gst_element_get_static_pad (a_decoder, "src");
671 seekable_pads = g_list_prepend (seekable_pads, seekable);
672 rate_pads = g_list_prepend (rate_pads, seekable);
674 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
681 make_mp3_pipeline (const gchar * location)
683 GstElement *pipeline;
684 GstElement *src, *parser, *decoder, *audiosink, *queue;
687 pipeline = gst_pipeline_new ("app");
689 src = gst_element_factory_make_or_warn (SOURCE, "src");
690 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
691 decoder = gst_element_factory_make_or_warn ("mad", "dec");
692 queue = gst_element_factory_make_or_warn ("queue", "queue");
693 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
695 seekable_elements = g_list_prepend (seekable_elements, audiosink);
697 g_object_set (G_OBJECT (src), "location", location, NULL);
698 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
700 gst_bin_add (GST_BIN (pipeline), src);
701 gst_bin_add (GST_BIN (pipeline), parser);
702 gst_bin_add (GST_BIN (pipeline), decoder);
703 gst_bin_add (GST_BIN (pipeline), queue);
704 gst_bin_add (GST_BIN (pipeline), audiosink);
706 gst_element_link (src, parser);
707 gst_element_link (parser, decoder);
708 gst_element_link (decoder, queue);
709 gst_element_link (queue, audiosink);
711 seekable = gst_element_get_static_pad (queue, "src");
712 seekable_pads = g_list_prepend (seekable_pads, seekable);
713 rate_pads = g_list_prepend (rate_pads, seekable);
715 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
721 make_avi_pipeline (const gchar * location)
723 GstElement *pipeline, *audio_bin, *video_bin;
724 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
725 GstElement *a_queue = NULL, *v_queue = NULL;
728 pipeline = gst_pipeline_new ("app");
730 src = gst_element_factory_make_or_warn (SOURCE, "src");
731 g_object_set (G_OBJECT (src), "location", location, NULL);
733 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
734 seekable_elements = g_list_prepend (seekable_elements, demux);
736 gst_bin_add (GST_BIN (pipeline), src);
737 gst_bin_add (GST_BIN (pipeline), demux);
738 gst_element_link (src, demux);
740 audio_bin = gst_bin_new ("a_decoder_bin");
741 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
742 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
743 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
744 gst_element_link (a_decoder, a_queue);
745 gst_element_link (a_queue, audiosink);
746 gst_bin_add (GST_BIN (audio_bin), a_decoder);
747 gst_bin_add (GST_BIN (audio_bin), a_queue);
748 gst_bin_add (GST_BIN (audio_bin), audiosink);
749 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
751 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
754 seekable = gst_element_get_static_pad (a_queue, "src");
755 seekable_pads = g_list_prepend (seekable_pads, seekable);
756 rate_pads = g_list_prepend (rate_pads, seekable);
758 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
761 video_bin = gst_bin_new ("v_decoder_bin");
762 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
763 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
764 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
765 gst_element_link (v_decoder, v_queue);
766 gst_element_link (v_queue, videosink);
767 gst_bin_add (GST_BIN (video_bin), v_decoder);
768 gst_bin_add (GST_BIN (video_bin), v_queue);
769 gst_bin_add (GST_BIN (video_bin), videosink);
771 gst_element_set_state (video_bin, GST_STATE_PAUSED);
773 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
776 seekable = gst_element_get_static_pad (v_queue, "src");
777 seekable_pads = g_list_prepend (seekable_pads, seekable);
778 rate_pads = g_list_prepend (rate_pads, seekable);
780 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
787 make_mpeg_pipeline (const gchar * location)
789 GstElement *pipeline, *audio_bin, *video_bin;
790 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
791 GstElement *audiosink, *videosink;
792 GstElement *a_queue, *v_queue;
796 pipeline = gst_pipeline_new ("app");
798 src = gst_element_factory_make_or_warn (SOURCE, "src");
799 g_object_set (G_OBJECT (src), "location", location, NULL);
801 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
802 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
804 gst_bin_add (GST_BIN (pipeline), src);
805 gst_bin_add (GST_BIN (pipeline), demux);
806 gst_element_link (src, demux);
808 audio_bin = gst_bin_new ("a_decoder_bin");
809 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
810 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
811 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
812 gst_bin_add (GST_BIN (audio_bin), a_decoder);
813 gst_bin_add (GST_BIN (audio_bin), a_queue);
814 gst_bin_add (GST_BIN (audio_bin), audiosink);
816 gst_element_link (a_decoder, a_queue);
817 gst_element_link (a_queue, audiosink);
819 gst_bin_add (GST_BIN (pipeline), audio_bin);
821 pad = gst_element_get_static_pad (a_decoder, "sink");
822 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
823 gst_object_unref (pad);
825 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
828 video_bin = gst_bin_new ("v_decoder_bin");
829 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
830 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
831 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
832 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
834 gst_bin_add (GST_BIN (video_bin), v_decoder);
835 gst_bin_add (GST_BIN (video_bin), v_queue);
836 gst_bin_add (GST_BIN (video_bin), v_filter);
837 gst_bin_add (GST_BIN (video_bin), videosink);
839 gst_element_link (v_decoder, v_queue);
840 gst_element_link (v_queue, v_filter);
841 gst_element_link (v_filter, videosink);
843 gst_bin_add (GST_BIN (pipeline), video_bin);
845 pad = gst_element_get_static_pad (v_decoder, "sink");
846 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
847 gst_object_unref (pad);
849 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
852 seekable = gst_element_get_static_pad (v_filter, "src");
853 seekable_pads = g_list_prepend (seekable_pads, seekable);
854 rate_pads = g_list_prepend (rate_pads, seekable);
856 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
863 make_mpegnt_pipeline (const gchar * location)
865 GstElement *pipeline, *audio_bin, *video_bin;
866 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
867 GstElement *audiosink, *videosink;
871 pipeline = gst_pipeline_new ("app");
873 src = gst_element_factory_make_or_warn (SOURCE, "src");
874 g_object_set (G_OBJECT (src), "location", location, NULL);
876 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
877 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
879 seekable_elements = g_list_prepend (seekable_elements, demux);
881 gst_bin_add (GST_BIN (pipeline), src);
882 gst_bin_add (GST_BIN (pipeline), demux);
883 gst_element_link (src, demux);
885 audio_bin = gst_bin_new ("a_decoder_bin");
886 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
887 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
888 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
889 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
890 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
891 gst_element_link (a_decoder, a_queue);
892 gst_element_link (a_queue, audiosink);
893 gst_bin_add (GST_BIN (audio_bin), a_decoder);
894 gst_bin_add (GST_BIN (audio_bin), a_queue);
895 gst_bin_add (GST_BIN (audio_bin), audiosink);
897 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
900 seekable = gst_element_get_static_pad (a_queue, "src");
901 seekable_pads = g_list_prepend (seekable_pads, seekable);
902 rate_pads = g_list_prepend (rate_pads, seekable);
904 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
907 video_bin = gst_bin_new ("v_decoder_bin");
908 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
909 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
910 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
911 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
913 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
915 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
918 seekable = gst_element_get_static_pad (v_decoder, "src");
919 seekable_pads = g_list_prepend (seekable_pads, seekable);
920 rate_pads = g_list_prepend (rate_pads, seekable);
922 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
929 playerbin_set_uri (GstElement * player, const gchar * location)
933 /* Add "file://" prefix for convenience */
934 if (g_str_has_prefix (location, "/")) {
935 uri = g_strconcat ("file://", location, NULL);
936 g_object_set (G_OBJECT (player), "uri", uri, NULL);
939 g_object_set (G_OBJECT (player), "uri", location, NULL);
944 construct_playerbin (const gchar * name, const gchar * location)
948 player = gst_element_factory_make (name, "player");
951 playerbin_set_uri (player, location);
953 seekable_elements = g_list_prepend (seekable_elements, player);
955 /* force element seeking on this pipeline */
962 make_playerbin_pipeline (const gchar * location)
964 return construct_playerbin ("playbin", location);
968 make_playerbin2_pipeline (const gchar * location)
970 GstElement *pipeline = construct_playerbin ("playbin2", location);
972 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
973 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
978 #ifndef GST_DISABLE_PARSE
980 make_parselaunch_pipeline (const gchar * description)
982 GstElement *pipeline;
983 GError *error = NULL;
985 pipeline = gst_parse_launch (description, &error);
987 seekable_elements = g_list_prepend (seekable_elements, pipeline);
998 GstElement *(*func) (const gchar * location);
1002 static Pipeline pipelines[] = {
1003 {"mp3", make_mp3_pipeline},
1004 {"avi", make_avi_pipeline},
1005 {"mpeg1", make_mpeg_pipeline},
1006 {"mpegparse", make_parse_pipeline},
1007 {"vorbis", make_vorbis_pipeline},
1008 {"theora", make_theora_pipeline},
1009 {"ogg/v/t", make_vorbis_theora_pipeline},
1010 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
1011 {"sid", make_sid_pipeline},
1012 {"flac", make_flac_pipeline},
1013 {"wav", make_wav_pipeline},
1014 {"mod", make_mod_pipeline},
1015 {"dv", make_dv_pipeline},
1016 {"mpeg1nothreads", make_mpegnt_pipeline},
1017 {"playerbin", make_playerbin_pipeline},
1018 #ifndef GST_DISABLE_PARSE
1019 {"parse-launch", make_parselaunch_pipeline},
1021 {"playerbin2", make_playerbin2_pipeline},
1025 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
1027 /* ui callbacks and helpers */
1030 format_value (GtkScale * scale, gdouble value)
1036 real = value * duration / 100;
1037 seconds = (gint64) real / GST_SECOND;
1038 subseconds = (gint64) real / (GST_SECOND / 100);
1040 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1041 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1046 shuttle_format_value (GtkScale * scale, gdouble value)
1048 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
1054 const GstFormat format;
1058 static seek_format seek_formats[] = {
1059 {"tim", GST_FORMAT_TIME},
1060 {"byt", GST_FORMAT_BYTES},
1061 {"buf", GST_FORMAT_BUFFERS},
1062 {"def", GST_FORMAT_DEFAULT},
1066 G_GNUC_UNUSED static void
1069 GList *walk = rate_pads;
1072 GstPad *pad = GST_PAD (walk->data);
1075 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1076 while (seek_formats[i].name) {
1080 format = seek_formats[i].format;
1082 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
1084 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1086 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1091 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1093 walk = g_list_next (walk);
1097 G_GNUC_UNUSED static void
1098 query_positions_elems (void)
1100 GList *walk = seekable_elements;
1103 GstElement *element = GST_ELEMENT (walk->data);
1106 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1107 while (seek_formats[i].name) {
1108 gint64 position, total;
1111 format = seek_formats[i].format;
1113 if (gst_element_query_position (element, &format, &position) &&
1114 gst_element_query_duration (element, &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*",
1123 g_print (" %s\n", GST_ELEMENT_NAME (element));
1125 walk = g_list_next (walk);
1129 G_GNUC_UNUSED static void
1130 query_positions_pads (void)
1132 GList *walk = seekable_pads;
1135 GstPad *pad = GST_PAD (walk->data);
1138 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1139 while (seek_formats[i].name) {
1141 gint64 position, total;
1143 format = seek_formats[i].format;
1145 if (gst_pad_query_position (pad, &format, &position) &&
1146 gst_pad_query_duration (pad, &format, &total)) {
1147 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1148 seek_formats[i].name, position, total);
1150 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1156 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1158 walk = g_list_next (walk);
1162 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1163 gpointer user_data);
1164 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1165 gpointer user_data);
1166 static void seek_cb (GtkWidget * widget);
1169 set_scale (gdouble value)
1171 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1173 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1175 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1176 gtk_adjustment_set_value (adjustment, value);
1177 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1179 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1181 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1183 gtk_widget_queue_draw (hscale);
1187 update_fill (gpointer data)
1190 if (seekable_elements) {
1191 GstElement *element = GST_ELEMENT (seekable_elements->data);
1194 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1195 if (gst_element_query (element, query)) {
1196 gint64 start, stop, buffering_total;
1201 GstBufferingMode mode;
1202 gint avg_in, avg_out;
1203 gint64 buffering_left;
1205 gst_query_parse_buffering_percent (query, &busy, &percent);
1206 gst_query_parse_buffering_range (query, &format, &start, &stop,
1208 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
1211 /* note that we could start the playback when buffering_left < remaining
1213 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
1214 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
1215 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1219 fill = 100.0 * stop / GST_FORMAT_PERCENT_MAX;
1223 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1225 gst_query_unref (query);
1232 update_scale (gpointer data)
1234 GstFormat format = GST_FORMAT_TIME;
1240 if (seekable_elements) {
1241 GstElement *element = GST_ELEMENT (seekable_elements->data);
1243 gst_element_query_position (element, &format, &position);
1244 gst_element_query_duration (element, &format, &duration);
1247 if (seekable_pads) {
1248 GstPad *pad = GST_PAD (seekable_pads->data);
1250 gst_pad_query_position (pad, &format, &position);
1251 gst_pad_query_duration (pad, &format, &duration);
1257 query_positions_elems ();
1259 query_positions_pads ();
1264 if (position >= duration)
1265 duration = position;
1268 set_scale (position * 100.0 / duration);
1271 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1272 if (pipeline_type == 16) {
1273 g_object_notify (G_OBJECT (pipeline), "volume");
1279 static void do_seek (GtkWidget * widget);
1280 static void connect_bus_signals (GstElement * pipeline);
1281 static void set_update_scale (gboolean active);
1282 static void set_update_fill (gboolean active);
1285 end_scrub (GtkWidget * widget)
1287 GST_DEBUG ("end scrub, PAUSE");
1288 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1289 seek_timeout_id = 0;
1295 send_event (GstEvent * event)
1297 gboolean res = FALSE;
1300 GList *walk = seekable_pads;
1303 GstPad *seekable = GST_PAD (walk->data);
1305 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1307 gst_event_ref (event);
1308 res = gst_pad_send_event (seekable, event);
1310 walk = g_list_next (walk);
1313 GList *walk = seekable_elements;
1316 GstElement *seekable = GST_ELEMENT (walk->data);
1318 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1320 gst_event_ref (event);
1321 res = gst_element_send_event (seekable, event);
1323 walk = g_list_next (walk);
1326 gst_event_unref (event);
1331 do_seek (GtkWidget * widget)
1334 gboolean res = FALSE;
1338 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
1342 flags |= GST_SEEK_FLAG_FLUSH;
1344 flags |= GST_SEEK_FLAG_ACCURATE;
1346 flags |= GST_SEEK_FLAG_KEY_UNIT;
1348 flags |= GST_SEEK_FLAG_SEGMENT;
1350 flags |= GST_SEEK_FLAG_SKIP;
1353 s_event = gst_event_new_seek (rate,
1354 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1355 GST_CLOCK_TIME_NONE);
1356 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1357 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1359 s_event = gst_event_new_seek (rate,
1360 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1361 GST_SEEK_TYPE_SET, real);
1362 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1363 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1366 res = send_event (s_event);
1370 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1372 set_update_scale (TRUE);
1375 g_print ("seek failed\n");
1376 set_update_scale (TRUE);
1381 seek_cb (GtkWidget * widget)
1383 /* If the timer hasn't expired yet, then the pipeline is running */
1384 if (play_scrub && seek_timeout_id != 0) {
1385 GST_DEBUG ("do scrub seek, PAUSED");
1386 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1389 GST_DEBUG ("do seek");
1393 GST_DEBUG ("do scrub seek, PLAYING");
1394 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1396 if (seek_timeout_id == 0) {
1398 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1404 set_update_fill (gboolean active)
1406 GST_DEBUG ("fill scale is %d", active);
1411 g_timeout_add (FILL_INTERVAL, (GSourceFunc) update_fill, pipeline);
1415 g_source_remove (fill_id);
1422 set_update_scale (gboolean active)
1425 GST_DEBUG ("update scale is %d", active);
1428 if (update_id == 0) {
1430 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, pipeline);
1434 g_source_remove (update_id);
1441 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1443 if (event->type != GDK_BUTTON_PRESS)
1446 set_update_scale (FALSE);
1448 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1449 GST_DEBUG ("start scrub seek, PAUSE");
1450 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1453 if (changed_id == 0 && flush_seek && scrub) {
1455 g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb),
1463 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1466 g_signal_handler_disconnect (hscale, changed_id);
1470 if (!flush_seek || !scrub) {
1471 GST_DEBUG ("do final seek");
1475 if (seek_timeout_id != 0) {
1476 g_source_remove (seek_timeout_id);
1477 seek_timeout_id = 0;
1478 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1480 if (state == GST_STATE_PAUSED) {
1481 GST_DEBUG ("stop scrub seek, PAUSED");
1482 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1485 if (state == GST_STATE_PLAYING) {
1486 GST_DEBUG ("stop scrub seek, PLAYING");
1487 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1495 play_cb (GtkButton * button, gpointer data)
1497 GstStateChangeReturn ret;
1499 if (state != GST_STATE_PLAYING) {
1500 g_print ("PLAY pipeline\n");
1501 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1503 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1505 case GST_STATE_CHANGE_FAILURE:
1507 case GST_STATE_CHANGE_NO_PREROLL:
1513 state = GST_STATE_PLAYING;
1514 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1521 g_print ("PLAY failed\n");
1522 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1527 pause_cb (GtkButton * button, gpointer data)
1529 g_static_mutex_lock (&state_mutex);
1530 if (state != GST_STATE_PAUSED) {
1531 GstStateChangeReturn ret;
1533 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1534 g_print ("PAUSE pipeline\n");
1535 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1537 case GST_STATE_CHANGE_FAILURE:
1539 case GST_STATE_CHANGE_NO_PREROLL:
1546 state = GST_STATE_PAUSED;
1547 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1549 g_static_mutex_unlock (&state_mutex);
1555 g_static_mutex_unlock (&state_mutex);
1556 g_print ("PAUSE failed\n");
1557 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1562 stop_cb (GtkButton * button, gpointer data)
1564 if (state != STOP_STATE) {
1565 GstStateChangeReturn ret;
1567 g_print ("READY pipeline\n");
1568 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1570 g_static_mutex_lock (&state_mutex);
1571 ret = gst_element_set_state (pipeline, STOP_STATE);
1572 if (ret == GST_STATE_CHANGE_FAILURE)
1576 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1580 set_update_scale (FALSE);
1582 set_update_fill (FALSE);
1584 if (pipeline_type == 16)
1585 clear_streams (pipeline);
1586 g_static_mutex_unlock (&state_mutex);
1589 /* if one uses parse_launch, play, stop and play again it fails as all the
1590 * pads after the demuxer can't be reconnected
1592 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1593 gst_element_set_state (pipeline, GST_STATE_NULL);
1594 gst_object_unref (pipeline);
1596 g_list_free (seekable_elements);
1597 seekable_elements = NULL;
1598 g_list_free (seekable_pads);
1599 seekable_pads = NULL;
1600 g_list_free (rate_pads);
1603 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1604 g_assert (pipeline);
1605 gst_element_set_state (pipeline, STOP_STATE);
1606 connect_bus_signals (pipeline);
1614 g_static_mutex_unlock (&state_mutex);
1615 g_print ("STOP failed\n");
1616 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1621 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1623 accurate_seek = gtk_toggle_button_get_active (button);
1627 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1629 keyframe_seek = gtk_toggle_button_get_active (button);
1633 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1635 loop_seek = gtk_toggle_button_get_active (button);
1636 if (state == GST_STATE_PLAYING) {
1642 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1644 flush_seek = gtk_toggle_button_get_active (button);
1648 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1650 scrub = gtk_toggle_button_get_active (button);
1654 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1656 play_scrub = gtk_toggle_button_get_active (button);
1660 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1662 skip_seek = gtk_toggle_button_get_active (button);
1663 if (state == GST_STATE_PLAYING) {
1669 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1671 gboolean res = FALSE;
1675 rate = gtk_spin_button_get_value (button);
1677 GST_DEBUG ("rate changed to %lf", rate);
1681 flags |= GST_SEEK_FLAG_FLUSH;
1683 flags |= GST_SEEK_FLAG_SEGMENT;
1685 flags |= GST_SEEK_FLAG_ACCURATE;
1687 flags |= GST_SEEK_FLAG_KEY_UNIT;
1689 flags |= GST_SEEK_FLAG_SKIP;
1692 s_event = gst_event_new_seek (rate,
1693 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1694 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1696 s_event = gst_event_new_seek (rate,
1697 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1698 GST_SEEK_TYPE_SET, position);
1701 res = send_event (s_event);
1705 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1708 g_print ("seek failed\n");
1712 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1716 g_object_get (pipeline, "flags", &flags, NULL);
1718 flags |= (1 << num);
1720 flags &= ~(1 << num);
1721 g_object_set (pipeline, "flags", flags, NULL);
1725 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1729 state = gtk_toggle_button_get_active (button);
1730 update_flag (pipeline, 3, state);
1731 gtk_widget_set_sensitive (vis_combo, state);
1735 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1739 state = gtk_toggle_button_get_active (button);
1740 update_flag (pipeline, 1, state);
1741 gtk_widget_set_sensitive (audio_combo, state);
1745 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1749 state = gtk_toggle_button_get_active (button);
1750 update_flag (pipeline, 0, state);
1751 gtk_widget_set_sensitive (video_combo, state);
1755 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1759 state = gtk_toggle_button_get_active (button);
1760 update_flag (pipeline, 2, state);
1761 gtk_widget_set_sensitive (text_combo, state);
1765 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1769 mute = gtk_toggle_button_get_active (button);
1770 g_object_set (pipeline, "mute", mute, NULL);
1774 download_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1778 state = gtk_toggle_button_get_active (button);
1779 update_flag (pipeline, 7, state);
1783 buffer_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1787 state = gtk_toggle_button_get_active (button);
1788 update_flag (pipeline, 8, state);
1792 clear_streams (GstElement * pipeline)
1796 /* remove previous info */
1797 for (i = 0; i < n_video; i++)
1798 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (video_combo), 0);
1799 for (i = 0; i < n_audio; i++)
1800 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (audio_combo), 0);
1801 for (i = 0; i < n_text; i++)
1802 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (text_combo), 0);
1804 n_audio = n_video = n_text = 0;
1805 gtk_widget_set_sensitive (video_combo, FALSE);
1806 gtk_widget_set_sensitive (audio_combo, FALSE);
1807 gtk_widget_set_sensitive (text_combo, FALSE);
1809 need_streams = TRUE;
1813 update_streams (GstPipeline * pipeline)
1817 if (pipeline_type == 16 && need_streams) {
1823 /* remove previous info */
1824 clear_streams (GST_ELEMENT_CAST (pipeline));
1826 /* here we get and update the different streams detected by playbin2 */
1827 g_object_get (pipeline, "n-video", &n_video, NULL);
1828 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1829 g_object_get (pipeline, "n-text", &n_text, NULL);
1831 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1834 for (i = 0; i < n_video; i++) {
1835 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1837 str = gst_structure_to_string ((GstStructure *) tags);
1838 g_print ("video %d: %s\n", i, str);
1841 /* find good name for the label */
1842 name = g_strdup_printf ("video %d", i + 1);
1843 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (video_combo), name);
1846 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1847 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1848 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1851 for (i = 0; i < n_audio; i++) {
1852 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1854 str = gst_structure_to_string ((GstStructure *) tags);
1855 g_print ("audio %d: %s\n", i, str);
1858 /* find good name for the label */
1859 name = g_strdup_printf ("audio %d", i + 1);
1860 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (audio_combo), name);
1863 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1864 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1865 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1868 for (i = 0; i < n_text; i++) {
1869 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1873 const GValue *value;
1875 str = gst_structure_to_string ((GstStructure *) tags);
1876 g_print ("text %d: %s\n", i, str);
1879 /* get the language code if we can */
1880 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1881 if (value && G_VALUE_HOLDS_STRING (value)) {
1882 name = g_strdup_printf ("text %s", g_value_get_string (value));
1885 /* find good name for the label if we didn't use a tag */
1887 name = g_strdup_printf ("text %d", i + 1);
1889 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (text_combo), name);
1892 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1893 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1894 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1896 need_streams = FALSE;
1901 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1905 active = gtk_combo_box_get_active (combo);
1907 g_print ("setting current video track %d\n", active);
1908 g_object_set (pipeline, "current-video", active, NULL);
1912 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1916 active = gtk_combo_box_get_active (combo);
1918 g_print ("setting current audio track %d\n", active);
1919 g_object_set (pipeline, "current-audio", active, NULL);
1923 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1927 active = gtk_combo_box_get_active (combo);
1929 g_print ("setting current text track %d\n", active);
1930 g_object_set (pipeline, "current-text", active, NULL);
1934 filter_features (GstPluginFeature * feature, gpointer data)
1936 GstElementFactory *f;
1938 if (!GST_IS_ELEMENT_FACTORY (feature))
1940 f = GST_ELEMENT_FACTORY (feature);
1941 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1948 init_visualization_features (void)
1952 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1954 list = gst_registry_feature_filter (gst_registry_get_default (),
1955 filter_features, FALSE, NULL);
1957 for (walk = list; walk; walk = g_list_next (walk)) {
1961 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1962 name = gst_element_factory_get_longname (entry.factory);
1964 g_array_append_val (vis_entries, entry);
1965 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (vis_combo), name);
1967 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1971 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1975 GstElement *element;
1977 /* get the selected index and get the factory for this index */
1978 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1979 if (vis_entries->len > 0) {
1980 entry = &g_array_index (vis_entries, VisEntry, index);
1982 /* create an instance of the element from the factory */
1983 element = gst_element_factory_create (entry->factory, NULL);
1987 /* set vis plugin for playbin2 */
1988 g_object_set (pipeline, "vis-plugin", element, NULL);
1993 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1997 volume = gtk_spin_button_get_value (button);
1999 g_object_set (pipeline, "volume", volume, NULL);
2003 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
2005 gdouble cur_volume, new_volume;
2007 g_object_get (pipeline, "volume", &new_volume, NULL);
2008 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
2009 if (fabs (cur_volume - new_volume) > 0.001) {
2010 g_signal_handlers_block_by_func (volume_spinbutton,
2011 volume_spinbutton_changed_cb, pipeline);
2012 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
2013 g_signal_handlers_unblock_by_func (volume_spinbutton,
2014 volume_spinbutton_changed_cb, pipeline);
2019 shot_cb (GtkButton * button, gpointer data)
2024 /* convert to our desired format (RGB24) */
2025 caps = gst_caps_new_simple ("video/x-raw-rgb",
2026 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
2027 /* Note: we don't ask for a specific width/height here, so that
2028 * videoscale can adjust dimensions from a non-1/1 pixel aspect
2029 * ratio to a 1/1 pixel-aspect-ratio */
2030 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
2031 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
2032 "red_mask", G_TYPE_INT, 0xff0000,
2033 "green_mask", G_TYPE_INT, 0x00ff00,
2034 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
2036 /* convert the latest frame to the requested format */
2037 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
2038 gst_caps_unref (caps);
2046 GError *error = NULL;
2050 /* get the snapshot buffer format now. We set the caps on the appsink so
2051 * that it can only be an rgb buffer. The only thing we have not specified
2052 * on the caps is the height, which is dependant on the pixel-aspect-ratio
2053 * of the source material */
2054 caps = GST_BUFFER_CAPS (buffer);
2056 g_warning ("could not get snapshot format\n");
2059 s = gst_caps_get_structure (caps, 0);
2061 /* we need to get the final caps on the buffer to get the size */
2062 res = gst_structure_get_int (s, "width", &width);
2063 res |= gst_structure_get_int (s, "height", &height);
2065 g_warning ("could not get snapshot dimension\n");
2069 /* create pixmap from buffer and save, gstreamer video buffers have a stride
2070 * that is rounded up to the nearest multiple of 4 */
2071 data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
2072 pixbuf = gdk_pixbuf_new_from_data (data,
2073 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2074 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2076 /* save the pixbuf */
2077 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2078 gst_buffer_unmap (buffer, data, size);
2080 /* save the pixbuf */
2081 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2084 gst_buffer_unref (buffer);
2088 /* called when the Step button is pressed */
2090 step_cb (GtkButton * button, gpointer data)
2096 gboolean flush, res;
2099 active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo));
2101 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
2102 (step_amount_spinbutton));
2103 rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton));
2108 format = GST_FORMAT_BUFFERS;
2111 format = GST_FORMAT_TIME;
2112 amount *= GST_MSECOND;
2115 format = GST_FORMAT_UNDEFINED;
2119 event = gst_event_new_step (format, amount, rate, flush, FALSE);
2121 res = send_event (event);
2124 g_print ("Sending step event failed\n");
2129 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2131 const GstStructure *s;
2133 s = gst_message_get_structure (message);
2134 g_print ("message from \"%s\" (%s): ",
2135 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2136 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2140 sstr = gst_structure_to_string (s);
2141 g_print ("%s\n", sstr);
2144 g_print ("no message details\n");
2148 static gboolean shuttling = FALSE;
2149 static gdouble shuttle_rate = 0.0;
2150 static gdouble play_rate = 1.0;
2153 do_shuttle (GstElement * element)
2158 duration = 40 * GST_MSECOND;
2162 gst_element_send_event (element,
2163 gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE,
2168 msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element)
2174 gboolean intermediate;
2178 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
2179 &intermediate, &duration, &eos);
2182 g_print ("stepped till EOS\n");
2186 if (g_static_mutex_trylock (&state_mutex)) {
2188 do_shuttle (element);
2189 g_static_mutex_unlock (&state_mutex);
2191 /* ignore step messages that come while we are doing a state change */
2192 g_print ("state change is busy\n");
2197 shuttle_toggled (GtkToggleButton * button, GstElement * element)
2201 active = gtk_toggle_button_get_active (button);
2203 if (active != shuttling) {
2205 g_print ("shuttling %s\n", shuttling ? "active" : "inactive");
2209 pause_cb (NULL, NULL);
2210 gst_element_get_state (element, NULL, NULL, -1);
2216 shuttle_rate_switch (GstElement * element)
2222 if (state == GST_STATE_PLAYING) {
2223 /* pause when we need to */
2224 pause_cb (NULL, NULL);
2225 gst_element_get_state (element, NULL, NULL, -1);
2228 if (play_rate == 1.0)
2233 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate,
2234 GST_TIME_ARGS (position));
2236 flags = GST_SEEK_FLAG_FLUSH;
2237 flags |= GST_SEEK_FLAG_ACCURATE;
2239 if (play_rate >= 0.0) {
2240 s_event = gst_event_new_seek (play_rate,
2241 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
2242 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
2244 s_event = gst_event_new_seek (play_rate,
2245 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2246 GST_SEEK_TYPE_SET, position);
2248 res = send_event (s_event);
2250 gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT);
2252 g_print ("seek failed\n");
2257 shuttle_value_changed (GtkRange * range, GstElement * element)
2261 rate = gtk_adjustment_get_value (shuttle_adjustment);
2264 g_print ("rate 0.0, pause\n");
2265 pause_cb (NULL, NULL);
2266 gst_element_get_state (element, NULL, NULL, -1);
2268 g_print ("rate changed %0.3g\n", rate);
2270 if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) {
2271 shuttle_rate_switch (element);
2274 shuttle_rate = ABS (rate);
2275 if (state != GST_STATE_PLAYING) {
2276 do_shuttle (element);
2277 play_cb (NULL, NULL);
2283 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2285 GST_DEBUG ("async done");
2286 /* when we get ASYNC_DONE we can query position, duration and other
2288 update_scale (pipeline);
2290 /* update the available streams */
2291 update_streams (pipeline);
2295 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2297 const GstStructure *s;
2299 s = gst_message_get_structure (message);
2301 /* We only care about state changed on the pipeline */
2302 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2303 GstState old, new, pending;
2305 gst_message_parse_state_changed (message, &old, &new, &pending);
2307 /* When state of the pipeline changes to paused or playing we start updating scale */
2308 if (new == GST_STATE_PLAYING) {
2309 set_update_scale (TRUE);
2311 set_update_scale (FALSE);
2317 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2324 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2325 gst_message_parse_segment_done (message, &format, &position);
2326 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2329 /* in the segment-done callback we never flush as this would not make sense
2330 * for seamless playback. */
2332 flags |= GST_SEEK_FLAG_SEGMENT;
2334 flags |= GST_SEEK_FLAG_SKIP;
2336 s_event = gst_event_new_seek (rate,
2337 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2338 GST_SEEK_TYPE_SET, duration);
2340 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2341 rate, GST_TIME_ARGS (duration));
2343 res = send_event (s_event);
2345 g_print ("segment seek failed\n");
2348 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2351 do_stream_buffering (gint percent)
2355 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2356 bufstr = g_strdup_printf ("Buffering...%d", percent);
2357 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2360 if (percent == 100) {
2361 /* a 100% message means buffering is done */
2363 /* if the desired state is playing, go back */
2364 if (state == GST_STATE_PLAYING) {
2365 /* no state management needed for live pipelines */
2367 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2368 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2370 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2371 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2374 /* buffering busy */
2375 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2376 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2378 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2379 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2387 do_download_buffering (gint percent)
2389 if (!buffering && percent < 100) {
2394 bufstr = g_strdup_printf ("Downloading...");
2395 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2398 /* once we get a buffering message, we'll do the fill update */
2399 set_update_fill (TRUE);
2401 if (state == GST_STATE_PLAYING && !is_live) {
2402 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2403 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2404 /* user has to manually start the playback */
2405 state = GST_STATE_PAUSED;
2411 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2415 gst_message_parse_buffering (message, &percent);
2417 /* get more stats */
2418 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2422 case GST_BUFFERING_DOWNLOAD:
2423 do_download_buffering (percent);
2425 case GST_BUFFERING_LIVE:
2426 case GST_BUFFERING_TIMESHIFT:
2427 case GST_BUFFERING_STREAM:
2428 do_stream_buffering (percent);
2434 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2436 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2438 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2439 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2444 static gulong embed_xid = 0;
2446 /* We set the xid here in response to the prepare-xwindow-id message via a
2447 * bus sync handler because we don't know the actual videosink used from the
2448 * start (as we don't know the pipeline, or bin elements such as autovideosink
2449 * or gconfvideosink may be used which create the actual videosink only once
2450 * the pipeline is started) */
2451 static GstBusSyncReply
2452 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2454 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
2455 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
2456 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2458 g_print ("got prepare-xwindow-id, setting XID %lu\n", embed_xid);
2460 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2461 "force-aspect-ratio")) {
2462 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2465 /* Should have been initialised from main thread before (can't use
2466 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2467 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2468 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2469 * shouldn't be done from a non-GUI thread without explicit locking). */
2470 g_assert (embed_xid != 0);
2472 gst_x_overlay_set_window_handle (GST_X_OVERLAY (element), embed_xid);
2474 return GST_BUS_PASS;
2479 handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
2481 if (state < GST_STATE_PAUSED) {
2482 GtkAllocation allocation;
2483 GdkWindow *window = gtk_widget_get_window (widget);
2486 gtk_widget_get_allocation (widget, &allocation);
2487 cr = gdk_cairo_create (window);
2488 cairo_set_source_rgb (cr, 0, 0, 0);
2489 cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
2497 realize_cb (GtkWidget * widget, gpointer data)
2499 #if GTK_CHECK_VERSION(2,18,0)
2501 GdkWindow *window = gtk_widget_get_window (widget);
2503 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2505 if (!gdk_window_ensure_native (window))
2506 g_error ("Couldn't create native window needed for GstXOverlay!");
2512 GdkWindow *window = gtk_widget_get_window (video_window);
2514 embed_xid = GDK_WINDOW_XID (window);
2515 g_print ("Window realize: video window XID = %lu\n", embed_xid);
2521 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2523 message_received (bus, message, data);
2525 /* Set new uri for playerbins and continue playback */
2526 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2527 stop_cb (NULL, NULL);
2528 l = g_list_next (l);
2530 playerbin_set_uri (GST_ELEMENT (data), l->data);
2531 play_cb (NULL, NULL);
2537 msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data)
2540 message_received (bus, message, data);
2544 connect_bus_signals (GstElement * pipeline)
2546 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2549 /* handle prepare-xwindow-id element message synchronously */
2550 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2554 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2555 gst_bus_enable_sync_message_emission (bus);
2557 g_signal_connect (bus, "message::state-changed",
2558 (GCallback) msg_state_changed, pipeline);
2559 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2561 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2564 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2566 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2568 g_signal_connect (bus, "message::error", (GCallback) message_received,
2570 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2572 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2573 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2575 g_signal_connect (bus, "message::element", (GCallback) message_received,
2577 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2579 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2581 // g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done,
2583 g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done,
2585 g_signal_connect (bus, "sync-message::step-done",
2586 (GCallback) msg_sync_step_done, pipeline);
2588 gst_object_unref (bus);
2591 /* Return GList of paths described in location string */
2593 handle_wildcards (const gchar * location)
2596 gchar *path = g_path_get_dirname (location);
2597 gchar *pattern = g_path_get_basename (location);
2598 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2599 GDir *dir = g_dir_open (path, 0, NULL);
2602 g_print ("matching %s from %s\n", pattern, path);
2605 g_print ("opening directory %s failed\n", path);
2609 while ((name = g_dir_read_name (dir)) != NULL) {
2610 if (g_pattern_match_string (pspec, name)) {
2611 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2612 g_print (" found clip %s\n", name);
2618 g_pattern_spec_free (pspec);
2626 delete_event_cb (void)
2628 stop_cb (NULL, NULL);
2633 print_usage (int argc, char **argv)
2637 g_print ("usage: %s <type> <filename>\n", argv[0]);
2638 g_print (" possible types:\n");
2640 for (i = 0; i < NUM_TYPES; i++) {
2641 g_print (" %d = %s\n", i, pipelines[i].name);
2646 read_joystick (GIOChannel * source, GIOCondition condition, gpointer user_data)
2648 gchar buf[sizeof (struct js_event)];
2649 struct js_event *js = (struct js_event *) buf;
2651 gsize bytes_read = 0;
2655 g_io_channel_read_chars (source, buf, sizeof (struct js_event),
2658 g_print ("error reading from joystick: %s", err->message);
2661 } else if (bytes_read != sizeof (struct js_event)) {
2662 g_print ("error reading joystick, read %u bytes of %u\n",
2663 (guint) bytes_read, (guint) sizeof (struct js_event));
2665 } else if (result != G_IO_STATUS_NORMAL) {
2666 g_print ("reading from joystick returned status %d", result);
2669 switch (js->type & ~JS_EVENT_INIT) {
2671 if (js->number == 0) {
2672 gdouble new_rate = (gdouble) (js->value) / 3000;
2673 g_print ("Got: %d (rate %g)\n", js->value, new_rate);
2675 gtk_adjustment_set_value (shuttle_adjustment, new_rate);
2684 main (int argc, char **argv)
2686 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2687 *flagtable, *boxes2, *step;
2688 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2689 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2690 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2691 GtkWidget *rate_label, *volume_label;
2692 GOptionEntry options[] = {
2693 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2694 "Show pad stats", NULL},
2695 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2696 "Seek on elements instead of pads", NULL},
2697 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2698 "Verbose properties", NULL},
2699 {"joystick", 'j', 0, G_OPTION_ARG_STRING, &js_device,
2700 "Joystick device to use", NULL},
2703 GOptionContext *ctx;
2706 if (!g_thread_supported ())
2707 g_thread_init (NULL);
2709 ctx = g_option_context_new ("- test seeking in gsteamer");
2710 g_option_context_add_main_entries (ctx, options, NULL);
2711 g_option_context_add_group (ctx, gst_init_get_option_group ());
2712 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2714 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2715 g_print ("Error initializing: %s\n", err->message);
2719 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2722 print_usage (argc, argv);
2726 pipeline_type = atoi (argv[1]);
2728 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2729 print_usage (argc, argv);
2733 pipeline_spec = argv[2];
2735 if (js_device == NULL)
2736 js_device = g_strdup ("/dev/input/js0");
2738 js_fd = g_open (js_device, O_RDONLY, 0);
2740 g_print ("Failed to open joystick device %s\n", js_device);
2744 if (g_strrstr (pipeline_spec, "*") != NULL ||
2745 g_strrstr (pipeline_spec, "?") != NULL) {
2746 paths = handle_wildcards (pipeline_spec);
2748 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2752 g_print ("opening %s failed\n", pipeline_spec);
2758 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2759 g_assert (pipeline);
2761 /* initialize gui elements ... */
2762 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2763 video_window = gtk_drawing_area_new ();
2764 g_signal_connect (video_window, "expose-event",
2765 G_CALLBACK (handle_expose_cb), NULL);
2766 g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL);
2767 gtk_widget_set_double_buffered (video_window, FALSE);
2769 statusbar = gtk_statusbar_new ();
2770 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2771 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2772 hbox = gtk_hbox_new (FALSE, 0);
2773 vbox = gtk_vbox_new (FALSE, 0);
2774 flagtable = gtk_table_new (4, 2, FALSE);
2775 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2777 /* media controls */
2778 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2779 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2780 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2783 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2784 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2785 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2786 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2787 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2788 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2789 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2790 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2791 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2792 rate_label = gtk_label_new ("Rate");
2794 gtk_widget_set_tooltip_text (accurate_checkbox,
2795 "accurate position is requested, this might be considerably slower for some formats");
2796 gtk_widget_set_tooltip_text (key_checkbox,
2797 "seek to the nearest keyframe. This might be faster but less accurate");
2798 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2799 gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking");
2800 gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, "
2801 "negative value trigger reverse playback");
2802 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2803 gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking");
2804 gtk_widget_set_tooltip_text (skip_checkbox,
2805 "Skip frames while playing at high frame rates");
2807 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2808 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2810 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2816 step = gtk_expander_new ("step options");
2817 hbox = gtk_hbox_new (FALSE, 0);
2819 format_combo = gtk_combo_box_text_new ();
2820 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2822 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2824 gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0);
2825 gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2);
2827 step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2828 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0);
2829 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0);
2830 gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE,
2833 step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2834 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3);
2835 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0);
2836 gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2);
2838 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2839 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2840 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2842 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2846 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2847 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2848 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2849 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2852 shuttle_adjustment =
2853 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2854 shuttle_hscale = gtk_hscale_new (shuttle_adjustment);
2855 gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2);
2856 gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP);
2857 g_signal_connect (shuttle_hscale, "value_changed",
2858 G_CALLBACK (shuttle_value_changed), pipeline);
2859 g_signal_connect (shuttle_hscale, "format_value",
2860 G_CALLBACK (shuttle_format_value), pipeline);
2862 gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2);
2864 gtk_container_add (GTK_CONTAINER (step), hbox);
2869 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
2870 hscale = gtk_hscale_new (adjustment);
2871 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2872 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
2873 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2874 gtk_range_set_fill_level (GTK_RANGE (hscale), 100.0);
2876 g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek),
2878 g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek),
2880 g_signal_connect (hscale, "format_value", G_CALLBACK (format_value),
2883 if (pipeline_type == 16) {
2884 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2885 panel = gtk_hbox_new (FALSE, 0);
2886 video_combo = gtk_combo_box_text_new ();
2887 audio_combo = gtk_combo_box_text_new ();
2888 text_combo = gtk_combo_box_text_new ();
2889 gtk_widget_set_sensitive (video_combo, FALSE);
2890 gtk_widget_set_sensitive (audio_combo, FALSE);
2891 gtk_widget_set_sensitive (text_combo, FALSE);
2892 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2893 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2894 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2895 g_signal_connect (G_OBJECT (video_combo), "changed",
2896 G_CALLBACK (video_combo_cb), pipeline);
2897 g_signal_connect (G_OBJECT (audio_combo), "changed",
2898 G_CALLBACK (audio_combo_cb), pipeline);
2899 g_signal_connect (G_OBJECT (text_combo), "changed",
2900 G_CALLBACK (text_combo_cb), pipeline);
2901 /* playbin2 panel for flag checkboxes and volume/mute */
2902 boxes = gtk_hbox_new (FALSE, 0);
2903 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2904 video_checkbox = gtk_check_button_new_with_label ("Video");
2905 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2906 text_checkbox = gtk_check_button_new_with_label ("Text");
2907 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2908 download_checkbox = gtk_check_button_new_with_label ("Download");
2909 buffer_checkbox = gtk_check_button_new_with_label ("Buffer");
2910 volume_label = gtk_label_new ("Volume");
2911 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2912 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2913 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2914 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2915 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2916 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2917 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2918 gtk_box_pack_start (GTK_BOX (boxes), download_checkbox, TRUE, TRUE, 2);
2919 gtk_box_pack_start (GTK_BOX (boxes), buffer_checkbox, TRUE, TRUE, 2);
2920 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
2921 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2922 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2923 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2924 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2925 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2926 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2927 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
2928 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffer_checkbox), FALSE);
2929 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2930 G_CALLBACK (vis_toggle_cb), pipeline);
2931 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2932 G_CALLBACK (audio_toggle_cb), pipeline);
2933 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2934 G_CALLBACK (video_toggle_cb), pipeline);
2935 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2936 G_CALLBACK (text_toggle_cb), pipeline);
2937 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2938 G_CALLBACK (mute_toggle_cb), pipeline);
2939 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
2940 G_CALLBACK (download_toggle_cb), pipeline);
2941 g_signal_connect (G_OBJECT (buffer_checkbox), "toggled",
2942 G_CALLBACK (buffer_toggle_cb), pipeline);
2943 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2944 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2945 /* playbin2 panel for snapshot */
2946 boxes2 = gtk_hbox_new (FALSE, 0);
2947 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2948 gtk_widget_set_tooltip_text (shot_button,
2949 "save a screenshot .png in the current directory");
2950 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2952 vis_combo = gtk_combo_box_text_new ();
2953 g_signal_connect (G_OBJECT (vis_combo), "changed",
2954 G_CALLBACK (vis_combo_cb), pipeline);
2955 gtk_widget_set_sensitive (vis_combo, FALSE);
2956 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2957 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2959 /* fill the vis combo box and the array of factories */
2960 init_visualization_features ();
2962 panel = boxes = boxes2 = NULL;
2965 /* do the packing stuff ... */
2966 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2967 /* FIXME: can we avoid this for audio only? */
2968 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
2969 DEFAULT_VIDEO_HEIGHT);
2970 gtk_container_add (GTK_CONTAINER (window), vbox);
2971 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
2972 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2973 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2974 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2975 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2976 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2977 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2979 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2980 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2981 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2982 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2983 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2985 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2986 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2987 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2989 if (panel && boxes && boxes2) {
2990 expander = gtk_expander_new ("playbin2 options");
2991 pb2vbox = gtk_vbox_new (FALSE, 0);
2992 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2993 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2994 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2995 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2996 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2998 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2999 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
3000 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
3002 /* connect things ... */
3003 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
3005 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
3007 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
3009 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
3010 G_CALLBACK (accurate_toggle_cb), pipeline);
3011 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
3012 G_CALLBACK (key_toggle_cb), pipeline);
3013 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
3014 G_CALLBACK (loop_toggle_cb), pipeline);
3015 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
3016 G_CALLBACK (flush_toggle_cb), pipeline);
3017 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
3018 G_CALLBACK (scrub_toggle_cb), pipeline);
3019 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
3020 G_CALLBACK (play_scrub_toggle_cb), pipeline);
3021 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
3022 G_CALLBACK (skip_toggle_cb), pipeline);
3023 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
3024 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
3026 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
3029 gtk_widget_show_all (window);
3031 /* realize window now so that the video window gets created and we can
3032 * obtain its XID before the pipeline is started up and the videosink
3033 * asks for the XID of the window to render onto */
3034 gtk_widget_realize (window);
3036 /* we should have the XID now */
3037 g_assert (embed_xid != 0);
3040 g_signal_connect (pipeline, "deep_notify",
3041 G_CALLBACK (gst_object_default_deep_notify), NULL);
3045 GIOChannel *js_watch = g_io_channel_unix_new (js_fd);
3046 g_io_channel_set_encoding (js_watch, NULL, NULL);
3047 g_io_add_watch (js_watch, G_IO_IN, read_joystick, NULL);
3050 connect_bus_signals (pipeline);
3053 g_print ("NULL pipeline\n");
3054 gst_element_set_state (pipeline, GST_STATE_NULL);
3056 g_print ("free pipeline\n");
3057 gst_object_unref (pipeline);
3059 g_list_foreach (paths, (GFunc) g_free, NULL);
3060 g_list_free (paths);