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.
39 #include <gdk/gdkwin32.h>
42 #include <gst/interfaces/xoverlay.h>
44 #if (!GTK_CHECK_VERSION(2, 23, 0) || GTK_CHECK_VERSION(2, 90, 0)) && !GTK_CHECK_VERSION(2, 91, 1)
45 #define gtk_combo_box_text_new gtk_combo_box_new_text
46 #define gtk_combo_box_text_append_text gtk_combo_box_append_text
47 #define gtk_combo_box_text_remove gtk_combo_box_remove_text
48 #define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX
51 GST_DEBUG_CATEGORY_STATIC (seek_debug);
52 #define GST_CAT_DEFAULT (seek_debug)
54 #if !GTK_CHECK_VERSION (2, 17, 7)
56 gtk_widget_get_allocation (GtkWidget * w, GtkAllocation * a)
64 #define SOURCE "filesrc"
66 #define ASINK DEFAULT_AUDIOSINK
67 //#define ASINK "pulsesink"
68 //#define ASINK "alsasink"
69 //#define ASINK "osssink"
70 //#define ASINK "directsoundsink"
73 #define VSINK "directdrawsink"
75 #define VSINK "xvimagesink"
77 //#define VSINK "sdlvideosink"
78 //#define VSINK "ximagesink"
79 //#define VSINK "aasink"
80 //#define VSINK "cacasink"
81 //#define VSINK "dshowvideosink"
82 //#define VSINK "sdlvideosink"
83 //#define VSINK "glimagesink"
85 #define FILL_INTERVAL 100
86 //#define UPDATE_INTERVAL 500
87 //#define UPDATE_INTERVAL 100
88 #define UPDATE_INTERVAL 40
90 /* number of milliseconds to play for after a seek */
91 #define SCRUB_TIME 100
93 /* timeout for gst_element_get_state() after a seek */
94 #define SEEK_TIMEOUT 40 * GST_MSECOND
96 #define DEFAULT_VIDEO_HEIGHT 300
98 /* the state to go to when stop is pressed */
99 #define STOP_STATE GST_STATE_READY
101 #define N_GRAD 1000.0
103 static GList *seekable_pads = NULL;
104 static GList *rate_pads = NULL;
105 static GList *seekable_elements = NULL;
107 static gboolean accurate_seek = FALSE;
108 static gboolean keyframe_seek = FALSE;
109 static gboolean loop_seek = FALSE;
110 static gboolean flush_seek = TRUE;
111 static gboolean scrub = TRUE;
112 static gboolean play_scrub = FALSE;
113 static gboolean skip_seek = FALSE;
114 static gdouble rate = 1.0;
116 static GstElement *pipeline;
117 static gint pipeline_type;
118 static const gchar *pipeline_spec;
119 static gint64 position = -1;
120 static gint64 duration = -1;
121 static GtkAdjustment *adjustment;
122 static GtkWidget *hscale, *statusbar;
123 static guint status_id = 0;
124 static gboolean stats = FALSE;
125 static gboolean elem_seek = FALSE;
126 static gboolean verbose = FALSE;
128 static gboolean is_live = FALSE;
129 static gboolean buffering = FALSE;
130 static GstBufferingMode mode;
131 static gint64 buffering_left;
132 static GstState state = GST_STATE_NULL;
133 static guint update_id = 0;
134 static guint seek_timeout_id = 0;
135 static gulong changed_id;
136 static guint fill_id = 0;
138 static gint n_video = 0, n_audio = 0, n_text = 0;
139 static gboolean need_streams = TRUE;
140 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
141 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
142 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
143 static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
144 static GtkWidget *buffer_checkbox, *rate_spinbutton;
146 static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
148 static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
149 static GtkWidget *shuttle_checkbox, *step_button;
150 static GtkWidget *shuttle_hscale;
151 static GtkAdjustment *shuttle_adjustment;
153 static GList *paths = NULL, *l = NULL;
155 /* we keep an array of the visualisation entries so that we can easily switch
156 * with the combo box index. */
159 GstElementFactory *factory;
162 static GArray *vis_entries;
164 static void clear_streams (GstElement * pipeline);
165 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
168 /* pipeline construction */
172 const gchar *padname;
179 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
181 GstElement *element = gst_element_factory_make (type, name);
184 g_warning ("Failed to create element %s of type %s", name, type);
191 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
194 dyn_link *connect = (dyn_link *) data;
196 padname = gst_pad_get_name (newpad);
198 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
200 gst_bin_add (GST_BIN (pipeline), connect->bin);
201 gst_pad_link (newpad, connect->target);
203 //seekable_pads = g_list_prepend (seekable_pads, newpad);
204 rate_pads = g_list_prepend (rate_pads, newpad);
210 setup_dynamic_link (GstElement * element, const gchar * padname,
211 GstPad * target, GstElement * bin)
215 connect = g_new0 (dyn_link, 1);
216 connect->padname = g_strdup (padname);
217 connect->target = target;
220 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
225 make_mod_pipeline (const gchar * location)
227 GstElement *pipeline;
228 GstElement *src, *decoder, *audiosink;
231 pipeline = gst_pipeline_new ("app");
233 src = gst_element_factory_make_or_warn (SOURCE, "src");
234 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
235 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
236 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
238 g_object_set (G_OBJECT (src), "location", location, NULL);
240 gst_bin_add (GST_BIN (pipeline), src);
241 gst_bin_add (GST_BIN (pipeline), decoder);
242 gst_bin_add (GST_BIN (pipeline), audiosink);
244 gst_element_link (src, decoder);
245 gst_element_link (decoder, audiosink);
247 seekable = gst_element_get_static_pad (decoder, "src");
248 seekable_pads = g_list_prepend (seekable_pads, seekable);
249 rate_pads = g_list_prepend (rate_pads, seekable);
251 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
257 make_dv_pipeline (const gchar * location)
259 GstElement *pipeline;
260 GstElement *src, *demux, *decoder, *audiosink, *videosink;
261 GstElement *a_queue, *v_queue;
264 pipeline = gst_pipeline_new ("app");
266 src = gst_element_factory_make_or_warn (SOURCE, "src");
267 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
268 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
269 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
270 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
271 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
272 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
274 g_object_set (G_OBJECT (src), "location", location, NULL);
276 gst_bin_add (GST_BIN (pipeline), src);
277 gst_bin_add (GST_BIN (pipeline), demux);
278 gst_bin_add (GST_BIN (pipeline), a_queue);
279 gst_bin_add (GST_BIN (pipeline), audiosink);
280 gst_bin_add (GST_BIN (pipeline), v_queue);
281 gst_bin_add (GST_BIN (pipeline), decoder);
282 gst_bin_add (GST_BIN (pipeline), videosink);
284 gst_element_link (src, demux);
285 gst_element_link (a_queue, audiosink);
286 gst_element_link (v_queue, decoder);
287 gst_element_link (decoder, videosink);
289 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
291 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
294 seekable = gst_element_get_static_pad (decoder, "src");
295 seekable_pads = g_list_prepend (seekable_pads, seekable);
296 rate_pads = g_list_prepend (rate_pads, seekable);
302 make_wav_pipeline (const gchar * location)
304 GstElement *pipeline;
305 GstElement *src, *decoder, *audiosink;
307 pipeline = gst_pipeline_new ("app");
309 src = gst_element_factory_make_or_warn (SOURCE, "src");
310 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
311 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
313 g_object_set (G_OBJECT (src), "location", location, NULL);
315 gst_bin_add (GST_BIN (pipeline), src);
316 gst_bin_add (GST_BIN (pipeline), decoder);
317 gst_bin_add (GST_BIN (pipeline), audiosink);
319 gst_element_link (src, decoder);
321 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
324 seekable_elements = g_list_prepend (seekable_elements, audiosink);
326 /* force element seeking on this pipeline */
333 make_flac_pipeline (const gchar * location)
335 GstElement *pipeline;
336 GstElement *src, *decoder, *audiosink;
339 pipeline = gst_pipeline_new ("app");
341 src = gst_element_factory_make_or_warn (SOURCE, "src");
342 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
343 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
344 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
346 g_object_set (G_OBJECT (src), "location", location, NULL);
348 gst_bin_add (GST_BIN (pipeline), src);
349 gst_bin_add (GST_BIN (pipeline), decoder);
350 gst_bin_add (GST_BIN (pipeline), audiosink);
352 gst_element_link (src, decoder);
353 gst_element_link (decoder, audiosink);
355 seekable = gst_element_get_static_pad (decoder, "src");
356 seekable_pads = g_list_prepend (seekable_pads, seekable);
357 rate_pads = g_list_prepend (rate_pads, seekable);
359 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
365 make_sid_pipeline (const gchar * location)
367 GstElement *pipeline;
368 GstElement *src, *decoder, *audiosink;
371 pipeline = gst_pipeline_new ("app");
373 src = gst_element_factory_make_or_warn (SOURCE, "src");
374 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
375 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
376 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
378 g_object_set (G_OBJECT (src), "location", location, NULL);
380 gst_bin_add (GST_BIN (pipeline), src);
381 gst_bin_add (GST_BIN (pipeline), decoder);
382 gst_bin_add (GST_BIN (pipeline), audiosink);
384 gst_element_link (src, decoder);
385 gst_element_link (decoder, audiosink);
387 seekable = gst_element_get_static_pad (decoder, "src");
388 seekable_pads = g_list_prepend (seekable_pads, seekable);
389 rate_pads = g_list_prepend (rate_pads, seekable);
391 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
397 make_parse_pipeline (const gchar * location)
399 GstElement *pipeline;
400 GstElement *src, *parser, *fakesink;
403 pipeline = gst_pipeline_new ("app");
405 src = gst_element_factory_make_or_warn (SOURCE, "src");
406 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
407 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
408 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
409 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
411 g_object_set (G_OBJECT (src), "location", location, NULL);
413 gst_bin_add (GST_BIN (pipeline), src);
414 gst_bin_add (GST_BIN (pipeline), parser);
415 gst_bin_add (GST_BIN (pipeline), fakesink);
417 gst_element_link (src, parser);
418 gst_element_link (parser, fakesink);
420 seekable = gst_element_get_static_pad (parser, "src");
421 seekable_pads = g_list_prepend (seekable_pads, seekable);
422 rate_pads = g_list_prepend (rate_pads, seekable);
424 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
430 make_vorbis_pipeline (const gchar * location)
432 GstElement *pipeline, *audio_bin;
433 GstElement *src, *demux, *decoder, *convert, *audiosink;
434 GstPad *pad, *seekable;
436 pipeline = gst_pipeline_new ("app");
438 src = gst_element_factory_make_or_warn (SOURCE, "src");
439 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
440 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
441 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
442 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
443 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
445 g_object_set (G_OBJECT (src), "location", location, NULL);
447 audio_bin = gst_bin_new ("a_decoder_bin");
449 gst_bin_add (GST_BIN (pipeline), src);
450 gst_bin_add (GST_BIN (pipeline), demux);
451 gst_bin_add (GST_BIN (audio_bin), decoder);
452 gst_bin_add (GST_BIN (audio_bin), convert);
453 gst_bin_add (GST_BIN (audio_bin), audiosink);
454 gst_bin_add (GST_BIN (pipeline), audio_bin);
456 gst_element_link (src, demux);
457 gst_element_link (decoder, convert);
458 gst_element_link (convert, audiosink);
460 pad = gst_element_get_static_pad (decoder, "sink");
461 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
462 gst_object_unref (pad);
464 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
467 seekable = gst_element_get_static_pad (decoder, "src");
468 seekable_pads = g_list_prepend (seekable_pads, seekable);
469 rate_pads = g_list_prepend (rate_pads, seekable);
471 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
477 make_theora_pipeline (const gchar * location)
479 GstElement *pipeline, *video_bin;
480 GstElement *src, *demux, *decoder, *convert, *videosink;
481 GstPad *pad, *seekable;
483 pipeline = gst_pipeline_new ("app");
485 src = gst_element_factory_make_or_warn (SOURCE, "src");
486 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
487 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
488 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
489 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
491 g_object_set (G_OBJECT (src), "location", location, NULL);
493 video_bin = gst_bin_new ("v_decoder_bin");
495 gst_bin_add (GST_BIN (pipeline), src);
496 gst_bin_add (GST_BIN (pipeline), demux);
497 gst_bin_add (GST_BIN (video_bin), decoder);
498 gst_bin_add (GST_BIN (video_bin), convert);
499 gst_bin_add (GST_BIN (video_bin), videosink);
500 gst_bin_add (GST_BIN (pipeline), video_bin);
502 gst_element_link (src, demux);
503 gst_element_link (decoder, convert);
504 gst_element_link (convert, videosink);
506 pad = gst_element_get_static_pad (decoder, "sink");
507 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
508 gst_object_unref (pad);
510 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
513 seekable = gst_element_get_static_pad (decoder, "src");
514 seekable_pads = g_list_prepend (seekable_pads, seekable);
515 rate_pads = g_list_prepend (rate_pads, seekable);
517 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
523 make_vorbis_theora_pipeline (const gchar * location)
525 GstElement *pipeline, *audio_bin, *video_bin;
526 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
527 GstElement *audiosink, *videosink;
528 GstElement *a_queue, *v_queue, *v_scale;
532 pipeline = gst_pipeline_new ("app");
534 src = gst_element_factory_make_or_warn (SOURCE, "src");
535 g_object_set (G_OBJECT (src), "location", location, NULL);
537 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
539 gst_bin_add (GST_BIN (pipeline), src);
540 gst_bin_add (GST_BIN (pipeline), demux);
541 gst_element_link (src, demux);
543 audio_bin = gst_bin_new ("a_decoder_bin");
544 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
545 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
546 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
547 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
549 gst_bin_add (GST_BIN (pipeline), audio_bin);
551 gst_bin_add (GST_BIN (audio_bin), a_queue);
552 gst_bin_add (GST_BIN (audio_bin), a_decoder);
553 gst_bin_add (GST_BIN (audio_bin), a_convert);
554 gst_bin_add (GST_BIN (audio_bin), audiosink);
556 gst_element_link (a_queue, a_decoder);
557 gst_element_link (a_decoder, a_convert);
558 gst_element_link (a_convert, audiosink);
560 pad = gst_element_get_static_pad (a_queue, "sink");
561 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
562 gst_object_unref (pad);
564 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
567 video_bin = gst_bin_new ("v_decoder_bin");
568 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
569 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
571 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
572 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
573 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
575 gst_bin_add (GST_BIN (pipeline), video_bin);
577 gst_bin_add (GST_BIN (video_bin), v_queue);
578 gst_bin_add (GST_BIN (video_bin), v_decoder);
579 gst_bin_add (GST_BIN (video_bin), v_convert);
580 gst_bin_add (GST_BIN (video_bin), v_scale);
581 gst_bin_add (GST_BIN (video_bin), videosink);
583 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
586 pad = gst_element_get_static_pad (v_queue, "sink");
587 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
588 gst_object_unref (pad);
590 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
593 seekable = gst_element_get_static_pad (a_decoder, "src");
594 seekable_pads = g_list_prepend (seekable_pads, seekable);
595 rate_pads = g_list_prepend (rate_pads, seekable);
597 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
604 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
606 GstElement *pipeline, *audio_bin, *video_bin;
607 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
608 GstElement *audiosink, *videosink;
609 GstElement *a_queue, *v_queue;
610 GstPad *seekable, *pad;
612 pipeline = gst_pipeline_new ("app");
614 src = gst_element_factory_make_or_warn (SOURCE, "src");
615 g_object_set (G_OBJECT (src), "location", location, NULL);
617 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
619 gst_bin_add (GST_BIN (pipeline), src);
620 gst_bin_add (GST_BIN (pipeline), demux);
621 gst_element_link (src, demux);
623 audio_bin = gst_bin_new ("a_decoder_bin");
624 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
625 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
626 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
627 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
629 gst_bin_add (GST_BIN (audio_bin), a_queue);
630 gst_bin_add (GST_BIN (audio_bin), a_decoder);
631 gst_bin_add (GST_BIN (audio_bin), a_convert);
632 gst_bin_add (GST_BIN (audio_bin), audiosink);
634 gst_element_link (a_queue, a_decoder);
635 gst_element_link (a_decoder, a_convert);
636 gst_element_link (a_convert, audiosink);
638 gst_bin_add (GST_BIN (pipeline), audio_bin);
640 pad = gst_element_get_static_pad (a_queue, "sink");
641 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
642 gst_object_unref (pad);
644 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
647 video_bin = gst_bin_new ("v_decoder_bin");
648 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
649 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
651 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
652 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
654 gst_bin_add (GST_BIN (video_bin), v_queue);
655 gst_bin_add (GST_BIN (video_bin), v_decoder);
656 gst_bin_add (GST_BIN (video_bin), v_convert);
657 gst_bin_add (GST_BIN (video_bin), videosink);
659 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
661 gst_bin_add (GST_BIN (pipeline), video_bin);
663 pad = gst_element_get_static_pad (v_queue, "sink");
664 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
665 gst_object_unref (pad);
667 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
670 seekable = gst_element_get_static_pad (a_decoder, "src");
671 seekable_pads = g_list_prepend (seekable_pads, seekable);
672 rate_pads = g_list_prepend (rate_pads, seekable);
674 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
681 make_mp3_pipeline (const gchar * location)
683 GstElement *pipeline;
684 GstElement *src, *parser, *decoder, *audiosink, *queue;
687 pipeline = gst_pipeline_new ("app");
689 src = gst_element_factory_make_or_warn (SOURCE, "src");
690 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
691 decoder = gst_element_factory_make_or_warn ("mad", "dec");
692 queue = gst_element_factory_make_or_warn ("queue", "queue");
693 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
695 seekable_elements = g_list_prepend (seekable_elements, audiosink);
697 g_object_set (G_OBJECT (src), "location", location, NULL);
698 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
700 gst_bin_add (GST_BIN (pipeline), src);
701 gst_bin_add (GST_BIN (pipeline), parser);
702 gst_bin_add (GST_BIN (pipeline), decoder);
703 gst_bin_add (GST_BIN (pipeline), queue);
704 gst_bin_add (GST_BIN (pipeline), audiosink);
706 gst_element_link (src, parser);
707 gst_element_link (parser, decoder);
708 gst_element_link (decoder, queue);
709 gst_element_link (queue, audiosink);
711 seekable = gst_element_get_static_pad (queue, "src");
712 seekable_pads = g_list_prepend (seekable_pads, seekable);
713 rate_pads = g_list_prepend (rate_pads, seekable);
715 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
721 make_avi_pipeline (const gchar * location)
723 GstElement *pipeline, *audio_bin, *video_bin;
724 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
725 GstElement *a_queue = NULL, *v_queue = NULL;
728 pipeline = gst_pipeline_new ("app");
730 src = gst_element_factory_make_or_warn (SOURCE, "src");
731 g_object_set (G_OBJECT (src), "location", location, NULL);
733 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
734 seekable_elements = g_list_prepend (seekable_elements, demux);
736 gst_bin_add (GST_BIN (pipeline), src);
737 gst_bin_add (GST_BIN (pipeline), demux);
738 gst_element_link (src, demux);
740 audio_bin = gst_bin_new ("a_decoder_bin");
741 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
742 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
743 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
744 gst_element_link (a_decoder, a_queue);
745 gst_element_link (a_queue, audiosink);
746 gst_bin_add (GST_BIN (audio_bin), a_decoder);
747 gst_bin_add (GST_BIN (audio_bin), a_queue);
748 gst_bin_add (GST_BIN (audio_bin), audiosink);
749 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
751 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
754 seekable = gst_element_get_static_pad (a_queue, "src");
755 seekable_pads = g_list_prepend (seekable_pads, seekable);
756 rate_pads = g_list_prepend (rate_pads, seekable);
758 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
761 video_bin = gst_bin_new ("v_decoder_bin");
762 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
763 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
764 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
765 gst_element_link (v_decoder, v_queue);
766 gst_element_link (v_queue, videosink);
767 gst_bin_add (GST_BIN (video_bin), v_decoder);
768 gst_bin_add (GST_BIN (video_bin), v_queue);
769 gst_bin_add (GST_BIN (video_bin), videosink);
771 gst_element_set_state (video_bin, GST_STATE_PAUSED);
773 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
776 seekable = gst_element_get_static_pad (v_queue, "src");
777 seekable_pads = g_list_prepend (seekable_pads, seekable);
778 rate_pads = g_list_prepend (rate_pads, seekable);
780 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
787 make_mpeg_pipeline (const gchar * location)
789 GstElement *pipeline, *audio_bin, *video_bin;
790 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
791 GstElement *audiosink, *videosink;
792 GstElement *a_queue, *v_queue;
796 pipeline = gst_pipeline_new ("app");
798 src = gst_element_factory_make_or_warn (SOURCE, "src");
799 g_object_set (G_OBJECT (src), "location", location, NULL);
801 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
802 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
804 gst_bin_add (GST_BIN (pipeline), src);
805 gst_bin_add (GST_BIN (pipeline), demux);
806 gst_element_link (src, demux);
808 audio_bin = gst_bin_new ("a_decoder_bin");
809 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
810 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
811 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
812 gst_bin_add (GST_BIN (audio_bin), a_decoder);
813 gst_bin_add (GST_BIN (audio_bin), a_queue);
814 gst_bin_add (GST_BIN (audio_bin), audiosink);
816 gst_element_link (a_decoder, a_queue);
817 gst_element_link (a_queue, audiosink);
819 gst_bin_add (GST_BIN (pipeline), audio_bin);
821 pad = gst_element_get_static_pad (a_decoder, "sink");
822 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
823 gst_object_unref (pad);
825 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
828 video_bin = gst_bin_new ("v_decoder_bin");
829 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
830 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
831 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
832 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
834 gst_bin_add (GST_BIN (video_bin), v_decoder);
835 gst_bin_add (GST_BIN (video_bin), v_queue);
836 gst_bin_add (GST_BIN (video_bin), v_filter);
837 gst_bin_add (GST_BIN (video_bin), videosink);
839 gst_element_link (v_decoder, v_queue);
840 gst_element_link (v_queue, v_filter);
841 gst_element_link (v_filter, videosink);
843 gst_bin_add (GST_BIN (pipeline), video_bin);
845 pad = gst_element_get_static_pad (v_decoder, "sink");
846 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
847 gst_object_unref (pad);
849 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
852 seekable = gst_element_get_static_pad (v_filter, "src");
853 seekable_pads = g_list_prepend (seekable_pads, seekable);
854 rate_pads = g_list_prepend (rate_pads, seekable);
856 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
863 make_mpegnt_pipeline (const gchar * location)
865 GstElement *pipeline, *audio_bin, *video_bin;
866 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
867 GstElement *audiosink, *videosink;
871 pipeline = gst_pipeline_new ("app");
873 src = gst_element_factory_make_or_warn (SOURCE, "src");
874 g_object_set (G_OBJECT (src), "location", location, NULL);
876 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
877 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
879 seekable_elements = g_list_prepend (seekable_elements, demux);
881 gst_bin_add (GST_BIN (pipeline), src);
882 gst_bin_add (GST_BIN (pipeline), demux);
883 gst_element_link (src, demux);
885 audio_bin = gst_bin_new ("a_decoder_bin");
886 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
887 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
888 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
889 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
890 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
891 gst_element_link (a_decoder, a_queue);
892 gst_element_link (a_queue, audiosink);
893 gst_bin_add (GST_BIN (audio_bin), a_decoder);
894 gst_bin_add (GST_BIN (audio_bin), a_queue);
895 gst_bin_add (GST_BIN (audio_bin), audiosink);
897 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
900 seekable = gst_element_get_static_pad (a_queue, "src");
901 seekable_pads = g_list_prepend (seekable_pads, seekable);
902 rate_pads = g_list_prepend (rate_pads, seekable);
904 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
907 video_bin = gst_bin_new ("v_decoder_bin");
908 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
909 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
910 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
911 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
913 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
915 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
918 seekable = gst_element_get_static_pad (v_decoder, "src");
919 seekable_pads = g_list_prepend (seekable_pads, seekable);
920 rate_pads = g_list_prepend (rate_pads, seekable);
922 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
929 playerbin_set_uri (GstElement * player, const gchar * location)
933 /* Add "file://" prefix for convenience */
934 if (g_str_has_prefix (location, "/") || !gst_uri_is_valid (location)) {
935 uri = gst_filename_to_uri (location, NULL);
936 g_print ("Setting URI: %s\n", uri);
937 g_object_set (G_OBJECT (player), "uri", uri, NULL);
940 g_print ("Setting URI: %s\n", location);
941 g_object_set (G_OBJECT (player), "uri", location, NULL);
946 construct_playerbin (const gchar * name, const gchar * location)
950 player = gst_element_factory_make (name, "player");
953 playerbin_set_uri (player, location);
955 seekable_elements = g_list_prepend (seekable_elements, player);
957 /* force element seeking on this pipeline */
964 make_playerbin_pipeline (const gchar * location)
966 return construct_playerbin ("playbin", location);
970 make_playerbin2_pipeline (const gchar * location)
972 GstElement *pipeline = construct_playerbin ("playbin2", location);
974 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
975 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
980 #ifndef GST_DISABLE_PARSE
982 make_parselaunch_pipeline (const gchar * description)
984 GstElement *pipeline;
985 GError *error = NULL;
987 pipeline = gst_parse_launch (description, &error);
989 seekable_elements = g_list_prepend (seekable_elements, pipeline);
1000 GstElement *(*func) (const gchar * location);
1004 static Pipeline pipelines[] = {
1005 {"mp3", make_mp3_pipeline},
1006 {"avi", make_avi_pipeline},
1007 {"mpeg1", make_mpeg_pipeline},
1008 {"mpegparse", make_parse_pipeline},
1009 {"vorbis", make_vorbis_pipeline},
1010 {"theora", make_theora_pipeline},
1011 {"ogg/v/t", make_vorbis_theora_pipeline},
1012 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
1013 {"sid", make_sid_pipeline},
1014 {"flac", make_flac_pipeline},
1015 {"wav", make_wav_pipeline},
1016 {"mod", make_mod_pipeline},
1017 {"dv", make_dv_pipeline},
1018 {"mpeg1nothreads", make_mpegnt_pipeline},
1019 {"playerbin", make_playerbin_pipeline},
1020 #ifndef GST_DISABLE_PARSE
1021 {"parse-launch", make_parselaunch_pipeline},
1023 {"playerbin2", make_playerbin2_pipeline},
1027 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
1029 /* ui callbacks and helpers */
1032 format_value (GtkScale * scale, gdouble value)
1038 real = value * duration / N_GRAD;
1039 seconds = (gint64) real / GST_SECOND;
1040 subseconds = (gint64) real / (GST_SECOND / N_GRAD);
1042 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1043 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1048 shuttle_format_value (GtkScale * scale, gdouble value)
1050 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
1056 const GstFormat format;
1060 static seek_format seek_formats[] = {
1061 {"tim", GST_FORMAT_TIME},
1062 {"byt", GST_FORMAT_BYTES},
1063 {"buf", GST_FORMAT_BUFFERS},
1064 {"def", GST_FORMAT_DEFAULT},
1068 G_GNUC_UNUSED static void
1071 GList *walk = rate_pads;
1074 GstPad *pad = GST_PAD (walk->data);
1077 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1078 while (seek_formats[i].name) {
1082 format = seek_formats[i].format;
1084 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
1086 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1088 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1093 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1095 walk = g_list_next (walk);
1099 G_GNUC_UNUSED static void
1100 query_positions_elems (void)
1102 GList *walk = seekable_elements;
1105 GstElement *element = GST_ELEMENT (walk->data);
1108 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1109 while (seek_formats[i].name) {
1110 gint64 position, total;
1113 format = seek_formats[i].format;
1115 if (gst_element_query_position (element, &format, &position) &&
1116 gst_element_query_duration (element, &format, &total)) {
1117 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1118 seek_formats[i].name, position, total);
1120 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1125 g_print (" %s\n", GST_ELEMENT_NAME (element));
1127 walk = g_list_next (walk);
1131 G_GNUC_UNUSED static void
1132 query_positions_pads (void)
1134 GList *walk = seekable_pads;
1137 GstPad *pad = GST_PAD (walk->data);
1140 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1141 while (seek_formats[i].name) {
1143 gint64 position, total;
1145 format = seek_formats[i].format;
1147 if (gst_pad_query_position (pad, &format, &position) &&
1148 gst_pad_query_duration (pad, &format, &total)) {
1149 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1150 seek_formats[i].name, position, total);
1152 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1158 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1160 walk = g_list_next (walk);
1164 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1165 gpointer user_data);
1166 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1167 gpointer user_data);
1168 static void seek_cb (GtkWidget * widget);
1171 set_scale (gdouble value)
1173 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1175 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1177 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1178 gtk_adjustment_set_value (adjustment, value);
1179 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1181 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1183 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1185 gtk_widget_queue_draw (hscale);
1189 update_fill (gpointer data)
1192 if (seekable_elements) {
1193 GstElement *element = GST_ELEMENT (seekable_elements->data);
1196 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1197 if (gst_element_query (element, query)) {
1198 gint64 start, stop, buffering_total;
1203 GstBufferingMode mode;
1204 gint avg_in, avg_out;
1205 gint64 buffering_left;
1207 gst_query_parse_buffering_percent (query, &busy, &percent);
1208 gst_query_parse_buffering_range (query, &format, &start, &stop,
1210 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
1213 /* note that we could start the playback when buffering_left < remaining
1215 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
1216 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
1217 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1221 fill = N_GRAD * stop / GST_FORMAT_PERCENT_MAX;
1225 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1227 gst_query_unref (query);
1234 update_scale (gpointer data)
1236 GstFormat format = GST_FORMAT_TIME;
1242 if (seekable_elements) {
1243 GstElement *element = GST_ELEMENT (seekable_elements->data);
1245 gst_element_query_position (element, &format, &position);
1246 gst_element_query_duration (element, &format, &duration);
1249 if (seekable_pads) {
1250 GstPad *pad = GST_PAD (seekable_pads->data);
1252 gst_pad_query_position (pad, &format, &position);
1253 gst_pad_query_duration (pad, &format, &duration);
1259 query_positions_elems ();
1261 query_positions_pads ();
1266 if (position >= duration)
1267 duration = position;
1270 set_scale (position * N_GRAD / duration);
1273 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1274 if (pipeline_type == 16) {
1275 g_object_notify (G_OBJECT (pipeline), "volume");
1281 static void do_seek (GtkWidget * widget);
1282 static void connect_bus_signals (GstElement * pipeline);
1283 static void set_update_scale (gboolean active);
1284 static void set_update_fill (gboolean active);
1287 end_scrub (GtkWidget * widget)
1289 GST_DEBUG ("end scrub, PAUSE");
1290 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1291 seek_timeout_id = 0;
1297 send_event (GstEvent * event)
1299 gboolean res = FALSE;
1302 GList *walk = seekable_pads;
1305 GstPad *seekable = GST_PAD (walk->data);
1307 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1309 gst_event_ref (event);
1310 res = gst_pad_send_event (seekable, event);
1312 walk = g_list_next (walk);
1315 GList *walk = seekable_elements;
1318 GstElement *seekable = GST_ELEMENT (walk->data);
1320 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1322 gst_event_ref (event);
1323 res = gst_element_send_event (seekable, event);
1325 walk = g_list_next (walk);
1328 gst_event_unref (event);
1333 do_seek (GtkWidget * widget)
1336 gboolean res = FALSE;
1340 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / N_GRAD;
1342 GST_DEBUG ("value=%f, real=%" G_GINT64_FORMAT,
1343 gtk_range_get_value (GTK_RANGE (widget)), real);
1347 flags |= GST_SEEK_FLAG_FLUSH;
1349 flags |= GST_SEEK_FLAG_ACCURATE;
1351 flags |= GST_SEEK_FLAG_KEY_UNIT;
1353 flags |= GST_SEEK_FLAG_SEGMENT;
1355 flags |= GST_SEEK_FLAG_SKIP;
1358 s_event = gst_event_new_seek (rate,
1359 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1360 GST_CLOCK_TIME_NONE);
1361 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1362 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1364 s_event = gst_event_new_seek (rate,
1365 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1366 GST_SEEK_TYPE_SET, real);
1367 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1368 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1371 res = send_event (s_event);
1375 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1377 set_update_scale (TRUE);
1380 g_print ("seek failed\n");
1381 set_update_scale (TRUE);
1386 seek_cb (GtkWidget * widget)
1388 /* If the timer hasn't expired yet, then the pipeline is running */
1389 if (play_scrub && seek_timeout_id != 0) {
1390 GST_DEBUG ("do scrub seek, PAUSED");
1391 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1394 GST_DEBUG ("do seek");
1398 GST_DEBUG ("do scrub seek, PLAYING");
1399 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1401 if (seek_timeout_id == 0) {
1403 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1409 set_update_fill (gboolean active)
1411 GST_DEBUG ("fill scale is %d", active);
1416 g_timeout_add (FILL_INTERVAL, (GSourceFunc) update_fill, pipeline);
1420 g_source_remove (fill_id);
1427 set_update_scale (gboolean active)
1430 GST_DEBUG ("update scale is %d", active);
1433 if (update_id == 0) {
1435 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, pipeline);
1439 g_source_remove (update_id);
1446 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1448 if (event->type != GDK_BUTTON_PRESS)
1451 set_update_scale (FALSE);
1453 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1454 GST_DEBUG ("start scrub seek, PAUSE");
1455 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1458 if (changed_id == 0 && flush_seek && scrub) {
1460 g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb),
1468 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1471 g_signal_handler_disconnect (hscale, changed_id);
1475 if (!flush_seek || !scrub) {
1476 GST_DEBUG ("do final seek");
1480 if (seek_timeout_id != 0) {
1481 g_source_remove (seek_timeout_id);
1482 seek_timeout_id = 0;
1483 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1485 if (state == GST_STATE_PAUSED) {
1486 GST_DEBUG ("stop scrub seek, PAUSED");
1487 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1490 if (state == GST_STATE_PLAYING) {
1491 GST_DEBUG ("stop scrub seek, PLAYING");
1492 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1500 play_cb (GtkButton * button, gpointer data)
1502 GstStateChangeReturn ret;
1504 if (state != GST_STATE_PLAYING) {
1505 g_print ("PLAY pipeline\n");
1506 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1508 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1510 case GST_STATE_CHANGE_FAILURE:
1512 case GST_STATE_CHANGE_NO_PREROLL:
1518 state = GST_STATE_PLAYING;
1519 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1526 g_print ("PLAY failed\n");
1527 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1532 pause_cb (GtkButton * button, gpointer data)
1534 g_static_mutex_lock (&state_mutex);
1535 if (state != GST_STATE_PAUSED) {
1536 GstStateChangeReturn ret;
1538 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1539 g_print ("PAUSE pipeline\n");
1540 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1542 case GST_STATE_CHANGE_FAILURE:
1544 case GST_STATE_CHANGE_NO_PREROLL:
1551 state = GST_STATE_PAUSED;
1552 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1554 g_static_mutex_unlock (&state_mutex);
1560 g_static_mutex_unlock (&state_mutex);
1561 g_print ("PAUSE failed\n");
1562 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1567 stop_cb (GtkButton * button, gpointer data)
1569 if (state != STOP_STATE) {
1570 GstStateChangeReturn ret;
1572 g_print ("READY pipeline\n");
1573 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1575 g_static_mutex_lock (&state_mutex);
1576 ret = gst_element_set_state (pipeline, STOP_STATE);
1577 if (ret == GST_STATE_CHANGE_FAILURE)
1581 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1585 set_update_scale (FALSE);
1587 set_update_fill (FALSE);
1589 if (pipeline_type == 16)
1590 clear_streams (pipeline);
1591 g_static_mutex_unlock (&state_mutex);
1594 /* if one uses parse_launch, play, stop and play again it fails as all the
1595 * pads after the demuxer can't be reconnected
1597 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1598 gst_element_set_state (pipeline, GST_STATE_NULL);
1599 gst_object_unref (pipeline);
1601 g_list_free (seekable_elements);
1602 seekable_elements = NULL;
1603 g_list_free (seekable_pads);
1604 seekable_pads = NULL;
1605 g_list_free (rate_pads);
1608 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1609 g_assert (pipeline);
1610 gst_element_set_state (pipeline, STOP_STATE);
1611 connect_bus_signals (pipeline);
1619 g_static_mutex_unlock (&state_mutex);
1620 g_print ("STOP failed\n");
1621 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1626 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1628 accurate_seek = gtk_toggle_button_get_active (button);
1632 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1634 keyframe_seek = gtk_toggle_button_get_active (button);
1638 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1640 loop_seek = gtk_toggle_button_get_active (button);
1641 if (state == GST_STATE_PLAYING) {
1647 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1649 flush_seek = gtk_toggle_button_get_active (button);
1653 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1655 scrub = gtk_toggle_button_get_active (button);
1659 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1661 play_scrub = gtk_toggle_button_get_active (button);
1665 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1667 skip_seek = gtk_toggle_button_get_active (button);
1668 if (state == GST_STATE_PLAYING) {
1674 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1676 gboolean res = FALSE;
1680 rate = gtk_spin_button_get_value (button);
1682 GST_DEBUG ("rate changed to %lf", rate);
1686 flags |= GST_SEEK_FLAG_FLUSH;
1688 flags |= GST_SEEK_FLAG_SEGMENT;
1690 flags |= GST_SEEK_FLAG_ACCURATE;
1692 flags |= GST_SEEK_FLAG_KEY_UNIT;
1694 flags |= GST_SEEK_FLAG_SKIP;
1697 s_event = gst_event_new_seek (rate,
1698 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1699 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1701 s_event = gst_event_new_seek (rate,
1702 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1703 GST_SEEK_TYPE_SET, position);
1706 res = send_event (s_event);
1710 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1713 g_print ("seek failed\n");
1717 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1721 g_object_get (pipeline, "flags", &flags, NULL);
1723 flags |= (1 << num);
1725 flags &= ~(1 << num);
1726 g_object_set (pipeline, "flags", flags, NULL);
1730 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1734 state = gtk_toggle_button_get_active (button);
1735 update_flag (pipeline, 3, state);
1736 gtk_widget_set_sensitive (vis_combo, state);
1740 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1744 state = gtk_toggle_button_get_active (button);
1745 update_flag (pipeline, 1, state);
1746 gtk_widget_set_sensitive (audio_combo, state);
1750 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1754 state = gtk_toggle_button_get_active (button);
1755 update_flag (pipeline, 0, state);
1756 gtk_widget_set_sensitive (video_combo, state);
1760 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1764 state = gtk_toggle_button_get_active (button);
1765 update_flag (pipeline, 2, state);
1766 gtk_widget_set_sensitive (text_combo, state);
1770 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1774 mute = gtk_toggle_button_get_active (button);
1775 g_object_set (pipeline, "mute", mute, NULL);
1779 download_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1783 state = gtk_toggle_button_get_active (button);
1784 update_flag (pipeline, 7, state);
1788 buffer_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1792 state = gtk_toggle_button_get_active (button);
1793 update_flag (pipeline, 8, state);
1797 clear_streams (GstElement * pipeline)
1801 /* remove previous info */
1802 for (i = 0; i < n_video; i++)
1803 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (video_combo), 0);
1804 for (i = 0; i < n_audio; i++)
1805 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (audio_combo), 0);
1806 for (i = 0; i < n_text; i++)
1807 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (text_combo), 0);
1809 n_audio = n_video = n_text = 0;
1810 gtk_widget_set_sensitive (video_combo, FALSE);
1811 gtk_widget_set_sensitive (audio_combo, FALSE);
1812 gtk_widget_set_sensitive (text_combo, FALSE);
1814 need_streams = TRUE;
1818 update_streams (GstPipeline * pipeline)
1822 if (pipeline_type == 16 && need_streams) {
1828 /* remove previous info */
1829 clear_streams (GST_ELEMENT_CAST (pipeline));
1831 /* here we get and update the different streams detected by playbin2 */
1832 g_object_get (pipeline, "n-video", &n_video, NULL);
1833 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1834 g_object_get (pipeline, "n-text", &n_text, NULL);
1836 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1839 for (i = 0; i < n_video; i++) {
1840 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1842 str = gst_structure_to_string ((GstStructure *) tags);
1843 g_print ("video %d: %s\n", i, str);
1846 /* find good name for the label */
1847 name = g_strdup_printf ("video %d", i + 1);
1848 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (video_combo), name);
1851 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1852 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1853 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1856 for (i = 0; i < n_audio; i++) {
1857 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1859 str = gst_structure_to_string ((GstStructure *) tags);
1860 g_print ("audio %d: %s\n", i, str);
1863 /* find good name for the label */
1864 name = g_strdup_printf ("audio %d", i + 1);
1865 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (audio_combo), name);
1868 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1869 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1870 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1873 for (i = 0; i < n_text; i++) {
1874 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1878 const GValue *value;
1880 str = gst_structure_to_string ((GstStructure *) tags);
1881 g_print ("text %d: %s\n", i, str);
1884 /* get the language code if we can */
1885 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1886 if (value && G_VALUE_HOLDS_STRING (value)) {
1887 name = g_strdup_printf ("text %s", g_value_get_string (value));
1890 /* find good name for the label if we didn't use a tag */
1892 name = g_strdup_printf ("text %d", i + 1);
1894 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (text_combo), name);
1897 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1898 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1899 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1901 need_streams = FALSE;
1906 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1910 active = gtk_combo_box_get_active (combo);
1912 g_print ("setting current video track %d\n", active);
1913 g_object_set (pipeline, "current-video", active, NULL);
1917 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1921 active = gtk_combo_box_get_active (combo);
1923 g_print ("setting current audio track %d\n", active);
1924 g_object_set (pipeline, "current-audio", active, NULL);
1928 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1932 active = gtk_combo_box_get_active (combo);
1934 g_print ("setting current text track %d\n", active);
1935 g_object_set (pipeline, "current-text", active, NULL);
1939 filter_features (GstPluginFeature * feature, gpointer data)
1941 GstElementFactory *f;
1943 if (!GST_IS_ELEMENT_FACTORY (feature))
1945 f = GST_ELEMENT_FACTORY (feature);
1946 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1953 init_visualization_features (void)
1957 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1959 list = gst_registry_feature_filter (gst_registry_get_default (),
1960 filter_features, FALSE, NULL);
1962 for (walk = list; walk; walk = g_list_next (walk)) {
1966 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1967 name = gst_element_factory_get_longname (entry.factory);
1969 g_array_append_val (vis_entries, entry);
1970 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (vis_combo), name);
1972 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1976 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1980 GstElement *element;
1982 /* get the selected index and get the factory for this index */
1983 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1984 if (vis_entries->len > 0) {
1985 entry = &g_array_index (vis_entries, VisEntry, index);
1987 /* create an instance of the element from the factory */
1988 element = gst_element_factory_create (entry->factory, NULL);
1992 /* set vis plugin for playbin2 */
1993 g_object_set (pipeline, "vis-plugin", element, NULL);
1998 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
2002 volume = gtk_spin_button_get_value (button);
2004 g_object_set (pipeline, "volume", volume, NULL);
2008 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
2010 gdouble cur_volume, new_volume;
2012 g_object_get (pipeline, "volume", &new_volume, NULL);
2013 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
2014 if (fabs (cur_volume - new_volume) > 0.001) {
2015 g_signal_handlers_block_by_func (volume_spinbutton,
2016 volume_spinbutton_changed_cb, pipeline);
2017 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
2018 g_signal_handlers_unblock_by_func (volume_spinbutton,
2019 volume_spinbutton_changed_cb, pipeline);
2024 shot_cb (GtkButton * button, gpointer data)
2029 /* convert to our desired format (RGB24) */
2030 caps = gst_caps_new_simple ("video/x-raw-rgb",
2031 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
2032 /* Note: we don't ask for a specific width/height here, so that
2033 * videoscale can adjust dimensions from a non-1/1 pixel aspect
2034 * ratio to a 1/1 pixel-aspect-ratio */
2035 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
2036 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
2037 "red_mask", G_TYPE_INT, 0xff0000,
2038 "green_mask", G_TYPE_INT, 0x00ff00,
2039 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
2041 /* convert the latest frame to the requested format */
2042 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
2043 gst_caps_unref (caps);
2051 GError *error = NULL;
2053 /* get the snapshot buffer format now. We set the caps on the appsink so
2054 * that it can only be an rgb buffer. The only thing we have not specified
2055 * on the caps is the height, which is dependant on the pixel-aspect-ratio
2056 * of the source material */
2057 caps = GST_BUFFER_CAPS (buffer);
2059 g_warning ("could not get snapshot format\n");
2062 s = gst_caps_get_structure (caps, 0);
2064 /* we need to get the final caps on the buffer to get the size */
2065 res = gst_structure_get_int (s, "width", &width);
2066 res |= gst_structure_get_int (s, "height", &height);
2068 g_warning ("could not get snapshot dimension\n");
2072 /* create pixmap from buffer and save, gstreamer video buffers have a stride
2073 * that is rounded up to the nearest multiple of 4 */
2074 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
2075 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2076 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2078 /* save the pixbuf */
2079 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2082 gst_buffer_unref (buffer);
2086 /* called when the Step button is pressed */
2088 step_cb (GtkButton * button, gpointer data)
2094 gboolean flush, res;
2097 active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo));
2099 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
2100 (step_amount_spinbutton));
2101 rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton));
2106 format = GST_FORMAT_BUFFERS;
2109 format = GST_FORMAT_TIME;
2110 amount *= GST_MSECOND;
2113 format = GST_FORMAT_UNDEFINED;
2117 event = gst_event_new_step (format, amount, rate, flush, FALSE);
2119 res = send_event (event);
2122 g_print ("Sending step event failed\n");
2127 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2129 const GstStructure *s;
2131 s = gst_message_get_structure (message);
2132 g_print ("message from \"%s\" (%s): ",
2133 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2134 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2138 sstr = gst_structure_to_string (s);
2139 g_print ("%s\n", sstr);
2142 g_print ("no message details\n");
2146 static gboolean shuttling = FALSE;
2147 static gdouble shuttle_rate = 0.0;
2148 static gdouble play_rate = 1.0;
2151 do_shuttle (GstElement * element)
2156 duration = 40 * GST_MSECOND;
2160 gst_element_send_event (element,
2161 gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE,
2166 msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element)
2172 gboolean intermediate;
2176 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
2177 &intermediate, &duration, &eos);
2180 g_print ("stepped till EOS\n");
2184 if (g_static_mutex_trylock (&state_mutex)) {
2186 do_shuttle (element);
2187 g_static_mutex_unlock (&state_mutex);
2189 /* ignore step messages that come while we are doing a state change */
2190 g_print ("state change is busy\n");
2195 shuttle_toggled (GtkToggleButton * button, GstElement * element)
2199 active = gtk_toggle_button_get_active (button);
2201 if (active != shuttling) {
2203 g_print ("shuttling %s\n", shuttling ? "active" : "inactive");
2207 pause_cb (NULL, NULL);
2208 gst_element_get_state (element, NULL, NULL, -1);
2214 shuttle_rate_switch (GstElement * element)
2220 if (state == GST_STATE_PLAYING) {
2221 /* pause when we need to */
2222 pause_cb (NULL, NULL);
2223 gst_element_get_state (element, NULL, NULL, -1);
2226 if (play_rate == 1.0)
2231 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate,
2232 GST_TIME_ARGS (position));
2234 flags = GST_SEEK_FLAG_FLUSH;
2235 flags |= GST_SEEK_FLAG_ACCURATE;
2237 if (play_rate >= 0.0) {
2238 s_event = gst_event_new_seek (play_rate,
2239 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
2240 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
2242 s_event = gst_event_new_seek (play_rate,
2243 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2244 GST_SEEK_TYPE_SET, position);
2246 res = send_event (s_event);
2248 gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT);
2250 g_print ("seek failed\n");
2255 shuttle_value_changed (GtkRange * range, GstElement * element)
2259 rate = gtk_adjustment_get_value (shuttle_adjustment);
2262 g_print ("rate 0.0, pause\n");
2263 pause_cb (NULL, NULL);
2264 gst_element_get_state (element, NULL, NULL, -1);
2266 g_print ("rate changed %0.3g\n", rate);
2268 if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) {
2269 shuttle_rate_switch (element);
2272 shuttle_rate = ABS (rate);
2273 if (state != GST_STATE_PLAYING) {
2274 do_shuttle (element);
2275 play_cb (NULL, NULL);
2281 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2283 GST_DEBUG ("async done");
2284 /* when we get ASYNC_DONE we can query position, duration and other
2286 update_scale (pipeline);
2288 /* update the available streams */
2289 update_streams (pipeline);
2293 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2295 const GstStructure *s;
2297 s = gst_message_get_structure (message);
2299 /* We only care about state changed on the pipeline */
2300 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2301 GstState old, new, pending;
2303 gst_message_parse_state_changed (message, &old, &new, &pending);
2305 /* When state of the pipeline changes to paused or playing we start updating scale */
2306 if (new == GST_STATE_PLAYING) {
2307 set_update_scale (TRUE);
2309 set_update_scale (FALSE);
2315 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2322 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2323 gst_message_parse_segment_done (message, &format, &position);
2324 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2327 /* in the segment-done callback we never flush as this would not make sense
2328 * for seamless playback. */
2330 flags |= GST_SEEK_FLAG_SEGMENT;
2332 flags |= GST_SEEK_FLAG_SKIP;
2334 s_event = gst_event_new_seek (rate,
2335 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2336 GST_SEEK_TYPE_SET, duration);
2338 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2339 rate, GST_TIME_ARGS (duration));
2341 res = send_event (s_event);
2343 g_print ("segment seek failed\n");
2346 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2349 do_stream_buffering (gint percent)
2353 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2354 bufstr = g_strdup_printf ("Buffering...%d", percent);
2355 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2358 if (percent == 100) {
2359 /* a 100% message means buffering is done */
2361 /* if the desired state is playing, go back */
2362 if (state == GST_STATE_PLAYING) {
2363 /* no state management needed for live pipelines */
2365 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2366 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2368 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2369 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2372 /* buffering busy */
2373 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2374 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2376 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2377 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2385 do_download_buffering (gint percent)
2387 if (!buffering && percent < 100) {
2392 bufstr = g_strdup_printf ("Downloading...");
2393 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2396 /* once we get a buffering message, we'll do the fill update */
2397 set_update_fill (TRUE);
2399 if (state == GST_STATE_PLAYING && !is_live) {
2400 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2401 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2402 /* user has to manually start the playback */
2403 state = GST_STATE_PAUSED;
2409 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2413 gst_message_parse_buffering (message, &percent);
2415 /* get more stats */
2416 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2420 case GST_BUFFERING_DOWNLOAD:
2421 do_download_buffering (percent);
2423 case GST_BUFFERING_LIVE:
2425 case GST_BUFFERING_TIMESHIFT:
2426 case GST_BUFFERING_STREAM:
2427 do_stream_buffering (percent);
2433 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2435 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2436 if (state == GST_STATE_PLAYING) {
2437 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2438 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2442 #if defined (HAVE_X) || defined (G_OS_WIN32)
2444 static gulong embed_xid = 0;
2446 /* We set the xid here in response to the prepare-xwindow-id message via a
2447 * bus sync handler because we don't know the actual videosink used from the
2448 * start (as we don't know the pipeline, or bin elements such as autovideosink
2449 * or gconfvideosink may be used which create the actual videosink only once
2450 * the pipeline is started) */
2451 static GstBusSyncReply
2452 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2454 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
2455 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
2456 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2458 g_print ("got prepare-xwindow-id, setting XID %lu\n", embed_xid);
2460 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2461 "force-aspect-ratio")) {
2462 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2465 /* Should have been initialised from main thread before (can't use
2466 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2467 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2468 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2469 * shouldn't be done from a non-GUI thread without explicit locking). */
2470 g_assert (embed_xid != 0);
2472 gst_x_overlay_set_window_handle (GST_X_OVERLAY (element), embed_xid);
2474 return GST_BUS_PASS;
2479 handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
2481 if (state < GST_STATE_PAUSED) {
2482 GtkAllocation allocation;
2483 GdkWindow *window = gtk_widget_get_window (widget);
2486 gtk_widget_get_allocation (widget, &allocation);
2487 cr = gdk_cairo_create (window);
2488 cairo_set_source_rgb (cr, 0, 0, 0);
2489 cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
2497 realize_cb (GtkWidget * widget, gpointer data)
2499 #if GTK_CHECK_VERSION(2,18,0)
2501 GdkWindow *window = gtk_widget_get_window (widget);
2503 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2505 if (!gdk_window_ensure_native (window))
2506 g_error ("Couldn't create native window needed for GstXOverlay!");
2510 #if defined (HAVE_X) || defined (G_OS_WIN32)
2512 GdkWindow *window = gtk_widget_get_window (video_window);
2515 embed_xid = GDK_WINDOW_HWND (window);
2517 embed_xid = GDK_WINDOW_XID (window);
2519 g_print ("Window realize: video window XID = %lu\n", embed_xid);
2525 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2527 message_received (bus, message, data);
2529 /* Set new uri for playerbins and continue playback */
2530 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2531 stop_cb (NULL, NULL);
2532 l = g_list_next (l);
2534 playerbin_set_uri (GST_ELEMENT (data), l->data);
2535 play_cb (NULL, NULL);
2541 msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data)
2544 message_received (bus, message, data);
2548 connect_bus_signals (GstElement * pipeline)
2550 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2553 /* handle prepare-xwindow-id element message synchronously */
2554 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2558 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2559 gst_bus_enable_sync_message_emission (bus);
2561 g_signal_connect (bus, "message::state-changed",
2562 (GCallback) msg_state_changed, pipeline);
2563 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2565 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2568 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2570 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2572 g_signal_connect (bus, "message::error", (GCallback) message_received,
2574 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2576 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2577 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2579 g_signal_connect (bus, "message::element", (GCallback) message_received,
2581 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2583 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2585 // g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done,
2587 g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done,
2589 g_signal_connect (bus, "sync-message::step-done",
2590 (GCallback) msg_sync_step_done, pipeline);
2592 gst_object_unref (bus);
2595 /* Return GList of paths described in location string */
2597 handle_wildcards (const gchar * location)
2600 gchar *path = g_path_get_dirname (location);
2601 gchar *pattern = g_path_get_basename (location);
2602 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2603 GDir *dir = g_dir_open (path, 0, NULL);
2606 g_print ("matching %s from %s\n", pattern, path);
2609 g_print ("opening directory %s failed\n", path);
2613 while ((name = g_dir_read_name (dir)) != NULL) {
2614 if (g_pattern_match_string (pspec, name)) {
2615 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2616 g_print (" found clip %s\n", name);
2622 g_pattern_spec_free (pspec);
2630 delete_event_cb (void)
2632 stop_cb (NULL, NULL);
2637 print_usage (int argc, char **argv)
2641 g_print ("usage: %s <type> <filename>\n", argv[0]);
2642 g_print (" possible types:\n");
2644 for (i = 0; i < NUM_TYPES; i++) {
2645 g_print (" %d = %s\n", i, pipelines[i].name);
2650 main (int argc, char **argv)
2652 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2653 *flagtable, *boxes2, *step;
2654 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2655 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2656 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2657 GtkWidget *rate_label, *volume_label;
2658 GOptionEntry options[] = {
2659 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2660 "Show pad stats", NULL},
2661 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2662 "Seek on elements instead of pads", NULL},
2663 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2664 "Verbose properties", NULL},
2667 GOptionContext *ctx;
2670 if (!g_thread_supported ())
2671 g_thread_init (NULL);
2673 ctx = g_option_context_new ("- test seeking in gsteamer");
2674 g_option_context_add_main_entries (ctx, options, NULL);
2675 g_option_context_add_group (ctx, gst_init_get_option_group ());
2676 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2678 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2679 g_print ("Error initializing: %s\n", err->message);
2683 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2686 print_usage (argc, argv);
2690 pipeline_type = atoi (argv[1]);
2692 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2693 print_usage (argc, argv);
2697 pipeline_spec = argv[2];
2699 if (g_path_is_absolute (pipeline_spec) &&
2700 (g_strrstr (pipeline_spec, "*") != NULL ||
2701 g_strrstr (pipeline_spec, "?") != NULL)) {
2702 paths = handle_wildcards (pipeline_spec);
2704 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2708 g_print ("opening %s failed\n", pipeline_spec);
2714 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2715 g_assert (pipeline);
2717 /* initialize gui elements ... */
2718 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2719 video_window = gtk_drawing_area_new ();
2720 g_signal_connect (video_window, "expose-event",
2721 G_CALLBACK (handle_expose_cb), NULL);
2722 g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL);
2723 gtk_widget_set_double_buffered (video_window, FALSE);
2725 statusbar = gtk_statusbar_new ();
2726 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2727 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2728 hbox = gtk_hbox_new (FALSE, 0);
2729 vbox = gtk_vbox_new (FALSE, 0);
2730 flagtable = gtk_table_new (4, 2, FALSE);
2731 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2733 /* media controls */
2734 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2735 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2736 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2739 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2740 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2741 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2742 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2743 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2744 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2745 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2746 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2747 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2748 rate_label = gtk_label_new ("Rate");
2750 gtk_widget_set_tooltip_text (accurate_checkbox,
2751 "accurate position is requested, this might be considerably slower for some formats");
2752 gtk_widget_set_tooltip_text (key_checkbox,
2753 "seek to the nearest keyframe. This might be faster but less accurate");
2754 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2755 gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking");
2756 gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, "
2757 "negative value trigger reverse playback");
2758 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2759 gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking");
2760 gtk_widget_set_tooltip_text (skip_checkbox,
2761 "Skip frames while playing at high frame rates");
2763 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2764 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2766 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2772 step = gtk_expander_new ("step options");
2773 hbox = gtk_hbox_new (FALSE, 0);
2775 format_combo = gtk_combo_box_text_new ();
2776 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2778 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2780 gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0);
2781 gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2);
2783 step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2784 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0);
2785 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0);
2786 gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE,
2789 step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2790 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3);
2791 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0);
2792 gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2);
2794 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2795 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2796 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2798 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2802 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2803 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2804 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2805 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2808 shuttle_adjustment =
2809 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2810 shuttle_hscale = gtk_hscale_new (shuttle_adjustment);
2811 gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2);
2812 gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP);
2813 g_signal_connect (shuttle_hscale, "value_changed",
2814 G_CALLBACK (shuttle_value_changed), pipeline);
2815 g_signal_connect (shuttle_hscale, "format_value",
2816 G_CALLBACK (shuttle_format_value), pipeline);
2818 gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2);
2820 gtk_container_add (GTK_CONTAINER (step), hbox);
2825 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, N_GRAD, 0.1, 1.0, 1.0));
2826 hscale = gtk_hscale_new (adjustment);
2827 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2828 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
2829 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2830 gtk_range_set_fill_level (GTK_RANGE (hscale), N_GRAD);
2832 g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek),
2834 g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek),
2836 g_signal_connect (hscale, "format_value", G_CALLBACK (format_value),
2839 if (pipeline_type == 16) {
2840 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2841 panel = gtk_hbox_new (FALSE, 0);
2842 video_combo = gtk_combo_box_text_new ();
2843 audio_combo = gtk_combo_box_text_new ();
2844 text_combo = gtk_combo_box_text_new ();
2845 gtk_widget_set_sensitive (video_combo, FALSE);
2846 gtk_widget_set_sensitive (audio_combo, FALSE);
2847 gtk_widget_set_sensitive (text_combo, FALSE);
2848 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2849 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2850 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2851 g_signal_connect (G_OBJECT (video_combo), "changed",
2852 G_CALLBACK (video_combo_cb), pipeline);
2853 g_signal_connect (G_OBJECT (audio_combo), "changed",
2854 G_CALLBACK (audio_combo_cb), pipeline);
2855 g_signal_connect (G_OBJECT (text_combo), "changed",
2856 G_CALLBACK (text_combo_cb), pipeline);
2857 /* playbin2 panel for flag checkboxes and volume/mute */
2858 boxes = gtk_hbox_new (FALSE, 0);
2859 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2860 video_checkbox = gtk_check_button_new_with_label ("Video");
2861 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2862 text_checkbox = gtk_check_button_new_with_label ("Text");
2863 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2864 download_checkbox = gtk_check_button_new_with_label ("Download");
2865 buffer_checkbox = gtk_check_button_new_with_label ("Buffer");
2866 volume_label = gtk_label_new ("Volume");
2867 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2868 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2869 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2870 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2871 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2872 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2873 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2874 gtk_box_pack_start (GTK_BOX (boxes), download_checkbox, TRUE, TRUE, 2);
2875 gtk_box_pack_start (GTK_BOX (boxes), buffer_checkbox, TRUE, TRUE, 2);
2876 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
2877 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2878 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2879 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2880 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2881 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2882 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2883 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
2884 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffer_checkbox), FALSE);
2885 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2886 G_CALLBACK (vis_toggle_cb), pipeline);
2887 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2888 G_CALLBACK (audio_toggle_cb), pipeline);
2889 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2890 G_CALLBACK (video_toggle_cb), pipeline);
2891 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2892 G_CALLBACK (text_toggle_cb), pipeline);
2893 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2894 G_CALLBACK (mute_toggle_cb), pipeline);
2895 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
2896 G_CALLBACK (download_toggle_cb), pipeline);
2897 g_signal_connect (G_OBJECT (buffer_checkbox), "toggled",
2898 G_CALLBACK (buffer_toggle_cb), pipeline);
2899 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2900 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2901 /* playbin2 panel for snapshot */
2902 boxes2 = gtk_hbox_new (FALSE, 0);
2903 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2904 gtk_widget_set_tooltip_text (shot_button,
2905 "save a screenshot .png in the current directory");
2906 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2908 vis_combo = gtk_combo_box_text_new ();
2909 g_signal_connect (G_OBJECT (vis_combo), "changed",
2910 G_CALLBACK (vis_combo_cb), pipeline);
2911 gtk_widget_set_sensitive (vis_combo, FALSE);
2912 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2913 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2915 /* fill the vis combo box and the array of factories */
2916 init_visualization_features ();
2918 panel = boxes = boxes2 = NULL;
2921 /* do the packing stuff ... */
2922 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2923 /* FIXME: can we avoid this for audio only? */
2924 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
2925 DEFAULT_VIDEO_HEIGHT);
2926 gtk_container_add (GTK_CONTAINER (window), vbox);
2927 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
2928 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2929 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2930 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2931 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2932 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2933 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2935 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2936 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2937 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2938 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2939 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2941 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2942 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2943 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2945 if (panel && boxes && boxes2) {
2946 expander = gtk_expander_new ("playbin2 options");
2947 pb2vbox = gtk_vbox_new (FALSE, 0);
2948 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2949 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2950 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2951 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2952 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2954 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2955 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
2956 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
2958 /* connect things ... */
2959 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
2961 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
2963 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
2965 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2966 G_CALLBACK (accurate_toggle_cb), pipeline);
2967 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2968 G_CALLBACK (key_toggle_cb), pipeline);
2969 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2970 G_CALLBACK (loop_toggle_cb), pipeline);
2971 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2972 G_CALLBACK (flush_toggle_cb), pipeline);
2973 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2974 G_CALLBACK (scrub_toggle_cb), pipeline);
2975 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2976 G_CALLBACK (play_scrub_toggle_cb), pipeline);
2977 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2978 G_CALLBACK (skip_toggle_cb), pipeline);
2979 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
2980 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
2982 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
2985 gtk_widget_show_all (window);
2987 /* realize window now so that the video window gets created and we can
2988 * obtain its XID before the pipeline is started up and the videosink
2989 * asks for the XID of the window to render onto */
2990 gtk_widget_realize (window);
2993 /* we should have the XID now */
2994 g_assert (embed_xid != 0);
2998 g_signal_connect (pipeline, "deep_notify",
2999 G_CALLBACK (gst_object_default_deep_notify), NULL);
3002 connect_bus_signals (pipeline);
3005 g_print ("NULL pipeline\n");
3006 gst_element_set_state (pipeline, GST_STATE_NULL);
3008 g_print ("free pipeline\n");
3009 gst_object_unref (pipeline);
3011 g_list_foreach (paths, (GFunc) g_free, NULL);
3012 g_list_free (paths);