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 GST_DEBUG_CATEGORY_STATIC (seek_debug);
41 #define GST_CAT_DEFAULT (seek_debug)
43 #if !GTK_CHECK_VERSION (2, 17, 7)
45 gtk_widget_get_allocation (GtkWidget * w, GtkAllocation * a)
53 //#define SOURCE "filesrc"
54 #define SOURCE "gnomevfssrc"
56 #define ASINK "alsasink"
57 //#define ASINK "osssink"
59 #define VSINK "xvimagesink"
60 //#define VSINK "sdlvideosink"
61 //#define VSINK "ximagesink"
62 //#define VSINK "aasink"
63 //#define VSINK "cacasink"
65 #define FILL_INTERVAL 100
66 //#define UPDATE_INTERVAL 500
67 //#define UPDATE_INTERVAL 100
68 #define UPDATE_INTERVAL 40
70 /* number of milliseconds to play for after a seek */
71 #define SCRUB_TIME 100
73 /* timeout for gst_element_get_state() after a seek */
74 #define SEEK_TIMEOUT 40 * GST_MSECOND
76 #define DEFAULT_VIDEO_HEIGHT 300
78 /* the state to go to when stop is pressed */
79 #define STOP_STATE GST_STATE_READY
83 static GList *seekable_pads = NULL;
84 static GList *rate_pads = NULL;
85 static GList *seekable_elements = NULL;
87 static gboolean accurate_seek = FALSE;
88 static gboolean keyframe_seek = FALSE;
89 static gboolean loop_seek = FALSE;
90 static gboolean flush_seek = TRUE;
91 static gboolean scrub = TRUE;
92 static gboolean play_scrub = FALSE;
93 static gboolean skip_seek = FALSE;
94 static gdouble rate = 1.0;
96 static GstElement *pipeline;
97 static gint pipeline_type;
98 static const gchar *pipeline_spec;
99 static gint64 position = -1;
100 static gint64 duration = -1;
101 static GtkAdjustment *adjustment;
102 static GtkWidget *hscale, *statusbar;
103 static guint status_id = 0;
104 static gboolean stats = FALSE;
105 static gboolean elem_seek = FALSE;
106 static gboolean verbose = FALSE;
108 static gboolean is_live = FALSE;
109 static gboolean buffering = FALSE;
110 static GstBufferingMode mode;
111 static gint64 buffering_left;
112 static GstState state = GST_STATE_NULL;
113 static guint update_id = 0;
114 static guint seek_timeout_id = 0;
115 static gulong changed_id;
116 static guint fill_id = 0;
118 static gint n_video = 0, n_audio = 0, n_text = 0;
119 static gboolean need_streams = TRUE;
120 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
121 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
122 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
123 static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
124 static GtkWidget *buffer_checkbox, *rate_spinbutton;
126 static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
128 static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
129 static GtkWidget *shuttle_checkbox, *step_button;
130 static GtkWidget *shuttle_hscale;
131 static GtkAdjustment *shuttle_adjustment;
133 static GList *paths = NULL, *l = NULL;
135 /* we keep an array of the visualisation entries so that we can easily switch
136 * with the combo box index. */
139 GstElementFactory *factory;
142 static GArray *vis_entries;
144 static void clear_streams (GstElement * pipeline);
145 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
148 /* pipeline construction */
152 const gchar *padname;
159 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
161 GstElement *element = gst_element_factory_make (type, name);
164 g_warning ("Failed to create element %s of type %s", name, type);
171 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
174 dyn_link *connect = (dyn_link *) data;
176 padname = gst_pad_get_name (newpad);
178 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
180 gst_bin_add (GST_BIN (pipeline), connect->bin);
181 gst_pad_link (newpad, connect->target);
183 //seekable_pads = g_list_prepend (seekable_pads, newpad);
184 rate_pads = g_list_prepend (rate_pads, newpad);
190 setup_dynamic_link (GstElement * element, const gchar * padname,
191 GstPad * target, GstElement * bin)
195 connect = g_new0 (dyn_link, 1);
196 connect->padname = g_strdup (padname);
197 connect->target = target;
200 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
205 make_mod_pipeline (const gchar * location)
207 GstElement *pipeline;
208 GstElement *src, *decoder, *audiosink;
211 pipeline = gst_pipeline_new ("app");
213 src = gst_element_factory_make_or_warn (SOURCE, "src");
214 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
215 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
216 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
218 g_object_set (G_OBJECT (src), "location", location, NULL);
220 gst_bin_add (GST_BIN (pipeline), src);
221 gst_bin_add (GST_BIN (pipeline), decoder);
222 gst_bin_add (GST_BIN (pipeline), audiosink);
224 gst_element_link (src, decoder);
225 gst_element_link (decoder, audiosink);
227 seekable = gst_element_get_static_pad (decoder, "src");
228 seekable_pads = g_list_prepend (seekable_pads, seekable);
229 rate_pads = g_list_prepend (rate_pads, seekable);
231 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
237 make_dv_pipeline (const gchar * location)
239 GstElement *pipeline;
240 GstElement *src, *demux, *decoder, *audiosink, *videosink;
241 GstElement *a_queue, *v_queue;
244 pipeline = gst_pipeline_new ("app");
246 src = gst_element_factory_make_or_warn (SOURCE, "src");
247 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
248 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
249 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
250 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
251 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
252 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
254 g_object_set (G_OBJECT (src), "location", location, NULL);
256 gst_bin_add (GST_BIN (pipeline), src);
257 gst_bin_add (GST_BIN (pipeline), demux);
258 gst_bin_add (GST_BIN (pipeline), a_queue);
259 gst_bin_add (GST_BIN (pipeline), audiosink);
260 gst_bin_add (GST_BIN (pipeline), v_queue);
261 gst_bin_add (GST_BIN (pipeline), decoder);
262 gst_bin_add (GST_BIN (pipeline), videosink);
264 gst_element_link (src, demux);
265 gst_element_link (a_queue, audiosink);
266 gst_element_link (v_queue, decoder);
267 gst_element_link (decoder, videosink);
269 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
271 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
274 seekable = gst_element_get_static_pad (decoder, "src");
275 seekable_pads = g_list_prepend (seekable_pads, seekable);
276 rate_pads = g_list_prepend (rate_pads, seekable);
282 make_wav_pipeline (const gchar * location)
284 GstElement *pipeline;
285 GstElement *src, *decoder, *audiosink;
287 pipeline = gst_pipeline_new ("app");
289 src = gst_element_factory_make_or_warn (SOURCE, "src");
290 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
291 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
293 g_object_set (G_OBJECT (src), "location", location, NULL);
295 gst_bin_add (GST_BIN (pipeline), src);
296 gst_bin_add (GST_BIN (pipeline), decoder);
297 gst_bin_add (GST_BIN (pipeline), audiosink);
299 gst_element_link (src, decoder);
301 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
304 seekable_elements = g_list_prepend (seekable_elements, audiosink);
306 /* force element seeking on this pipeline */
313 make_flac_pipeline (const gchar * location)
315 GstElement *pipeline;
316 GstElement *src, *decoder, *audiosink;
319 pipeline = gst_pipeline_new ("app");
321 src = gst_element_factory_make_or_warn (SOURCE, "src");
322 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
323 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
324 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
326 g_object_set (G_OBJECT (src), "location", location, NULL);
328 gst_bin_add (GST_BIN (pipeline), src);
329 gst_bin_add (GST_BIN (pipeline), decoder);
330 gst_bin_add (GST_BIN (pipeline), audiosink);
332 gst_element_link (src, decoder);
333 gst_element_link (decoder, audiosink);
335 seekable = gst_element_get_static_pad (decoder, "src");
336 seekable_pads = g_list_prepend (seekable_pads, seekable);
337 rate_pads = g_list_prepend (rate_pads, seekable);
339 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
345 make_sid_pipeline (const gchar * location)
347 GstElement *pipeline;
348 GstElement *src, *decoder, *audiosink;
351 pipeline = gst_pipeline_new ("app");
353 src = gst_element_factory_make_or_warn (SOURCE, "src");
354 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
355 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
356 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
358 g_object_set (G_OBJECT (src), "location", location, NULL);
360 gst_bin_add (GST_BIN (pipeline), src);
361 gst_bin_add (GST_BIN (pipeline), decoder);
362 gst_bin_add (GST_BIN (pipeline), audiosink);
364 gst_element_link (src, decoder);
365 gst_element_link (decoder, audiosink);
367 seekable = gst_element_get_static_pad (decoder, "src");
368 seekable_pads = g_list_prepend (seekable_pads, seekable);
369 rate_pads = g_list_prepend (rate_pads, seekable);
371 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
377 make_parse_pipeline (const gchar * location)
379 GstElement *pipeline;
380 GstElement *src, *parser, *fakesink;
383 pipeline = gst_pipeline_new ("app");
385 src = gst_element_factory_make_or_warn (SOURCE, "src");
386 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
387 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
388 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
389 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
391 g_object_set (G_OBJECT (src), "location", location, NULL);
393 gst_bin_add (GST_BIN (pipeline), src);
394 gst_bin_add (GST_BIN (pipeline), parser);
395 gst_bin_add (GST_BIN (pipeline), fakesink);
397 gst_element_link (src, parser);
398 gst_element_link (parser, fakesink);
400 seekable = gst_element_get_static_pad (parser, "src");
401 seekable_pads = g_list_prepend (seekable_pads, seekable);
402 rate_pads = g_list_prepend (rate_pads, seekable);
404 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
410 make_vorbis_pipeline (const gchar * location)
412 GstElement *pipeline, *audio_bin;
413 GstElement *src, *demux, *decoder, *convert, *audiosink;
414 GstPad *pad, *seekable;
416 pipeline = gst_pipeline_new ("app");
418 src = gst_element_factory_make_or_warn (SOURCE, "src");
419 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
420 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
421 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
422 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
423 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
425 g_object_set (G_OBJECT (src), "location", location, NULL);
427 audio_bin = gst_bin_new ("a_decoder_bin");
429 gst_bin_add (GST_BIN (pipeline), src);
430 gst_bin_add (GST_BIN (pipeline), demux);
431 gst_bin_add (GST_BIN (audio_bin), decoder);
432 gst_bin_add (GST_BIN (audio_bin), convert);
433 gst_bin_add (GST_BIN (audio_bin), audiosink);
434 gst_bin_add (GST_BIN (pipeline), audio_bin);
436 gst_element_link (src, demux);
437 gst_element_link (decoder, convert);
438 gst_element_link (convert, audiosink);
440 pad = gst_element_get_static_pad (decoder, "sink");
441 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
442 gst_object_unref (pad);
444 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
447 seekable = gst_element_get_static_pad (decoder, "src");
448 seekable_pads = g_list_prepend (seekable_pads, seekable);
449 rate_pads = g_list_prepend (rate_pads, seekable);
451 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
457 make_theora_pipeline (const gchar * location)
459 GstElement *pipeline, *video_bin;
460 GstElement *src, *demux, *decoder, *convert, *videosink;
461 GstPad *pad, *seekable;
463 pipeline = gst_pipeline_new ("app");
465 src = gst_element_factory_make_or_warn (SOURCE, "src");
466 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
467 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
468 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
469 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
471 g_object_set (G_OBJECT (src), "location", location, NULL);
473 video_bin = gst_bin_new ("v_decoder_bin");
475 gst_bin_add (GST_BIN (pipeline), src);
476 gst_bin_add (GST_BIN (pipeline), demux);
477 gst_bin_add (GST_BIN (video_bin), decoder);
478 gst_bin_add (GST_BIN (video_bin), convert);
479 gst_bin_add (GST_BIN (video_bin), videosink);
480 gst_bin_add (GST_BIN (pipeline), video_bin);
482 gst_element_link (src, demux);
483 gst_element_link (decoder, convert);
484 gst_element_link (convert, videosink);
486 pad = gst_element_get_static_pad (decoder, "sink");
487 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
488 gst_object_unref (pad);
490 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
493 seekable = gst_element_get_static_pad (decoder, "src");
494 seekable_pads = g_list_prepend (seekable_pads, seekable);
495 rate_pads = g_list_prepend (rate_pads, seekable);
497 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
503 make_vorbis_theora_pipeline (const gchar * location)
505 GstElement *pipeline, *audio_bin, *video_bin;
506 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
507 GstElement *audiosink, *videosink;
508 GstElement *a_queue, *v_queue, *v_scale;
512 pipeline = gst_pipeline_new ("app");
514 src = gst_element_factory_make_or_warn (SOURCE, "src");
515 g_object_set (G_OBJECT (src), "location", location, NULL);
517 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
519 gst_bin_add (GST_BIN (pipeline), src);
520 gst_bin_add (GST_BIN (pipeline), demux);
521 gst_element_link (src, demux);
523 audio_bin = gst_bin_new ("a_decoder_bin");
524 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
525 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
526 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
527 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
529 gst_bin_add (GST_BIN (pipeline), audio_bin);
531 gst_bin_add (GST_BIN (audio_bin), a_queue);
532 gst_bin_add (GST_BIN (audio_bin), a_decoder);
533 gst_bin_add (GST_BIN (audio_bin), a_convert);
534 gst_bin_add (GST_BIN (audio_bin), audiosink);
536 gst_element_link (a_queue, a_decoder);
537 gst_element_link (a_decoder, a_convert);
538 gst_element_link (a_convert, audiosink);
540 pad = gst_element_get_static_pad (a_queue, "sink");
541 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
542 gst_object_unref (pad);
544 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
547 video_bin = gst_bin_new ("v_decoder_bin");
548 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
549 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
551 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
552 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
553 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
555 gst_bin_add (GST_BIN (pipeline), video_bin);
557 gst_bin_add (GST_BIN (video_bin), v_queue);
558 gst_bin_add (GST_BIN (video_bin), v_decoder);
559 gst_bin_add (GST_BIN (video_bin), v_convert);
560 gst_bin_add (GST_BIN (video_bin), v_scale);
561 gst_bin_add (GST_BIN (video_bin), videosink);
563 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
566 pad = gst_element_get_static_pad (v_queue, "sink");
567 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
568 gst_object_unref (pad);
570 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
573 seekable = gst_element_get_static_pad (a_decoder, "src");
574 seekable_pads = g_list_prepend (seekable_pads, seekable);
575 rate_pads = g_list_prepend (rate_pads, seekable);
577 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
584 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
586 GstElement *pipeline, *audio_bin, *video_bin;
587 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
588 GstElement *audiosink, *videosink;
589 GstElement *a_queue, *v_queue;
590 GstPad *seekable, *pad;
592 pipeline = gst_pipeline_new ("app");
594 src = gst_element_factory_make_or_warn (SOURCE, "src");
595 g_object_set (G_OBJECT (src), "location", location, NULL);
597 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
599 gst_bin_add (GST_BIN (pipeline), src);
600 gst_bin_add (GST_BIN (pipeline), demux);
601 gst_element_link (src, demux);
603 audio_bin = gst_bin_new ("a_decoder_bin");
604 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
605 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
606 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
607 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
609 gst_bin_add (GST_BIN (audio_bin), a_queue);
610 gst_bin_add (GST_BIN (audio_bin), a_decoder);
611 gst_bin_add (GST_BIN (audio_bin), a_convert);
612 gst_bin_add (GST_BIN (audio_bin), audiosink);
614 gst_element_link (a_queue, a_decoder);
615 gst_element_link (a_decoder, a_convert);
616 gst_element_link (a_convert, audiosink);
618 gst_bin_add (GST_BIN (pipeline), audio_bin);
620 pad = gst_element_get_static_pad (a_queue, "sink");
621 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
622 gst_object_unref (pad);
624 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
627 video_bin = gst_bin_new ("v_decoder_bin");
628 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
629 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
631 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
632 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
634 gst_bin_add (GST_BIN (video_bin), v_queue);
635 gst_bin_add (GST_BIN (video_bin), v_decoder);
636 gst_bin_add (GST_BIN (video_bin), v_convert);
637 gst_bin_add (GST_BIN (video_bin), videosink);
639 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
641 gst_bin_add (GST_BIN (pipeline), video_bin);
643 pad = gst_element_get_static_pad (v_queue, "sink");
644 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
645 gst_object_unref (pad);
647 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
650 seekable = gst_element_get_static_pad (a_decoder, "src");
651 seekable_pads = g_list_prepend (seekable_pads, seekable);
652 rate_pads = g_list_prepend (rate_pads, seekable);
654 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
661 make_mp3_pipeline (const gchar * location)
663 GstElement *pipeline;
664 GstElement *src, *parser, *decoder, *audiosink, *queue;
667 pipeline = gst_pipeline_new ("app");
669 src = gst_element_factory_make_or_warn (SOURCE, "src");
670 parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
671 decoder = gst_element_factory_make_or_warn ("mad", "dec");
672 queue = gst_element_factory_make_or_warn ("queue", "queue");
673 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
675 seekable_elements = g_list_prepend (seekable_elements, audiosink);
677 g_object_set (G_OBJECT (src), "location", location, NULL);
678 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
680 gst_bin_add (GST_BIN (pipeline), src);
681 gst_bin_add (GST_BIN (pipeline), parser);
682 gst_bin_add (GST_BIN (pipeline), decoder);
683 gst_bin_add (GST_BIN (pipeline), queue);
684 gst_bin_add (GST_BIN (pipeline), audiosink);
686 gst_element_link (src, parser);
687 gst_element_link (parser, decoder);
688 gst_element_link (decoder, queue);
689 gst_element_link (queue, audiosink);
691 seekable = gst_element_get_static_pad (queue, "src");
692 seekable_pads = g_list_prepend (seekable_pads, seekable);
693 rate_pads = g_list_prepend (rate_pads, seekable);
695 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
701 make_avi_pipeline (const gchar * location)
703 GstElement *pipeline, *audio_bin, *video_bin;
704 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
705 GstElement *a_queue = NULL, *v_queue = NULL;
708 pipeline = gst_pipeline_new ("app");
710 src = gst_element_factory_make_or_warn (SOURCE, "src");
711 g_object_set (G_OBJECT (src), "location", location, NULL);
713 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
714 seekable_elements = g_list_prepend (seekable_elements, demux);
716 gst_bin_add (GST_BIN (pipeline), src);
717 gst_bin_add (GST_BIN (pipeline), demux);
718 gst_element_link (src, demux);
720 audio_bin = gst_bin_new ("a_decoder_bin");
721 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
722 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
723 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
724 gst_element_link (a_decoder, a_queue);
725 gst_element_link (a_queue, audiosink);
726 gst_bin_add (GST_BIN (audio_bin), a_decoder);
727 gst_bin_add (GST_BIN (audio_bin), a_queue);
728 gst_bin_add (GST_BIN (audio_bin), audiosink);
729 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
731 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
734 seekable = gst_element_get_static_pad (a_queue, "src");
735 seekable_pads = g_list_prepend (seekable_pads, seekable);
736 rate_pads = g_list_prepend (rate_pads, seekable);
738 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
741 video_bin = gst_bin_new ("v_decoder_bin");
742 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
743 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
744 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
745 gst_element_link (v_decoder, v_queue);
746 gst_element_link (v_queue, videosink);
747 gst_bin_add (GST_BIN (video_bin), v_decoder);
748 gst_bin_add (GST_BIN (video_bin), v_queue);
749 gst_bin_add (GST_BIN (video_bin), videosink);
751 gst_element_set_state (video_bin, GST_STATE_PAUSED);
753 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
756 seekable = gst_element_get_static_pad (v_queue, "src");
757 seekable_pads = g_list_prepend (seekable_pads, seekable);
758 rate_pads = g_list_prepend (rate_pads, seekable);
760 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
767 make_mpeg_pipeline (const gchar * location)
769 GstElement *pipeline, *audio_bin, *video_bin;
770 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
771 GstElement *audiosink, *videosink;
772 GstElement *a_queue, *v_queue;
776 pipeline = gst_pipeline_new ("app");
778 src = gst_element_factory_make_or_warn (SOURCE, "src");
779 g_object_set (G_OBJECT (src), "location", location, NULL);
781 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
782 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
784 gst_bin_add (GST_BIN (pipeline), src);
785 gst_bin_add (GST_BIN (pipeline), demux);
786 gst_element_link (src, demux);
788 audio_bin = gst_bin_new ("a_decoder_bin");
789 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
790 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
791 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
792 gst_bin_add (GST_BIN (audio_bin), a_decoder);
793 gst_bin_add (GST_BIN (audio_bin), a_queue);
794 gst_bin_add (GST_BIN (audio_bin), audiosink);
796 gst_element_link (a_decoder, a_queue);
797 gst_element_link (a_queue, audiosink);
799 gst_bin_add (GST_BIN (pipeline), audio_bin);
801 pad = gst_element_get_static_pad (a_decoder, "sink");
802 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
803 gst_object_unref (pad);
805 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
808 video_bin = gst_bin_new ("v_decoder_bin");
809 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
810 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
811 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
812 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
814 gst_bin_add (GST_BIN (video_bin), v_decoder);
815 gst_bin_add (GST_BIN (video_bin), v_queue);
816 gst_bin_add (GST_BIN (video_bin), v_filter);
817 gst_bin_add (GST_BIN (video_bin), videosink);
819 gst_element_link (v_decoder, v_queue);
820 gst_element_link (v_queue, v_filter);
821 gst_element_link (v_filter, videosink);
823 gst_bin_add (GST_BIN (pipeline), video_bin);
825 pad = gst_element_get_static_pad (v_decoder, "sink");
826 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
827 gst_object_unref (pad);
829 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
832 seekable = gst_element_get_static_pad (v_filter, "src");
833 seekable_pads = g_list_prepend (seekable_pads, seekable);
834 rate_pads = g_list_prepend (rate_pads, seekable);
836 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
843 make_mpegnt_pipeline (const gchar * location)
845 GstElement *pipeline, *audio_bin, *video_bin;
846 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
847 GstElement *audiosink, *videosink;
851 pipeline = gst_pipeline_new ("app");
853 src = gst_element_factory_make_or_warn (SOURCE, "src");
854 g_object_set (G_OBJECT (src), "location", location, NULL);
856 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
857 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
859 seekable_elements = g_list_prepend (seekable_elements, demux);
861 gst_bin_add (GST_BIN (pipeline), src);
862 gst_bin_add (GST_BIN (pipeline), demux);
863 gst_element_link (src, demux);
865 audio_bin = gst_bin_new ("a_decoder_bin");
866 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
867 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
868 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
869 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
870 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
871 gst_element_link (a_decoder, a_queue);
872 gst_element_link (a_queue, audiosink);
873 gst_bin_add (GST_BIN (audio_bin), a_decoder);
874 gst_bin_add (GST_BIN (audio_bin), a_queue);
875 gst_bin_add (GST_BIN (audio_bin), audiosink);
877 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
880 seekable = gst_element_get_static_pad (a_queue, "src");
881 seekable_pads = g_list_prepend (seekable_pads, seekable);
882 rate_pads = g_list_prepend (rate_pads, seekable);
884 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
887 video_bin = gst_bin_new ("v_decoder_bin");
888 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
889 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
890 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
891 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
893 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
895 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
898 seekable = gst_element_get_static_pad (v_decoder, "src");
899 seekable_pads = g_list_prepend (seekable_pads, seekable);
900 rate_pads = g_list_prepend (rate_pads, seekable);
902 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
909 playerbin_set_uri (GstElement * player, const gchar * location)
913 /* Add "file://" prefix for convenience */
914 if (g_str_has_prefix (location, "/")) {
915 uri = g_strconcat ("file://", location, NULL);
916 g_object_set (G_OBJECT (player), "uri", uri, NULL);
919 g_object_set (G_OBJECT (player), "uri", location, NULL);
924 construct_playerbin (const gchar * name, const gchar * location)
928 player = gst_element_factory_make (name, "player");
931 playerbin_set_uri (player, location);
933 seekable_elements = g_list_prepend (seekable_elements, player);
935 /* force element seeking on this pipeline */
942 make_playerbin_pipeline (const gchar * location)
944 return construct_playerbin ("playbin", location);
948 make_playerbin2_pipeline (const gchar * location)
950 GstElement *pipeline = construct_playerbin ("playbin2", location);
952 /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */
953 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
958 #ifndef GST_DISABLE_PARSE
960 make_parselaunch_pipeline (const gchar * description)
962 GstElement *pipeline;
963 GError *error = NULL;
965 pipeline = gst_parse_launch (description, &error);
967 seekable_elements = g_list_prepend (seekable_elements, pipeline);
978 GstElement *(*func) (const gchar * location);
982 static Pipeline pipelines[] = {
983 {"mp3", make_mp3_pipeline},
984 {"avi", make_avi_pipeline},
985 {"mpeg1", make_mpeg_pipeline},
986 {"mpegparse", make_parse_pipeline},
987 {"vorbis", make_vorbis_pipeline},
988 {"theora", make_theora_pipeline},
989 {"ogg/v/t", make_vorbis_theora_pipeline},
990 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
991 {"sid", make_sid_pipeline},
992 {"flac", make_flac_pipeline},
993 {"wav", make_wav_pipeline},
994 {"mod", make_mod_pipeline},
995 {"dv", make_dv_pipeline},
996 {"mpeg1nothreads", make_mpegnt_pipeline},
997 {"playerbin", make_playerbin_pipeline},
998 #ifndef GST_DISABLE_PARSE
999 {"parse-launch", make_parselaunch_pipeline},
1001 {"playerbin2", make_playerbin2_pipeline},
1005 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
1007 /* ui callbacks and helpers */
1010 format_value (GtkScale * scale, gdouble value)
1016 real = value * duration / N_GRAD;
1017 seconds = (gint64) real / GST_SECOND;
1018 subseconds = (gint64) real / (GST_SECOND / N_GRAD);
1020 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
1021 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
1026 shuttle_format_value (GtkScale * scale, gdouble value)
1028 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
1034 const GstFormat format;
1038 static seek_format seek_formats[] = {
1039 {"tim", GST_FORMAT_TIME},
1040 {"byt", GST_FORMAT_BYTES},
1041 {"buf", GST_FORMAT_BUFFERS},
1042 {"def", GST_FORMAT_DEFAULT},
1046 G_GNUC_UNUSED static void
1049 GList *walk = rate_pads;
1052 GstPad *pad = GST_PAD (walk->data);
1055 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
1056 while (seek_formats[i].name) {
1060 format = seek_formats[i].format;
1062 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
1064 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1066 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1071 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1073 walk = g_list_next (walk);
1077 G_GNUC_UNUSED static void
1078 query_positions_elems (void)
1080 GList *walk = seekable_elements;
1083 GstElement *element = GST_ELEMENT (walk->data);
1086 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1087 while (seek_formats[i].name) {
1088 gint64 position, total;
1091 format = seek_formats[i].format;
1093 if (gst_element_query_position (element, &format, &position) &&
1094 gst_element_query_duration (element, &format, &total)) {
1095 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1096 seek_formats[i].name, position, total);
1098 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1103 g_print (" %s\n", GST_ELEMENT_NAME (element));
1105 walk = g_list_next (walk);
1109 G_GNUC_UNUSED static void
1110 query_positions_pads (void)
1112 GList *walk = seekable_pads;
1115 GstPad *pad = GST_PAD (walk->data);
1118 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1119 while (seek_formats[i].name) {
1121 gint64 position, total;
1123 format = seek_formats[i].format;
1125 if (gst_pad_query_position (pad, &format, &position) &&
1126 gst_pad_query_duration (pad, &format, &total)) {
1127 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1128 seek_formats[i].name, position, total);
1130 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1136 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1138 walk = g_list_next (walk);
1142 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1143 gpointer user_data);
1144 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1145 gpointer user_data);
1146 static void seek_cb (GtkWidget * widget);
1149 set_scale (gdouble value)
1151 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1153 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1155 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1156 gtk_adjustment_set_value (adjustment, value);
1157 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1159 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1161 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1163 gtk_widget_queue_draw (hscale);
1167 update_fill (gpointer data)
1170 if (seekable_elements) {
1171 GstElement *element = GST_ELEMENT (seekable_elements->data);
1174 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1175 if (gst_element_query (element, query)) {
1176 gint64 start, stop, buffering_total;
1181 GstBufferingMode mode;
1182 gint avg_in, avg_out;
1183 gint64 buffering_left;
1185 gst_query_parse_buffering_percent (query, &busy, &percent);
1186 gst_query_parse_buffering_range (query, &format, &start, &stop,
1188 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
1191 /* note that we could start the playback when buffering_left < remaining
1193 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
1194 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
1195 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1199 fill = N_GRAD * stop / GST_FORMAT_PERCENT_MAX;
1203 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1205 gst_query_unref (query);
1212 update_scale (gpointer data)
1214 GstFormat format = GST_FORMAT_TIME;
1220 if (seekable_elements) {
1221 GstElement *element = GST_ELEMENT (seekable_elements->data);
1223 gst_element_query_position (element, &format, &position);
1224 gst_element_query_duration (element, &format, &duration);
1227 if (seekable_pads) {
1228 GstPad *pad = GST_PAD (seekable_pads->data);
1230 gst_pad_query_position (pad, &format, &position);
1231 gst_pad_query_duration (pad, &format, &duration);
1237 query_positions_elems ();
1239 query_positions_pads ();
1244 if (position >= duration)
1245 duration = position;
1248 set_scale (position * N_GRAD / duration);
1251 /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */
1252 if (pipeline_type == 16) {
1253 g_object_notify (G_OBJECT (pipeline), "volume");
1259 static void do_seek (GtkWidget * widget);
1260 static void connect_bus_signals (GstElement * pipeline);
1261 static void set_update_scale (gboolean active);
1262 static void set_update_fill (gboolean active);
1265 end_scrub (GtkWidget * widget)
1267 GST_DEBUG ("end scrub, PAUSE");
1268 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1269 seek_timeout_id = 0;
1275 send_event (GstEvent * event)
1277 gboolean res = FALSE;
1280 GList *walk = seekable_pads;
1283 GstPad *seekable = GST_PAD (walk->data);
1285 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1287 gst_event_ref (event);
1288 res = gst_pad_send_event (seekable, event);
1290 walk = g_list_next (walk);
1293 GList *walk = seekable_elements;
1296 GstElement *seekable = GST_ELEMENT (walk->data);
1298 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1300 gst_event_ref (event);
1301 res = gst_element_send_event (seekable, event);
1303 walk = g_list_next (walk);
1306 gst_event_unref (event);
1311 do_seek (GtkWidget * widget)
1314 gboolean res = FALSE;
1318 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / N_GRAD;
1320 GST_DEBUG ("value=%f, real=%" G_GINT64_FORMAT,
1321 gtk_range_get_value (GTK_RANGE (widget)), real);
1325 flags |= GST_SEEK_FLAG_FLUSH;
1327 flags |= GST_SEEK_FLAG_ACCURATE;
1329 flags |= GST_SEEK_FLAG_KEY_UNIT;
1331 flags |= GST_SEEK_FLAG_SEGMENT;
1333 flags |= GST_SEEK_FLAG_SKIP;
1336 s_event = gst_event_new_seek (rate,
1337 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
1338 GST_CLOCK_TIME_NONE);
1339 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1340 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1342 s_event = gst_event_new_seek (rate,
1343 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1344 GST_SEEK_TYPE_SET, real);
1345 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1346 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1349 res = send_event (s_event);
1353 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1355 set_update_scale (TRUE);
1358 g_print ("seek failed\n");
1359 set_update_scale (TRUE);
1364 seek_cb (GtkWidget * widget)
1366 /* If the timer hasn't expired yet, then the pipeline is running */
1367 if (play_scrub && seek_timeout_id != 0) {
1368 GST_DEBUG ("do scrub seek, PAUSED");
1369 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1372 GST_DEBUG ("do seek");
1376 GST_DEBUG ("do scrub seek, PLAYING");
1377 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1379 if (seek_timeout_id == 0) {
1381 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1387 set_update_fill (gboolean active)
1389 GST_DEBUG ("fill scale is %d", active);
1394 g_timeout_add (FILL_INTERVAL, (GtkFunction) update_fill, pipeline);
1398 g_source_remove (fill_id);
1405 set_update_scale (gboolean active)
1408 GST_DEBUG ("update scale is %d", active);
1411 if (update_id == 0) {
1413 g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
1417 g_source_remove (update_id);
1424 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1426 if (event->type != GDK_BUTTON_PRESS)
1429 set_update_scale (FALSE);
1431 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1432 GST_DEBUG ("start scrub seek, PAUSE");
1433 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1436 if (changed_id == 0 && flush_seek && scrub) {
1438 g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb),
1446 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1449 g_signal_handler_disconnect (hscale, changed_id);
1453 if (!flush_seek || !scrub) {
1454 GST_DEBUG ("do final seek");
1458 if (seek_timeout_id != 0) {
1459 g_source_remove (seek_timeout_id);
1460 seek_timeout_id = 0;
1461 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1463 if (state == GST_STATE_PAUSED) {
1464 GST_DEBUG ("stop scrub seek, PAUSED");
1465 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1468 if (state == GST_STATE_PLAYING) {
1469 GST_DEBUG ("stop scrub seek, PLAYING");
1470 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1478 play_cb (GtkButton * button, gpointer data)
1480 GstStateChangeReturn ret;
1482 if (state != GST_STATE_PLAYING) {
1483 g_print ("PLAY pipeline\n");
1484 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1486 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1488 case GST_STATE_CHANGE_FAILURE:
1490 case GST_STATE_CHANGE_NO_PREROLL:
1496 state = GST_STATE_PLAYING;
1497 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1504 g_print ("PLAY failed\n");
1505 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1510 pause_cb (GtkButton * button, gpointer data)
1512 g_static_mutex_lock (&state_mutex);
1513 if (state != GST_STATE_PAUSED) {
1514 GstStateChangeReturn ret;
1516 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1517 g_print ("PAUSE pipeline\n");
1518 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1520 case GST_STATE_CHANGE_FAILURE:
1522 case GST_STATE_CHANGE_NO_PREROLL:
1529 state = GST_STATE_PAUSED;
1530 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1532 g_static_mutex_unlock (&state_mutex);
1538 g_static_mutex_unlock (&state_mutex);
1539 g_print ("PAUSE failed\n");
1540 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1545 stop_cb (GtkButton * button, gpointer data)
1547 if (state != STOP_STATE) {
1548 GstStateChangeReturn ret;
1550 g_print ("READY pipeline\n");
1551 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1553 g_static_mutex_lock (&state_mutex);
1554 ret = gst_element_set_state (pipeline, STOP_STATE);
1555 if (ret == GST_STATE_CHANGE_FAILURE)
1559 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1563 set_update_scale (FALSE);
1565 set_update_fill (FALSE);
1567 if (pipeline_type == 16)
1568 clear_streams (pipeline);
1569 g_static_mutex_unlock (&state_mutex);
1572 /* if one uses parse_launch, play, stop and play again it fails as all the
1573 * pads after the demuxer can't be reconnected
1575 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1576 gst_element_set_state (pipeline, GST_STATE_NULL);
1577 gst_object_unref (pipeline);
1579 g_list_free (seekable_elements);
1580 seekable_elements = NULL;
1581 g_list_free (seekable_pads);
1582 seekable_pads = NULL;
1583 g_list_free (rate_pads);
1586 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1587 g_assert (pipeline);
1588 gst_element_set_state (pipeline, STOP_STATE);
1589 connect_bus_signals (pipeline);
1597 g_static_mutex_unlock (&state_mutex);
1598 g_print ("STOP failed\n");
1599 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1604 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1606 accurate_seek = gtk_toggle_button_get_active (button);
1610 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1612 keyframe_seek = gtk_toggle_button_get_active (button);
1616 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1618 loop_seek = gtk_toggle_button_get_active (button);
1619 if (state == GST_STATE_PLAYING) {
1625 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1627 flush_seek = gtk_toggle_button_get_active (button);
1631 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1633 scrub = gtk_toggle_button_get_active (button);
1637 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1639 play_scrub = gtk_toggle_button_get_active (button);
1643 skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1645 skip_seek = gtk_toggle_button_get_active (button);
1646 if (state == GST_STATE_PLAYING) {
1652 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1654 gboolean res = FALSE;
1658 rate = gtk_spin_button_get_value (button);
1660 GST_DEBUG ("rate changed to %lf", rate);
1664 flags |= GST_SEEK_FLAG_FLUSH;
1666 flags |= GST_SEEK_FLAG_SEGMENT;
1668 flags |= GST_SEEK_FLAG_ACCURATE;
1670 flags |= GST_SEEK_FLAG_KEY_UNIT;
1672 flags |= GST_SEEK_FLAG_SKIP;
1675 s_event = gst_event_new_seek (rate,
1676 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1677 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1679 s_event = gst_event_new_seek (rate,
1680 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1681 GST_SEEK_TYPE_SET, position);
1684 res = send_event (s_event);
1688 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1691 g_print ("seek failed\n");
1695 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1699 g_object_get (pipeline, "flags", &flags, NULL);
1701 flags |= (1 << num);
1703 flags &= ~(1 << num);
1704 g_object_set (pipeline, "flags", flags, NULL);
1708 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1712 state = gtk_toggle_button_get_active (button);
1713 update_flag (pipeline, 3, state);
1714 gtk_widget_set_sensitive (vis_combo, state);
1718 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1722 state = gtk_toggle_button_get_active (button);
1723 update_flag (pipeline, 1, state);
1724 gtk_widget_set_sensitive (audio_combo, state);
1728 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1732 state = gtk_toggle_button_get_active (button);
1733 update_flag (pipeline, 0, state);
1734 gtk_widget_set_sensitive (video_combo, state);
1738 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1742 state = gtk_toggle_button_get_active (button);
1743 update_flag (pipeline, 2, state);
1744 gtk_widget_set_sensitive (text_combo, state);
1748 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1752 mute = gtk_toggle_button_get_active (button);
1753 g_object_set (pipeline, "mute", mute, NULL);
1757 download_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1761 state = gtk_toggle_button_get_active (button);
1762 update_flag (pipeline, 7, state);
1766 buffer_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1770 state = gtk_toggle_button_get_active (button);
1771 update_flag (pipeline, 8, state);
1775 clear_streams (GstElement * pipeline)
1779 /* remove previous info */
1780 for (i = 0; i < n_video; i++)
1781 gtk_combo_box_remove_text (GTK_COMBO_BOX (video_combo), 0);
1782 for (i = 0; i < n_audio; i++)
1783 gtk_combo_box_remove_text (GTK_COMBO_BOX (audio_combo), 0);
1784 for (i = 0; i < n_text; i++)
1785 gtk_combo_box_remove_text (GTK_COMBO_BOX (text_combo), 0);
1787 n_audio = n_video = n_text = 0;
1788 gtk_widget_set_sensitive (video_combo, FALSE);
1789 gtk_widget_set_sensitive (audio_combo, FALSE);
1790 gtk_widget_set_sensitive (text_combo, FALSE);
1792 need_streams = TRUE;
1796 update_streams (GstPipeline * pipeline)
1800 if (pipeline_type == 16 && need_streams) {
1806 /* remove previous info */
1807 clear_streams (GST_ELEMENT_CAST (pipeline));
1809 /* here we get and update the different streams detected by playbin2 */
1810 g_object_get (pipeline, "n-video", &n_video, NULL);
1811 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1812 g_object_get (pipeline, "n-text", &n_text, NULL);
1814 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1817 for (i = 0; i < n_video; i++) {
1818 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1820 str = gst_structure_to_string ((GstStructure *) tags);
1821 g_print ("video %d: %s\n", i, str);
1824 /* find good name for the label */
1825 name = g_strdup_printf ("video %d", i + 1);
1826 gtk_combo_box_append_text (GTK_COMBO_BOX (video_combo), name);
1829 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1830 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1831 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1834 for (i = 0; i < n_audio; i++) {
1835 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1837 str = gst_structure_to_string ((GstStructure *) tags);
1838 g_print ("audio %d: %s\n", i, str);
1841 /* find good name for the label */
1842 name = g_strdup_printf ("audio %d", i + 1);
1843 gtk_combo_box_append_text (GTK_COMBO_BOX (audio_combo), name);
1846 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1847 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1848 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1851 for (i = 0; i < n_text; i++) {
1852 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1856 const GValue *value;
1858 str = gst_structure_to_string ((GstStructure *) tags);
1859 g_print ("text %d: %s\n", i, str);
1862 /* get the language code if we can */
1863 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1864 if (value && G_VALUE_HOLDS_STRING (value)) {
1865 name = g_strdup_printf ("text %s", g_value_get_string (value));
1868 /* find good name for the label if we didn't use a tag */
1870 name = g_strdup_printf ("text %d", i + 1);
1872 gtk_combo_box_append_text (GTK_COMBO_BOX (text_combo), name);
1875 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1876 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1877 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1879 need_streams = FALSE;
1884 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1888 active = gtk_combo_box_get_active (combo);
1890 g_print ("setting current video track %d\n", active);
1891 g_object_set (pipeline, "current-video", active, NULL);
1895 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1899 active = gtk_combo_box_get_active (combo);
1901 g_print ("setting current audio track %d\n", active);
1902 g_object_set (pipeline, "current-audio", active, NULL);
1906 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1910 active = gtk_combo_box_get_active (combo);
1912 g_print ("setting current text track %d\n", active);
1913 g_object_set (pipeline, "current-text", active, NULL);
1917 filter_features (GstPluginFeature * feature, gpointer data)
1919 GstElementFactory *f;
1921 if (!GST_IS_ELEMENT_FACTORY (feature))
1923 f = GST_ELEMENT_FACTORY (feature);
1924 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1931 init_visualization_features (void)
1935 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1937 list = gst_registry_feature_filter (gst_registry_get_default (),
1938 filter_features, FALSE, NULL);
1940 for (walk = list; walk; walk = g_list_next (walk)) {
1944 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1945 name = gst_element_factory_get_longname (entry.factory);
1947 g_array_append_val (vis_entries, entry);
1948 gtk_combo_box_append_text (GTK_COMBO_BOX (vis_combo), name);
1950 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1954 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1958 GstElement *element;
1960 /* get the selected index and get the factory for this index */
1961 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1962 if (vis_entries->len > 0) {
1963 entry = &g_array_index (vis_entries, VisEntry, index);
1965 /* create an instance of the element from the factory */
1966 element = gst_element_factory_create (entry->factory, NULL);
1970 /* set vis plugin for playbin2 */
1971 g_object_set (pipeline, "vis-plugin", element, NULL);
1976 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1980 volume = gtk_spin_button_get_value (button);
1982 g_object_set (pipeline, "volume", volume, NULL);
1986 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat)
1988 gdouble cur_volume, new_volume;
1990 g_object_get (pipeline, "volume", &new_volume, NULL);
1991 cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton));
1992 if (fabs (cur_volume - new_volume) > 0.001) {
1993 g_signal_handlers_block_by_func (volume_spinbutton,
1994 volume_spinbutton_changed_cb, pipeline);
1995 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume);
1996 g_signal_handlers_unblock_by_func (volume_spinbutton,
1997 volume_spinbutton_changed_cb, pipeline);
2002 shot_cb (GtkButton * button, gpointer data)
2007 /* convert to our desired format (RGB24) */
2008 caps = gst_caps_new_simple ("video/x-raw-rgb",
2009 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
2010 /* Note: we don't ask for a specific width/height here, so that
2011 * videoscale can adjust dimensions from a non-1/1 pixel aspect
2012 * ratio to a 1/1 pixel-aspect-ratio */
2013 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
2014 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
2015 "red_mask", G_TYPE_INT, 0xff0000,
2016 "green_mask", G_TYPE_INT, 0x00ff00,
2017 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
2019 /* convert the latest frame to the requested format */
2020 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
2021 gst_caps_unref (caps);
2029 GError *error = NULL;
2031 /* get the snapshot buffer format now. We set the caps on the appsink so
2032 * that it can only be an rgb buffer. The only thing we have not specified
2033 * on the caps is the height, which is dependant on the pixel-aspect-ratio
2034 * of the source material */
2035 caps = GST_BUFFER_CAPS (buffer);
2037 g_warning ("could not get snapshot format\n");
2040 s = gst_caps_get_structure (caps, 0);
2042 /* we need to get the final caps on the buffer to get the size */
2043 res = gst_structure_get_int (s, "width", &width);
2044 res |= gst_structure_get_int (s, "height", &height);
2046 g_warning ("could not get snapshot dimension\n");
2050 /* create pixmap from buffer and save, gstreamer video buffers have a stride
2051 * that is rounded up to the nearest multiple of 4 */
2052 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
2053 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
2054 GST_ROUND_UP_4 (width * 3), NULL, NULL);
2056 /* save the pixbuf */
2057 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
2060 gst_buffer_unref (buffer);
2064 /* called when the Step button is pressed */
2066 step_cb (GtkButton * button, gpointer data)
2072 gboolean flush, res;
2075 active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo));
2077 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
2078 (step_amount_spinbutton));
2079 rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton));
2084 format = GST_FORMAT_BUFFERS;
2087 format = GST_FORMAT_TIME;
2088 amount *= GST_MSECOND;
2091 format = GST_FORMAT_UNDEFINED;
2095 event = gst_event_new_step (format, amount, rate, flush, FALSE);
2097 res = send_event (event);
2101 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2103 const GstStructure *s;
2105 s = gst_message_get_structure (message);
2106 g_print ("message from \"%s\" (%s): ",
2107 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
2108 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
2112 sstr = gst_structure_to_string (s);
2113 g_print ("%s\n", sstr);
2116 g_print ("no message details\n");
2120 static gboolean shuttling = FALSE;
2121 static gdouble shuttle_rate = 0.0;
2122 static gdouble play_rate = 1.0;
2125 do_shuttle (GstElement * element)
2130 duration = 40 * GST_MSECOND;
2134 gst_element_send_event (element,
2135 gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE,
2140 msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element)
2146 gboolean intermediate;
2150 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
2151 &intermediate, &duration, &eos);
2154 g_print ("stepped till EOS\n");
2158 if (g_static_mutex_trylock (&state_mutex)) {
2160 do_shuttle (element);
2161 g_static_mutex_unlock (&state_mutex);
2163 /* ignore step messages that come while we are doing a state change */
2164 g_print ("state change is busy\n");
2169 shuttle_toggled (GtkToggleButton * button, GstElement * element)
2173 active = gtk_toggle_button_get_active (button);
2175 if (active != shuttling) {
2177 g_print ("shuttling %s\n", shuttling ? "active" : "inactive");
2181 pause_cb (NULL, NULL);
2182 gst_element_get_state (element, NULL, NULL, -1);
2188 shuttle_rate_switch (GstElement * element)
2194 if (state == GST_STATE_PLAYING) {
2195 /* pause when we need to */
2196 pause_cb (NULL, NULL);
2197 gst_element_get_state (element, NULL, NULL, -1);
2200 if (play_rate == 1.0)
2205 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate,
2206 GST_TIME_ARGS (position));
2208 flags = GST_SEEK_FLAG_FLUSH;
2209 flags |= GST_SEEK_FLAG_ACCURATE;
2211 if (play_rate >= 0.0) {
2212 s_event = gst_event_new_seek (play_rate,
2213 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
2214 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
2216 s_event = gst_event_new_seek (play_rate,
2217 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2218 GST_SEEK_TYPE_SET, position);
2220 res = send_event (s_event);
2222 gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT);
2224 g_print ("seek failed\n");
2229 shuttle_value_changed (GtkRange * range, GstElement * element)
2233 rate = gtk_adjustment_get_value (shuttle_adjustment);
2236 g_print ("rate 0.0, pause\n");
2237 pause_cb (NULL, NULL);
2238 gst_element_get_state (element, NULL, NULL, -1);
2240 g_print ("rate changed %0.3g\n", rate);
2242 if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) {
2243 shuttle_rate_switch (element);
2246 shuttle_rate = ABS (rate);
2247 if (state != GST_STATE_PLAYING) {
2248 do_shuttle (element);
2249 play_cb (NULL, NULL);
2255 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2257 GST_DEBUG ("async done");
2258 /* when we get ASYNC_DONE we can query position, duration and other
2260 update_scale (pipeline);
2262 /* update the available streams */
2263 update_streams (pipeline);
2267 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2269 const GstStructure *s;
2271 s = gst_message_get_structure (message);
2273 /* We only care about state changed on the pipeline */
2274 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
2275 GstState old, new, pending;
2277 gst_message_parse_state_changed (message, &old, &new, &pending);
2279 /* When state of the pipeline changes to paused or playing we start updating scale */
2280 if (new == GST_STATE_PLAYING) {
2281 set_update_scale (TRUE);
2283 set_update_scale (FALSE);
2289 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
2296 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2297 gst_message_parse_segment_done (message, &format, &position);
2298 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
2301 /* in the segment-done callback we never flush as this would not make sense
2302 * for seamless playback. */
2304 flags |= GST_SEEK_FLAG_SEGMENT;
2306 flags |= GST_SEEK_FLAG_SKIP;
2308 s_event = gst_event_new_seek (rate,
2309 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
2310 GST_SEEK_TYPE_SET, duration);
2312 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
2313 rate, GST_TIME_ARGS (duration));
2315 res = send_event (s_event);
2317 g_print ("segment seek failed\n");
2320 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
2323 do_stream_buffering (gint percent)
2327 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2328 bufstr = g_strdup_printf ("Buffering...%d", percent);
2329 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2332 if (percent == 100) {
2333 /* a 100% message means buffering is done */
2335 /* if the desired state is playing, go back */
2336 if (state == GST_STATE_PLAYING) {
2337 /* no state management needed for live pipelines */
2339 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2340 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2342 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2343 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2346 /* buffering busy */
2347 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2348 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2350 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2351 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2359 do_download_buffering (gint percent)
2361 if (!buffering && percent < 100) {
2366 bufstr = g_strdup_printf ("Downloading...");
2367 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2370 /* once we get a buffering message, we'll do the fill update */
2371 set_update_fill (TRUE);
2373 if (state == GST_STATE_PLAYING && !is_live) {
2374 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2375 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2376 /* user has to manually start the playback */
2377 state = GST_STATE_PAUSED;
2383 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2387 gst_message_parse_buffering (message, &percent);
2389 /* get more stats */
2390 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2394 case GST_BUFFERING_DOWNLOAD:
2395 do_download_buffering (percent);
2397 case GST_BUFFERING_LIVE:
2398 case GST_BUFFERING_TIMESHIFT:
2399 case GST_BUFFERING_STREAM:
2400 do_stream_buffering (percent);
2406 msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data)
2408 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
2409 if (state == GST_STATE_PLAYING) {
2410 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2411 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2417 static gulong embed_xid = 0;
2419 /* We set the xid here in response to the prepare-xwindow-id message via a
2420 * bus sync handler because we don't know the actual videosink used from the
2421 * start (as we don't know the pipeline, or bin elements such as autovideosink
2422 * or gconfvideosink may be used which create the actual videosink only once
2423 * the pipeline is started) */
2424 static GstBusSyncReply
2425 bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data)
2427 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
2428 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
2429 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2431 g_print ("got prepare-xwindow-id, setting XID %lu\n", embed_xid);
2433 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2434 "force-aspect-ratio")) {
2435 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2438 /* Should have been initialised from main thread before (can't use
2439 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2440 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2441 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2442 * shouldn't be done from a non-GUI thread without explicit locking). */
2443 g_assert (embed_xid != 0);
2445 gst_x_overlay_set_window_handle (GST_X_OVERLAY (element), embed_xid);
2447 return GST_BUS_PASS;
2452 handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
2454 if (state < GST_STATE_PAUSED) {
2455 GtkAllocation allocation;
2456 GdkWindow *window = gtk_widget_get_window (widget);
2459 gtk_widget_get_allocation (widget, &allocation);
2460 cr = gdk_cairo_create (window);
2461 cairo_set_source_rgb (cr, 0, 0, 0);
2462 cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
2470 realize_cb (GtkWidget * widget, gpointer data)
2472 #if GTK_CHECK_VERSION(2,18,0)
2474 GdkWindow *window = gtk_widget_get_window (widget);
2476 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2478 if (!gdk_window_ensure_native (window))
2479 g_error ("Couldn't create native window needed for GstXOverlay!");
2485 GdkWindow *window = gtk_widget_get_window (video_window);
2487 embed_xid = GDK_WINDOW_XID (window);
2488 g_print ("Window realize: video window XID = %lu\n", embed_xid);
2494 msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data)
2496 message_received (bus, message, data);
2498 /* Set new uri for playerbins and continue playback */
2499 if (l && (pipeline_type == 14 || pipeline_type == 16)) {
2500 stop_cb (NULL, NULL);
2501 l = g_list_next (l);
2503 playerbin_set_uri (GST_ELEMENT (data), l->data);
2504 play_cb (NULL, NULL);
2510 msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data)
2513 message_received (bus, message, data);
2517 connect_bus_signals (GstElement * pipeline)
2519 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2522 /* handle prepare-xwindow-id element message synchronously */
2523 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
2527 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2528 gst_bus_enable_sync_message_emission (bus);
2530 g_signal_connect (bus, "message::state-changed",
2531 (GCallback) msg_state_changed, pipeline);
2532 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2534 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2537 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2539 g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost,
2541 g_signal_connect (bus, "message::error", (GCallback) message_received,
2543 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2545 g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline);
2546 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2548 g_signal_connect (bus, "message::element", (GCallback) message_received,
2550 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2552 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2554 // g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done,
2556 g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done,
2558 g_signal_connect (bus, "sync-message::step-done",
2559 (GCallback) msg_sync_step_done, pipeline);
2561 gst_object_unref (bus);
2564 /* Return GList of paths described in location string */
2566 handle_wildcards (const gchar * location)
2569 gchar *path = g_path_get_dirname (location);
2570 gchar *pattern = g_path_get_basename (location);
2571 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2572 GDir *dir = g_dir_open (path, 0, NULL);
2575 g_print ("matching %s from %s\n", pattern, path);
2578 g_print ("opening directory %s failed\n", path);
2582 while ((name = g_dir_read_name (dir)) != NULL) {
2583 if (g_pattern_match_string (pspec, name)) {
2584 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2585 g_print (" found clip %s\n", name);
2591 g_pattern_spec_free (pspec);
2599 delete_event_cb (void)
2601 stop_cb (NULL, NULL);
2606 print_usage (int argc, char **argv)
2610 g_print ("usage: %s <type> <filename>\n", argv[0]);
2611 g_print (" possible types:\n");
2613 for (i = 0; i < NUM_TYPES; i++) {
2614 g_print (" %d = %s\n", i, pipelines[i].name);
2619 main (int argc, char **argv)
2621 GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2622 *flagtable, *boxes2, *step;
2623 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2624 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2625 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2626 GtkWidget *rate_label, *volume_label;
2627 GOptionEntry options[] = {
2628 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2629 "Show pad stats", NULL},
2630 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2631 "Seek on elements instead of pads", NULL},
2632 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2633 "Verbose properties", NULL},
2636 GOptionContext *ctx;
2639 if (!g_thread_supported ())
2640 g_thread_init (NULL);
2642 ctx = g_option_context_new ("- test seeking in gsteamer");
2643 g_option_context_add_main_entries (ctx, options, NULL);
2644 g_option_context_add_group (ctx, gst_init_get_option_group ());
2645 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2647 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2648 g_print ("Error initializing: %s\n", err->message);
2652 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2655 print_usage (argc, argv);
2659 pipeline_type = atoi (argv[1]);
2661 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2662 print_usage (argc, argv);
2666 pipeline_spec = argv[2];
2668 if (g_path_is_absolute (pipeline_spec) &&
2669 (g_strrstr (pipeline_spec, "*") != NULL ||
2670 g_strrstr (pipeline_spec, "?") != NULL)) {
2671 paths = handle_wildcards (pipeline_spec);
2673 paths = g_list_prepend (paths, g_strdup (pipeline_spec));
2677 g_print ("opening %s failed\n", pipeline_spec);
2683 pipeline = pipelines[pipeline_type].func ((gchar *) l->data);
2684 g_assert (pipeline);
2686 /* initialize gui elements ... */
2687 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2688 video_window = gtk_drawing_area_new ();
2689 g_signal_connect (video_window, "expose-event",
2690 G_CALLBACK (handle_expose_cb), NULL);
2691 g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL);
2692 gtk_widget_set_double_buffered (video_window, FALSE);
2694 statusbar = gtk_statusbar_new ();
2695 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2696 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2697 hbox = gtk_hbox_new (FALSE, 0);
2698 vbox = gtk_vbox_new (FALSE, 0);
2699 flagtable = gtk_table_new (4, 2, FALSE);
2700 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2702 /* media controls */
2703 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2704 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2705 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2708 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2709 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2710 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2711 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2712 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2713 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2714 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2715 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2716 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2717 rate_label = gtk_label_new ("Rate");
2719 gtk_widget_set_tooltip_text (accurate_checkbox,
2720 "accurate position is requested, this might be considerably slower for some formats");
2721 gtk_widget_set_tooltip_text (key_checkbox,
2722 "seek to the nearest keyframe. This might be faster but less accurate");
2723 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2724 gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking");
2725 gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, "
2726 "negative value trigger reverse playback");
2727 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2728 gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking");
2729 gtk_widget_set_tooltip_text (skip_checkbox,
2730 "Skip frames while playing at high frame rates");
2732 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2733 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2735 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2741 step = gtk_expander_new ("step options");
2742 hbox = gtk_hbox_new (FALSE, 0);
2744 format_combo = gtk_combo_box_new_text ();
2745 gtk_combo_box_append_text (GTK_COMBO_BOX (format_combo), "frames");
2746 gtk_combo_box_append_text (GTK_COMBO_BOX (format_combo), "time (ms)");
2747 gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0);
2748 gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2);
2750 step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2751 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0);
2752 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0);
2753 gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE,
2756 step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2757 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3);
2758 gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0);
2759 gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2);
2761 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2762 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2763 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2765 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2769 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2770 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2771 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2772 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2775 shuttle_adjustment =
2776 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2777 shuttle_hscale = gtk_hscale_new (shuttle_adjustment);
2778 gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2);
2779 gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP);
2780 gtk_range_set_update_policy (GTK_RANGE (shuttle_hscale),
2781 GTK_UPDATE_CONTINUOUS);
2782 g_signal_connect (shuttle_hscale, "value_changed",
2783 G_CALLBACK (shuttle_value_changed), pipeline);
2784 g_signal_connect (shuttle_hscale, "format_value",
2785 G_CALLBACK (shuttle_format_value), pipeline);
2787 gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2);
2789 gtk_container_add (GTK_CONTAINER (step), hbox);
2794 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, N_GRAD, 0.1, 1.0, 1.0));
2795 hscale = gtk_hscale_new (adjustment);
2796 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2797 gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
2798 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2799 gtk_range_set_fill_level (GTK_RANGE (hscale), N_GRAD);
2800 gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);
2802 g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek),
2804 g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek),
2806 g_signal_connect (hscale, "format_value", G_CALLBACK (format_value),
2809 if (pipeline_type == 16) {
2810 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2811 panel = gtk_hbox_new (FALSE, 0);
2812 video_combo = gtk_combo_box_new_text ();
2813 audio_combo = gtk_combo_box_new_text ();
2814 text_combo = gtk_combo_box_new_text ();
2815 gtk_widget_set_sensitive (video_combo, FALSE);
2816 gtk_widget_set_sensitive (audio_combo, FALSE);
2817 gtk_widget_set_sensitive (text_combo, FALSE);
2818 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2819 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2820 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2821 g_signal_connect (G_OBJECT (video_combo), "changed",
2822 G_CALLBACK (video_combo_cb), pipeline);
2823 g_signal_connect (G_OBJECT (audio_combo), "changed",
2824 G_CALLBACK (audio_combo_cb), pipeline);
2825 g_signal_connect (G_OBJECT (text_combo), "changed",
2826 G_CALLBACK (text_combo_cb), pipeline);
2827 /* playbin2 panel for flag checkboxes and volume/mute */
2828 boxes = gtk_hbox_new (FALSE, 0);
2829 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2830 video_checkbox = gtk_check_button_new_with_label ("Video");
2831 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2832 text_checkbox = gtk_check_button_new_with_label ("Text");
2833 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2834 download_checkbox = gtk_check_button_new_with_label ("Download");
2835 buffer_checkbox = gtk_check_button_new_with_label ("Buffer");
2836 volume_label = gtk_label_new ("Volume");
2837 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2838 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2839 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2840 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2841 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2842 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2843 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2844 gtk_box_pack_start (GTK_BOX (boxes), download_checkbox, TRUE, TRUE, 2);
2845 gtk_box_pack_start (GTK_BOX (boxes), buffer_checkbox, TRUE, TRUE, 2);
2846 gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2);
2847 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2848 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2849 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2850 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2851 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2852 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2853 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
2854 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffer_checkbox), FALSE);
2855 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2856 G_CALLBACK (vis_toggle_cb), pipeline);
2857 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2858 G_CALLBACK (audio_toggle_cb), pipeline);
2859 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2860 G_CALLBACK (video_toggle_cb), pipeline);
2861 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2862 G_CALLBACK (text_toggle_cb), pipeline);
2863 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2864 G_CALLBACK (mute_toggle_cb), pipeline);
2865 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
2866 G_CALLBACK (download_toggle_cb), pipeline);
2867 g_signal_connect (G_OBJECT (buffer_checkbox), "toggled",
2868 G_CALLBACK (buffer_toggle_cb), pipeline);
2869 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2870 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2871 /* playbin2 panel for snapshot */
2872 boxes2 = gtk_hbox_new (FALSE, 0);
2873 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2874 gtk_widget_set_tooltip_text (shot_button,
2875 "save a screenshot .png in the current directory");
2876 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2878 vis_combo = gtk_combo_box_new_text ();
2879 g_signal_connect (G_OBJECT (vis_combo), "changed",
2880 G_CALLBACK (vis_combo_cb), pipeline);
2881 gtk_widget_set_sensitive (vis_combo, FALSE);
2882 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2883 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2885 /* fill the vis combo box and the array of factories */
2886 init_visualization_features ();
2888 panel = boxes = boxes2 = NULL;
2891 /* do the packing stuff ... */
2892 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2893 /* FIXME: can we avoid this for audio only? */
2894 gtk_widget_set_size_request (GTK_WIDGET (video_window), -1,
2895 DEFAULT_VIDEO_HEIGHT);
2896 gtk_container_add (GTK_CONTAINER (window), vbox);
2897 gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2);
2898 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2899 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2900 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2901 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2902 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2903 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2905 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2906 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2907 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2908 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2909 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2911 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2912 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2913 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2915 if (panel && boxes && boxes2) {
2916 expander = gtk_expander_new ("playbin2 options");
2917 pb2vbox = gtk_vbox_new (FALSE, 0);
2918 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2919 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2920 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2921 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2922 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2924 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2925 gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2);
2926 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2);
2928 /* connect things ... */
2929 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
2931 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
2933 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
2935 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2936 G_CALLBACK (accurate_toggle_cb), pipeline);
2937 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2938 G_CALLBACK (key_toggle_cb), pipeline);
2939 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2940 G_CALLBACK (loop_toggle_cb), pipeline);
2941 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2942 G_CALLBACK (flush_toggle_cb), pipeline);
2943 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2944 G_CALLBACK (scrub_toggle_cb), pipeline);
2945 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2946 G_CALLBACK (play_scrub_toggle_cb), pipeline);
2947 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2948 G_CALLBACK (skip_toggle_cb), pipeline);
2949 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
2950 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
2952 g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL);
2955 gtk_widget_show_all (window);
2957 /* realize window now so that the video window gets created and we can
2958 * obtain its XID before the pipeline is started up and the videosink
2959 * asks for the XID of the window to render onto */
2960 gtk_widget_realize (window);
2963 /* we should have the XID now */
2964 g_assert (embed_xid != 0);
2968 g_signal_connect (pipeline, "deep_notify",
2969 G_CALLBACK (gst_object_default_deep_notify), NULL);
2972 connect_bus_signals (pipeline);
2975 g_print ("NULL pipeline\n");
2976 gst_element_set_state (pipeline, GST_STATE_NULL);
2978 g_print ("free pipeline\n");
2979 gst_object_unref (pipeline);
2981 g_list_foreach (paths, (GFunc) g_free, NULL);
2982 g_list_free (paths);