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/videooverlay.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)
69 #define SOURCE "filesrc"
71 #define ASINK "alsasink"
72 //#define ASINK "osssink"
74 #define VSINK "xvimagesink"
75 //#define VSINK "sdlvideosink"
76 //#define VSINK "ximagesink"
77 //#define VSINK "aasink"
78 //#define VSINK "cacasink"
80 #define FILL_INTERVAL 100
81 //#define UPDATE_INTERVAL 500
82 //#define UPDATE_INTERVAL 100
83 //#define UPDATE_INTERVAL 10
84 #define UPDATE_INTERVAL 40
86 /* number of milliseconds to play for after a seek */
87 #define SCRUB_TIME 100
89 /* timeout for gst_element_get_state() after a seek */
90 #define SEEK_TIMEOUT 40 * GST_MSECOND
92 #define DEFAULT_VIDEO_HEIGHT 300
94 /* the state to go to when stop is pressed */
95 #define STOP_STATE GST_STATE_READY
98 static GList *seekable_pads = NULL;
99 static GList *rate_pads = NULL;
100 static GList *seekable_elements = NULL;
102 static gboolean accurate_seek = FALSE;
103 static gboolean keyframe_seek = FALSE;
104 static gboolean loop_seek = FALSE;
105 static gboolean flush_seek = TRUE;
106 static gboolean scrub = TRUE;
107 static gboolean play_scrub = FALSE;
108 static gboolean skip_seek = FALSE;
109 static gdouble rate = 1.0;
111 static GstElement *pipeline;
112 static gint pipeline_type;
113 static const gchar *pipeline_spec;
114 static gint64 position = -1;
115 static gint64 duration = -1;
116 static GtkAdjustment *adjustment;
117 static GtkWidget *hscale, *statusbar;
118 static guint status_id = 0;
119 static gboolean stats = FALSE;
120 static gboolean elem_seek = FALSE;
121 static gboolean verbose = FALSE;
122 static gchar *js_device = NULL;
124 static gboolean is_live = FALSE;
125 static gboolean buffering = FALSE;
126 static GstBufferingMode mode;
127 static gint64 buffering_left;
128 static GstState state = GST_STATE_NULL;
129 static guint update_id = 0;
130 static guint seek_timeout_id = 0;
131 static gulong changed_id;
132 static guint fill_id = 0;
134 static gint n_video = 0, n_audio = 0, n_text = 0;
135 static gboolean need_streams = TRUE;
136 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
137 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
138 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
139 static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
140 static GtkWidget *buffer_checkbox, *rate_spinbutton;
142 static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
144 static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
145 static GtkWidget *shuttle_checkbox, *step_button;
146 static GtkWidget *shuttle_hscale;
147 static GtkAdjustment *shuttle_adjustment;
149 static GList *paths = NULL, *l = NULL;
153 /* we keep an array of the visualisation entries so that we can easily switch
154 * with the combo box index. */
157 GstElementFactory *factory;
160 static GArray *vis_entries;
162 static void clear_streams (GstElement * pipeline);
163 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
166 /* pipeline construction */
170 const gchar *padname;
177 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
179 GstElement *element = gst_element_factory_make (type, name);
182 g_warning ("Failed to create element %s of type %s", name, type);
189 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
192 dyn_link *connect = (dyn_link *) data;
194 padname = gst_pad_get_name (newpad);
196 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
198 gst_bin_add (GST_BIN (pipeline), connect->bin);
199 gst_pad_link (newpad, connect->target);
201 //seekable_pads = g_list_prepend (seekable_pads, newpad);
202 rate_pads = g_list_prepend (rate_pads, newpad);
208 setup_dynamic_link (GstElement * element, const gchar * padname,
209 GstPad * target, GstElement * bin)
213 connect = g_new0 (dyn_link, 1);
214 connect->padname = g_strdup (padname);
215 connect->target = target;
218 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
223 make_mod_pipeline (const gchar * location)
225 GstElement *pipeline;
226 GstElement *src, *decoder, *audiosink;
229 pipeline = gst_pipeline_new ("app");
231 src = gst_element_factory_make_or_warn (SOURCE, "src");
232 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
233 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
234 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
236 g_object_set (G_OBJECT (src), "location", location, NULL);
238 gst_bin_add (GST_BIN (pipeline), src);
239 gst_bin_add (GST_BIN (pipeline), decoder);
240 gst_bin_add (GST_BIN (pipeline), audiosink);
242 gst_element_link (src, decoder);
243 gst_element_link (decoder, audiosink);
245 seekable = gst_element_get_static_pad (decoder, "src");
246 seekable_pads = g_list_prepend (seekable_pads, seekable);
247 rate_pads = g_list_prepend (rate_pads, seekable);
249 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
255 make_dv_pipeline (const gchar * location)
257 GstElement *pipeline;
258 GstElement *src, *demux, *decoder, *audiosink, *videosink;
259 GstElement *a_queue, *v_queue;
262 pipeline = gst_pipeline_new ("app");
264 src = gst_element_factory_make_or_warn (SOURCE, "src");
265 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
266 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
267 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
268 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
269 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
270 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
272 g_object_set (G_OBJECT (src), "location", location, NULL);
274 gst_bin_add (GST_BIN (pipeline), src);
275 gst_bin_add (GST_BIN (pipeline), demux);
276 gst_bin_add (GST_BIN (pipeline), a_queue);
277 gst_bin_add (GST_BIN (pipeline), audiosink);
278 gst_bin_add (GST_BIN (pipeline), v_queue);
279 gst_bin_add (GST_BIN (pipeline), decoder);
280 gst_bin_add (GST_BIN (pipeline), videosink);
282 gst_element_link (src, demux);
283 gst_element_link (a_queue, audiosink);
284 gst_element_link (v_queue, decoder);
285 gst_element_link (decoder, videosink);
287 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
289 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
292 seekable = gst_element_get_static_pad (decoder, "src");
293 seekable_pads = g_list_prepend (seekable_pads, seekable);
294 rate_pads = g_list_prepend (rate_pads, seekable);
300 make_wav_pipeline (const gchar * location)
302 GstElement *pipeline;
303 GstElement *src, *decoder, *audiosink;
305 pipeline = gst_pipeline_new ("app");
307 src = gst_element_factory_make_or_warn (SOURCE, "src");
308 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
309 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
311 g_object_set (G_OBJECT (src), "location", location, NULL);
313 gst_bin_add (GST_BIN (pipeline), src);
314 gst_bin_add (GST_BIN (pipeline), decoder);
315 gst_bin_add (GST_BIN (pipeline), audiosink);
317 gst_element_link (src, decoder);
319 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
322 seekable_elements = g_list_prepend (seekable_elements, audiosink);
324 /* force element seeking on this pipeline */
331 make_flac_pipeline (const gchar * location)
333 GstElement *pipeline;
334 GstElement *src, *decoder, *audiosink;
337 pipeline = gst_pipeline_new ("app");
339 src = gst_element_factory_make_or_warn (SOURCE, "src");
340 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
341 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
342 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
344 g_object_set (G_OBJECT (src), "location", location, NULL);
346 gst_bin_add (GST_BIN (pipeline), src);
347 gst_bin_add (GST_BIN (pipeline), decoder);
348 gst_bin_add (GST_BIN (pipeline), audiosink);
350 gst_element_link (src, decoder);
351 gst_element_link (decoder, audiosink);
353 seekable = gst_element_get_static_pad (decoder, "src");
354 seekable_pads = g_list_prepend (seekable_pads, seekable);
355 rate_pads = g_list_prepend (rate_pads, seekable);
357 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
363 make_sid_pipeline (const gchar * location)
365 GstElement *pipeline;
366 GstElement *src, *decoder, *audiosink;
369 pipeline = gst_pipeline_new ("app");
371 src = gst_element_factory_make_or_warn (SOURCE, "src");
372 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
373 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
374 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
376 g_object_set (G_OBJECT (src), "location", location, NULL);
378 gst_bin_add (GST_BIN (pipeline), src);
379 gst_bin_add (GST_BIN (pipeline), decoder);
380 gst_bin_add (GST_BIN (pipeline), audiosink);
382 gst_element_link (src, decoder);
383 gst_element_link (decoder, audiosink);
385 seekable = gst_element_get_static_pad (decoder, "src");
386 seekable_pads = g_list_prepend (seekable_pads, seekable);
387 rate_pads = g_list_prepend (rate_pads, seekable);
389 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
395 make_parse_pipeline (const gchar * location)
397 GstElement *pipeline;
398 GstElement *src, *parser, *fakesink;
401 pipeline = gst_pipeline_new ("app");
403 src = gst_element_factory_make_or_warn (SOURCE, "src");
404 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
405 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
406 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
407 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
409 g_object_set (G_OBJECT (src), "location", location, NULL);
411 gst_bin_add (GST_BIN (pipeline), src);
412 gst_bin_add (GST_BIN (pipeline), parser);
413 gst_bin_add (GST_BIN (pipeline), fakesink);
415 gst_element_link (src, parser);
416 gst_element_link (parser, fakesink);
418 seekable = gst_element_get_static_pad (parser, "src");
419 seekable_pads = g_list_prepend (seekable_pads, seekable);
420 rate_pads = g_list_prepend (rate_pads, seekable);
422 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
428 make_vorbis_pipeline (const gchar * location)
430 GstElement *pipeline, *audio_bin;
431 GstElement *src, *demux, *decoder, *convert, *audiosink;
432 GstPad *pad, *seekable;
434 pipeline = gst_pipeline_new ("app");
436 src = gst_element_factory_make_or_warn (SOURCE, "src");
437 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
438 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
439 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
440 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
441 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
443 g_object_set (G_OBJECT (src), "location", location, NULL);
445 audio_bin = gst_bin_new ("a_decoder_bin");
447 gst_bin_add (GST_BIN (pipeline), src);
448 gst_bin_add (GST_BIN (pipeline), demux);
449 gst_bin_add (GST_BIN (audio_bin), decoder);
450 gst_bin_add (GST_BIN (audio_bin), convert);
451 gst_bin_add (GST_BIN (audio_bin), audiosink);
452 gst_bin_add (GST_BIN (pipeline), audio_bin);
454 gst_element_link (src, demux);
455 gst_element_link (decoder, convert);
456 gst_element_link (convert, audiosink);
458 pad = gst_element_get_static_pad (decoder, "sink");
459 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
460 gst_object_unref (pad);
462 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
465 seekable = gst_element_get_static_pad (decoder, "src");
466 seekable_pads = g_list_prepend (seekable_pads, seekable);
467 rate_pads = g_list_prepend (rate_pads, seekable);
469 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
475 make_theora_pipeline (const gchar * location)
477 GstElement *pipeline, *video_bin;
478 GstElement *src, *demux, *decoder, *convert, *videosink;
479 GstPad *pad, *seekable;
481 pipeline = gst_pipeline_new ("app");
483 src = gst_element_factory_make_or_warn (SOURCE, "src");
484 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
485 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
486 convert = gst_element_factory_make_or_warn ("videoconvert", "convert");
487 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
489 g_object_set (G_OBJECT (src), "location", location, NULL);
491 video_bin = gst_bin_new ("v_decoder_bin");
493 gst_bin_add (GST_BIN (pipeline), src);
494 gst_bin_add (GST_BIN (pipeline), demux);
495 gst_bin_add (GST_BIN (video_bin), decoder);
496 gst_bin_add (GST_BIN (video_bin), convert);
497 gst_bin_add (GST_BIN (video_bin), videosink);
498 gst_bin_add (GST_BIN (pipeline), video_bin);
500 gst_element_link (src, demux);
501 gst_element_link (decoder, convert);
502 gst_element_link (convert, videosink);
504 pad = gst_element_get_static_pad (decoder, "sink");
505 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
506 gst_object_unref (pad);
508 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
511 seekable = gst_element_get_static_pad (decoder, "src");
512 seekable_pads = g_list_prepend (seekable_pads, seekable);
513 rate_pads = g_list_prepend (rate_pads, seekable);
515 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
521 make_vorbis_theora_pipeline (const gchar * location)
523 GstElement *pipeline, *audio_bin, *video_bin;
524 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
525 GstElement *audiosink, *videosink;
526 GstElement *a_queue, *v_queue, *v_scale;
530 pipeline = gst_pipeline_new ("app");
532 src = gst_element_factory_make_or_warn (SOURCE, "src");
533 g_object_set (G_OBJECT (src), "location", location, NULL);
535 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
537 gst_bin_add (GST_BIN (pipeline), src);
538 gst_bin_add (GST_BIN (pipeline), demux);
539 gst_element_link (src, demux);
541 audio_bin = gst_bin_new ("a_decoder_bin");
542 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
543 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
544 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
545 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
547 gst_bin_add (GST_BIN (pipeline), audio_bin);
549 gst_bin_add (GST_BIN (audio_bin), a_queue);
550 gst_bin_add (GST_BIN (audio_bin), a_decoder);
551 gst_bin_add (GST_BIN (audio_bin), a_convert);
552 gst_bin_add (GST_BIN (audio_bin), audiosink);
554 gst_element_link (a_queue, a_decoder);
555 gst_element_link (a_decoder, a_convert);
556 gst_element_link (a_convert, audiosink);
558 pad = gst_element_get_static_pad (a_queue, "sink");
559 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
560 gst_object_unref (pad);
562 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
565 video_bin = gst_bin_new ("v_decoder_bin");
566 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
567 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
568 v_convert = gst_element_factory_make_or_warn ("videoconvert", "v_convert");
569 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
570 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
572 gst_bin_add (GST_BIN (pipeline), video_bin);
574 gst_bin_add (GST_BIN (video_bin), v_queue);
575 gst_bin_add (GST_BIN (video_bin), v_decoder);
576 gst_bin_add (GST_BIN (video_bin), v_convert);
577 gst_bin_add (GST_BIN (video_bin), v_scale);
578 gst_bin_add (GST_BIN (video_bin), videosink);
580 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
583 pad = gst_element_get_static_pad (v_queue, "sink");
584 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
585 gst_object_unref (pad);
587 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
590 seekable = gst_element_get_static_pad (a_decoder, "src");
591 seekable_pads = g_list_prepend (seekable_pads, seekable);
592 rate_pads = g_list_prepend (rate_pads, seekable);
594 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
601 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
603 GstElement *pipeline, *audio_bin, *video_bin;
604 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
605 GstElement *audiosink, *videosink;
606 GstElement *a_queue, *v_queue;
607 GstPad *seekable, *pad;
609 pipeline = gst_pipeline_new ("app");
611 src = gst_element_factory_make_or_warn (SOURCE, "src");
612 g_object_set (G_OBJECT (src), "location", location, NULL);
614 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
616 gst_bin_add (GST_BIN (pipeline), src);
617 gst_bin_add (GST_BIN (pipeline), demux);
618 gst_element_link (src, demux);
620 audio_bin = gst_bin_new ("a_decoder_bin");
621 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
622 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
623 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
624 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
626 gst_bin_add (GST_BIN (audio_bin), a_queue);
627 gst_bin_add (GST_BIN (audio_bin), a_decoder);
628 gst_bin_add (GST_BIN (audio_bin), a_convert);
629 gst_bin_add (GST_BIN (audio_bin), audiosink);
631 gst_element_link (a_queue, a_decoder);
632 gst_element_link (a_decoder, a_convert);
633 gst_element_link (a_convert, audiosink);
635 gst_bin_add (GST_BIN (pipeline), audio_bin);
637 pad = gst_element_get_static_pad (a_queue, "sink");
638 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
639 gst_object_unref (pad);
641 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
644 video_bin = gst_bin_new ("v_decoder_bin");
645 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
646 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
647 v_convert = gst_element_factory_make_or_warn ("videoconvert", "v_convert");
648 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
650 gst_bin_add (GST_BIN (video_bin), v_queue);
651 gst_bin_add (GST_BIN (video_bin), v_decoder);
652 gst_bin_add (GST_BIN (video_bin), v_convert);
653 gst_bin_add (GST_BIN (video_bin), videosink);
655 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
657 gst_bin_add (GST_BIN (pipeline), video_bin);
659 pad = gst_element_get_static_pad (v_queue, "sink");
660 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
661 gst_object_unref (pad);
663 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
666 seekable = gst_element_get_static_pad (a_decoder, "src");
667 seekable_pads = g_list_prepend (seekable_pads, seekable);
668 rate_pads = g_list_prepend (rate_pads, seekable);
670 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
677 make_mp3_pipeline (const gchar * location)
679 GstElement *pipeline;
680 GstElement *src, *parser, *decoder, *audiosink, *queue;
683 pipeline = gst_pipeline_new ("app");
685 src = gst_element_factory_make_or_warn (SOURCE, "src");
686 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
687 decoder = gst_element_factory_make_or_warn ("mad", "dec");
688 queue = gst_element_factory_make_or_warn ("queue", "queue");
689 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
691 seekable_elements = g_list_prepend (seekable_elements, audiosink);
693 g_object_set (G_OBJECT (src), "location", location, NULL);
694 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
696 gst_bin_add (GST_BIN (pipeline), src);
697 gst_bin_add (GST_BIN (pipeline), parser);
698 gst_bin_add (GST_BIN (pipeline), decoder);
699 gst_bin_add (GST_BIN (pipeline), queue);
700 gst_bin_add (GST_BIN (pipeline), audiosink);
702 gst_element_link (src, parser);
703 gst_element_link (parser, decoder);
704 gst_element_link (decoder, queue);
705 gst_element_link (queue, audiosink);
707 seekable = gst_element_get_static_pad (queue, "src");
708 seekable_pads = g_list_prepend (seekable_pads, seekable);
709 rate_pads = g_list_prepend (rate_pads, seekable);
711 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
717 make_avi_pipeline (const gchar * location)
719 GstElement *pipeline, *audio_bin, *video_bin;
720 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
721 GstElement *a_queue = NULL, *v_queue = NULL;
724 pipeline = gst_pipeline_new ("app");
726 src = gst_element_factory_make_or_warn (SOURCE, "src");
727 g_object_set (G_OBJECT (src), "location", location, NULL);
729 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
730 seekable_elements = g_list_prepend (seekable_elements, demux);
732 gst_bin_add (GST_BIN (pipeline), src);
733 gst_bin_add (GST_BIN (pipeline), demux);
734 gst_element_link (src, demux);
736 audio_bin = gst_bin_new ("a_decoder_bin");
737 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
738 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
739 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
740 gst_element_link (a_decoder, a_queue);
741 gst_element_link (a_queue, audiosink);
742 gst_bin_add (GST_BIN (audio_bin), a_decoder);
743 gst_bin_add (GST_BIN (audio_bin), a_queue);
744 gst_bin_add (GST_BIN (audio_bin), audiosink);
745 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
747 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
750 seekable = gst_element_get_static_pad (a_queue, "src");
751 seekable_pads = g_list_prepend (seekable_pads, seekable);
752 rate_pads = g_list_prepend (rate_pads, seekable);
754 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
757 video_bin = gst_bin_new ("v_decoder_bin");
758 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
759 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
760 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
761 gst_element_link (v_decoder, v_queue);
762 gst_element_link (v_queue, videosink);
763 gst_bin_add (GST_BIN (video_bin), v_decoder);
764 gst_bin_add (GST_BIN (video_bin), v_queue);
765 gst_bin_add (GST_BIN (video_bin), videosink);
767 gst_element_set_state (video_bin, GST_STATE_PAUSED);
769 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
772 seekable = gst_element_get_static_pad (v_queue, "src");
773 seekable_pads = g_list_prepend (seekable_pads, seekable);
774 rate_pads = g_list_prepend (rate_pads, seekable);
776 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
783 make_mpeg_pipeline (const gchar * location)
785 GstElement *pipeline, *audio_bin, *video_bin;
786 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
787 GstElement *audiosink, *videosink;
788 GstElement *a_queue, *v_queue;
792 pipeline = gst_pipeline_new ("app");
794 src = gst_element_factory_make_or_warn (SOURCE, "src");
795 g_object_set (G_OBJECT (src), "location", location, NULL);
797 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
798 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
800 gst_bin_add (GST_BIN (pipeline), src);
801 gst_bin_add (GST_BIN (pipeline), demux);
802 gst_element_link (src, demux);
804 audio_bin = gst_bin_new ("a_decoder_bin");
805 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
806 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
807 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
808 gst_bin_add (GST_BIN (audio_bin), a_decoder);
809 gst_bin_add (GST_BIN (audio_bin), a_queue);
810 gst_bin_add (GST_BIN (audio_bin), audiosink);
812 gst_element_link (a_decoder, a_queue);
813 gst_element_link (a_queue, audiosink);
815 gst_bin_add (GST_BIN (pipeline), audio_bin);
817 pad = gst_element_get_static_pad (a_decoder, "sink");
818 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
819 gst_object_unref (pad);
821 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
824 video_bin = gst_bin_new ("v_decoder_bin");
825 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
826 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
827 v_filter = gst_element_factory_make_or_warn ("videoconvert", "v_filter");
828 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
830 gst_bin_add (GST_BIN (video_bin), v_decoder);
831 gst_bin_add (GST_BIN (video_bin), v_queue);
832 gst_bin_add (GST_BIN (video_bin), v_filter);
833 gst_bin_add (GST_BIN (video_bin), videosink);
835 gst_element_link (v_decoder, v_queue);
836 gst_element_link (v_queue, v_filter);
837 gst_element_link (v_filter, videosink);
839 gst_bin_add (GST_BIN (pipeline), video_bin);
841 pad = gst_element_get_static_pad (v_decoder, "sink");
842 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
843 gst_object_unref (pad);
845 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
848 seekable = gst_element_get_static_pad (v_filter, "src");
849 seekable_pads = g_list_prepend (seekable_pads, seekable);
850 rate_pads = g_list_prepend (rate_pads, seekable);
852 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
859 make_mpegnt_pipeline (const gchar * location)
861 GstElement *pipeline, *audio_bin, *video_bin;
862 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
863 GstElement *audiosink, *videosink;
867 pipeline = gst_pipeline_new ("app");
869 src = gst_element_factory_make_or_warn (SOURCE, "src");
870 g_object_set (G_OBJECT (src), "location", location, NULL);
872 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
873 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
875 seekable_elements = g_list_prepend (seekable_elements, demux);
877 gst_bin_add (GST_BIN (pipeline), src);
878 gst_bin_add (GST_BIN (pipeline), demux);
879 gst_element_link (src, demux);
881 audio_bin = gst_bin_new ("a_decoder_bin");
882 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
883 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
884 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
885 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
886 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
887 gst_element_link (a_decoder, a_queue);
888 gst_element_link (a_queue, audiosink);
889 gst_bin_add (GST_BIN (audio_bin), a_decoder);
890 gst_bin_add (GST_BIN (audio_bin), a_queue);
891 gst_bin_add (GST_BIN (audio_bin), audiosink);
893 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
896 seekable = gst_element_get_static_pad (a_queue, "src");
897 seekable_pads = g_list_prepend (seekable_pads, seekable);
898 rate_pads = g_list_prepend (rate_pads, seekable);
900 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
903 video_bin = gst_bin_new ("v_decoder_bin");
904 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
905 v_filter = gst_element_factory_make_or_warn ("videoconvert", "v_filter");
906 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
907 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
909 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
911 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
914 seekable = gst_element_get_static_pad (v_decoder, "src");
915 seekable_pads = g_list_prepend (seekable_pads, seekable);
916 rate_pads = g_list_prepend (rate_pads, seekable);
918 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
925 playerbin_set_uri (GstElement * player, const gchar * location)
929 /* Add "file://" prefix for convenience */
930 if (g_str_has_prefix (location, "/")) {
931 uri = g_strconcat ("file://", location, NULL);
932 g_object_set (G_OBJECT (player), "uri", uri, NULL);
935 g_object_set (G_OBJECT (player), "uri", location, NULL);
940 construct_playerbin (const gchar * name, const gchar * location)
944 player = gst_element_factory_make (name, "player");
947 playerbin_set_uri (player, location);
949 seekable_elements = g_list_prepend (seekable_elements, player);
951 /* force element seeking on this pipeline */
958 make_playerbin_pipeline (const gchar * location)
960 return construct_playerbin ("playbin", location);
964 make_playerbin2_pipeline (const gchar * location)
966 GstElement *pipeline = construct_playerbin ("playbin2", location);
968 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
969 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
974 #ifndef GST_DISABLE_PARSE
976 make_parselaunch_pipeline (const gchar * description)
978 GstElement *pipeline;
979 GError *error = NULL;
981 pipeline = gst_parse_launch (description, &error);
983 seekable_elements = g_list_prepend (seekable_elements, pipeline);
994 GstElement *(*func) (const gchar * location);
998 static Pipeline pipelines[] = {
999 {"mp3", make_mp3_pipeline},
1000 {"avi", make_avi_pipeline},
1001 {"mpeg1", make_mpeg_pipeline},
1002 {"mpegparse", make_parse_pipeline},
1003 {"vorbis", make_vorbis_pipeline},
1004 {"theora", make_theora_pipeline},
1005 {"ogg/v/t", make_vorbis_theora_pipeline},
1006 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
1007 {"sid", make_sid_pipeline},
1008 {"flac", make_flac_pipeline},
1009 {"wav", make_wav_pipeline},
1010 {"mod", make_mod_pipeline},
1011 {"dv", make_dv_pipeline},
1012 {"mpeg1nothreads", make_mpegnt_pipeline},
1013 {"playerbin", make_playerbin_pipeline},
1014 #ifndef GST_DISABLE_PARSE
1015 {"parse-launch", make_parselaunch_pipeline},
1017 {"playerbin2", make_playerbin2_pipeline},
1021 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
1023 /* ui callbacks and helpers */
1026 format_value (GtkScale * scale, gdouble value)
1032 real = value * duration / 100;
1033 seconds = (gint64) real / GST_SECOND;
1034 subseconds = (gint64) real / (GST_SECOND / 100);
1036 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1037 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1042 shuttle_format_value (GtkScale * scale, gdouble value)
1044 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
1050 const GstFormat format;
1054 static seek_format seek_formats[] = {
1055 {"tim", GST_FORMAT_TIME},
1056 {"byt", GST_FORMAT_BYTES},
1057 {"buf", GST_FORMAT_BUFFERS},
1058 {"def", GST_FORMAT_DEFAULT},
1062 G_GNUC_UNUSED static void
1065 GList *walk = rate_pads;
1068 GstPad *pad = GST_PAD (walk->data);
1071 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1072 while (seek_formats[i].name) {
1076 format = seek_formats[i].format;
1078 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, format,
1080 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1082 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1087 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1089 walk = g_list_next (walk);
1093 G_GNUC_UNUSED static void
1094 query_positions_elems (void)
1096 GList *walk = seekable_elements;
1099 GstElement *element = GST_ELEMENT (walk->data);
1102 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1103 while (seek_formats[i].name) {
1104 gint64 position, total;
1107 format = seek_formats[i].format;
1109 if (gst_element_query_position (element, format, &position) &&
1110 gst_element_query_duration (element, format, &total)) {
1111 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1112 seek_formats[i].name, position, total);
1114 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1119 g_print (" %s\n", GST_ELEMENT_NAME (element));
1121 walk = g_list_next (walk);
1125 G_GNUC_UNUSED static void
1126 query_positions_pads (void)
1128 GList *walk = seekable_pads;
1131 GstPad *pad = GST_PAD (walk->data);
1134 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1135 while (seek_formats[i].name) {
1137 gint64 position, total;
1139 format = seek_formats[i].format;
1141 if (gst_pad_query_position (pad, format, &position) &&
1142 gst_pad_query_duration (pad, format, &total)) {
1143 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1144 seek_formats[i].name, position, total);
1146 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1152 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1154 walk = g_list_next (walk);
1158 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1159 gpointer user_data);
1160 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1161 gpointer user_data);
1162 static void seek_cb (GtkWidget * widget);
1165 set_scale (gdouble value)
1167 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1169 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1171 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1172 gtk_adjustment_set_value (adjustment, value);
1173 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1175 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1177 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1179 gtk_widget_queue_draw (hscale);
1183 update_fill (gpointer data)
1186 if (seekable_elements) {
1187 GstElement *element = GST_ELEMENT (seekable_elements->data);
1190 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1191 if (gst_element_query (element, query)) {
1192 gint64 start, stop, buffering_total;
1197 GstBufferingMode mode;
1198 gint avg_in, avg_out;
1199 gint64 buffering_left;
1201 gst_query_parse_buffering_percent (query, &busy, &percent);
1202 gst_query_parse_buffering_range (query, &format, &start, &stop,
1204 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
1207 /* note that we could start the playback when buffering_left < remaining
1209 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
1210 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
1211 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1215 fill = 100.0 * stop / GST_FORMAT_PERCENT_MAX;
1219 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1221 gst_query_unref (query);
1228 update_scale (gpointer data)
1231 if (seekable_elements) {
1232 GstElement *element = GST_ELEMENT (seekable_elements->data);
1234 gst_element_query_position (element, GST_FORMAT_TIME, &position);
1235 gst_element_query_duration (element, GST_FORMAT_TIME, &duration);
1238 if (seekable_pads) {
1239 GstPad *pad = GST_PAD (seekable_pads->data);
1241 gst_pad_query_position (pad, GST_FORMAT_TIME, &position);
1242 gst_pad_query_duration (pad, GST_FORMAT_TIME, &duration);
1248 query_positions_elems ();
1250 query_positions_pads ();
1255 if (position >= duration)
1256 duration = position;
1259 set_scale (position * 100.0 / duration);
1262 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1263 if (pipeline_type == 16) {
1264 g_object_notify (G_OBJECT (pipeline), "volume");
1270 static void do_seek (GtkWidget * widget);
1271 static void connect_bus_signals (GstElement * pipeline);
1272 static void set_update_scale (gboolean active);
1273 static void set_update_fill (gboolean active);
1276 end_scrub (GtkWidget * widget)
1278 GST_DEBUG ("end scrub, PAUSE");
1279 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1280 seek_timeout_id = 0;
1286 send_event (GstEvent * event)
1288 gboolean res = FALSE;
1291 GList *walk = seekable_pads;
1294 GstPad *seekable = GST_PAD (walk->data);
1296 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1298 gst_event_ref (event);
1299 res = gst_pad_send_event (seekable, event);
1301 walk = g_list_next (walk);
1304 GList *walk = seekable_elements;
1307 GstElement *seekable = GST_ELEMENT (walk->data);
1309 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1311 gst_event_ref (event);
1312 res = gst_element_send_event (seekable, event);
1314 walk = g_list_next (walk);
1317 gst_event_unref (event);
1322 do_seek (GtkWidget * widget)
1325 gboolean res = FALSE;
1329 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
1333 flags |= GST_SEEK_FLAG_FLUSH;
1335 flags |= GST_SEEK_FLAG_ACCURATE;
1337 flags |= GST_SEEK_FLAG_KEY_UNIT;
1339 flags |= GST_SEEK_FLAG_SEGMENT;
1341 flags |= GST_SEEK_FLAG_SKIP;
1344 s_event = gst_event_new_seek (rate,
1345 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1346 GST_CLOCK_TIME_NONE);
1347 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1348 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1350 s_event = gst_event_new_seek (rate,
1351 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1352 GST_SEEK_TYPE_SET, real);
1353 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1354 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1357 res = send_event (s_event);
1361 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1363 set_update_scale (TRUE);
1366 g_print ("seek failed\n");
1367 set_update_scale (TRUE);
1372 seek_cb (GtkWidget * widget)
1374 /* If the timer hasn't expired yet, then the pipeline is running */
1375 if (play_scrub && seek_timeout_id != 0) {
1376 GST_DEBUG ("do scrub seek, PAUSED");
1377 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1380 GST_DEBUG ("do seek");
1384 GST_DEBUG ("do scrub seek, PLAYING");
1385 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1387 if (seek_timeout_id == 0) {
1389 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1395 set_update_fill (gboolean active)
1397 GST_DEBUG ("fill scale is %d", active);
1402 g_timeout_add (FILL_INTERVAL, (GSourceFunc) update_fill, pipeline);
1406 g_source_remove (fill_id);
1413 set_update_scale (gboolean active)
1416 GST_DEBUG ("update scale is %d", active);
1419 if (update_id == 0) {
1421 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, pipeline);
1425 g_source_remove (update_id);
1432 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1434 if (event->type != GDK_BUTTON_PRESS)
1437 set_update_scale (FALSE);
1439 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1440 GST_DEBUG ("start scrub seek, PAUSE");
1441 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1444 if (changed_id == 0 && flush_seek && scrub) {
1446 g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb),
1454 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1457 g_signal_handler_disconnect (hscale, changed_id);
1461 if (!flush_seek || !scrub) {
1462 GST_DEBUG ("do final seek");
1466 if (seek_timeout_id != 0) {
1467 g_source_remove (seek_timeout_id);
1468 seek_timeout_id = 0;
1469 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1471 if (state == GST_STATE_PAUSED) {
1472 GST_DEBUG ("stop scrub seek, PAUSED");
1473 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1476 if (state == GST_STATE_PLAYING) {
1477 GST_DEBUG ("stop scrub seek, PLAYING");
1478 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1486 play_cb (GtkButton * button, gpointer data)
1488 GstStateChangeReturn ret;
1490 if (state != GST_STATE_PLAYING) {
1491 g_print ("PLAY pipeline\n");
1492 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1494 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1496 case GST_STATE_CHANGE_FAILURE:
1498 case GST_STATE_CHANGE_NO_PREROLL:
1504 state = GST_STATE_PLAYING;
1505 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1512 g_print ("PLAY failed\n");
1513 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1518 pause_cb (GtkButton * button, gpointer data)
1520 g_static_mutex_lock (&state_mutex);
1521 if (state != GST_STATE_PAUSED) {
1522 GstStateChangeReturn ret;
1524 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1525 g_print ("PAUSE pipeline\n");
1526 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1528 case GST_STATE_CHANGE_FAILURE:
1530 case GST_STATE_CHANGE_NO_PREROLL:
1537 state = GST_STATE_PAUSED;
1538 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1540 g_static_mutex_unlock (&state_mutex);
1546 g_static_mutex_unlock (&state_mutex);
1547 g_print ("PAUSE failed\n");
1548 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1553 stop_cb (GtkButton * button, gpointer data)
1555 if (state != STOP_STATE) {
1556 GstStateChangeReturn ret;
1558 g_print ("READY pipeline\n");
1559 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1561 g_static_mutex_lock (&state_mutex);
1562 ret = gst_element_set_state (pipeline, STOP_STATE);
1563 if (ret == GST_STATE_CHANGE_FAILURE)
1567 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1571 set_update_scale (FALSE);
1573 set_update_fill (FALSE);
1575 if (pipeline_type == 16)
1576 clear_streams (pipeline);
1577 g_static_mutex_unlock (&state_mutex);
1580 /* if one uses parse_launch, play, stop and play again it fails as all the
1581 * pads after the demuxer can't be reconnected
1583 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1584 gst_element_set_state (pipeline, GST_STATE_NULL);
1585 gst_object_unref (pipeline);
1587 g_list_free (seekable_elements);
1588 seekable_elements = NULL;
1589 g_list_free (seekable_pads);
1590 seekable_pads = NULL;
1591 g_list_free (rate_pads);
1594 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1595 g_assert (pipeline);
1596 gst_element_set_state (pipeline, STOP_STATE);
1597 connect_bus_signals (pipeline);
1605 g_static_mutex_unlock (&state_mutex);
1606 g_print ("STOP failed\n");
1607 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1612 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1614 accurate_seek = gtk_toggle_button_get_active (button);
1618 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1620 keyframe_seek = gtk_toggle_button_get_active (button);
1624 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1626 loop_seek = gtk_toggle_button_get_active (button);
1627 if (state == GST_STATE_PLAYING) {
1633 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1635 flush_seek = gtk_toggle_button_get_active (button);
1639 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1641 scrub = gtk_toggle_button_get_active (button);
1645 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1647 play_scrub = gtk_toggle_button_get_active (button);
1651 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1653 skip_seek = gtk_toggle_button_get_active (button);
1654 if (state == GST_STATE_PLAYING) {
1660 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1662 gboolean res = FALSE;
1666 rate = gtk_spin_button_get_value (button);
1668 GST_DEBUG ("rate changed to %lf", rate);
1672 flags |= GST_SEEK_FLAG_FLUSH;
1674 flags |= GST_SEEK_FLAG_SEGMENT;
1676 flags |= GST_SEEK_FLAG_ACCURATE;
1678 flags |= GST_SEEK_FLAG_KEY_UNIT;
1680 flags |= GST_SEEK_FLAG_SKIP;
1683 s_event = gst_event_new_seek (rate,
1684 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1685 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1687 s_event = gst_event_new_seek (rate,
1688 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1689 GST_SEEK_TYPE_SET, position);
1692 res = send_event (s_event);
1696 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1699 g_print ("seek failed\n");
1703 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1707 g_object_get (pipeline, "flags", &flags, NULL);
1709 flags |= (1 << num);
1711 flags &= ~(1 << num);
1712 g_object_set (pipeline, "flags", flags, NULL);
1716 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1720 state = gtk_toggle_button_get_active (button);
1721 update_flag (pipeline, 3, state);
1722 gtk_widget_set_sensitive (vis_combo, state);
1726 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1730 state = gtk_toggle_button_get_active (button);
1731 update_flag (pipeline, 1, state);
1732 gtk_widget_set_sensitive (audio_combo, state);
1736 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1740 state = gtk_toggle_button_get_active (button);
1741 update_flag (pipeline, 0, state);
1742 gtk_widget_set_sensitive (video_combo, state);
1746 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1750 state = gtk_toggle_button_get_active (button);
1751 update_flag (pipeline, 2, state);
1752 gtk_widget_set_sensitive (text_combo, state);
1756 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1760 mute = gtk_toggle_button_get_active (button);
1761 g_object_set (pipeline, "mute", mute, NULL);
1765 download_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1769 state = gtk_toggle_button_get_active (button);
1770 update_flag (pipeline, 7, state);
1774 buffer_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1778 state = gtk_toggle_button_get_active (button);
1779 update_flag (pipeline, 8, state);
1783 clear_streams (GstElement * pipeline)
1787 /* remove previous info */
1788 for (i = 0; i < n_video; i++)
1789 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (video_combo), 0);
1790 for (i = 0; i < n_audio; i++)
1791 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (audio_combo), 0);
1792 for (i = 0; i < n_text; i++)
1793 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (text_combo), 0);
1795 n_audio = n_video = n_text = 0;
1796 gtk_widget_set_sensitive (video_combo, FALSE);
1797 gtk_widget_set_sensitive (audio_combo, FALSE);
1798 gtk_widget_set_sensitive (text_combo, FALSE);
1800 need_streams = TRUE;
1804 update_streams (GstPipeline * pipeline)
1808 if (pipeline_type == 16 && need_streams) {
1814 /* remove previous info */
1815 clear_streams (GST_ELEMENT_CAST (pipeline));
1817 /* here we get and update the different streams detected by playbin2 */
1818 g_object_get (pipeline, "n-video", &n_video, NULL);
1819 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1820 g_object_get (pipeline, "n-text", &n_text, NULL);
1822 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1825 for (i = 0; i < n_video; i++) {
1826 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1828 str = gst_structure_to_string ((GstStructure *) tags);
1829 g_print ("video %d: %s\n", i, str);
1832 /* find good name for the label */
1833 name = g_strdup_printf ("video %d", i + 1);
1834 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (video_combo), name);
1837 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1838 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1839 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1842 for (i = 0; i < n_audio; i++) {
1843 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1845 str = gst_structure_to_string ((GstStructure *) tags);
1846 g_print ("audio %d: %s\n", i, str);
1849 /* find good name for the label */
1850 name = g_strdup_printf ("audio %d", i + 1);
1851 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (audio_combo), name);
1854 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1855 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1856 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1859 for (i = 0; i < n_text; i++) {
1860 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1864 const GValue *value;
1866 str = gst_structure_to_string ((GstStructure *) tags);
1867 g_print ("text %d: %s\n", i, str);
1870 /* get the language code if we can */
1871 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1872 if (value && G_VALUE_HOLDS_STRING (value)) {
1873 name = g_strdup_printf ("text %s", g_value_get_string (value));
1876 /* find good name for the label if we didn't use a tag */
1878 name = g_strdup_printf ("text %d", i + 1);
1880 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (text_combo), name);
1883 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1884 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1885 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1887 need_streams = FALSE;
1892 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1896 active = gtk_combo_box_get_active (combo);
1898 g_print ("setting current video track %d\n", active);
1899 g_object_set (pipeline, "current-video", active, NULL);
1903 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1907 active = gtk_combo_box_get_active (combo);
1909 g_print ("setting current audio track %d\n", active);
1910 g_object_set (pipeline, "current-audio", active, NULL);
1914 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1918 active = gtk_combo_box_get_active (combo);
1920 g_print ("setting current text track %d\n", active);
1921 g_object_set (pipeline, "current-text", active, NULL);
1925 filter_features (GstPluginFeature * feature, gpointer data)
1927 GstElementFactory *f;
1929 if (!GST_IS_ELEMENT_FACTORY (feature))
1931 f = GST_ELEMENT_FACTORY (feature);
1932 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1939 init_visualization_features (void)
1943 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1945 list = gst_registry_feature_filter (gst_registry_get_default (),
1946 filter_features, FALSE, NULL);
1948 for (walk = list; walk; walk = g_list_next (walk)) {
1952 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1953 name = gst_element_factory_get_longname (entry.factory);
1955 g_array_append_val (vis_entries, entry);
1956 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (vis_combo), name);
1958 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1962 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1966 GstElement *element;
1968 /* get the selected index and get the factory for this index */
1969 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1970 if (vis_entries->len > 0) {
1971 entry = &g_array_index (vis_entries, VisEntry, index);
1973 /* create an instance of the element from the factory */
1974 element = gst_element_factory_create (entry->factory, NULL);
1978 /* set vis plugin for playbin2 */
1979 g_object_set (pipeline, "vis-plugin", element, NULL);
1984 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1988 volume = gtk_spin_button_get_value (button);
1990 g_object_set (pipeline, "volume", volume, NULL);
1994 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
1996 gdouble cur_volume, new_volume;
1998 g_object_get (pipeline, "volume", &new_volume, NULL);
1999 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
2000 if (fabs (cur_volume - new_volume) > 0.001) {
2001 g_signal_handlers_block_by_func (volume_spinbutton,
2002 volume_spinbutton_changed_cb, pipeline);
2003 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
2004 g_signal_handlers_unblock_by_func (volume_spinbutton,
2005 volume_spinbutton_changed_cb, pipeline);
2010 shot_cb (GtkButton * button, gpointer data)
2015 /* convert to our desired format (RGB24) */
2016 caps = gst_caps_new_simple ("video/x-raw-rgb",
2017 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
2018 /* Note: we don't ask for a specific width/height here, so that
2019 * videoscale can adjust dimensions from a non-1/1 pixel aspect
2020 * ratio to a 1/1 pixel-aspect-ratio */
2021 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
2022 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
2023 "red_mask", G_TYPE_INT, 0xff0000,
2024 "green_mask", G_TYPE_INT, 0x00ff00,
2025 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
2027 /* convert the latest frame to the requested format */
2028 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
2029 gst_caps_unref (caps);
2037 GError *error = NULL;
2041 /* get the snapshot buffer format now. We set the caps on the appsink so
2042 * that it can only be an rgb buffer. The only thing we have not specified
2043 * on the caps is the height, which is dependant on the pixel-aspect-ratio
2044 * of the source material */
2046 caps = GST_BUFFER_CAPS (buffer);
2048 /* FIXME, get the caps on the buffer somehow */
2051 g_warning ("could not get snapshot format\n");
2054 s = gst_caps_get_structure (caps, 0);
2056 /* we need to get the final caps on the buffer to get the size */
2057 res = gst_structure_get_int (s, "width", &width);
2058 res |= gst_structure_get_int (s, "height", &height);
2060 g_warning ("could not get snapshot dimension\n");
2064 /* create pixmap from buffer and save, gstreamer video buffers have a stride
2065 * that is rounded up to the nearest multiple of 4 */
2066 data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
2067 pixbuf = gdk_pixbuf_new_from_data (data,
2068 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2069 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2071 /* save the pixbuf */
2072 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2073 gst_buffer_unmap (buffer, data, size);
2075 /* save the pixbuf */
2076 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2079 gst_buffer_unref (buffer);
2083 /* called when the Step button is pressed */
2085 step_cb (GtkButton * button, gpointer data)
2091 gboolean flush, res;
2094 active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo));
2096 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
2097 (step_amount_spinbutton));
2098 rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton));
2103 format = GST_FORMAT_BUFFERS;
2106 format = GST_FORMAT_TIME;
2107 amount *= GST_MSECOND;
2110 format = GST_FORMAT_UNDEFINED;
2114 event = gst_event_new_step (format, amount, rate, flush, FALSE);
2116 res = send_event (event);
2119 g_print ("Sending step event failed\n");
2124 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2126 const GstStructure *s;
2128 s = gst_message_get_structure (message);
2129 g_print ("message from \"%s\" (%s): ",
2130 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2131 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2135 sstr = gst_structure_to_string (s);
2136 g_print ("%s\n", sstr);
2139 g_print ("no message details\n");
2143 static gboolean shuttling = FALSE;
2144 static gdouble shuttle_rate = 0.0;
2145 static gdouble play_rate = 1.0;
2148 do_shuttle (GstElement * element)
2153 duration = 40 * GST_MSECOND;
2157 gst_element_send_event (element,
2158 gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE,
2163 msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element)
2169 gboolean intermediate;
2173 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
2174 &intermediate, &duration, &eos);
2177 g_print ("stepped till EOS\n");
2181 if (g_static_mutex_trylock (&state_mutex)) {
2183 do_shuttle (element);
2184 g_static_mutex_unlock (&state_mutex);
2186 /* ignore step messages that come while we are doing a state change */
2187 g_print ("state change is busy\n");
2192 shuttle_toggled (GtkToggleButton * button, GstElement * element)
2196 active = gtk_toggle_button_get_active (button);
2198 if (active != shuttling) {
2200 g_print ("shuttling %s\n", shuttling ? "active" : "inactive");
2204 pause_cb (NULL, NULL);
2205 gst_element_get_state (element, NULL, NULL, -1);
2211 shuttle_rate_switch (GstElement * element)
2217 if (state == GST_STATE_PLAYING) {
2218 /* pause when we need to */
2219 pause_cb (NULL, NULL);
2220 gst_element_get_state (element, NULL, NULL, -1);
2223 if (play_rate == 1.0)
2228 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate,
2229 GST_TIME_ARGS (position));
2231 flags = GST_SEEK_FLAG_FLUSH;
2232 flags |= GST_SEEK_FLAG_ACCURATE;
2234 if (play_rate >= 0.0) {
2235 s_event = gst_event_new_seek (play_rate,
2236 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
2237 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
2239 s_event = gst_event_new_seek (play_rate,
2240 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2241 GST_SEEK_TYPE_SET, position);
2243 res = send_event (s_event);
2245 gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT);
2247 g_print ("seek failed\n");
2252 shuttle_value_changed (GtkRange * range, GstElement * element)
2256 rate = gtk_adjustment_get_value (shuttle_adjustment);
2259 g_print ("rate 0.0, pause\n");
2260 pause_cb (NULL, NULL);
2261 gst_element_get_state (element, NULL, NULL, -1);
2263 g_print ("rate changed %0.3g\n", rate);
2265 if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) {
2266 shuttle_rate_switch (element);
2269 shuttle_rate = ABS (rate);
2270 if (state != GST_STATE_PLAYING) {
2271 do_shuttle (element);
2272 play_cb (NULL, NULL);
2278 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2280 GST_DEBUG ("async done");
2281 /* when we get ASYNC_DONE we can query position, duration and other
2283 update_scale (pipeline);
2285 /* update the available streams */
2286 update_streams (pipeline);
2290 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2292 const GstStructure *s;
2294 s = gst_message_get_structure (message);
2296 /* We only care about state changed on the pipeline */
2297 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2298 GstState old, new, pending;
2300 gst_message_parse_state_changed (message, &old, &new, &pending);
2302 /* When state of the pipeline changes to paused or playing we start updating scale */
2303 if (new == GST_STATE_PLAYING) {
2304 set_update_scale (TRUE);
2306 set_update_scale (FALSE);
2312 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2319 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2320 gst_message_parse_segment_done (message, &format, &position);
2321 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2324 /* in the segment-done callback we never flush as this would not make sense
2325 * for seamless playback. */
2327 flags |= GST_SEEK_FLAG_SEGMENT;
2329 flags |= GST_SEEK_FLAG_SKIP;
2331 s_event = gst_event_new_seek (rate,
2332 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2333 GST_SEEK_TYPE_SET, duration);
2335 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2336 rate, GST_TIME_ARGS (duration));
2338 res = send_event (s_event);
2340 g_print ("segment seek failed\n");
2343 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2346 do_stream_buffering (gint percent)
2350 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2351 bufstr = g_strdup_printf ("Buffering...%d", percent);
2352 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2355 if (percent == 100) {
2356 /* a 100% message means buffering is done */
2358 /* if the desired state is playing, go back */
2359 if (state == GST_STATE_PLAYING) {
2360 /* no state management needed for live pipelines */
2362 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2363 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2365 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2366 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2369 /* buffering busy */
2370 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2371 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2373 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2374 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2382 do_download_buffering (gint percent)
2384 if (!buffering && percent < 100) {
2389 bufstr = g_strdup_printf ("Downloading...");
2390 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2393 /* once we get a buffering message, we'll do the fill update */
2394 set_update_fill (TRUE);
2396 if (state == GST_STATE_PLAYING && !is_live) {
2397 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2398 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2399 /* user has to manually start the playback */
2400 state = GST_STATE_PAUSED;
2406 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2410 gst_message_parse_buffering (message, &percent);
2412 /* get more stats */
2413 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2417 case GST_BUFFERING_DOWNLOAD:
2418 do_download_buffering (percent);
2420 case GST_BUFFERING_LIVE:
2421 case GST_BUFFERING_TIMESHIFT:
2422 case GST_BUFFERING_STREAM:
2423 do_stream_buffering (percent);
2429 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2431 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2433 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2434 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2439 static gulong embed_xid = 0;
2441 /* We set the xid here in response to the prepare-window-handle message via a
2442 * bus sync handler because we don't know the actual videosink used from the
2443 * start (as we don't know the pipeline, or bin elements such as autovideosink
2444 * or gconfvideosink may be used which create the actual videosink only once
2445 * the pipeline is started) */
2446 static GstBusSyncReply
2447 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2449 GstElement *element;
2451 if (!gst_is_video_overlay_prepare_window_handle_message (message))
2452 return GST_BUS_PASS;
2454 element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2456 g_print ("got prepare-window-handle, setting XID %lu\n", embed_xid);
2458 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2459 "force-aspect-ratio")) {
2460 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2463 /* Should have been initialised from main thread before (can't use
2464 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2465 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2466 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2467 * shouldn't be done from a non-GUI thread without explicit locking). */
2468 g_assert (embed_xid != 0);
2470 gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (element), embed_xid);
2471 return GST_BUS_PASS;
2476 handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
2478 if (state < GST_STATE_PAUSED) {
2479 GtkAllocation allocation;
2480 GdkWindow *window = gtk_widget_get_window (widget);
2483 gtk_widget_get_allocation (widget, &allocation);
2484 cr = gdk_cairo_create (window);
2485 cairo_set_source_rgb (cr, 0, 0, 0);
2486 cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
2494 realize_cb (GtkWidget * widget, gpointer data)
2496 #if GTK_CHECK_VERSION(2,18,0)
2498 GdkWindow *window = gtk_widget_get_window (widget);
2500 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2502 if (!gdk_window_ensure_native (window))
2503 g_error ("Couldn't create native window needed for GstVideoOverlay!");
2509 GdkWindow *window = gtk_widget_get_window (video_window);
2511 embed_xid = GDK_WINDOW_XID (window);
2512 g_print ("Window realize: video window XID = %lu\n", embed_xid);
2518 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2520 message_received (bus, message, data);
2522 /* Set new uri for playerbins and continue playback */
2523 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2524 stop_cb (NULL, NULL);
2525 l = g_list_next (l);
2527 playerbin_set_uri (GST_ELEMENT (data), l->data);
2528 play_cb (NULL, NULL);
2534 msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data)
2537 message_received (bus, message, data);
2541 connect_bus_signals (GstElement * pipeline)
2543 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2546 /* handle prepare-window-handle element message synchronously */
2547 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2551 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2552 gst_bus_enable_sync_message_emission (bus);
2554 g_signal_connect (bus, "message::state-changed",
2555 (GCallback) msg_state_changed, pipeline);
2556 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2558 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2561 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2563 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2565 g_signal_connect (bus, "message::error", (GCallback) message_received,
2567 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2569 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2570 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2572 g_signal_connect (bus, "message::element", (GCallback) message_received,
2574 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2576 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2578 // g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done,
2580 g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done,
2582 g_signal_connect (bus, "sync-message::step-done",
2583 (GCallback) msg_sync_step_done, pipeline);
2585 gst_object_unref (bus);
2588 /* Return GList of paths described in location string */
2590 handle_wildcards (const gchar * location)
2593 gchar *path = g_path_get_dirname (location);
2594 gchar *pattern = g_path_get_basename (location);
2595 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2596 GDir *dir = g_dir_open (path, 0, NULL);
2599 g_print ("matching %s from %s\n", pattern, path);
2602 g_print ("opening directory %s failed\n", path);
2606 while ((name = g_dir_read_name (dir)) != NULL) {
2607 if (g_pattern_match_string (pspec, name)) {
2608 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2609 g_print (" found clip %s\n", name);
2615 g_pattern_spec_free (pspec);
2623 delete_event_cb (void)
2625 stop_cb (NULL, NULL);
2630 print_usage (int argc, char **argv)
2634 g_print ("usage: %s <type> <filename>\n", argv[0]);
2635 g_print (" possible types:\n");
2637 for (i = 0; i < NUM_TYPES; i++) {
2638 g_print (" %d = %s\n", i, pipelines[i].name);
2643 read_joystick (GIOChannel * source, GIOCondition condition, gpointer user_data)
2645 gchar buf[sizeof (struct js_event)];
2646 struct js_event *js = (struct js_event *) buf;
2648 gsize bytes_read = 0;
2652 g_io_channel_read_chars (source, buf, sizeof (struct js_event),
2655 g_print ("error reading from joystick: %s", err->message);
2658 } else if (bytes_read != sizeof (struct js_event)) {
2659 g_print ("error reading joystick, read %u bytes of %u\n",
2660 (guint) bytes_read, (guint) sizeof (struct js_event));
2662 } else if (result != G_IO_STATUS_NORMAL) {
2663 g_print ("reading from joystick returned status %d", result);
2666 switch (js->type & ~JS_EVENT_INIT) {
2668 if (js->number == 0) {
2669 gdouble new_rate = (gdouble) (js->value) / 3000;
2670 g_print ("Got: %d (rate %g)\n", js->value, new_rate);
2672 gtk_adjustment_set_value (shuttle_adjustment, new_rate);
2681 main (int argc, char **argv)
2683 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2684 *flagtable, *boxes2, *step;
2685 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2686 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2687 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2688 GtkWidget *rate_label, *volume_label;
2689 GOptionEntry options[] = {
2690 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2691 "Show pad stats", NULL},
2692 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2693 "Seek on elements instead of pads", NULL},
2694 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2695 "Verbose properties", NULL},
2696 {"joystick", 'j', 0, G_OPTION_ARG_STRING, &js_device,
2697 "Joystick device to use", NULL},
2700 GOptionContext *ctx;
2703 if (!g_thread_supported ())
2704 g_thread_init (NULL);
2706 ctx = g_option_context_new ("- test seeking in gsteamer");
2707 g_option_context_add_main_entries (ctx, options, NULL);
2708 g_option_context_add_group (ctx, gst_init_get_option_group ());
2709 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2711 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2712 g_print ("Error initializing: %s\n", err->message);
2716 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2719 print_usage (argc, argv);
2723 pipeline_type = atoi (argv[1]);
2725 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2726 print_usage (argc, argv);
2730 pipeline_spec = argv[2];
2732 if (js_device == NULL)
2733 js_device = g_strdup ("/dev/input/js0");
2735 js_fd = g_open (js_device, O_RDONLY, 0);
2737 g_print ("Failed to open joystick device %s\n", js_device);
2741 if (g_strrstr (pipeline_spec, "*") != NULL ||
2742 g_strrstr (pipeline_spec, "?") != NULL) {
2743 paths = handle_wildcards (pipeline_spec);
2745 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2749 g_print ("opening %s failed\n", pipeline_spec);
2755 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2756 g_assert (pipeline);
2758 /* initialize gui elements ... */
2759 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2760 video_window = gtk_drawing_area_new ();
2761 g_signal_connect (video_window, "expose-event",
2762 G_CALLBACK (handle_expose_cb), NULL);
2763 g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL);
2764 gtk_widget_set_double_buffered (video_window, FALSE);
2766 statusbar = gtk_statusbar_new ();
2767 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2768 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2769 hbox = gtk_hbox_new (FALSE, 0);
2770 vbox = gtk_vbox_new (FALSE, 0);
2771 flagtable = gtk_table_new (4, 2, FALSE);
2772 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2774 /* media controls */
2775 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2776 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2777 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2780 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2781 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2782 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2783 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2784 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2785 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2786 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2787 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2788 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2789 rate_label = gtk_label_new ("Rate");
2791 gtk_widget_set_tooltip_text (accurate_checkbox,
2792 "accurate position is requested, this might be considerably slower for some formats");
2793 gtk_widget_set_tooltip_text (key_checkbox,
2794 "seek to the nearest keyframe. This might be faster but less accurate");
2795 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2796 gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking");
2797 gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, "
2798 "negative value trigger reverse playback");
2799 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2800 gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking");
2801 gtk_widget_set_tooltip_text (skip_checkbox,
2802 "Skip frames while playing at high frame rates");
2804 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2805 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2807 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2813 step = gtk_expander_new ("step options");
2814 hbox = gtk_hbox_new (FALSE, 0);
2816 format_combo = gtk_combo_box_text_new ();
2817 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2819 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2821 gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0);
2822 gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2);
2824 step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2825 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0);
2826 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0);
2827 gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE,
2830 step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2831 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3);
2832 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0);
2833 gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2);
2835 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2836 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2837 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2839 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2843 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2844 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2845 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2846 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2849 shuttle_adjustment =
2850 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2851 shuttle_hscale = gtk_hscale_new (shuttle_adjustment);
2852 gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2);
2853 gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP);
2854 g_signal_connect (shuttle_hscale, "value_changed",
2855 G_CALLBACK (shuttle_value_changed), pipeline);
2856 g_signal_connect (shuttle_hscale, "format_value",
2857 G_CALLBACK (shuttle_format_value), pipeline);
2859 gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2);
2861 gtk_container_add (GTK_CONTAINER (step), hbox);
2866 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
2867 hscale = gtk_hscale_new (adjustment);
2868 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2869 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
2870 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2871 gtk_range_set_fill_level (GTK_RANGE (hscale), 100.0);
2873 g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek),
2875 g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek),
2877 g_signal_connect (hscale, "format_value", G_CALLBACK (format_value),
2880 if (pipeline_type == 16) {
2881 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2882 panel = gtk_hbox_new (FALSE, 0);
2883 video_combo = gtk_combo_box_text_new ();
2884 audio_combo = gtk_combo_box_text_new ();
2885 text_combo = gtk_combo_box_text_new ();
2886 gtk_widget_set_sensitive (video_combo, FALSE);
2887 gtk_widget_set_sensitive (audio_combo, FALSE);
2888 gtk_widget_set_sensitive (text_combo, FALSE);
2889 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2890 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2891 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2892 g_signal_connect (G_OBJECT (video_combo), "changed",
2893 G_CALLBACK (video_combo_cb), pipeline);
2894 g_signal_connect (G_OBJECT (audio_combo), "changed",
2895 G_CALLBACK (audio_combo_cb), pipeline);
2896 g_signal_connect (G_OBJECT (text_combo), "changed",
2897 G_CALLBACK (text_combo_cb), pipeline);
2898 /* playbin2 panel for flag checkboxes and volume/mute */
2899 boxes = gtk_hbox_new (FALSE, 0);
2900 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2901 video_checkbox = gtk_check_button_new_with_label ("Video");
2902 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2903 text_checkbox = gtk_check_button_new_with_label ("Text");
2904 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2905 download_checkbox = gtk_check_button_new_with_label ("Download");
2906 buffer_checkbox = gtk_check_button_new_with_label ("Buffer");
2907 volume_label = gtk_label_new ("Volume");
2908 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2909 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2910 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2911 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2912 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2913 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2914 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2915 gtk_box_pack_start (GTK_BOX (boxes), download_checkbox, TRUE, TRUE, 2);
2916 gtk_box_pack_start (GTK_BOX (boxes), buffer_checkbox, TRUE, TRUE, 2);
2917 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
2918 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2919 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2920 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2921 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2922 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2923 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2924 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
2925 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffer_checkbox), FALSE);
2926 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2927 G_CALLBACK (vis_toggle_cb), pipeline);
2928 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2929 G_CALLBACK (audio_toggle_cb), pipeline);
2930 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2931 G_CALLBACK (video_toggle_cb), pipeline);
2932 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2933 G_CALLBACK (text_toggle_cb), pipeline);
2934 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2935 G_CALLBACK (mute_toggle_cb), pipeline);
2936 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
2937 G_CALLBACK (download_toggle_cb), pipeline);
2938 g_signal_connect (G_OBJECT (buffer_checkbox), "toggled",
2939 G_CALLBACK (buffer_toggle_cb), pipeline);
2940 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2941 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2942 /* playbin2 panel for snapshot */
2943 boxes2 = gtk_hbox_new (FALSE, 0);
2944 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2945 gtk_widget_set_tooltip_text (shot_button,
2946 "save a screenshot .png in the current directory");
2947 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2949 vis_combo = gtk_combo_box_text_new ();
2950 g_signal_connect (G_OBJECT (vis_combo), "changed",
2951 G_CALLBACK (vis_combo_cb), pipeline);
2952 gtk_widget_set_sensitive (vis_combo, FALSE);
2953 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2954 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2956 /* fill the vis combo box and the array of factories */
2957 init_visualization_features ();
2959 panel = boxes = boxes2 = NULL;
2962 /* do the packing stuff ... */
2963 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2964 /* FIXME: can we avoid this for audio only? */
2965 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
2966 DEFAULT_VIDEO_HEIGHT);
2967 gtk_container_add (GTK_CONTAINER (window), vbox);
2968 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
2969 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2970 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2971 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2972 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2973 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2974 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2976 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2977 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2978 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2979 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2980 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2982 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2983 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2984 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2986 if (panel && boxes && boxes2) {
2987 expander = gtk_expander_new ("playbin2 options");
2988 pb2vbox = gtk_vbox_new (FALSE, 0);
2989 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2990 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2991 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2992 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2993 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2995 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2996 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
2997 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
2999 /* connect things ... */
3000 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
3002 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
3004 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
3006 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
3007 G_CALLBACK (accurate_toggle_cb), pipeline);
3008 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
3009 G_CALLBACK (key_toggle_cb), pipeline);
3010 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
3011 G_CALLBACK (loop_toggle_cb), pipeline);
3012 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
3013 G_CALLBACK (flush_toggle_cb), pipeline);
3014 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
3015 G_CALLBACK (scrub_toggle_cb), pipeline);
3016 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
3017 G_CALLBACK (play_scrub_toggle_cb), pipeline);
3018 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
3019 G_CALLBACK (skip_toggle_cb), pipeline);
3020 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
3021 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
3023 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
3026 gtk_widget_show_all (window);
3028 /* realize window now so that the video window gets created and we can
3029 * obtain its XID before the pipeline is started up and the videosink
3030 * asks for the XID of the window to render onto */
3031 gtk_widget_realize (window);
3033 /* we should have the XID now */
3034 g_assert (embed_xid != 0);
3037 g_signal_connect (pipeline, "deep_notify",
3038 G_CALLBACK (gst_object_default_deep_notify), NULL);
3042 GIOChannel *js_watch = g_io_channel_unix_new (js_fd);
3043 g_io_channel_set_encoding (js_watch, NULL, NULL);
3044 g_io_add_watch (js_watch, G_IO_IN, read_joystick, NULL);
3047 connect_bus_signals (pipeline);
3050 g_print ("NULL pipeline\n");
3051 gst_element_set_state (pipeline, GST_STATE_NULL);
3053 g_print ("free pipeline\n");
3054 gst_object_unref (pipeline);
3056 g_list_foreach (paths, (GFunc) g_free, NULL);
3057 g_list_free (paths);