3 * seek.c: seeking sample application
5 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
6 * 2006 Stefan Kost <ensonic@users.sf.net>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
38 #include <gst/interfaces/xoverlay.h>
40 #if (!GTK_CHECK_VERSION(2, 23, 0) || GTK_CHECK_VERSION(2, 90, 0)) && !GTK_CHECK_VERSION(2, 91, 1)
41 #define gtk_combo_box_text_new gtk_combo_box_new_text
42 #define gtk_combo_box_text_append_text gtk_combo_box_append_text
43 #define gtk_combo_box_text_remove gtk_combo_box_remove_text
44 #define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX
47 GST_DEBUG_CATEGORY_STATIC (seek_debug);
48 #define GST_CAT_DEFAULT (seek_debug)
50 #if !GTK_CHECK_VERSION (2, 17, 7)
52 gtk_widget_get_allocation (GtkWidget * w, GtkAllocation * a)
60 //#define SOURCE "filesrc"
61 #define SOURCE "gnomevfssrc"
63 #define ASINK "alsasink"
64 //#define ASINK "osssink"
66 #define VSINK "xvimagesink"
67 //#define VSINK "sdlvideosink"
68 //#define VSINK "ximagesink"
69 //#define VSINK "aasink"
70 //#define VSINK "cacasink"
72 #define FILL_INTERVAL 100
73 //#define UPDATE_INTERVAL 500
74 //#define UPDATE_INTERVAL 100
75 #define UPDATE_INTERVAL 40
77 /* number of milliseconds to play for after a seek */
78 #define SCRUB_TIME 100
80 /* timeout for gst_element_get_state() after a seek */
81 #define SEEK_TIMEOUT 40 * GST_MSECOND
83 #define DEFAULT_VIDEO_HEIGHT 300
85 /* the state to go to when stop is pressed */
86 #define STOP_STATE GST_STATE_READY
90 static GList *seekable_pads = NULL;
91 static GList *rate_pads = NULL;
92 static GList *seekable_elements = NULL;
94 static gboolean accurate_seek = FALSE;
95 static gboolean keyframe_seek = FALSE;
96 static gboolean loop_seek = FALSE;
97 static gboolean flush_seek = TRUE;
98 static gboolean scrub = TRUE;
99 static gboolean play_scrub = FALSE;
100 static gboolean skip_seek = FALSE;
101 static gdouble rate = 1.0;
103 static GstElement *pipeline;
104 static gint pipeline_type;
105 static const gchar *pipeline_spec;
106 static gint64 position = -1;
107 static gint64 duration = -1;
108 static GtkAdjustment *adjustment;
109 static GtkWidget *hscale, *statusbar;
110 static guint status_id = 0;
111 static gboolean stats = FALSE;
112 static gboolean elem_seek = FALSE;
113 static gboolean verbose = FALSE;
115 static gboolean is_live = FALSE;
116 static gboolean buffering = FALSE;
117 static GstBufferingMode mode;
118 static gint64 buffering_left;
119 static GstState state = GST_STATE_NULL;
120 static guint update_id = 0;
121 static guint seek_timeout_id = 0;
122 static gulong changed_id;
123 static guint fill_id = 0;
125 static gint n_video = 0, n_audio = 0, n_text = 0;
126 static gboolean need_streams = TRUE;
127 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
128 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
129 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
130 static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
131 static GtkWidget *buffer_checkbox, *rate_spinbutton;
133 static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
135 static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
136 static GtkWidget *shuttle_checkbox, *step_button;
137 static GtkWidget *shuttle_hscale;
138 static GtkAdjustment *shuttle_adjustment;
140 static GList *paths = NULL, *l = NULL;
142 /* we keep an array of the visualisation entries so that we can easily switch
143 * with the combo box index. */
146 GstElementFactory *factory;
149 static GArray *vis_entries;
151 static void clear_streams (GstElement * pipeline);
152 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
155 /* pipeline construction */
159 const gchar *padname;
166 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
168 GstElement *element = gst_element_factory_make (type, name);
171 g_warning ("Failed to create element %s of type %s", name, type);
178 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
181 dyn_link *connect = (dyn_link *) data;
183 padname = gst_pad_get_name (newpad);
185 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
187 gst_bin_add (GST_BIN (pipeline), connect->bin);
188 gst_pad_link (newpad, connect->target);
190 //seekable_pads = g_list_prepend (seekable_pads, newpad);
191 rate_pads = g_list_prepend (rate_pads, newpad);
197 setup_dynamic_link (GstElement * element, const gchar * padname,
198 GstPad * target, GstElement * bin)
202 connect = g_new0 (dyn_link, 1);
203 connect->padname = g_strdup (padname);
204 connect->target = target;
207 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
212 make_mod_pipeline (const gchar * location)
214 GstElement *pipeline;
215 GstElement *src, *decoder, *audiosink;
218 pipeline = gst_pipeline_new ("app");
220 src = gst_element_factory_make_or_warn (SOURCE, "src");
221 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
222 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
223 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
225 g_object_set (G_OBJECT (src), "location", location, NULL);
227 gst_bin_add (GST_BIN (pipeline), src);
228 gst_bin_add (GST_BIN (pipeline), decoder);
229 gst_bin_add (GST_BIN (pipeline), audiosink);
231 gst_element_link (src, decoder);
232 gst_element_link (decoder, audiosink);
234 seekable = gst_element_get_static_pad (decoder, "src");
235 seekable_pads = g_list_prepend (seekable_pads, seekable);
236 rate_pads = g_list_prepend (rate_pads, seekable);
238 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
244 make_dv_pipeline (const gchar * location)
246 GstElement *pipeline;
247 GstElement *src, *demux, *decoder, *audiosink, *videosink;
248 GstElement *a_queue, *v_queue;
251 pipeline = gst_pipeline_new ("app");
253 src = gst_element_factory_make_or_warn (SOURCE, "src");
254 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
255 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
256 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
257 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
258 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
259 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
261 g_object_set (G_OBJECT (src), "location", location, NULL);
263 gst_bin_add (GST_BIN (pipeline), src);
264 gst_bin_add (GST_BIN (pipeline), demux);
265 gst_bin_add (GST_BIN (pipeline), a_queue);
266 gst_bin_add (GST_BIN (pipeline), audiosink);
267 gst_bin_add (GST_BIN (pipeline), v_queue);
268 gst_bin_add (GST_BIN (pipeline), decoder);
269 gst_bin_add (GST_BIN (pipeline), videosink);
271 gst_element_link (src, demux);
272 gst_element_link (a_queue, audiosink);
273 gst_element_link (v_queue, decoder);
274 gst_element_link (decoder, videosink);
276 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
278 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
281 seekable = gst_element_get_static_pad (decoder, "src");
282 seekable_pads = g_list_prepend (seekable_pads, seekable);
283 rate_pads = g_list_prepend (rate_pads, seekable);
289 make_wav_pipeline (const gchar * location)
291 GstElement *pipeline;
292 GstElement *src, *decoder, *audiosink;
294 pipeline = gst_pipeline_new ("app");
296 src = gst_element_factory_make_or_warn (SOURCE, "src");
297 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
298 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
300 g_object_set (G_OBJECT (src), "location", location, NULL);
302 gst_bin_add (GST_BIN (pipeline), src);
303 gst_bin_add (GST_BIN (pipeline), decoder);
304 gst_bin_add (GST_BIN (pipeline), audiosink);
306 gst_element_link (src, decoder);
308 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
311 seekable_elements = g_list_prepend (seekable_elements, audiosink);
313 /* force element seeking on this pipeline */
320 make_flac_pipeline (const gchar * location)
322 GstElement *pipeline;
323 GstElement *src, *decoder, *audiosink;
326 pipeline = gst_pipeline_new ("app");
328 src = gst_element_factory_make_or_warn (SOURCE, "src");
329 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
330 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
331 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
333 g_object_set (G_OBJECT (src), "location", location, NULL);
335 gst_bin_add (GST_BIN (pipeline), src);
336 gst_bin_add (GST_BIN (pipeline), decoder);
337 gst_bin_add (GST_BIN (pipeline), audiosink);
339 gst_element_link (src, decoder);
340 gst_element_link (decoder, audiosink);
342 seekable = gst_element_get_static_pad (decoder, "src");
343 seekable_pads = g_list_prepend (seekable_pads, seekable);
344 rate_pads = g_list_prepend (rate_pads, seekable);
346 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
352 make_sid_pipeline (const gchar * location)
354 GstElement *pipeline;
355 GstElement *src, *decoder, *audiosink;
358 pipeline = gst_pipeline_new ("app");
360 src = gst_element_factory_make_or_warn (SOURCE, "src");
361 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
362 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
363 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
365 g_object_set (G_OBJECT (src), "location", location, NULL);
367 gst_bin_add (GST_BIN (pipeline), src);
368 gst_bin_add (GST_BIN (pipeline), decoder);
369 gst_bin_add (GST_BIN (pipeline), audiosink);
371 gst_element_link (src, decoder);
372 gst_element_link (decoder, audiosink);
374 seekable = gst_element_get_static_pad (decoder, "src");
375 seekable_pads = g_list_prepend (seekable_pads, seekable);
376 rate_pads = g_list_prepend (rate_pads, seekable);
378 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
384 make_parse_pipeline (const gchar * location)
386 GstElement *pipeline;
387 GstElement *src, *parser, *fakesink;
390 pipeline = gst_pipeline_new ("app");
392 src = gst_element_factory_make_or_warn (SOURCE, "src");
393 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
394 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
395 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
396 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
398 g_object_set (G_OBJECT (src), "location", location, NULL);
400 gst_bin_add (GST_BIN (pipeline), src);
401 gst_bin_add (GST_BIN (pipeline), parser);
402 gst_bin_add (GST_BIN (pipeline), fakesink);
404 gst_element_link (src, parser);
405 gst_element_link (parser, fakesink);
407 seekable = gst_element_get_static_pad (parser, "src");
408 seekable_pads = g_list_prepend (seekable_pads, seekable);
409 rate_pads = g_list_prepend (rate_pads, seekable);
411 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
417 make_vorbis_pipeline (const gchar * location)
419 GstElement *pipeline, *audio_bin;
420 GstElement *src, *demux, *decoder, *convert, *audiosink;
421 GstPad *pad, *seekable;
423 pipeline = gst_pipeline_new ("app");
425 src = gst_element_factory_make_or_warn (SOURCE, "src");
426 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
427 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
428 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
429 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
430 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
432 g_object_set (G_OBJECT (src), "location", location, NULL);
434 audio_bin = gst_bin_new ("a_decoder_bin");
436 gst_bin_add (GST_BIN (pipeline), src);
437 gst_bin_add (GST_BIN (pipeline), demux);
438 gst_bin_add (GST_BIN (audio_bin), decoder);
439 gst_bin_add (GST_BIN (audio_bin), convert);
440 gst_bin_add (GST_BIN (audio_bin), audiosink);
441 gst_bin_add (GST_BIN (pipeline), audio_bin);
443 gst_element_link (src, demux);
444 gst_element_link (decoder, convert);
445 gst_element_link (convert, audiosink);
447 pad = gst_element_get_static_pad (decoder, "sink");
448 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
449 gst_object_unref (pad);
451 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
454 seekable = gst_element_get_static_pad (decoder, "src");
455 seekable_pads = g_list_prepend (seekable_pads, seekable);
456 rate_pads = g_list_prepend (rate_pads, seekable);
458 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
464 make_theora_pipeline (const gchar * location)
466 GstElement *pipeline, *video_bin;
467 GstElement *src, *demux, *decoder, *convert, *videosink;
468 GstPad *pad, *seekable;
470 pipeline = gst_pipeline_new ("app");
472 src = gst_element_factory_make_or_warn (SOURCE, "src");
473 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
474 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
475 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
476 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
478 g_object_set (G_OBJECT (src), "location", location, NULL);
480 video_bin = gst_bin_new ("v_decoder_bin");
482 gst_bin_add (GST_BIN (pipeline), src);
483 gst_bin_add (GST_BIN (pipeline), demux);
484 gst_bin_add (GST_BIN (video_bin), decoder);
485 gst_bin_add (GST_BIN (video_bin), convert);
486 gst_bin_add (GST_BIN (video_bin), videosink);
487 gst_bin_add (GST_BIN (pipeline), video_bin);
489 gst_element_link (src, demux);
490 gst_element_link (decoder, convert);
491 gst_element_link (convert, videosink);
493 pad = gst_element_get_static_pad (decoder, "sink");
494 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
495 gst_object_unref (pad);
497 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
500 seekable = gst_element_get_static_pad (decoder, "src");
501 seekable_pads = g_list_prepend (seekable_pads, seekable);
502 rate_pads = g_list_prepend (rate_pads, seekable);
504 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
510 make_vorbis_theora_pipeline (const gchar * location)
512 GstElement *pipeline, *audio_bin, *video_bin;
513 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
514 GstElement *audiosink, *videosink;
515 GstElement *a_queue, *v_queue, *v_scale;
519 pipeline = gst_pipeline_new ("app");
521 src = gst_element_factory_make_or_warn (SOURCE, "src");
522 g_object_set (G_OBJECT (src), "location", location, NULL);
524 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
526 gst_bin_add (GST_BIN (pipeline), src);
527 gst_bin_add (GST_BIN (pipeline), demux);
528 gst_element_link (src, demux);
530 audio_bin = gst_bin_new ("a_decoder_bin");
531 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
532 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
533 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
534 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
536 gst_bin_add (GST_BIN (pipeline), audio_bin);
538 gst_bin_add (GST_BIN (audio_bin), a_queue);
539 gst_bin_add (GST_BIN (audio_bin), a_decoder);
540 gst_bin_add (GST_BIN (audio_bin), a_convert);
541 gst_bin_add (GST_BIN (audio_bin), audiosink);
543 gst_element_link (a_queue, a_decoder);
544 gst_element_link (a_decoder, a_convert);
545 gst_element_link (a_convert, audiosink);
547 pad = gst_element_get_static_pad (a_queue, "sink");
548 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
549 gst_object_unref (pad);
551 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
554 video_bin = gst_bin_new ("v_decoder_bin");
555 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
556 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
558 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
559 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
560 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
562 gst_bin_add (GST_BIN (pipeline), video_bin);
564 gst_bin_add (GST_BIN (video_bin), v_queue);
565 gst_bin_add (GST_BIN (video_bin), v_decoder);
566 gst_bin_add (GST_BIN (video_bin), v_convert);
567 gst_bin_add (GST_BIN (video_bin), v_scale);
568 gst_bin_add (GST_BIN (video_bin), videosink);
570 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
573 pad = gst_element_get_static_pad (v_queue, "sink");
574 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
575 gst_object_unref (pad);
577 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
580 seekable = gst_element_get_static_pad (a_decoder, "src");
581 seekable_pads = g_list_prepend (seekable_pads, seekable);
582 rate_pads = g_list_prepend (rate_pads, seekable);
584 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
591 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
593 GstElement *pipeline, *audio_bin, *video_bin;
594 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
595 GstElement *audiosink, *videosink;
596 GstElement *a_queue, *v_queue;
597 GstPad *seekable, *pad;
599 pipeline = gst_pipeline_new ("app");
601 src = gst_element_factory_make_or_warn (SOURCE, "src");
602 g_object_set (G_OBJECT (src), "location", location, NULL);
604 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
606 gst_bin_add (GST_BIN (pipeline), src);
607 gst_bin_add (GST_BIN (pipeline), demux);
608 gst_element_link (src, demux);
610 audio_bin = gst_bin_new ("a_decoder_bin");
611 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
612 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
613 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
614 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
616 gst_bin_add (GST_BIN (audio_bin), a_queue);
617 gst_bin_add (GST_BIN (audio_bin), a_decoder);
618 gst_bin_add (GST_BIN (audio_bin), a_convert);
619 gst_bin_add (GST_BIN (audio_bin), audiosink);
621 gst_element_link (a_queue, a_decoder);
622 gst_element_link (a_decoder, a_convert);
623 gst_element_link (a_convert, audiosink);
625 gst_bin_add (GST_BIN (pipeline), audio_bin);
627 pad = gst_element_get_static_pad (a_queue, "sink");
628 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
629 gst_object_unref (pad);
631 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
634 video_bin = gst_bin_new ("v_decoder_bin");
635 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
636 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
638 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
639 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
641 gst_bin_add (GST_BIN (video_bin), v_queue);
642 gst_bin_add (GST_BIN (video_bin), v_decoder);
643 gst_bin_add (GST_BIN (video_bin), v_convert);
644 gst_bin_add (GST_BIN (video_bin), videosink);
646 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
648 gst_bin_add (GST_BIN (pipeline), video_bin);
650 pad = gst_element_get_static_pad (v_queue, "sink");
651 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
652 gst_object_unref (pad);
654 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
657 seekable = gst_element_get_static_pad (a_decoder, "src");
658 seekable_pads = g_list_prepend (seekable_pads, seekable);
659 rate_pads = g_list_prepend (rate_pads, seekable);
661 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
668 make_mp3_pipeline (const gchar * location)
670 GstElement *pipeline;
671 GstElement *src, *parser, *decoder, *audiosink, *queue;
674 pipeline = gst_pipeline_new ("app");
676 src = gst_element_factory_make_or_warn (SOURCE, "src");
677 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
678 decoder = gst_element_factory_make_or_warn ("mad", "dec");
679 queue = gst_element_factory_make_or_warn ("queue", "queue");
680 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
682 seekable_elements = g_list_prepend (seekable_elements, audiosink);
684 g_object_set (G_OBJECT (src), "location", location, NULL);
685 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
687 gst_bin_add (GST_BIN (pipeline), src);
688 gst_bin_add (GST_BIN (pipeline), parser);
689 gst_bin_add (GST_BIN (pipeline), decoder);
690 gst_bin_add (GST_BIN (pipeline), queue);
691 gst_bin_add (GST_BIN (pipeline), audiosink);
693 gst_element_link (src, parser);
694 gst_element_link (parser, decoder);
695 gst_element_link (decoder, queue);
696 gst_element_link (queue, audiosink);
698 seekable = gst_element_get_static_pad (queue, "src");
699 seekable_pads = g_list_prepend (seekable_pads, seekable);
700 rate_pads = g_list_prepend (rate_pads, seekable);
702 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
708 make_avi_pipeline (const gchar * location)
710 GstElement *pipeline, *audio_bin, *video_bin;
711 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
712 GstElement *a_queue = NULL, *v_queue = NULL;
715 pipeline = gst_pipeline_new ("app");
717 src = gst_element_factory_make_or_warn (SOURCE, "src");
718 g_object_set (G_OBJECT (src), "location", location, NULL);
720 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
721 seekable_elements = g_list_prepend (seekable_elements, demux);
723 gst_bin_add (GST_BIN (pipeline), src);
724 gst_bin_add (GST_BIN (pipeline), demux);
725 gst_element_link (src, demux);
727 audio_bin = gst_bin_new ("a_decoder_bin");
728 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
729 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
730 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
731 gst_element_link (a_decoder, a_queue);
732 gst_element_link (a_queue, audiosink);
733 gst_bin_add (GST_BIN (audio_bin), a_decoder);
734 gst_bin_add (GST_BIN (audio_bin), a_queue);
735 gst_bin_add (GST_BIN (audio_bin), audiosink);
736 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
738 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
741 seekable = gst_element_get_static_pad (a_queue, "src");
742 seekable_pads = g_list_prepend (seekable_pads, seekable);
743 rate_pads = g_list_prepend (rate_pads, seekable);
745 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
748 video_bin = gst_bin_new ("v_decoder_bin");
749 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
750 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
751 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
752 gst_element_link (v_decoder, v_queue);
753 gst_element_link (v_queue, videosink);
754 gst_bin_add (GST_BIN (video_bin), v_decoder);
755 gst_bin_add (GST_BIN (video_bin), v_queue);
756 gst_bin_add (GST_BIN (video_bin), videosink);
758 gst_element_set_state (video_bin, GST_STATE_PAUSED);
760 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
763 seekable = gst_element_get_static_pad (v_queue, "src");
764 seekable_pads = g_list_prepend (seekable_pads, seekable);
765 rate_pads = g_list_prepend (rate_pads, seekable);
767 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
774 make_mpeg_pipeline (const gchar * location)
776 GstElement *pipeline, *audio_bin, *video_bin;
777 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
778 GstElement *audiosink, *videosink;
779 GstElement *a_queue, *v_queue;
783 pipeline = gst_pipeline_new ("app");
785 src = gst_element_factory_make_or_warn (SOURCE, "src");
786 g_object_set (G_OBJECT (src), "location", location, NULL);
788 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
789 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
791 gst_bin_add (GST_BIN (pipeline), src);
792 gst_bin_add (GST_BIN (pipeline), demux);
793 gst_element_link (src, demux);
795 audio_bin = gst_bin_new ("a_decoder_bin");
796 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
797 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
798 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
799 gst_bin_add (GST_BIN (audio_bin), a_decoder);
800 gst_bin_add (GST_BIN (audio_bin), a_queue);
801 gst_bin_add (GST_BIN (audio_bin), audiosink);
803 gst_element_link (a_decoder, a_queue);
804 gst_element_link (a_queue, audiosink);
806 gst_bin_add (GST_BIN (pipeline), audio_bin);
808 pad = gst_element_get_static_pad (a_decoder, "sink");
809 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
810 gst_object_unref (pad);
812 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
815 video_bin = gst_bin_new ("v_decoder_bin");
816 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
817 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
818 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
819 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
821 gst_bin_add (GST_BIN (video_bin), v_decoder);
822 gst_bin_add (GST_BIN (video_bin), v_queue);
823 gst_bin_add (GST_BIN (video_bin), v_filter);
824 gst_bin_add (GST_BIN (video_bin), videosink);
826 gst_element_link (v_decoder, v_queue);
827 gst_element_link (v_queue, v_filter);
828 gst_element_link (v_filter, videosink);
830 gst_bin_add (GST_BIN (pipeline), video_bin);
832 pad = gst_element_get_static_pad (v_decoder, "sink");
833 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
834 gst_object_unref (pad);
836 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
839 seekable = gst_element_get_static_pad (v_filter, "src");
840 seekable_pads = g_list_prepend (seekable_pads, seekable);
841 rate_pads = g_list_prepend (rate_pads, seekable);
843 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
850 make_mpegnt_pipeline (const gchar * location)
852 GstElement *pipeline, *audio_bin, *video_bin;
853 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
854 GstElement *audiosink, *videosink;
858 pipeline = gst_pipeline_new ("app");
860 src = gst_element_factory_make_or_warn (SOURCE, "src");
861 g_object_set (G_OBJECT (src), "location", location, NULL);
863 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
864 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
866 seekable_elements = g_list_prepend (seekable_elements, demux);
868 gst_bin_add (GST_BIN (pipeline), src);
869 gst_bin_add (GST_BIN (pipeline), demux);
870 gst_element_link (src, demux);
872 audio_bin = gst_bin_new ("a_decoder_bin");
873 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
874 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
875 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
876 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
877 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
878 gst_element_link (a_decoder, a_queue);
879 gst_element_link (a_queue, audiosink);
880 gst_bin_add (GST_BIN (audio_bin), a_decoder);
881 gst_bin_add (GST_BIN (audio_bin), a_queue);
882 gst_bin_add (GST_BIN (audio_bin), audiosink);
884 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
887 seekable = gst_element_get_static_pad (a_queue, "src");
888 seekable_pads = g_list_prepend (seekable_pads, seekable);
889 rate_pads = g_list_prepend (rate_pads, seekable);
891 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
894 video_bin = gst_bin_new ("v_decoder_bin");
895 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
896 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
897 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
898 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
900 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
902 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
905 seekable = gst_element_get_static_pad (v_decoder, "src");
906 seekable_pads = g_list_prepend (seekable_pads, seekable);
907 rate_pads = g_list_prepend (rate_pads, seekable);
909 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
916 playerbin_set_uri (GstElement * player, const gchar * location)
920 /* Add "file://" prefix for convenience */
921 if (g_str_has_prefix (location, "/")) {
922 uri = g_strconcat ("file://", location, NULL);
923 g_object_set (G_OBJECT (player), "uri", uri, NULL);
926 g_object_set (G_OBJECT (player), "uri", location, NULL);
931 construct_playerbin (const gchar * name, const gchar * location)
935 player = gst_element_factory_make (name, "player");
938 playerbin_set_uri (player, location);
940 seekable_elements = g_list_prepend (seekable_elements, player);
942 /* force element seeking on this pipeline */
949 make_playerbin_pipeline (const gchar * location)
951 return construct_playerbin ("playbin", location);
955 make_playerbin2_pipeline (const gchar * location)
957 GstElement *pipeline = construct_playerbin ("playbin2", location);
959 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
960 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
965 #ifndef GST_DISABLE_PARSE
967 make_parselaunch_pipeline (const gchar * description)
969 GstElement *pipeline;
970 GError *error = NULL;
972 pipeline = gst_parse_launch (description, &error);
974 seekable_elements = g_list_prepend (seekable_elements, pipeline);
985 GstElement *(*func) (const gchar * location);
989 static Pipeline pipelines[] = {
990 {"mp3", make_mp3_pipeline},
991 {"avi", make_avi_pipeline},
992 {"mpeg1", make_mpeg_pipeline},
993 {"mpegparse", make_parse_pipeline},
994 {"vorbis", make_vorbis_pipeline},
995 {"theora", make_theora_pipeline},
996 {"ogg/v/t", make_vorbis_theora_pipeline},
997 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
998 {"sid", make_sid_pipeline},
999 {"flac", make_flac_pipeline},
1000 {"wav", make_wav_pipeline},
1001 {"mod", make_mod_pipeline},
1002 {"dv", make_dv_pipeline},
1003 {"mpeg1nothreads", make_mpegnt_pipeline},
1004 {"playerbin", make_playerbin_pipeline},
1005 #ifndef GST_DISABLE_PARSE
1006 {"parse-launch", make_parselaunch_pipeline},
1008 {"playerbin2", make_playerbin2_pipeline},
1012 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
1014 /* ui callbacks and helpers */
1017 format_value (GtkScale * scale, gdouble value)
1023 real = value * duration / N_GRAD;
1024 seconds = (gint64) real / GST_SECOND;
1025 subseconds = (gint64) real / (GST_SECOND / N_GRAD);
1027 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1028 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1033 shuttle_format_value (GtkScale * scale, gdouble value)
1035 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
1041 const GstFormat format;
1045 static seek_format seek_formats[] = {
1046 {"tim", GST_FORMAT_TIME},
1047 {"byt", GST_FORMAT_BYTES},
1048 {"buf", GST_FORMAT_BUFFERS},
1049 {"def", GST_FORMAT_DEFAULT},
1053 G_GNUC_UNUSED static void
1056 GList *walk = rate_pads;
1059 GstPad *pad = GST_PAD (walk->data);
1062 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1063 while (seek_formats[i].name) {
1067 format = seek_formats[i].format;
1069 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
1071 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1073 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1078 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1080 walk = g_list_next (walk);
1084 G_GNUC_UNUSED static void
1085 query_positions_elems (void)
1087 GList *walk = seekable_elements;
1090 GstElement *element = GST_ELEMENT (walk->data);
1093 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1094 while (seek_formats[i].name) {
1095 gint64 position, total;
1098 format = seek_formats[i].format;
1100 if (gst_element_query_position (element, &format, &position) &&
1101 gst_element_query_duration (element, &format, &total)) {
1102 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1103 seek_formats[i].name, position, total);
1105 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1110 g_print (" %s\n", GST_ELEMENT_NAME (element));
1112 walk = g_list_next (walk);
1116 G_GNUC_UNUSED static void
1117 query_positions_pads (void)
1119 GList *walk = seekable_pads;
1122 GstPad *pad = GST_PAD (walk->data);
1125 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1126 while (seek_formats[i].name) {
1128 gint64 position, total;
1130 format = seek_formats[i].format;
1132 if (gst_pad_query_position (pad, &format, &position) &&
1133 gst_pad_query_duration (pad, &format, &total)) {
1134 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1135 seek_formats[i].name, position, total);
1137 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1143 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1145 walk = g_list_next (walk);
1149 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1150 gpointer user_data);
1151 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1152 gpointer user_data);
1153 static void seek_cb (GtkWidget * widget);
1156 set_scale (gdouble value)
1158 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1160 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1162 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1163 gtk_adjustment_set_value (adjustment, value);
1164 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1166 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1168 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1170 gtk_widget_queue_draw (hscale);
1174 update_fill (gpointer data)
1177 if (seekable_elements) {
1178 GstElement *element = GST_ELEMENT (seekable_elements->data);
1181 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1182 if (gst_element_query (element, query)) {
1183 gint64 start, stop, buffering_total;
1188 GstBufferingMode mode;
1189 gint avg_in, avg_out;
1190 gint64 buffering_left;
1192 gst_query_parse_buffering_percent (query, &busy, &percent);
1193 gst_query_parse_buffering_range (query, &format, &start, &stop,
1195 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
1198 /* note that we could start the playback when buffering_left < remaining
1200 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
1201 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
1202 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1206 fill = N_GRAD * stop / GST_FORMAT_PERCENT_MAX;
1210 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1212 gst_query_unref (query);
1219 update_scale (gpointer data)
1221 GstFormat format = GST_FORMAT_TIME;
1227 if (seekable_elements) {
1228 GstElement *element = GST_ELEMENT (seekable_elements->data);
1230 gst_element_query_position (element, &format, &position);
1231 gst_element_query_duration (element, &format, &duration);
1234 if (seekable_pads) {
1235 GstPad *pad = GST_PAD (seekable_pads->data);
1237 gst_pad_query_position (pad, &format, &position);
1238 gst_pad_query_duration (pad, &format, &duration);
1244 query_positions_elems ();
1246 query_positions_pads ();
1251 if (position >= duration)
1252 duration = position;
1255 set_scale (position * N_GRAD / duration);
1258 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1259 if (pipeline_type == 16) {
1260 g_object_notify (G_OBJECT (pipeline), "volume");
1266 static void do_seek (GtkWidget * widget);
1267 static void connect_bus_signals (GstElement * pipeline);
1268 static void set_update_scale (gboolean active);
1269 static void set_update_fill (gboolean active);
1272 end_scrub (GtkWidget * widget)
1274 GST_DEBUG ("end scrub, PAUSE");
1275 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1276 seek_timeout_id = 0;
1282 send_event (GstEvent * event)
1284 gboolean res = FALSE;
1287 GList *walk = seekable_pads;
1290 GstPad *seekable = GST_PAD (walk->data);
1292 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1294 gst_event_ref (event);
1295 res = gst_pad_send_event (seekable, event);
1297 walk = g_list_next (walk);
1300 GList *walk = seekable_elements;
1303 GstElement *seekable = GST_ELEMENT (walk->data);
1305 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1307 gst_event_ref (event);
1308 res = gst_element_send_event (seekable, event);
1310 walk = g_list_next (walk);
1313 gst_event_unref (event);
1318 do_seek (GtkWidget * widget)
1321 gboolean res = FALSE;
1325 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / N_GRAD;
1327 GST_DEBUG ("value=%f, real=%" G_GINT64_FORMAT,
1328 gtk_range_get_value (GTK_RANGE (widget)), real);
1332 flags |= GST_SEEK_FLAG_FLUSH;
1334 flags |= GST_SEEK_FLAG_ACCURATE;
1336 flags |= GST_SEEK_FLAG_KEY_UNIT;
1338 flags |= GST_SEEK_FLAG_SEGMENT;
1340 flags |= GST_SEEK_FLAG_SKIP;
1343 s_event = gst_event_new_seek (rate,
1344 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1345 GST_CLOCK_TIME_NONE);
1346 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1347 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1349 s_event = gst_event_new_seek (rate,
1350 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1351 GST_SEEK_TYPE_SET, real);
1352 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1353 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1356 res = send_event (s_event);
1360 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1362 set_update_scale (TRUE);
1365 g_print ("seek failed\n");
1366 set_update_scale (TRUE);
1371 seek_cb (GtkWidget * widget)
1373 /* If the timer hasn't expired yet, then the pipeline is running */
1374 if (play_scrub && seek_timeout_id != 0) {
1375 GST_DEBUG ("do scrub seek, PAUSED");
1376 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1379 GST_DEBUG ("do seek");
1383 GST_DEBUG ("do scrub seek, PLAYING");
1384 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1386 if (seek_timeout_id == 0) {
1388 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1394 set_update_fill (gboolean active)
1396 GST_DEBUG ("fill scale is %d", active);
1401 g_timeout_add (FILL_INTERVAL, (GSourceFunc) update_fill, pipeline);
1405 g_source_remove (fill_id);
1412 set_update_scale (gboolean active)
1415 GST_DEBUG ("update scale is %d", active);
1418 if (update_id == 0) {
1420 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, pipeline);
1424 g_source_remove (update_id);
1431 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1433 if (event->type != GDK_BUTTON_PRESS)
1436 set_update_scale (FALSE);
1438 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1439 GST_DEBUG ("start scrub seek, PAUSE");
1440 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1443 if (changed_id == 0 && flush_seek && scrub) {
1445 g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb),
1453 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1456 g_signal_handler_disconnect (hscale, changed_id);
1460 if (!flush_seek || !scrub) {
1461 GST_DEBUG ("do final seek");
1465 if (seek_timeout_id != 0) {
1466 g_source_remove (seek_timeout_id);
1467 seek_timeout_id = 0;
1468 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1470 if (state == GST_STATE_PAUSED) {
1471 GST_DEBUG ("stop scrub seek, PAUSED");
1472 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1475 if (state == GST_STATE_PLAYING) {
1476 GST_DEBUG ("stop scrub seek, PLAYING");
1477 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1485 play_cb (GtkButton * button, gpointer data)
1487 GstStateChangeReturn ret;
1489 if (state != GST_STATE_PLAYING) {
1490 g_print ("PLAY pipeline\n");
1491 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1493 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1495 case GST_STATE_CHANGE_FAILURE:
1497 case GST_STATE_CHANGE_NO_PREROLL:
1503 state = GST_STATE_PLAYING;
1504 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1511 g_print ("PLAY failed\n");
1512 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1517 pause_cb (GtkButton * button, gpointer data)
1519 g_static_mutex_lock (&state_mutex);
1520 if (state != GST_STATE_PAUSED) {
1521 GstStateChangeReturn ret;
1523 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1524 g_print ("PAUSE pipeline\n");
1525 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1527 case GST_STATE_CHANGE_FAILURE:
1529 case GST_STATE_CHANGE_NO_PREROLL:
1536 state = GST_STATE_PAUSED;
1537 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1539 g_static_mutex_unlock (&state_mutex);
1545 g_static_mutex_unlock (&state_mutex);
1546 g_print ("PAUSE failed\n");
1547 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1552 stop_cb (GtkButton * button, gpointer data)
1554 if (state != STOP_STATE) {
1555 GstStateChangeReturn ret;
1557 g_print ("READY pipeline\n");
1558 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1560 g_static_mutex_lock (&state_mutex);
1561 ret = gst_element_set_state (pipeline, STOP_STATE);
1562 if (ret == GST_STATE_CHANGE_FAILURE)
1566 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1570 set_update_scale (FALSE);
1572 set_update_fill (FALSE);
1574 if (pipeline_type == 16)
1575 clear_streams (pipeline);
1576 g_static_mutex_unlock (&state_mutex);
1579 /* if one uses parse_launch, play, stop and play again it fails as all the
1580 * pads after the demuxer can't be reconnected
1582 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1583 gst_element_set_state (pipeline, GST_STATE_NULL);
1584 gst_object_unref (pipeline);
1586 g_list_free (seekable_elements);
1587 seekable_elements = NULL;
1588 g_list_free (seekable_pads);
1589 seekable_pads = NULL;
1590 g_list_free (rate_pads);
1593 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1594 g_assert (pipeline);
1595 gst_element_set_state (pipeline, STOP_STATE);
1596 connect_bus_signals (pipeline);
1604 g_static_mutex_unlock (&state_mutex);
1605 g_print ("STOP failed\n");
1606 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1611 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1613 accurate_seek = gtk_toggle_button_get_active (button);
1617 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1619 keyframe_seek = gtk_toggle_button_get_active (button);
1623 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1625 loop_seek = gtk_toggle_button_get_active (button);
1626 if (state == GST_STATE_PLAYING) {
1632 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1634 flush_seek = gtk_toggle_button_get_active (button);
1638 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1640 scrub = gtk_toggle_button_get_active (button);
1644 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1646 play_scrub = gtk_toggle_button_get_active (button);
1650 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1652 skip_seek = gtk_toggle_button_get_active (button);
1653 if (state == GST_STATE_PLAYING) {
1659 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1661 gboolean res = FALSE;
1665 rate = gtk_spin_button_get_value (button);
1667 GST_DEBUG ("rate changed to %lf", rate);
1671 flags |= GST_SEEK_FLAG_FLUSH;
1673 flags |= GST_SEEK_FLAG_SEGMENT;
1675 flags |= GST_SEEK_FLAG_ACCURATE;
1677 flags |= GST_SEEK_FLAG_KEY_UNIT;
1679 flags |= GST_SEEK_FLAG_SKIP;
1682 s_event = gst_event_new_seek (rate,
1683 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1684 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1686 s_event = gst_event_new_seek (rate,
1687 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1688 GST_SEEK_TYPE_SET, position);
1691 res = send_event (s_event);
1695 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1698 g_print ("seek failed\n");
1702 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1706 g_object_get (pipeline, "flags", &flags, NULL);
1708 flags |= (1 << num);
1710 flags &= ~(1 << num);
1711 g_object_set (pipeline, "flags", flags, NULL);
1715 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1719 state = gtk_toggle_button_get_active (button);
1720 update_flag (pipeline, 3, state);
1721 gtk_widget_set_sensitive (vis_combo, state);
1725 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1729 state = gtk_toggle_button_get_active (button);
1730 update_flag (pipeline, 1, state);
1731 gtk_widget_set_sensitive (audio_combo, state);
1735 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1739 state = gtk_toggle_button_get_active (button);
1740 update_flag (pipeline, 0, state);
1741 gtk_widget_set_sensitive (video_combo, state);
1745 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1749 state = gtk_toggle_button_get_active (button);
1750 update_flag (pipeline, 2, state);
1751 gtk_widget_set_sensitive (text_combo, state);
1755 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1759 mute = gtk_toggle_button_get_active (button);
1760 g_object_set (pipeline, "mute", mute, NULL);
1764 download_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1768 state = gtk_toggle_button_get_active (button);
1769 update_flag (pipeline, 7, state);
1773 buffer_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1777 state = gtk_toggle_button_get_active (button);
1778 update_flag (pipeline, 8, state);
1782 clear_streams (GstElement * pipeline)
1786 /* remove previous info */
1787 for (i = 0; i < n_video; i++)
1788 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (video_combo), 0);
1789 for (i = 0; i < n_audio; i++)
1790 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (audio_combo), 0);
1791 for (i = 0; i < n_text; i++)
1792 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (text_combo), 0);
1794 n_audio = n_video = n_text = 0;
1795 gtk_widget_set_sensitive (video_combo, FALSE);
1796 gtk_widget_set_sensitive (audio_combo, FALSE);
1797 gtk_widget_set_sensitive (text_combo, FALSE);
1799 need_streams = TRUE;
1803 update_streams (GstPipeline * pipeline)
1807 if (pipeline_type == 16 && need_streams) {
1813 /* remove previous info */
1814 clear_streams (GST_ELEMENT_CAST (pipeline));
1816 /* here we get and update the different streams detected by playbin2 */
1817 g_object_get (pipeline, "n-video", &n_video, NULL);
1818 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1819 g_object_get (pipeline, "n-text", &n_text, NULL);
1821 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1824 for (i = 0; i < n_video; i++) {
1825 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1827 str = gst_structure_to_string ((GstStructure *) tags);
1828 g_print ("video %d: %s\n", i, str);
1831 /* find good name for the label */
1832 name = g_strdup_printf ("video %d", i + 1);
1833 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (video_combo), name);
1836 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1837 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1838 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1841 for (i = 0; i < n_audio; i++) {
1842 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1844 str = gst_structure_to_string ((GstStructure *) tags);
1845 g_print ("audio %d: %s\n", i, str);
1848 /* find good name for the label */
1849 name = g_strdup_printf ("audio %d", i + 1);
1850 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (audio_combo), name);
1853 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1854 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1855 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1858 for (i = 0; i < n_text; i++) {
1859 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1863 const GValue *value;
1865 str = gst_structure_to_string ((GstStructure *) tags);
1866 g_print ("text %d: %s\n", i, str);
1869 /* get the language code if we can */
1870 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1871 if (value && G_VALUE_HOLDS_STRING (value)) {
1872 name = g_strdup_printf ("text %s", g_value_get_string (value));
1875 /* find good name for the label if we didn't use a tag */
1877 name = g_strdup_printf ("text %d", i + 1);
1879 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (text_combo), name);
1882 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1883 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1884 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1886 need_streams = FALSE;
1891 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1895 active = gtk_combo_box_get_active (combo);
1897 g_print ("setting current video track %d\n", active);
1898 g_object_set (pipeline, "current-video", active, NULL);
1902 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1906 active = gtk_combo_box_get_active (combo);
1908 g_print ("setting current audio track %d\n", active);
1909 g_object_set (pipeline, "current-audio", active, NULL);
1913 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1917 active = gtk_combo_box_get_active (combo);
1919 g_print ("setting current text track %d\n", active);
1920 g_object_set (pipeline, "current-text", active, NULL);
1924 filter_features (GstPluginFeature * feature, gpointer data)
1926 GstElementFactory *f;
1928 if (!GST_IS_ELEMENT_FACTORY (feature))
1930 f = GST_ELEMENT_FACTORY (feature);
1931 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1938 init_visualization_features (void)
1942 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1944 list = gst_registry_feature_filter (gst_registry_get_default (),
1945 filter_features, FALSE, NULL);
1947 for (walk = list; walk; walk = g_list_next (walk)) {
1951 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1952 name = gst_element_factory_get_longname (entry.factory);
1954 g_array_append_val (vis_entries, entry);
1955 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (vis_combo), name);
1957 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1961 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1965 GstElement *element;
1967 /* get the selected index and get the factory for this index */
1968 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1969 if (vis_entries->len > 0) {
1970 entry = &g_array_index (vis_entries, VisEntry, index);
1972 /* create an instance of the element from the factory */
1973 element = gst_element_factory_create (entry->factory, NULL);
1977 /* set vis plugin for playbin2 */
1978 g_object_set (pipeline, "vis-plugin", element, NULL);
1983 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1987 volume = gtk_spin_button_get_value (button);
1989 g_object_set (pipeline, "volume", volume, NULL);
1993 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
1995 gdouble cur_volume, new_volume;
1997 g_object_get (pipeline, "volume", &new_volume, NULL);
1998 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
1999 if (fabs (cur_volume - new_volume) > 0.001) {
2000 g_signal_handlers_block_by_func (volume_spinbutton,
2001 volume_spinbutton_changed_cb, pipeline);
2002 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
2003 g_signal_handlers_unblock_by_func (volume_spinbutton,
2004 volume_spinbutton_changed_cb, pipeline);
2009 shot_cb (GtkButton * button, gpointer data)
2014 /* convert to our desired format (RGB24) */
2015 caps = gst_caps_new_simple ("video/x-raw-rgb",
2016 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
2017 /* Note: we don't ask for a specific width/height here, so that
2018 * videoscale can adjust dimensions from a non-1/1 pixel aspect
2019 * ratio to a 1/1 pixel-aspect-ratio */
2020 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
2021 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
2022 "red_mask", G_TYPE_INT, 0xff0000,
2023 "green_mask", G_TYPE_INT, 0x00ff00,
2024 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
2026 /* convert the latest frame to the requested format */
2027 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
2028 gst_caps_unref (caps);
2036 GError *error = NULL;
2038 /* get the snapshot buffer format now. We set the caps on the appsink so
2039 * that it can only be an rgb buffer. The only thing we have not specified
2040 * on the caps is the height, which is dependant on the pixel-aspect-ratio
2041 * of the source material */
2042 caps = GST_BUFFER_CAPS (buffer);
2044 g_warning ("could not get snapshot format\n");
2047 s = gst_caps_get_structure (caps, 0);
2049 /* we need to get the final caps on the buffer to get the size */
2050 res = gst_structure_get_int (s, "width", &width);
2051 res |= gst_structure_get_int (s, "height", &height);
2053 g_warning ("could not get snapshot dimension\n");
2057 /* create pixmap from buffer and save, gstreamer video buffers have a stride
2058 * that is rounded up to the nearest multiple of 4 */
2059 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
2060 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2061 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2063 /* save the pixbuf */
2064 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2067 gst_buffer_unref (buffer);
2071 /* called when the Step button is pressed */
2073 step_cb (GtkButton * button, gpointer data)
2079 gboolean flush, res;
2082 active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo));
2084 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
2085 (step_amount_spinbutton));
2086 rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton));
2091 format = GST_FORMAT_BUFFERS;
2094 format = GST_FORMAT_TIME;
2095 amount *= GST_MSECOND;
2098 format = GST_FORMAT_UNDEFINED;
2102 event = gst_event_new_step (format, amount, rate, flush, FALSE);
2104 res = send_event (event);
2107 g_print ("Sending step event failed\n");
2112 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2114 const GstStructure *s;
2116 s = gst_message_get_structure (message);
2117 g_print ("message from \"%s\" (%s): ",
2118 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2119 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2123 sstr = gst_structure_to_string (s);
2124 g_print ("%s\n", sstr);
2127 g_print ("no message details\n");
2131 static gboolean shuttling = FALSE;
2132 static gdouble shuttle_rate = 0.0;
2133 static gdouble play_rate = 1.0;
2136 do_shuttle (GstElement * element)
2141 duration = 40 * GST_MSECOND;
2145 gst_element_send_event (element,
2146 gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE,
2151 msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element)
2157 gboolean intermediate;
2161 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
2162 &intermediate, &duration, &eos);
2165 g_print ("stepped till EOS\n");
2169 if (g_static_mutex_trylock (&state_mutex)) {
2171 do_shuttle (element);
2172 g_static_mutex_unlock (&state_mutex);
2174 /* ignore step messages that come while we are doing a state change */
2175 g_print ("state change is busy\n");
2180 shuttle_toggled (GtkToggleButton * button, GstElement * element)
2184 active = gtk_toggle_button_get_active (button);
2186 if (active != shuttling) {
2188 g_print ("shuttling %s\n", shuttling ? "active" : "inactive");
2192 pause_cb (NULL, NULL);
2193 gst_element_get_state (element, NULL, NULL, -1);
2199 shuttle_rate_switch (GstElement * element)
2205 if (state == GST_STATE_PLAYING) {
2206 /* pause when we need to */
2207 pause_cb (NULL, NULL);
2208 gst_element_get_state (element, NULL, NULL, -1);
2211 if (play_rate == 1.0)
2216 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate,
2217 GST_TIME_ARGS (position));
2219 flags = GST_SEEK_FLAG_FLUSH;
2220 flags |= GST_SEEK_FLAG_ACCURATE;
2222 if (play_rate >= 0.0) {
2223 s_event = gst_event_new_seek (play_rate,
2224 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
2225 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
2227 s_event = gst_event_new_seek (play_rate,
2228 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2229 GST_SEEK_TYPE_SET, position);
2231 res = send_event (s_event);
2233 gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT);
2235 g_print ("seek failed\n");
2240 shuttle_value_changed (GtkRange * range, GstElement * element)
2244 rate = gtk_adjustment_get_value (shuttle_adjustment);
2247 g_print ("rate 0.0, pause\n");
2248 pause_cb (NULL, NULL);
2249 gst_element_get_state (element, NULL, NULL, -1);
2251 g_print ("rate changed %0.3g\n", rate);
2253 if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) {
2254 shuttle_rate_switch (element);
2257 shuttle_rate = ABS (rate);
2258 if (state != GST_STATE_PLAYING) {
2259 do_shuttle (element);
2260 play_cb (NULL, NULL);
2266 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2268 GST_DEBUG ("async done");
2269 /* when we get ASYNC_DONE we can query position, duration and other
2271 update_scale (pipeline);
2273 /* update the available streams */
2274 update_streams (pipeline);
2278 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2280 const GstStructure *s;
2282 s = gst_message_get_structure (message);
2284 /* We only care about state changed on the pipeline */
2285 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2286 GstState old, new, pending;
2288 gst_message_parse_state_changed (message, &old, &new, &pending);
2290 /* When state of the pipeline changes to paused or playing we start updating scale */
2291 if (new == GST_STATE_PLAYING) {
2292 set_update_scale (TRUE);
2294 set_update_scale (FALSE);
2300 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2307 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2308 gst_message_parse_segment_done (message, &format, &position);
2309 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2312 /* in the segment-done callback we never flush as this would not make sense
2313 * for seamless playback. */
2315 flags |= GST_SEEK_FLAG_SEGMENT;
2317 flags |= GST_SEEK_FLAG_SKIP;
2319 s_event = gst_event_new_seek (rate,
2320 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2321 GST_SEEK_TYPE_SET, duration);
2323 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2324 rate, GST_TIME_ARGS (duration));
2326 res = send_event (s_event);
2328 g_print ("segment seek failed\n");
2331 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2334 do_stream_buffering (gint percent)
2338 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2339 bufstr = g_strdup_printf ("Buffering...%d", percent);
2340 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2343 if (percent == 100) {
2344 /* a 100% message means buffering is done */
2346 /* if the desired state is playing, go back */
2347 if (state == GST_STATE_PLAYING) {
2348 /* no state management needed for live pipelines */
2350 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2351 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2353 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2354 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2357 /* buffering busy */
2358 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2359 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2361 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2362 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2370 do_download_buffering (gint percent)
2372 if (!buffering && percent < 100) {
2377 bufstr = g_strdup_printf ("Downloading...");
2378 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2381 /* once we get a buffering message, we'll do the fill update */
2382 set_update_fill (TRUE);
2384 if (state == GST_STATE_PLAYING && !is_live) {
2385 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2386 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2387 /* user has to manually start the playback */
2388 state = GST_STATE_PAUSED;
2394 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2398 gst_message_parse_buffering (message, &percent);
2400 /* get more stats */
2401 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2405 case GST_BUFFERING_DOWNLOAD:
2406 do_download_buffering (percent);
2408 case GST_BUFFERING_LIVE:
2410 case GST_BUFFERING_TIMESHIFT:
2411 case GST_BUFFERING_STREAM:
2412 do_stream_buffering (percent);
2418 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2420 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2421 if (state == GST_STATE_PLAYING) {
2422 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2423 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2429 static gulong embed_xid = 0;
2431 /* We set the xid here in response to the prepare-xwindow-id message via a
2432 * bus sync handler because we don't know the actual videosink used from the
2433 * start (as we don't know the pipeline, or bin elements such as autovideosink
2434 * or gconfvideosink may be used which create the actual videosink only once
2435 * the pipeline is started) */
2436 static GstBusSyncReply
2437 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2439 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
2440 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
2441 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2443 g_print ("got prepare-xwindow-id, setting XID %lu\n", embed_xid);
2445 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2446 "force-aspect-ratio")) {
2447 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2450 /* Should have been initialised from main thread before (can't use
2451 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2452 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2453 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2454 * shouldn't be done from a non-GUI thread without explicit locking). */
2455 g_assert (embed_xid != 0);
2457 gst_x_overlay_set_window_handle (GST_X_OVERLAY (element), embed_xid);
2459 return GST_BUS_PASS;
2464 handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
2466 if (state < GST_STATE_PAUSED) {
2467 GtkAllocation allocation;
2468 GdkWindow *window = gtk_widget_get_window (widget);
2471 gtk_widget_get_allocation (widget, &allocation);
2472 cr = gdk_cairo_create (window);
2473 cairo_set_source_rgb (cr, 0, 0, 0);
2474 cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
2482 realize_cb (GtkWidget * widget, gpointer data)
2484 #if GTK_CHECK_VERSION(2,18,0)
2486 GdkWindow *window = gtk_widget_get_window (widget);
2488 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2490 if (!gdk_window_ensure_native (window))
2491 g_error ("Couldn't create native window needed for GstXOverlay!");
2497 GdkWindow *window = gtk_widget_get_window (video_window);
2499 embed_xid = GDK_WINDOW_XID (window);
2500 g_print ("Window realize: video window XID = %lu\n", embed_xid);
2506 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2508 message_received (bus, message, data);
2510 /* Set new uri for playerbins and continue playback */
2511 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2512 stop_cb (NULL, NULL);
2513 l = g_list_next (l);
2515 playerbin_set_uri (GST_ELEMENT (data), l->data);
2516 play_cb (NULL, NULL);
2522 msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data)
2525 message_received (bus, message, data);
2529 connect_bus_signals (GstElement * pipeline)
2531 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2534 /* handle prepare-xwindow-id element message synchronously */
2535 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2539 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2540 gst_bus_enable_sync_message_emission (bus);
2542 g_signal_connect (bus, "message::state-changed",
2543 (GCallback) msg_state_changed, pipeline);
2544 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2546 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2549 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2551 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2553 g_signal_connect (bus, "message::error", (GCallback) message_received,
2555 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2557 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2558 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2560 g_signal_connect (bus, "message::element", (GCallback) message_received,
2562 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2564 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2566 // g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done,
2568 g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done,
2570 g_signal_connect (bus, "sync-message::step-done",
2571 (GCallback) msg_sync_step_done, pipeline);
2573 gst_object_unref (bus);
2576 /* Return GList of paths described in location string */
2578 handle_wildcards (const gchar * location)
2581 gchar *path = g_path_get_dirname (location);
2582 gchar *pattern = g_path_get_basename (location);
2583 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2584 GDir *dir = g_dir_open (path, 0, NULL);
2587 g_print ("matching %s from %s\n", pattern, path);
2590 g_print ("opening directory %s failed\n", path);
2594 while ((name = g_dir_read_name (dir)) != NULL) {
2595 if (g_pattern_match_string (pspec, name)) {
2596 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2597 g_print (" found clip %s\n", name);
2603 g_pattern_spec_free (pspec);
2611 delete_event_cb (void)
2613 stop_cb (NULL, NULL);
2618 print_usage (int argc, char **argv)
2622 g_print ("usage: %s <type> <filename>\n", argv[0]);
2623 g_print (" possible types:\n");
2625 for (i = 0; i < NUM_TYPES; i++) {
2626 g_print (" %d = %s\n", i, pipelines[i].name);
2631 main (int argc, char **argv)
2633 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2634 *flagtable, *boxes2, *step;
2635 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2636 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2637 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2638 GtkWidget *rate_label, *volume_label;
2639 GOptionEntry options[] = {
2640 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2641 "Show pad stats", NULL},
2642 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2643 "Seek on elements instead of pads", NULL},
2644 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2645 "Verbose properties", NULL},
2648 GOptionContext *ctx;
2651 if (!g_thread_supported ())
2652 g_thread_init (NULL);
2654 ctx = g_option_context_new ("- test seeking in gsteamer");
2655 g_option_context_add_main_entries (ctx, options, NULL);
2656 g_option_context_add_group (ctx, gst_init_get_option_group ());
2657 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2659 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2660 g_print ("Error initializing: %s\n", err->message);
2664 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2667 print_usage (argc, argv);
2671 pipeline_type = atoi (argv[1]);
2673 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2674 print_usage (argc, argv);
2678 pipeline_spec = argv[2];
2680 if (g_path_is_absolute (pipeline_spec) &&
2681 (g_strrstr (pipeline_spec, "*") != NULL ||
2682 g_strrstr (pipeline_spec, "?") != NULL)) {
2683 paths = handle_wildcards (pipeline_spec);
2685 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2689 g_print ("opening %s failed\n", pipeline_spec);
2695 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2696 g_assert (pipeline);
2698 /* initialize gui elements ... */
2699 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2700 video_window = gtk_drawing_area_new ();
2701 g_signal_connect (video_window, "expose-event",
2702 G_CALLBACK (handle_expose_cb), NULL);
2703 g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL);
2704 gtk_widget_set_double_buffered (video_window, FALSE);
2706 statusbar = gtk_statusbar_new ();
2707 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2708 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2709 hbox = gtk_hbox_new (FALSE, 0);
2710 vbox = gtk_vbox_new (FALSE, 0);
2711 flagtable = gtk_table_new (4, 2, FALSE);
2712 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2714 /* media controls */
2715 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2716 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2717 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2720 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2721 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2722 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2723 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2724 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2725 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2726 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2727 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2728 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2729 rate_label = gtk_label_new ("Rate");
2731 gtk_widget_set_tooltip_text (accurate_checkbox,
2732 "accurate position is requested, this might be considerably slower for some formats");
2733 gtk_widget_set_tooltip_text (key_checkbox,
2734 "seek to the nearest keyframe. This might be faster but less accurate");
2735 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2736 gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking");
2737 gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, "
2738 "negative value trigger reverse playback");
2739 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2740 gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking");
2741 gtk_widget_set_tooltip_text (skip_checkbox,
2742 "Skip frames while playing at high frame rates");
2744 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2745 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2747 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2753 step = gtk_expander_new ("step options");
2754 hbox = gtk_hbox_new (FALSE, 0);
2756 format_combo = gtk_combo_box_text_new ();
2757 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2759 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (format_combo),
2761 gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0);
2762 gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2);
2764 step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2765 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0);
2766 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0);
2767 gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE,
2770 step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2771 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3);
2772 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0);
2773 gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2);
2775 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2776 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2777 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2779 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2783 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2784 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2785 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2786 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2789 shuttle_adjustment =
2790 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2791 shuttle_hscale = gtk_hscale_new (shuttle_adjustment);
2792 gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2);
2793 gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP);
2794 g_signal_connect (shuttle_hscale, "value_changed",
2795 G_CALLBACK (shuttle_value_changed), pipeline);
2796 g_signal_connect (shuttle_hscale, "format_value",
2797 G_CALLBACK (shuttle_format_value), pipeline);
2799 gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2);
2801 gtk_container_add (GTK_CONTAINER (step), hbox);
2806 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, N_GRAD, 0.1, 1.0, 1.0));
2807 hscale = gtk_hscale_new (adjustment);
2808 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2809 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
2810 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2811 gtk_range_set_fill_level (GTK_RANGE (hscale), N_GRAD);
2813 g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek),
2815 g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek),
2817 g_signal_connect (hscale, "format_value", G_CALLBACK (format_value),
2820 if (pipeline_type == 16) {
2821 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2822 panel = gtk_hbox_new (FALSE, 0);
2823 video_combo = gtk_combo_box_text_new ();
2824 audio_combo = gtk_combo_box_text_new ();
2825 text_combo = gtk_combo_box_text_new ();
2826 gtk_widget_set_sensitive (video_combo, FALSE);
2827 gtk_widget_set_sensitive (audio_combo, FALSE);
2828 gtk_widget_set_sensitive (text_combo, FALSE);
2829 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2830 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2831 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2832 g_signal_connect (G_OBJECT (video_combo), "changed",
2833 G_CALLBACK (video_combo_cb), pipeline);
2834 g_signal_connect (G_OBJECT (audio_combo), "changed",
2835 G_CALLBACK (audio_combo_cb), pipeline);
2836 g_signal_connect (G_OBJECT (text_combo), "changed",
2837 G_CALLBACK (text_combo_cb), pipeline);
2838 /* playbin2 panel for flag checkboxes and volume/mute */
2839 boxes = gtk_hbox_new (FALSE, 0);
2840 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2841 video_checkbox = gtk_check_button_new_with_label ("Video");
2842 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2843 text_checkbox = gtk_check_button_new_with_label ("Text");
2844 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2845 download_checkbox = gtk_check_button_new_with_label ("Download");
2846 buffer_checkbox = gtk_check_button_new_with_label ("Buffer");
2847 volume_label = gtk_label_new ("Volume");
2848 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2849 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2850 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2851 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2852 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2853 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2854 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2855 gtk_box_pack_start (GTK_BOX (boxes), download_checkbox, TRUE, TRUE, 2);
2856 gtk_box_pack_start (GTK_BOX (boxes), buffer_checkbox, TRUE, TRUE, 2);
2857 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
2858 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2859 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2860 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2861 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2862 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2863 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2864 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
2865 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffer_checkbox), FALSE);
2866 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2867 G_CALLBACK (vis_toggle_cb), pipeline);
2868 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2869 G_CALLBACK (audio_toggle_cb), pipeline);
2870 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2871 G_CALLBACK (video_toggle_cb), pipeline);
2872 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2873 G_CALLBACK (text_toggle_cb), pipeline);
2874 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2875 G_CALLBACK (mute_toggle_cb), pipeline);
2876 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
2877 G_CALLBACK (download_toggle_cb), pipeline);
2878 g_signal_connect (G_OBJECT (buffer_checkbox), "toggled",
2879 G_CALLBACK (buffer_toggle_cb), pipeline);
2880 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2881 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2882 /* playbin2 panel for snapshot */
2883 boxes2 = gtk_hbox_new (FALSE, 0);
2884 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2885 gtk_widget_set_tooltip_text (shot_button,
2886 "save a screenshot .png in the current directory");
2887 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2889 vis_combo = gtk_combo_box_text_new ();
2890 g_signal_connect (G_OBJECT (vis_combo), "changed",
2891 G_CALLBACK (vis_combo_cb), pipeline);
2892 gtk_widget_set_sensitive (vis_combo, FALSE);
2893 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2894 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2896 /* fill the vis combo box and the array of factories */
2897 init_visualization_features ();
2899 panel = boxes = boxes2 = NULL;
2902 /* do the packing stuff ... */
2903 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2904 /* FIXME: can we avoid this for audio only? */
2905 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
2906 DEFAULT_VIDEO_HEIGHT);
2907 gtk_container_add (GTK_CONTAINER (window), vbox);
2908 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
2909 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2910 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2911 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2912 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2913 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2914 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2916 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2917 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2918 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2919 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2920 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2922 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2923 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2924 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2926 if (panel && boxes && boxes2) {
2927 expander = gtk_expander_new ("playbin2 options");
2928 pb2vbox = gtk_vbox_new (FALSE, 0);
2929 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2930 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2931 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2932 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2933 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2935 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2936 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
2937 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
2939 /* connect things ... */
2940 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
2942 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
2944 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
2946 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2947 G_CALLBACK (accurate_toggle_cb), pipeline);
2948 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2949 G_CALLBACK (key_toggle_cb), pipeline);
2950 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2951 G_CALLBACK (loop_toggle_cb), pipeline);
2952 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2953 G_CALLBACK (flush_toggle_cb), pipeline);
2954 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2955 G_CALLBACK (scrub_toggle_cb), pipeline);
2956 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2957 G_CALLBACK (play_scrub_toggle_cb), pipeline);
2958 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2959 G_CALLBACK (skip_toggle_cb), pipeline);
2960 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
2961 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
2963 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
2966 gtk_widget_show_all (window);
2968 /* realize window now so that the video window gets created and we can
2969 * obtain its XID before the pipeline is started up and the videosink
2970 * asks for the XID of the window to render onto */
2971 gtk_widget_realize (window);
2974 /* we should have the XID now */
2975 g_assert (embed_xid != 0);
2979 g_signal_connect (pipeline, "deep_notify",
2980 G_CALLBACK (gst_object_default_deep_notify), NULL);
2983 connect_bus_signals (pipeline);
2986 g_print ("NULL pipeline\n");
2987 gst_element_set_state (pipeline, GST_STATE_NULL);
2989 g_print ("free pipeline\n");
2990 gst_object_unref (pipeline);
2992 g_list_foreach (paths, (GFunc) g_free, NULL);
2993 g_list_free (paths);