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)
54 #define SOURCE "filesrc"
56 #define ASINK "alsasink"
57 //#define ASINK "osssink"
59 #define VSINK "xvimagesink"
60 //#define VSINK "sdlvideosink"
61 //#define VSINK "ximagesink"
62 //#define VSINK "aasink"
63 //#define VSINK "cacasink"
65 #define FILL_INTERVAL 100
66 //#define UPDATE_INTERVAL 500
67 //#define UPDATE_INTERVAL 100
68 //#define UPDATE_INTERVAL 10
69 #define UPDATE_INTERVAL 40
71 /* number of milliseconds to play for after a seek */
72 #define SCRUB_TIME 100
74 /* timeout for gst_element_get_state() after a seek */
75 #define SEEK_TIMEOUT 40 * GST_MSECOND
77 #define DEFAULT_VIDEO_HEIGHT 300
79 /* the state to go to when stop is pressed */
80 #define STOP_STATE GST_STATE_READY
83 static GList *seekable_pads = NULL;
84 static GList *rate_pads = NULL;
85 static GList *seekable_elements = NULL;
87 static gboolean accurate_seek = FALSE;
88 static gboolean keyframe_seek = FALSE;
89 static gboolean loop_seek = FALSE;
90 static gboolean flush_seek = TRUE;
91 static gboolean scrub = TRUE;
92 static gboolean play_scrub = FALSE;
93 static gboolean skip_seek = FALSE;
94 static gdouble rate = 1.0;
96 static GstElement *pipeline;
97 static gint pipeline_type;
98 static const gchar *pipeline_spec;
99 static gint64 position = -1;
100 static gint64 duration = -1;
101 static GtkAdjustment *adjustment;
102 static GtkWidget *hscale, *statusbar;
103 static guint status_id = 0;
104 static gboolean stats = FALSE;
105 static gboolean elem_seek = FALSE;
106 static gboolean verbose = FALSE;
107 static gchar *js_device = NULL;
109 static gboolean is_live = FALSE;
110 static gboolean buffering = FALSE;
111 static GstBufferingMode mode;
112 static gint64 buffering_left;
113 static GstState state = GST_STATE_NULL;
114 static guint update_id = 0;
115 static guint seek_timeout_id = 0;
116 static gulong changed_id;
117 static guint fill_id = 0;
119 static gint n_video = 0, n_audio = 0, n_text = 0;
120 static gboolean need_streams = TRUE;
121 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
122 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
123 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
124 static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
125 static GtkWidget *buffer_checkbox, *rate_spinbutton;
127 static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
129 static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
130 static GtkWidget *shuttle_checkbox, *step_button;
131 static GtkWidget *shuttle_hscale;
132 static GtkAdjustment *shuttle_adjustment;
134 static GList *paths = NULL, *l = NULL;
138 /* we keep an array of the visualisation entries so that we can easily switch
139 * with the combo box index. */
142 GstElementFactory *factory;
145 static GArray *vis_entries;
147 static void clear_streams (GstElement * pipeline);
148 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
151 /* pipeline construction */
155 const gchar *padname;
162 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
164 GstElement *element = gst_element_factory_make (type, name);
167 g_warning ("Failed to create element %s of type %s", name, type);
174 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
177 dyn_link *connect = (dyn_link *) data;
179 padname = gst_pad_get_name (newpad);
181 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
183 gst_bin_add (GST_BIN (pipeline), connect->bin);
184 gst_pad_link (newpad, connect->target);
186 //seekable_pads = g_list_prepend (seekable_pads, newpad);
187 rate_pads = g_list_prepend (rate_pads, newpad);
193 setup_dynamic_link (GstElement * element, const gchar * padname,
194 GstPad * target, GstElement * bin)
198 connect = g_new0 (dyn_link, 1);
199 connect->padname = g_strdup (padname);
200 connect->target = target;
203 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
208 make_mod_pipeline (const gchar * location)
210 GstElement *pipeline;
211 GstElement *src, *decoder, *audiosink;
214 pipeline = gst_pipeline_new ("app");
216 src = gst_element_factory_make_or_warn (SOURCE, "src");
217 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
218 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
219 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
221 g_object_set (G_OBJECT (src), "location", location, NULL);
223 gst_bin_add (GST_BIN (pipeline), src);
224 gst_bin_add (GST_BIN (pipeline), decoder);
225 gst_bin_add (GST_BIN (pipeline), audiosink);
227 gst_element_link (src, decoder);
228 gst_element_link (decoder, audiosink);
230 seekable = gst_element_get_static_pad (decoder, "src");
231 seekable_pads = g_list_prepend (seekable_pads, seekable);
232 rate_pads = g_list_prepend (rate_pads, seekable);
234 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
240 make_dv_pipeline (const gchar * location)
242 GstElement *pipeline;
243 GstElement *src, *demux, *decoder, *audiosink, *videosink;
244 GstElement *a_queue, *v_queue;
247 pipeline = gst_pipeline_new ("app");
249 src = gst_element_factory_make_or_warn (SOURCE, "src");
250 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
251 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
252 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
253 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
254 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
255 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
257 g_object_set (G_OBJECT (src), "location", location, NULL);
259 gst_bin_add (GST_BIN (pipeline), src);
260 gst_bin_add (GST_BIN (pipeline), demux);
261 gst_bin_add (GST_BIN (pipeline), a_queue);
262 gst_bin_add (GST_BIN (pipeline), audiosink);
263 gst_bin_add (GST_BIN (pipeline), v_queue);
264 gst_bin_add (GST_BIN (pipeline), decoder);
265 gst_bin_add (GST_BIN (pipeline), videosink);
267 gst_element_link (src, demux);
268 gst_element_link (a_queue, audiosink);
269 gst_element_link (v_queue, decoder);
270 gst_element_link (decoder, videosink);
272 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
274 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
277 seekable = gst_element_get_static_pad (decoder, "src");
278 seekable_pads = g_list_prepend (seekable_pads, seekable);
279 rate_pads = g_list_prepend (rate_pads, seekable);
285 make_wav_pipeline (const gchar * location)
287 GstElement *pipeline;
288 GstElement *src, *decoder, *audiosink;
290 pipeline = gst_pipeline_new ("app");
292 src = gst_element_factory_make_or_warn (SOURCE, "src");
293 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
294 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
296 g_object_set (G_OBJECT (src), "location", location, NULL);
298 gst_bin_add (GST_BIN (pipeline), src);
299 gst_bin_add (GST_BIN (pipeline), decoder);
300 gst_bin_add (GST_BIN (pipeline), audiosink);
302 gst_element_link (src, decoder);
304 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
307 seekable_elements = g_list_prepend (seekable_elements, audiosink);
309 /* force element seeking on this pipeline */
316 make_flac_pipeline (const gchar * location)
318 GstElement *pipeline;
319 GstElement *src, *decoder, *audiosink;
322 pipeline = gst_pipeline_new ("app");
324 src = gst_element_factory_make_or_warn (SOURCE, "src");
325 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
326 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
327 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
329 g_object_set (G_OBJECT (src), "location", location, NULL);
331 gst_bin_add (GST_BIN (pipeline), src);
332 gst_bin_add (GST_BIN (pipeline), decoder);
333 gst_bin_add (GST_BIN (pipeline), audiosink);
335 gst_element_link (src, decoder);
336 gst_element_link (decoder, audiosink);
338 seekable = gst_element_get_static_pad (decoder, "src");
339 seekable_pads = g_list_prepend (seekable_pads, seekable);
340 rate_pads = g_list_prepend (rate_pads, seekable);
342 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
348 make_sid_pipeline (const gchar * location)
350 GstElement *pipeline;
351 GstElement *src, *decoder, *audiosink;
354 pipeline = gst_pipeline_new ("app");
356 src = gst_element_factory_make_or_warn (SOURCE, "src");
357 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
358 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
359 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
361 g_object_set (G_OBJECT (src), "location", location, NULL);
363 gst_bin_add (GST_BIN (pipeline), src);
364 gst_bin_add (GST_BIN (pipeline), decoder);
365 gst_bin_add (GST_BIN (pipeline), audiosink);
367 gst_element_link (src, decoder);
368 gst_element_link (decoder, audiosink);
370 seekable = gst_element_get_static_pad (decoder, "src");
371 seekable_pads = g_list_prepend (seekable_pads, seekable);
372 rate_pads = g_list_prepend (rate_pads, seekable);
374 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
380 make_parse_pipeline (const gchar * location)
382 GstElement *pipeline;
383 GstElement *src, *parser, *fakesink;
386 pipeline = gst_pipeline_new ("app");
388 src = gst_element_factory_make_or_warn (SOURCE, "src");
389 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
390 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
391 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
392 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
394 g_object_set (G_OBJECT (src), "location", location, NULL);
396 gst_bin_add (GST_BIN (pipeline), src);
397 gst_bin_add (GST_BIN (pipeline), parser);
398 gst_bin_add (GST_BIN (pipeline), fakesink);
400 gst_element_link (src, parser);
401 gst_element_link (parser, fakesink);
403 seekable = gst_element_get_static_pad (parser, "src");
404 seekable_pads = g_list_prepend (seekable_pads, seekable);
405 rate_pads = g_list_prepend (rate_pads, seekable);
407 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
413 make_vorbis_pipeline (const gchar * location)
415 GstElement *pipeline, *audio_bin;
416 GstElement *src, *demux, *decoder, *convert, *audiosink;
417 GstPad *pad, *seekable;
419 pipeline = gst_pipeline_new ("app");
421 src = gst_element_factory_make_or_warn (SOURCE, "src");
422 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
423 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
424 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
425 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
426 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
428 g_object_set (G_OBJECT (src), "location", location, NULL);
430 audio_bin = gst_bin_new ("a_decoder_bin");
432 gst_bin_add (GST_BIN (pipeline), src);
433 gst_bin_add (GST_BIN (pipeline), demux);
434 gst_bin_add (GST_BIN (audio_bin), decoder);
435 gst_bin_add (GST_BIN (audio_bin), convert);
436 gst_bin_add (GST_BIN (audio_bin), audiosink);
437 gst_bin_add (GST_BIN (pipeline), audio_bin);
439 gst_element_link (src, demux);
440 gst_element_link (decoder, convert);
441 gst_element_link (convert, audiosink);
443 pad = gst_element_get_static_pad (decoder, "sink");
444 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
445 gst_object_unref (pad);
447 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
450 seekable = gst_element_get_static_pad (decoder, "src");
451 seekable_pads = g_list_prepend (seekable_pads, seekable);
452 rate_pads = g_list_prepend (rate_pads, seekable);
454 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
460 make_theora_pipeline (const gchar * location)
462 GstElement *pipeline, *video_bin;
463 GstElement *src, *demux, *decoder, *convert, *videosink;
464 GstPad *pad, *seekable;
466 pipeline = gst_pipeline_new ("app");
468 src = gst_element_factory_make_or_warn (SOURCE, "src");
469 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
470 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
471 convert = gst_element_factory_make_or_warn ("videoconvert", "convert");
472 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
474 g_object_set (G_OBJECT (src), "location", location, NULL);
476 video_bin = gst_bin_new ("v_decoder_bin");
478 gst_bin_add (GST_BIN (pipeline), src);
479 gst_bin_add (GST_BIN (pipeline), demux);
480 gst_bin_add (GST_BIN (video_bin), decoder);
481 gst_bin_add (GST_BIN (video_bin), convert);
482 gst_bin_add (GST_BIN (video_bin), videosink);
483 gst_bin_add (GST_BIN (pipeline), video_bin);
485 gst_element_link (src, demux);
486 gst_element_link (decoder, convert);
487 gst_element_link (convert, videosink);
489 pad = gst_element_get_static_pad (decoder, "sink");
490 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
491 gst_object_unref (pad);
493 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
496 seekable = gst_element_get_static_pad (decoder, "src");
497 seekable_pads = g_list_prepend (seekable_pads, seekable);
498 rate_pads = g_list_prepend (rate_pads, seekable);
500 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
506 make_vorbis_theora_pipeline (const gchar * location)
508 GstElement *pipeline, *audio_bin, *video_bin;
509 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
510 GstElement *audiosink, *videosink;
511 GstElement *a_queue, *v_queue, *v_scale;
515 pipeline = gst_pipeline_new ("app");
517 src = gst_element_factory_make_or_warn (SOURCE, "src");
518 g_object_set (G_OBJECT (src), "location", location, NULL);
520 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
522 gst_bin_add (GST_BIN (pipeline), src);
523 gst_bin_add (GST_BIN (pipeline), demux);
524 gst_element_link (src, demux);
526 audio_bin = gst_bin_new ("a_decoder_bin");
527 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
528 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
529 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
530 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
532 gst_bin_add (GST_BIN (pipeline), audio_bin);
534 gst_bin_add (GST_BIN (audio_bin), a_queue);
535 gst_bin_add (GST_BIN (audio_bin), a_decoder);
536 gst_bin_add (GST_BIN (audio_bin), a_convert);
537 gst_bin_add (GST_BIN (audio_bin), audiosink);
539 gst_element_link (a_queue, a_decoder);
540 gst_element_link (a_decoder, a_convert);
541 gst_element_link (a_convert, audiosink);
543 pad = gst_element_get_static_pad (a_queue, "sink");
544 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
545 gst_object_unref (pad);
547 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
550 video_bin = gst_bin_new ("v_decoder_bin");
551 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
552 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
553 v_convert = gst_element_factory_make_or_warn ("videoconvert", "v_convert");
554 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
555 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
557 gst_bin_add (GST_BIN (pipeline), video_bin);
559 gst_bin_add (GST_BIN (video_bin), v_queue);
560 gst_bin_add (GST_BIN (video_bin), v_decoder);
561 gst_bin_add (GST_BIN (video_bin), v_convert);
562 gst_bin_add (GST_BIN (video_bin), v_scale);
563 gst_bin_add (GST_BIN (video_bin), videosink);
565 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
568 pad = gst_element_get_static_pad (v_queue, "sink");
569 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
570 gst_object_unref (pad);
572 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
575 seekable = gst_element_get_static_pad (a_decoder, "src");
576 seekable_pads = g_list_prepend (seekable_pads, seekable);
577 rate_pads = g_list_prepend (rate_pads, seekable);
579 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
586 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
588 GstElement *pipeline, *audio_bin, *video_bin;
589 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
590 GstElement *audiosink, *videosink;
591 GstElement *a_queue, *v_queue;
592 GstPad *seekable, *pad;
594 pipeline = gst_pipeline_new ("app");
596 src = gst_element_factory_make_or_warn (SOURCE, "src");
597 g_object_set (G_OBJECT (src), "location", location, NULL);
599 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
601 gst_bin_add (GST_BIN (pipeline), src);
602 gst_bin_add (GST_BIN (pipeline), demux);
603 gst_element_link (src, demux);
605 audio_bin = gst_bin_new ("a_decoder_bin");
606 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
607 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
608 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
609 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
611 gst_bin_add (GST_BIN (audio_bin), a_queue);
612 gst_bin_add (GST_BIN (audio_bin), a_decoder);
613 gst_bin_add (GST_BIN (audio_bin), a_convert);
614 gst_bin_add (GST_BIN (audio_bin), audiosink);
616 gst_element_link (a_queue, a_decoder);
617 gst_element_link (a_decoder, a_convert);
618 gst_element_link (a_convert, audiosink);
620 gst_bin_add (GST_BIN (pipeline), audio_bin);
622 pad = gst_element_get_static_pad (a_queue, "sink");
623 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
624 gst_object_unref (pad);
626 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
629 video_bin = gst_bin_new ("v_decoder_bin");
630 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
631 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
632 v_convert = gst_element_factory_make_or_warn ("videoconvert", "v_convert");
633 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
635 gst_bin_add (GST_BIN (video_bin), v_queue);
636 gst_bin_add (GST_BIN (video_bin), v_decoder);
637 gst_bin_add (GST_BIN (video_bin), v_convert);
638 gst_bin_add (GST_BIN (video_bin), videosink);
640 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
642 gst_bin_add (GST_BIN (pipeline), video_bin);
644 pad = gst_element_get_static_pad (v_queue, "sink");
645 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
646 gst_object_unref (pad);
648 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
651 seekable = gst_element_get_static_pad (a_decoder, "src");
652 seekable_pads = g_list_prepend (seekable_pads, seekable);
653 rate_pads = g_list_prepend (rate_pads, seekable);
655 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
662 make_mp3_pipeline (const gchar * location)
664 GstElement *pipeline;
665 GstElement *src, *parser, *decoder, *audiosink, *queue;
668 pipeline = gst_pipeline_new ("app");
670 src = gst_element_factory_make_or_warn (SOURCE, "src");
671 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
672 decoder = gst_element_factory_make_or_warn ("mad", "dec");
673 queue = gst_element_factory_make_or_warn ("queue", "queue");
674 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
676 seekable_elements = g_list_prepend (seekable_elements, audiosink);
678 g_object_set (G_OBJECT (src), "location", location, NULL);
679 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
681 gst_bin_add (GST_BIN (pipeline), src);
682 gst_bin_add (GST_BIN (pipeline), parser);
683 gst_bin_add (GST_BIN (pipeline), decoder);
684 gst_bin_add (GST_BIN (pipeline), queue);
685 gst_bin_add (GST_BIN (pipeline), audiosink);
687 gst_element_link (src, parser);
688 gst_element_link (parser, decoder);
689 gst_element_link (decoder, queue);
690 gst_element_link (queue, audiosink);
692 seekable = gst_element_get_static_pad (queue, "src");
693 seekable_pads = g_list_prepend (seekable_pads, seekable);
694 rate_pads = g_list_prepend (rate_pads, seekable);
696 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
702 make_avi_pipeline (const gchar * location)
704 GstElement *pipeline, *audio_bin, *video_bin;
705 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
706 GstElement *a_queue = NULL, *v_queue = NULL;
709 pipeline = gst_pipeline_new ("app");
711 src = gst_element_factory_make_or_warn (SOURCE, "src");
712 g_object_set (G_OBJECT (src), "location", location, NULL);
714 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
715 seekable_elements = g_list_prepend (seekable_elements, demux);
717 gst_bin_add (GST_BIN (pipeline), src);
718 gst_bin_add (GST_BIN (pipeline), demux);
719 gst_element_link (src, demux);
721 audio_bin = gst_bin_new ("a_decoder_bin");
722 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
723 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
724 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
725 gst_element_link (a_decoder, a_queue);
726 gst_element_link (a_queue, audiosink);
727 gst_bin_add (GST_BIN (audio_bin), a_decoder);
728 gst_bin_add (GST_BIN (audio_bin), a_queue);
729 gst_bin_add (GST_BIN (audio_bin), audiosink);
730 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
732 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
735 seekable = gst_element_get_static_pad (a_queue, "src");
736 seekable_pads = g_list_prepend (seekable_pads, seekable);
737 rate_pads = g_list_prepend (rate_pads, seekable);
739 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
742 video_bin = gst_bin_new ("v_decoder_bin");
743 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
744 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
745 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
746 gst_element_link (v_decoder, v_queue);
747 gst_element_link (v_queue, videosink);
748 gst_bin_add (GST_BIN (video_bin), v_decoder);
749 gst_bin_add (GST_BIN (video_bin), v_queue);
750 gst_bin_add (GST_BIN (video_bin), videosink);
752 gst_element_set_state (video_bin, GST_STATE_PAUSED);
754 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
757 seekable = gst_element_get_static_pad (v_queue, "src");
758 seekable_pads = g_list_prepend (seekable_pads, seekable);
759 rate_pads = g_list_prepend (rate_pads, seekable);
761 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
768 make_mpeg_pipeline (const gchar * location)
770 GstElement *pipeline, *audio_bin, *video_bin;
771 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
772 GstElement *audiosink, *videosink;
773 GstElement *a_queue, *v_queue;
777 pipeline = gst_pipeline_new ("app");
779 src = gst_element_factory_make_or_warn (SOURCE, "src");
780 g_object_set (G_OBJECT (src), "location", location, NULL);
782 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
783 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
785 gst_bin_add (GST_BIN (pipeline), src);
786 gst_bin_add (GST_BIN (pipeline), demux);
787 gst_element_link (src, demux);
789 audio_bin = gst_bin_new ("a_decoder_bin");
790 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
791 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
792 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
793 gst_bin_add (GST_BIN (audio_bin), a_decoder);
794 gst_bin_add (GST_BIN (audio_bin), a_queue);
795 gst_bin_add (GST_BIN (audio_bin), audiosink);
797 gst_element_link (a_decoder, a_queue);
798 gst_element_link (a_queue, audiosink);
800 gst_bin_add (GST_BIN (pipeline), audio_bin);
802 pad = gst_element_get_static_pad (a_decoder, "sink");
803 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
804 gst_object_unref (pad);
806 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
809 video_bin = gst_bin_new ("v_decoder_bin");
810 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
811 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
812 v_filter = gst_element_factory_make_or_warn ("videoconvert", "v_filter");
813 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
815 gst_bin_add (GST_BIN (video_bin), v_decoder);
816 gst_bin_add (GST_BIN (video_bin), v_queue);
817 gst_bin_add (GST_BIN (video_bin), v_filter);
818 gst_bin_add (GST_BIN (video_bin), videosink);
820 gst_element_link (v_decoder, v_queue);
821 gst_element_link (v_queue, v_filter);
822 gst_element_link (v_filter, videosink);
824 gst_bin_add (GST_BIN (pipeline), video_bin);
826 pad = gst_element_get_static_pad (v_decoder, "sink");
827 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
828 gst_object_unref (pad);
830 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
833 seekable = gst_element_get_static_pad (v_filter, "src");
834 seekable_pads = g_list_prepend (seekable_pads, seekable);
835 rate_pads = g_list_prepend (rate_pads, seekable);
837 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
844 make_mpegnt_pipeline (const gchar * location)
846 GstElement *pipeline, *audio_bin, *video_bin;
847 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
848 GstElement *audiosink, *videosink;
852 pipeline = gst_pipeline_new ("app");
854 src = gst_element_factory_make_or_warn (SOURCE, "src");
855 g_object_set (G_OBJECT (src), "location", location, NULL);
857 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
858 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
860 seekable_elements = g_list_prepend (seekable_elements, demux);
862 gst_bin_add (GST_BIN (pipeline), src);
863 gst_bin_add (GST_BIN (pipeline), demux);
864 gst_element_link (src, demux);
866 audio_bin = gst_bin_new ("a_decoder_bin");
867 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
868 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
869 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
870 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
871 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
872 gst_element_link (a_decoder, a_queue);
873 gst_element_link (a_queue, audiosink);
874 gst_bin_add (GST_BIN (audio_bin), a_decoder);
875 gst_bin_add (GST_BIN (audio_bin), a_queue);
876 gst_bin_add (GST_BIN (audio_bin), audiosink);
878 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
881 seekable = gst_element_get_static_pad (a_queue, "src");
882 seekable_pads = g_list_prepend (seekable_pads, seekable);
883 rate_pads = g_list_prepend (rate_pads, seekable);
885 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
888 video_bin = gst_bin_new ("v_decoder_bin");
889 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
890 v_filter = gst_element_factory_make_or_warn ("videoconvert", "v_filter");
891 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
892 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
894 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
896 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
899 seekable = gst_element_get_static_pad (v_decoder, "src");
900 seekable_pads = g_list_prepend (seekable_pads, seekable);
901 rate_pads = g_list_prepend (rate_pads, seekable);
903 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
910 playerbin_set_uri (GstElement * player, const gchar * location)
914 /* Add "file://" prefix for convenience */
915 if (g_str_has_prefix (location, "/")) {
916 uri = g_strconcat ("file://", location, NULL);
917 g_object_set (G_OBJECT (player), "uri", uri, NULL);
920 g_object_set (G_OBJECT (player), "uri", location, NULL);
925 construct_playerbin (const gchar * name, const gchar * location)
929 player = gst_element_factory_make (name, "player");
932 playerbin_set_uri (player, location);
934 seekable_elements = g_list_prepend (seekable_elements, player);
936 /* force element seeking on this pipeline */
943 make_playerbin_pipeline (const gchar * location)
945 return construct_playerbin ("playbin", location);
949 make_playerbin2_pipeline (const gchar * location)
951 GstElement *pipeline = construct_playerbin ("playbin2", location);
953 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
954 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
959 #ifndef GST_DISABLE_PARSE
961 make_parselaunch_pipeline (const gchar * description)
963 GstElement *pipeline;
964 GError *error = NULL;
966 pipeline = gst_parse_launch (description, &error);
968 seekable_elements = g_list_prepend (seekable_elements, pipeline);
979 GstElement *(*func) (const gchar * location);
983 static Pipeline pipelines[] = {
984 {"mp3", make_mp3_pipeline},
985 {"avi", make_avi_pipeline},
986 {"mpeg1", make_mpeg_pipeline},
987 {"mpegparse", make_parse_pipeline},
988 {"vorbis", make_vorbis_pipeline},
989 {"theora", make_theora_pipeline},
990 {"ogg/v/t", make_vorbis_theora_pipeline},
991 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
992 {"sid", make_sid_pipeline},
993 {"flac", make_flac_pipeline},
994 {"wav", make_wav_pipeline},
995 {"mod", make_mod_pipeline},
996 {"dv", make_dv_pipeline},
997 {"mpeg1nothreads", make_mpegnt_pipeline},
998 {"playerbin", make_playerbin_pipeline},
999 #ifndef GST_DISABLE_PARSE
1000 {"parse-launch", make_parselaunch_pipeline},
1002 {"playerbin2", make_playerbin2_pipeline},
1006 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
1008 /* ui callbacks and helpers */
1011 format_value (GtkScale * scale, gdouble value)
1017 real = value * duration / 100;
1018 seconds = (gint64) real / GST_SECOND;
1019 subseconds = (gint64) real / (GST_SECOND / 100);
1021 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1022 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1027 shuttle_format_value (GtkScale * scale, gdouble value)
1029 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
1035 const GstFormat format;
1039 static seek_format seek_formats[] = {
1040 {"tim", GST_FORMAT_TIME},
1041 {"byt", GST_FORMAT_BYTES},
1042 {"buf", GST_FORMAT_BUFFERS},
1043 {"def", GST_FORMAT_DEFAULT},
1047 G_GNUC_UNUSED static void
1050 GList *walk = rate_pads;
1053 GstPad *pad = GST_PAD (walk->data);
1056 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1057 while (seek_formats[i].name) {
1061 format = seek_formats[i].format;
1063 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, format,
1065 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1067 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1072 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1074 walk = g_list_next (walk);
1078 G_GNUC_UNUSED static void
1079 query_positions_elems (void)
1081 GList *walk = seekable_elements;
1084 GstElement *element = GST_ELEMENT (walk->data);
1087 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1088 while (seek_formats[i].name) {
1089 gint64 position, total;
1092 format = seek_formats[i].format;
1094 if (gst_element_query_position (element, format, &position) &&
1095 gst_element_query_duration (element, format, &total)) {
1096 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1097 seek_formats[i].name, position, total);
1099 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1104 g_print (" %s\n", GST_ELEMENT_NAME (element));
1106 walk = g_list_next (walk);
1110 G_GNUC_UNUSED static void
1111 query_positions_pads (void)
1113 GList *walk = seekable_pads;
1116 GstPad *pad = GST_PAD (walk->data);
1119 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1120 while (seek_formats[i].name) {
1122 gint64 position, total;
1124 format = seek_formats[i].format;
1126 if (gst_pad_query_position (pad, format, &position) &&
1127 gst_pad_query_duration (pad, format, &total)) {
1128 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1129 seek_formats[i].name, position, total);
1131 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1137 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1139 walk = g_list_next (walk);
1143 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1144 gpointer user_data);
1145 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1146 gpointer user_data);
1147 static void seek_cb (GtkWidget * widget);
1150 set_scale (gdouble value)
1152 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1154 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1156 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1157 gtk_adjustment_set_value (adjustment, value);
1158 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1160 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1162 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1164 gtk_widget_queue_draw (hscale);
1168 update_fill (gpointer data)
1171 if (seekable_elements) {
1172 GstElement *element = GST_ELEMENT (seekable_elements->data);
1175 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1176 if (gst_element_query (element, query)) {
1177 gint64 start, stop, buffering_total;
1182 GstBufferingMode mode;
1183 gint avg_in, avg_out;
1184 gint64 buffering_left;
1186 gst_query_parse_buffering_percent (query, &busy, &percent);
1187 gst_query_parse_buffering_range (query, &format, &start, &stop,
1189 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
1192 /* note that we could start the playback when buffering_left < remaining
1194 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
1195 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
1196 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1200 fill = 100.0 * stop / GST_FORMAT_PERCENT_MAX;
1204 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1206 gst_query_unref (query);
1213 update_scale (gpointer data)
1216 if (seekable_elements) {
1217 GstElement *element = GST_ELEMENT (seekable_elements->data);
1219 gst_element_query_position (element, GST_FORMAT_TIME, &position);
1220 gst_element_query_duration (element, GST_FORMAT_TIME, &duration);
1223 if (seekable_pads) {
1224 GstPad *pad = GST_PAD (seekable_pads->data);
1226 gst_pad_query_position (pad, GST_FORMAT_TIME, &position);
1227 gst_pad_query_duration (pad, GST_FORMAT_TIME, &duration);
1233 query_positions_elems ();
1235 query_positions_pads ();
1240 if (position >= duration)
1241 duration = position;
1244 set_scale (position * 100.0 / duration);
1247 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1248 if (pipeline_type == 16) {
1249 g_object_notify (G_OBJECT (pipeline), "volume");
1255 static void do_seek (GtkWidget * widget);
1256 static void connect_bus_signals (GstElement * pipeline);
1257 static void set_update_scale (gboolean active);
1258 static void set_update_fill (gboolean active);
1261 end_scrub (GtkWidget * widget)
1263 GST_DEBUG ("end scrub, PAUSE");
1264 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1265 seek_timeout_id = 0;
1271 send_event (GstEvent * event)
1273 gboolean res = FALSE;
1276 GList *walk = seekable_pads;
1279 GstPad *seekable = GST_PAD (walk->data);
1281 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1283 gst_event_ref (event);
1284 res = gst_pad_send_event (seekable, event);
1286 walk = g_list_next (walk);
1289 GList *walk = seekable_elements;
1292 GstElement *seekable = GST_ELEMENT (walk->data);
1294 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1296 gst_event_ref (event);
1297 res = gst_element_send_event (seekable, event);
1299 walk = g_list_next (walk);
1302 gst_event_unref (event);
1307 do_seek (GtkWidget * widget)
1310 gboolean res = FALSE;
1314 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
1318 flags |= GST_SEEK_FLAG_FLUSH;
1320 flags |= GST_SEEK_FLAG_ACCURATE;
1322 flags |= GST_SEEK_FLAG_KEY_UNIT;
1324 flags |= GST_SEEK_FLAG_SEGMENT;
1326 flags |= GST_SEEK_FLAG_SKIP;
1329 s_event = gst_event_new_seek (rate,
1330 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1331 GST_CLOCK_TIME_NONE);
1332 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1333 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1335 s_event = gst_event_new_seek (rate,
1336 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1337 GST_SEEK_TYPE_SET, real);
1338 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1339 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1342 res = send_event (s_event);
1346 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1348 set_update_scale (TRUE);
1351 g_print ("seek failed\n");
1352 set_update_scale (TRUE);
1357 seek_cb (GtkWidget * widget)
1359 /* If the timer hasn't expired yet, then the pipeline is running */
1360 if (play_scrub && seek_timeout_id != 0) {
1361 GST_DEBUG ("do scrub seek, PAUSED");
1362 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1365 GST_DEBUG ("do seek");
1369 GST_DEBUG ("do scrub seek, PLAYING");
1370 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1372 if (seek_timeout_id == 0) {
1374 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1380 set_update_fill (gboolean active)
1382 GST_DEBUG ("fill scale is %d", active);
1387 g_timeout_add (FILL_INTERVAL, (GSourceFunc) update_fill, pipeline);
1391 g_source_remove (fill_id);
1398 set_update_scale (gboolean active)
1401 GST_DEBUG ("update scale is %d", active);
1404 if (update_id == 0) {
1406 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, pipeline);
1410 g_source_remove (update_id);
1417 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1419 if (event->type != GDK_BUTTON_PRESS)
1422 set_update_scale (FALSE);
1424 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1425 GST_DEBUG ("start scrub seek, PAUSE");
1426 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1429 if (changed_id == 0 && flush_seek && scrub) {
1431 g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb),
1439 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1442 g_signal_handler_disconnect (hscale, changed_id);
1446 if (!flush_seek || !scrub) {
1447 GST_DEBUG ("do final seek");
1451 if (seek_timeout_id != 0) {
1452 g_source_remove (seek_timeout_id);
1453 seek_timeout_id = 0;
1454 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1456 if (state == GST_STATE_PAUSED) {
1457 GST_DEBUG ("stop scrub seek, PAUSED");
1458 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1461 if (state == GST_STATE_PLAYING) {
1462 GST_DEBUG ("stop scrub seek, PLAYING");
1463 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1471 play_cb (GtkButton * button, gpointer data)
1473 GstStateChangeReturn ret;
1475 if (state != GST_STATE_PLAYING) {
1476 g_print ("PLAY pipeline\n");
1477 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1479 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1481 case GST_STATE_CHANGE_FAILURE:
1483 case GST_STATE_CHANGE_NO_PREROLL:
1489 state = GST_STATE_PLAYING;
1490 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1497 g_print ("PLAY failed\n");
1498 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1503 pause_cb (GtkButton * button, gpointer data)
1505 g_static_mutex_lock (&state_mutex);
1506 if (state != GST_STATE_PAUSED) {
1507 GstStateChangeReturn ret;
1509 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1510 g_print ("PAUSE pipeline\n");
1511 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1513 case GST_STATE_CHANGE_FAILURE:
1515 case GST_STATE_CHANGE_NO_PREROLL:
1522 state = GST_STATE_PAUSED;
1523 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1525 g_static_mutex_unlock (&state_mutex);
1531 g_static_mutex_unlock (&state_mutex);
1532 g_print ("PAUSE failed\n");
1533 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1538 stop_cb (GtkButton * button, gpointer data)
1540 if (state != STOP_STATE) {
1541 GstStateChangeReturn ret;
1543 g_print ("READY pipeline\n");
1544 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1546 g_static_mutex_lock (&state_mutex);
1547 ret = gst_element_set_state (pipeline, STOP_STATE);
1548 if (ret == GST_STATE_CHANGE_FAILURE)
1552 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1553 gtk_widget_queue_draw (video_window);
1557 set_update_scale (FALSE);
1559 set_update_fill (FALSE);
1561 if (pipeline_type == 16)
1562 clear_streams (pipeline);
1563 g_static_mutex_unlock (&state_mutex);
1566 /* if one uses parse_launch, play, stop and play again it fails as all the
1567 * pads after the demuxer can't be reconnected
1569 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1570 gst_element_set_state (pipeline, GST_STATE_NULL);
1571 gst_object_unref (pipeline);
1573 g_list_free (seekable_elements);
1574 seekable_elements = NULL;
1575 g_list_free (seekable_pads);
1576 seekable_pads = NULL;
1577 g_list_free (rate_pads);
1580 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1581 g_assert (pipeline);
1582 gst_element_set_state (pipeline, STOP_STATE);
1583 connect_bus_signals (pipeline);
1591 g_static_mutex_unlock (&state_mutex);
1592 g_print ("STOP failed\n");
1593 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1598 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1600 accurate_seek = gtk_toggle_button_get_active (button);
1604 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1606 keyframe_seek = gtk_toggle_button_get_active (button);
1610 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1612 loop_seek = gtk_toggle_button_get_active (button);
1613 if (state == GST_STATE_PLAYING) {
1619 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1621 flush_seek = gtk_toggle_button_get_active (button);
1625 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1627 scrub = gtk_toggle_button_get_active (button);
1631 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1633 play_scrub = gtk_toggle_button_get_active (button);
1637 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1639 skip_seek = gtk_toggle_button_get_active (button);
1640 if (state == GST_STATE_PLAYING) {
1646 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1648 gboolean res = FALSE;
1652 rate = gtk_spin_button_get_value (button);
1654 GST_DEBUG ("rate changed to %lf", rate);
1658 flags |= GST_SEEK_FLAG_FLUSH;
1660 flags |= GST_SEEK_FLAG_SEGMENT;
1662 flags |= GST_SEEK_FLAG_ACCURATE;
1664 flags |= GST_SEEK_FLAG_KEY_UNIT;
1666 flags |= GST_SEEK_FLAG_SKIP;
1669 s_event = gst_event_new_seek (rate,
1670 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1671 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1673 s_event = gst_event_new_seek (rate,
1674 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1675 GST_SEEK_TYPE_SET, position);
1678 res = send_event (s_event);
1682 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1685 g_print ("seek failed\n");
1689 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1693 g_object_get (pipeline, "flags", &flags, NULL);
1695 flags |= (1 << num);
1697 flags &= ~(1 << num);
1698 g_object_set (pipeline, "flags", flags, NULL);
1702 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1706 state = gtk_toggle_button_get_active (button);
1707 update_flag (pipeline, 3, state);
1708 gtk_widget_set_sensitive (vis_combo, state);
1712 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1716 state = gtk_toggle_button_get_active (button);
1717 update_flag (pipeline, 1, state);
1718 gtk_widget_set_sensitive (audio_combo, state);
1722 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1726 state = gtk_toggle_button_get_active (button);
1727 update_flag (pipeline, 0, state);
1728 gtk_widget_set_sensitive (video_combo, state);
1732 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1736 state = gtk_toggle_button_get_active (button);
1737 update_flag (pipeline, 2, state);
1738 gtk_widget_set_sensitive (text_combo, state);
1742 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1746 mute = gtk_toggle_button_get_active (button);
1747 g_object_set (pipeline, "mute", mute, NULL);
1751 download_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1755 state = gtk_toggle_button_get_active (button);
1756 update_flag (pipeline, 7, state);
1760 buffer_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1764 state = gtk_toggle_button_get_active (button);
1765 update_flag (pipeline, 8, state);
1769 clear_streams (GstElement * pipeline)
1773 /* remove previous info */
1774 for (i = 0; i < n_video; i++)
1775 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (video_combo), 0);
1776 for (i = 0; i < n_audio; i++)
1777 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (audio_combo), 0);
1778 for (i = 0; i < n_text; i++)
1779 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (text_combo), 0);
1781 n_audio = n_video = n_text = 0;
1782 gtk_widget_set_sensitive (video_combo, FALSE);
1783 gtk_widget_set_sensitive (audio_combo, FALSE);
1784 gtk_widget_set_sensitive (text_combo, FALSE);
1786 need_streams = TRUE;
1790 update_streams (GstPipeline * pipeline)
1794 if (pipeline_type == 16 && need_streams) {
1800 /* remove previous info */
1801 clear_streams (GST_ELEMENT_CAST (pipeline));
1803 /* here we get and update the different streams detected by playbin2 */
1804 g_object_get (pipeline, "n-video", &n_video, NULL);
1805 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1806 g_object_get (pipeline, "n-text", &n_text, NULL);
1808 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1811 for (i = 0; i < n_video; i++) {
1812 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1814 str = gst_structure_to_string ((GstStructure *) tags);
1815 g_print ("video %d: %s\n", i, str);
1818 /* find good name for the label */
1819 name = g_strdup_printf ("video %d", i + 1);
1820 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (video_combo), name);
1823 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1824 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1825 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1828 for (i = 0; i < n_audio; i++) {
1829 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1831 str = gst_structure_to_string ((GstStructure *) tags);
1832 g_print ("audio %d: %s\n", i, str);
1835 /* find good name for the label */
1836 name = g_strdup_printf ("audio %d", i + 1);
1837 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (audio_combo), name);
1840 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1841 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1842 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1845 for (i = 0; i < n_text; i++) {
1846 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1850 const GValue *value;
1852 str = gst_structure_to_string ((GstStructure *) tags);
1853 g_print ("text %d: %s\n", i, str);
1856 /* get the language code if we can */
1857 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1858 if (value && G_VALUE_HOLDS_STRING (value)) {
1859 name = g_strdup_printf ("text %s", g_value_get_string (value));
1862 /* find good name for the label if we didn't use a tag */
1864 name = g_strdup_printf ("text %d", i + 1);
1866 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (text_combo), name);
1869 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1870 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1871 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1873 need_streams = FALSE;
1878 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1882 active = gtk_combo_box_get_active (combo);
1884 g_print ("setting current video track %d\n", active);
1885 g_object_set (pipeline, "current-video", active, NULL);
1889 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1893 active = gtk_combo_box_get_active (combo);
1895 g_print ("setting current audio track %d\n", active);
1896 g_object_set (pipeline, "current-audio", active, NULL);
1900 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1904 active = gtk_combo_box_get_active (combo);
1906 g_print ("setting current text track %d\n", active);
1907 g_object_set (pipeline, "current-text", active, NULL);
1911 filter_features (GstPluginFeature * feature, gpointer data)
1913 GstElementFactory *f;
1915 if (!GST_IS_ELEMENT_FACTORY (feature))
1917 f = GST_ELEMENT_FACTORY (feature);
1918 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1925 init_visualization_features (void)
1929 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1931 list = gst_registry_feature_filter (gst_registry_get_default (),
1932 filter_features, FALSE, NULL);
1934 for (walk = list; walk; walk = g_list_next (walk)) {
1938 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1939 name = gst_element_factory_get_longname (entry.factory);
1941 g_array_append_val (vis_entries, entry);
1942 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (vis_combo), name);
1944 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1948 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1952 GstElement *element;
1954 /* get the selected index and get the factory for this index */
1955 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1956 if (vis_entries->len > 0) {
1957 entry = &g_array_index (vis_entries, VisEntry, index);
1959 /* create an instance of the element from the factory */
1960 element = gst_element_factory_create (entry->factory, NULL);
1964 /* set vis plugin for playbin2 */
1965 g_object_set (pipeline, "vis-plugin", element, NULL);
1970 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1974 volume = gtk_spin_button_get_value (button);
1976 g_object_set (pipeline, "volume", volume, NULL);
1980 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
1982 gdouble cur_volume, new_volume;
1984 g_object_get (pipeline, "volume", &new_volume, NULL);
1985 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
1986 if (fabs (cur_volume - new_volume) > 0.001) {
1987 g_signal_handlers_block_by_func (volume_spinbutton,
1988 volume_spinbutton_changed_cb, pipeline);
1989 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
1990 g_signal_handlers_unblock_by_func (volume_spinbutton,
1991 volume_spinbutton_changed_cb, pipeline);
1996 shot_cb (GtkButton * button, gpointer data)
2001 /* convert to our desired format (RGB24) */
2002 caps = gst_caps_new_simple ("video/x-raw-rgb",
2003 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
2004 /* Note: we don't ask for a specific width/height here, so that
2005 * videoscale can adjust dimensions from a non-1/1 pixel aspect
2006 * ratio to a 1/1 pixel-aspect-ratio */
2007 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
2008 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
2009 "red_mask", G_TYPE_INT, 0xff0000,
2010 "green_mask", G_TYPE_INT, 0x00ff00,
2011 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
2013 /* convert the latest frame to the requested format */
2014 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
2015 gst_caps_unref (caps);
2023 GError *error = NULL;
2027 /* get the snapshot buffer format now. We set the caps on the appsink so
2028 * that it can only be an rgb buffer. The only thing we have not specified
2029 * on the caps is the height, which is dependant on the pixel-aspect-ratio
2030 * of the source material */
2032 caps = GST_BUFFER_CAPS (buffer);
2034 /* FIXME, get the caps on the buffer somehow */
2037 g_warning ("could not get snapshot format\n");
2040 s = gst_caps_get_structure (caps, 0);
2042 /* we need to get the final caps on the buffer to get the size */
2043 res = gst_structure_get_int (s, "width", &width);
2044 res |= gst_structure_get_int (s, "height", &height);
2046 g_warning ("could not get snapshot dimension\n");
2050 /* create pixmap from buffer and save, gstreamer video buffers have a stride
2051 * that is rounded up to the nearest multiple of 4 */
2052 data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
2053 pixbuf = gdk_pixbuf_new_from_data (data,
2054 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2055 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2057 /* save the pixbuf */
2058 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2059 gst_buffer_unmap (buffer, data, size);
2061 /* save the pixbuf */
2062 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2065 gst_buffer_unref (buffer);
2069 /* called when the Step button is pressed */
2071 step_cb (GtkButton * button, gpointer data)
2077 gboolean flush, res;
2080 active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo));
2082 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
2083 (step_amount_spinbutton));
2084 rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton));
2089 format = GST_FORMAT_BUFFERS;
2092 format = GST_FORMAT_TIME;
2093 amount *= GST_MSECOND;
2096 format = GST_FORMAT_UNDEFINED;
2100 event = gst_event_new_step (format, amount, rate, flush, FALSE);
2102 res = send_event (event);
2105 g_print ("Sending step event failed\n");
2110 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2112 const GstStructure *s;
2114 s = gst_message_get_structure (message);
2115 g_print ("message from \"%s\" (%s): ",
2116 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2117 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2121 sstr = gst_structure_to_string (s);
2122 g_print ("%s\n", sstr);
2125 g_print ("no message details\n");
2129 static gboolean shuttling = FALSE;
2130 static gdouble shuttle_rate = 0.0;
2131 static gdouble play_rate = 1.0;
2134 do_shuttle (GstElement * element)
2139 duration = 40 * GST_MSECOND;
2143 gst_element_send_event (element,
2144 gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE,
2149 msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element)
2155 gboolean intermediate;
2159 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
2160 &intermediate, &duration, &eos);
2163 g_print ("stepped till EOS\n");
2167 if (g_static_mutex_trylock (&state_mutex)) {
2169 do_shuttle (element);
2170 g_static_mutex_unlock (&state_mutex);
2172 /* ignore step messages that come while we are doing a state change */
2173 g_print ("state change is busy\n");
2178 shuttle_toggled (GtkToggleButton * button, GstElement * element)
2182 active = gtk_toggle_button_get_active (button);
2184 if (active != shuttling) {
2186 g_print ("shuttling %s\n", shuttling ? "active" : "inactive");
2190 pause_cb (NULL, NULL);
2191 gst_element_get_state (element, NULL, NULL, -1);
2197 shuttle_rate_switch (GstElement * element)
2203 if (state == GST_STATE_PLAYING) {
2204 /* pause when we need to */
2205 pause_cb (NULL, NULL);
2206 gst_element_get_state (element, NULL, NULL, -1);
2209 if (play_rate == 1.0)
2214 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate,
2215 GST_TIME_ARGS (position));
2217 flags = GST_SEEK_FLAG_FLUSH;
2218 flags |= GST_SEEK_FLAG_ACCURATE;
2220 if (play_rate >= 0.0) {
2221 s_event = gst_event_new_seek (play_rate,
2222 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
2223 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
2225 s_event = gst_event_new_seek (play_rate,
2226 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2227 GST_SEEK_TYPE_SET, position);
2229 res = send_event (s_event);
2231 gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT);
2233 g_print ("seek failed\n");
2238 shuttle_value_changed (GtkRange * range, GstElement * element)
2242 rate = gtk_adjustment_get_value (shuttle_adjustment);
2245 g_print ("rate 0.0, pause\n");
2246 pause_cb (NULL, NULL);
2247 gst_element_get_state (element, NULL, NULL, -1);
2249 g_print ("rate changed %0.3g\n", rate);
2251 if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) {
2252 shuttle_rate_switch (element);
2255 shuttle_rate = ABS (rate);
2256 if (state != GST_STATE_PLAYING) {
2257 do_shuttle (element);
2258 play_cb (NULL, NULL);
2264 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2266 GST_DEBUG ("async done");
2267 /* when we get ASYNC_DONE we can query position, duration and other
2269 update_scale (pipeline);
2271 /* update the available streams */
2272 update_streams (pipeline);
2276 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2278 const GstStructure *s;
2280 s = gst_message_get_structure (message);
2282 /* We only care about state changed on the pipeline */
2283 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2284 GstState old, new, pending;
2286 gst_message_parse_state_changed (message, &old, &new, &pending);
2288 /* When state of the pipeline changes to paused or playing we start updating scale */
2289 if (new == GST_STATE_PLAYING) {
2290 set_update_scale (TRUE);
2292 set_update_scale (FALSE);
2298 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2305 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2306 gst_message_parse_segment_done (message, &format, &position);
2307 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2310 /* in the segment-done callback we never flush as this would not make sense
2311 * for seamless playback. */
2313 flags |= GST_SEEK_FLAG_SEGMENT;
2315 flags |= GST_SEEK_FLAG_SKIP;
2317 s_event = gst_event_new_seek (rate,
2318 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2319 GST_SEEK_TYPE_SET, duration);
2321 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2322 rate, GST_TIME_ARGS (duration));
2324 res = send_event (s_event);
2326 g_print ("segment seek failed\n");
2329 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2332 do_stream_buffering (gint percent)
2336 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2337 bufstr = g_strdup_printf ("Buffering...%d", percent);
2338 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2341 if (percent == 100) {
2342 /* a 100% message means buffering is done */
2344 /* if the desired state is playing, go back */
2345 if (state == GST_STATE_PLAYING) {
2346 /* no state management needed for live pipelines */
2348 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2349 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2351 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2352 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2355 /* buffering busy */
2356 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2357 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2359 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2360 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2368 do_download_buffering (gint percent)
2370 if (!buffering && percent < 100) {
2375 bufstr = g_strdup_printf ("Downloading...");
2376 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2379 /* once we get a buffering message, we'll do the fill update */
2380 set_update_fill (TRUE);
2382 if (state == GST_STATE_PLAYING && !is_live) {
2383 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2384 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2385 /* user has to manually start the playback */
2386 state = GST_STATE_PAUSED;
2392 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2396 gst_message_parse_buffering (message, &percent);
2398 /* get more stats */
2399 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2403 case GST_BUFFERING_DOWNLOAD:
2404 do_download_buffering (percent);
2406 case GST_BUFFERING_LIVE:
2407 case GST_BUFFERING_TIMESHIFT:
2408 case GST_BUFFERING_STREAM:
2409 do_stream_buffering (percent);
2415 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2417 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2419 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2420 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2425 static gulong embed_xid = 0;
2427 /* We set the xid here in response to the prepare-window-handle message via a
2428 * bus sync handler because we don't know the actual videosink used from the
2429 * start (as we don't know the pipeline, or bin elements such as autovideosink
2430 * or gconfvideosink may be used which create the actual videosink only once
2431 * the pipeline is started) */
2432 static GstBusSyncReply
2433 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2435 GstElement *element;
2437 if (!gst_is_video_overlay_prepare_window_handle_message (message))
2438 return GST_BUS_PASS;
2440 element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2442 g_print ("got prepare-window-handle, setting XID %lu\n", embed_xid);
2444 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2445 "force-aspect-ratio")) {
2446 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2449 /* Should have been initialised from main thread before (can't use
2450 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2451 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2452 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2453 * shouldn't be done from a non-GUI thread without explicit locking). */
2454 g_assert (embed_xid != 0);
2456 gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (element), embed_xid);
2457 return GST_BUS_PASS;
2462 draw_cb (GtkWidget * widget, cairo_t * cr, gpointer data)
2464 if (state < GST_STATE_PAUSED) {
2467 width = gtk_widget_get_allocated_width (widget);
2468 height = gtk_widget_get_allocated_height (widget);
2469 cairo_set_source_rgb (cr, 0, 0, 0);
2470 cairo_rectangle (cr, 0, 0, width, height);
2478 realize_cb (GtkWidget * widget, gpointer data)
2480 GdkWindow *window = gtk_widget_get_window (widget);
2482 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2484 if (!gdk_window_ensure_native (window))
2485 g_error ("Couldn't create native window needed for GstXOverlay!");
2488 embed_xid = GDK_WINDOW_XID (window);
2489 g_print ("Window realize: video window XID = %lu\n", embed_xid);
2494 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2496 message_received (bus, message, data);
2498 /* Set new uri for playerbins and continue playback */
2499 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2500 stop_cb (NULL, NULL);
2501 l = g_list_next (l);
2503 playerbin_set_uri (GST_ELEMENT (data), l->data);
2504 play_cb (NULL, NULL);
2510 msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data)
2513 message_received (bus, message, data);
2517 connect_bus_signals (GstElement * pipeline)
2519 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2522 /* handle prepare-window-handle element message synchronously */
2523 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2527 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2528 gst_bus_enable_sync_message_emission (bus);
2530 g_signal_connect (bus, "message::state-changed",
2531 (GCallback) msg_state_changed, pipeline);
2532 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2534 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2537 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2539 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2541 g_signal_connect (bus, "message::error", (GCallback) message_received,
2543 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2545 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2546 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2548 g_signal_connect (bus, "message::element", (GCallback) message_received,
2550 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2552 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2554 // g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done,
2556 g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done,
2558 g_signal_connect (bus, "sync-message::step-done",
2559 (GCallback) msg_sync_step_done, pipeline);
2561 gst_object_unref (bus);
2564 /* Return GList of paths described in location string */
2566 handle_wildcards (const gchar * location)
2569 gchar *path = g_path_get_dirname (location);
2570 gchar *pattern = g_path_get_basename (location);
2571 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2572 GDir *dir = g_dir_open (path, 0, NULL);
2575 g_print ("matching %s from %s\n", pattern, path);
2578 g_print ("opening directory %s failed\n", path);
2582 while ((name = g_dir_read_name (dir)) != NULL) {
2583 if (g_pattern_match_string (pspec, name)) {
2584 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2585 g_print (" found clip %s\n", name);
2591 g_pattern_spec_free (pspec);
2599 delete_event_cb (void)
2601 stop_cb (NULL, NULL);
2606 print_usage (int argc, char **argv)
2610 g_print ("usage: %s <type> <filename>\n", argv[0]);
2611 g_print (" possible types:\n");
2613 for (i = 0; i < NUM_TYPES; i++) {
2614 g_print (" %d = %s\n", i, pipelines[i].name);
2619 read_joystick (GIOChannel * source, GIOCondition condition, gpointer user_data)
2621 gchar buf[sizeof (struct js_event)];
2622 struct js_event *js = (struct js_event *) buf;
2624 gsize bytes_read = 0;
2628 g_io_channel_read_chars (source, buf, sizeof (struct js_event),
2631 g_print ("error reading from joystick: %s", err->message);
2634 } else if (bytes_read != sizeof (struct js_event)) {
2635 g_print ("error reading joystick, read %u bytes of %u\n",
2636 (guint) bytes_read, (guint) sizeof (struct js_event));
2638 } else if (result != G_IO_STATUS_NORMAL) {
2639 g_print ("reading from joystick returned status %d", result);
2642 switch (js->type & ~JS_EVENT_INIT) {
2644 if (js->number == 0) {
2645 gdouble new_rate = (gdouble) (js->value) / 3000;
2646 g_print ("Got: %d (rate %g)\n", js->value, new_rate);
2648 gtk_adjustment_set_value (shuttle_adjustment, new_rate);
2657 main (int argc, char **argv)
2659 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2660 *flagtable, *boxes2, *step;
2661 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2662 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2663 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2664 GtkWidget *rate_label, *volume_label;
2665 GOptionEntry options[] = {
2666 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2667 "Show pad stats", NULL},
2668 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2669 "Seek on elements instead of pads", NULL},
2670 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2671 "Verbose properties", NULL},
2672 {"joystick", 'j', 0, G_OPTION_ARG_STRING, &js_device,
2673 "Joystick device to use", NULL},
2676 GOptionContext *ctx;
2679 if (!g_thread_supported ())
2680 g_thread_init (NULL);
2682 ctx = g_option_context_new ("- test seeking in gsteamer");
2683 g_option_context_add_main_entries (ctx, options, NULL);
2684 g_option_context_add_group (ctx, gst_init_get_option_group ());
2685 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2687 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2688 g_print ("Error initializing: %s\n", err->message);
2692 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2695 print_usage (argc, argv);
2699 pipeline_type = atoi (argv[1]);
2701 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2702 print_usage (argc, argv);
2706 pipeline_spec = argv[2];
2708 if (js_device == NULL)
2709 js_device = g_strdup ("/dev/input/js0");
2711 js_fd = g_open (js_device, O_RDONLY, 0);
2713 g_print ("Failed to open joystick device %s\n", js_device);
2717 if (g_strrstr (pipeline_spec, "*") != NULL ||
2718 g_strrstr (pipeline_spec, "?") != NULL) {
2719 paths = handle_wildcards (pipeline_spec);
2721 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2725 g_print ("opening %s failed\n", pipeline_spec);
2731 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2732 g_assert (pipeline);
2734 /* initialize gui elements ... */
2735 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2736 video_window = gtk_drawing_area_new ();
2737 g_signal_connect (video_window, "draw", G_CALLBACK (draw_cb), NULL);
2738 g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL);
2739 gtk_widget_set_double_buffered (video_window, FALSE);
2741 statusbar = gtk_statusbar_new ();
2742 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2743 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2744 hbox = gtk_hbox_new (FALSE, 0);
2745 vbox = gtk_vbox_new (FALSE, 0);
2746 flagtable = gtk_table_new (4, 2, FALSE);
2747 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2749 /* media controls */
2750 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2751 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2752 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2755 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2756 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2757 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2758 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2759 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2760 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2761 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2762 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2763 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2764 rate_label = gtk_label_new ("Rate");
2766 gtk_widget_set_tooltip_text (accurate_checkbox,
2767 "accurate position is requested, this might be considerably slower for some formats");
2768 gtk_widget_set_tooltip_text (key_checkbox,
2769 "seek to the nearest keyframe. This might be faster but less accurate");
2770 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2771 gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking");
2772 gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, "
2773 "negative value trigger reverse playback");
2774 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2775 gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking");
2776 gtk_widget_set_tooltip_text (skip_checkbox,
2777 "Skip frames while playing at high frame rates");
2779 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2780 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2782 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2788 step = gtk_expander_new ("step options");
2789 hbox = gtk_hbox_new (FALSE, 0);
2791 format_combo = gtk_combo_box_text_new ();
2792 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2794 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2796 gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0);
2797 gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2);
2799 step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2800 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0);
2801 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0);
2802 gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE,
2805 step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2806 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3);
2807 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0);
2808 gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2);
2810 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2811 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2812 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2814 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2818 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2819 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2820 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2821 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2824 shuttle_adjustment =
2825 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2826 shuttle_hscale = gtk_hscale_new (shuttle_adjustment);
2827 gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2);
2828 gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP);
2829 g_signal_connect (shuttle_hscale, "value_changed",
2830 G_CALLBACK (shuttle_value_changed), pipeline);
2831 g_signal_connect (shuttle_hscale, "format_value",
2832 G_CALLBACK (shuttle_format_value), pipeline);
2834 gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2);
2836 gtk_container_add (GTK_CONTAINER (step), hbox);
2841 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
2842 hscale = gtk_hscale_new (adjustment);
2843 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2844 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
2845 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2846 gtk_range_set_fill_level (GTK_RANGE (hscale), 100.0);
2848 g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek),
2850 g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek),
2852 g_signal_connect (hscale, "format_value", G_CALLBACK (format_value),
2855 if (pipeline_type == 16) {
2856 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2857 panel = gtk_hbox_new (FALSE, 0);
2858 video_combo = gtk_combo_box_text_new ();
2859 audio_combo = gtk_combo_box_text_new ();
2860 text_combo = gtk_combo_box_text_new ();
2861 gtk_widget_set_sensitive (video_combo, FALSE);
2862 gtk_widget_set_sensitive (audio_combo, FALSE);
2863 gtk_widget_set_sensitive (text_combo, FALSE);
2864 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2865 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2866 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2867 g_signal_connect (G_OBJECT (video_combo), "changed",
2868 G_CALLBACK (video_combo_cb), pipeline);
2869 g_signal_connect (G_OBJECT (audio_combo), "changed",
2870 G_CALLBACK (audio_combo_cb), pipeline);
2871 g_signal_connect (G_OBJECT (text_combo), "changed",
2872 G_CALLBACK (text_combo_cb), pipeline);
2873 /* playbin2 panel for flag checkboxes and volume/mute */
2874 boxes = gtk_hbox_new (FALSE, 0);
2875 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2876 video_checkbox = gtk_check_button_new_with_label ("Video");
2877 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2878 text_checkbox = gtk_check_button_new_with_label ("Text");
2879 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2880 download_checkbox = gtk_check_button_new_with_label ("Download");
2881 buffer_checkbox = gtk_check_button_new_with_label ("Buffer");
2882 volume_label = gtk_label_new ("Volume");
2883 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2884 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2885 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2886 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2887 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2888 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2889 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2890 gtk_box_pack_start (GTK_BOX (boxes), download_checkbox, TRUE, TRUE, 2);
2891 gtk_box_pack_start (GTK_BOX (boxes), buffer_checkbox, TRUE, TRUE, 2);
2892 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
2893 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2894 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2895 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2896 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2897 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2898 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2899 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
2900 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffer_checkbox), FALSE);
2901 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2902 G_CALLBACK (vis_toggle_cb), pipeline);
2903 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2904 G_CALLBACK (audio_toggle_cb), pipeline);
2905 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2906 G_CALLBACK (video_toggle_cb), pipeline);
2907 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2908 G_CALLBACK (text_toggle_cb), pipeline);
2909 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2910 G_CALLBACK (mute_toggle_cb), pipeline);
2911 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
2912 G_CALLBACK (download_toggle_cb), pipeline);
2913 g_signal_connect (G_OBJECT (buffer_checkbox), "toggled",
2914 G_CALLBACK (buffer_toggle_cb), pipeline);
2915 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2916 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2917 /* playbin2 panel for snapshot */
2918 boxes2 = gtk_hbox_new (FALSE, 0);
2919 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2920 gtk_widget_set_tooltip_text (shot_button,
2921 "save a screenshot .png in the current directory");
2922 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2924 vis_combo = gtk_combo_box_text_new ();
2925 g_signal_connect (G_OBJECT (vis_combo), "changed",
2926 G_CALLBACK (vis_combo_cb), pipeline);
2927 gtk_widget_set_sensitive (vis_combo, FALSE);
2928 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2929 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2931 /* fill the vis combo box and the array of factories */
2932 init_visualization_features ();
2934 panel = boxes = boxes2 = NULL;
2937 /* do the packing stuff ... */
2938 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2939 /* FIXME: can we avoid this for audio only? */
2940 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
2941 DEFAULT_VIDEO_HEIGHT);
2942 gtk_container_add (GTK_CONTAINER (window), vbox);
2943 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
2944 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2945 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2946 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2947 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2948 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2949 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2951 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2952 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2953 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2954 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2955 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2957 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2958 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2959 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2961 if (panel && boxes && boxes2) {
2962 expander = gtk_expander_new ("playbin2 options");
2963 pb2vbox = gtk_vbox_new (FALSE, 0);
2964 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2965 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2966 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2967 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2968 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2970 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2971 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
2972 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
2974 /* connect things ... */
2975 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
2977 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
2979 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
2981 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2982 G_CALLBACK (accurate_toggle_cb), pipeline);
2983 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2984 G_CALLBACK (key_toggle_cb), pipeline);
2985 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2986 G_CALLBACK (loop_toggle_cb), pipeline);
2987 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2988 G_CALLBACK (flush_toggle_cb), pipeline);
2989 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2990 G_CALLBACK (scrub_toggle_cb), pipeline);
2991 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2992 G_CALLBACK (play_scrub_toggle_cb), pipeline);
2993 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2994 G_CALLBACK (skip_toggle_cb), pipeline);
2995 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
2996 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
2998 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
3001 gtk_widget_show_all (window);
3003 /* realize window now so that the video window gets created and we can
3004 * obtain its XID before the pipeline is started up and the videosink
3005 * asks for the XID of the window to render onto */
3006 gtk_widget_realize (window);
3008 /* we should have the XID now */
3009 g_assert (embed_xid != 0);
3012 g_signal_connect (pipeline, "deep_notify",
3013 G_CALLBACK (gst_object_default_deep_notify), NULL);
3017 GIOChannel *js_watch = g_io_channel_unix_new (js_fd);
3018 g_io_channel_set_encoding (js_watch, NULL, NULL);
3019 g_io_add_watch (js_watch, G_IO_IN, read_joystick, NULL);
3022 connect_bus_signals (pipeline);
3025 g_print ("NULL pipeline\n");
3026 gst_element_set_state (pipeline, GST_STATE_NULL);
3028 g_print ("free pipeline\n");
3029 gst_object_unref (pipeline);
3031 g_list_foreach (paths, (GFunc) g_free, NULL);
3032 g_list_free (paths);