3 * seek.c: seeking sample application
5 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
6 * 2006 Stefan Kost <ensonic@users.sf.net>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
29 GST_DEBUG_CATEGORY_STATIC (seek_debug);
30 #define GST_CAT_DEFAULT (seek_debug)
34 //#define SOURCE "filesrc"
35 #define SOURCE "gnomevfssrc"
37 #define ASINK "alsasink"
38 //#define ASINK "osssink"
40 #define VSINK "xvimagesink"
41 //#define VSINK "sdlvideosink"
42 //#define VSINK "ximagesink"
43 //#define VSINK "aasink"
44 //#define VSINK "cacasink"
46 #define FILL_INTERVAL 100
47 //#define UPDATE_INTERVAL 500
48 //#define UPDATE_INTERVAL 100
49 #define UPDATE_INTERVAL 10
51 /* number of milliseconds to play for after a seek */
52 #define SCRUB_TIME 100
54 /* timeout for gst_element_get_state() after a seek */
55 #define SEEK_TIMEOUT 40 * GST_MSECOND
58 static GList *seekable_pads = NULL;
59 static GList *rate_pads = NULL;
60 static GList *seekable_elements = NULL;
62 static gboolean accurate_seek = FALSE;
63 static gboolean keyframe_seek = FALSE;
64 static gboolean loop_seek = FALSE;
65 static gboolean flush_seek = TRUE;
66 static gboolean scrub = TRUE;
67 static gboolean play_scrub = FALSE;
68 static gdouble rate = 1.0;
70 static GstElement *pipeline;
71 static gint pipeline_type;
72 static const gchar *pipeline_spec;
73 static gint64 position = -1;
74 static gint64 duration = -1;
75 static GtkAdjustment *adjustment;
76 static GtkWidget *hscale, *statusbar;
77 static guint status_id = 0;
78 static gboolean stats = FALSE;
79 static gboolean elem_seek = FALSE;
80 static gboolean verbose = FALSE;
82 static gboolean is_live = FALSE;
83 static gboolean buffering = FALSE;
84 static GstBufferingMode mode;
85 static gint64 buffering_left;
86 static GstState state = GST_STATE_NULL;
87 static guint update_id = 0;
88 static guint seek_timeout_id = 0;
89 static gulong changed_id;
90 static guint fill_id = 0;
92 static gint n_video = 0, n_audio = 0, n_text = 0;
93 static gboolean need_streams = TRUE;
94 static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
95 static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
96 static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
98 /* we keep an array of the visualisation entries so that we can easily switch
99 * with the combo box index. */
102 GstElementFactory *factory;
105 static GArray *vis_entries;
107 static void clear_streams (GstElement * pipeline);
109 /* pipeline construction */
113 const gchar *padname;
120 gst_element_factory_make_or_warn (gchar * type, gchar * name)
122 GstElement *element = gst_element_factory_make (type, name);
125 g_warning ("Failed to create element %s of type %s", name, type);
132 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
135 dyn_link *connect = (dyn_link *) data;
137 padname = gst_pad_get_name (newpad);
139 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
141 gst_bin_add (GST_BIN (pipeline), connect->bin);
142 gst_pad_link (newpad, connect->target);
144 //seekable_pads = g_list_prepend (seekable_pads, newpad);
145 rate_pads = g_list_prepend (rate_pads, newpad);
151 setup_dynamic_link (GstElement * element, const gchar * padname,
152 GstPad * target, GstElement * bin)
156 connect = g_new0 (dyn_link, 1);
157 connect->padname = g_strdup (padname);
158 connect->target = target;
161 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
166 make_mod_pipeline (const gchar * location)
168 GstElement *pipeline;
169 GstElement *src, *decoder, *audiosink;
172 pipeline = gst_pipeline_new ("app");
174 src = gst_element_factory_make_or_warn (SOURCE, "src");
175 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
176 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
177 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
179 g_object_set (G_OBJECT (src), "location", location, NULL);
181 gst_bin_add (GST_BIN (pipeline), src);
182 gst_bin_add (GST_BIN (pipeline), decoder);
183 gst_bin_add (GST_BIN (pipeline), audiosink);
185 gst_element_link (src, decoder);
186 gst_element_link (decoder, audiosink);
188 seekable = gst_element_get_static_pad (decoder, "src");
189 seekable_pads = g_list_prepend (seekable_pads, seekable);
190 rate_pads = g_list_prepend (rate_pads, seekable);
192 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
198 make_dv_pipeline (const gchar * location)
200 GstElement *pipeline;
201 GstElement *src, *demux, *decoder, *audiosink, *videosink;
202 GstElement *a_queue, *v_queue;
205 pipeline = gst_pipeline_new ("app");
207 src = gst_element_factory_make_or_warn (SOURCE, "src");
208 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
209 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
210 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
211 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
212 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
213 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
215 g_object_set (G_OBJECT (src), "location", location, NULL);
217 gst_bin_add (GST_BIN (pipeline), src);
218 gst_bin_add (GST_BIN (pipeline), demux);
219 gst_bin_add (GST_BIN (pipeline), a_queue);
220 gst_bin_add (GST_BIN (pipeline), audiosink);
221 gst_bin_add (GST_BIN (pipeline), v_queue);
222 gst_bin_add (GST_BIN (pipeline), decoder);
223 gst_bin_add (GST_BIN (pipeline), videosink);
225 gst_element_link (src, demux);
226 gst_element_link (a_queue, audiosink);
227 gst_element_link (v_queue, decoder);
228 gst_element_link (decoder, videosink);
230 setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
232 setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
235 seekable = gst_element_get_static_pad (decoder, "src");
236 seekable_pads = g_list_prepend (seekable_pads, seekable);
237 rate_pads = g_list_prepend (rate_pads, seekable);
243 make_wav_pipeline (const gchar * location)
245 GstElement *pipeline;
246 GstElement *src, *decoder, *audiosink;
248 pipeline = gst_pipeline_new ("app");
250 src = gst_element_factory_make_or_warn (SOURCE, "src");
251 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
252 audiosink = gst_element_factory_make_or_warn (ASINK, "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), decoder);
258 gst_bin_add (GST_BIN (pipeline), audiosink);
260 gst_element_link (src, decoder);
262 setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
265 seekable_elements = g_list_prepend (seekable_elements, audiosink);
267 /* force element seeking on this pipeline */
274 make_flac_pipeline (const gchar * location)
276 GstElement *pipeline;
277 GstElement *src, *decoder, *audiosink;
280 pipeline = gst_pipeline_new ("app");
282 src = gst_element_factory_make_or_warn (SOURCE, "src");
283 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
284 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
285 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
287 g_object_set (G_OBJECT (src), "location", location, NULL);
289 gst_bin_add (GST_BIN (pipeline), src);
290 gst_bin_add (GST_BIN (pipeline), decoder);
291 gst_bin_add (GST_BIN (pipeline), audiosink);
293 gst_element_link (src, decoder);
294 gst_element_link (decoder, audiosink);
296 seekable = gst_element_get_static_pad (decoder, "src");
297 seekable_pads = g_list_prepend (seekable_pads, seekable);
298 rate_pads = g_list_prepend (rate_pads, seekable);
300 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
306 make_sid_pipeline (const gchar * location)
308 GstElement *pipeline;
309 GstElement *src, *decoder, *audiosink;
312 pipeline = gst_pipeline_new ("app");
314 src = gst_element_factory_make_or_warn (SOURCE, "src");
315 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
316 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
317 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
319 g_object_set (G_OBJECT (src), "location", location, NULL);
321 gst_bin_add (GST_BIN (pipeline), src);
322 gst_bin_add (GST_BIN (pipeline), decoder);
323 gst_bin_add (GST_BIN (pipeline), audiosink);
325 gst_element_link (src, decoder);
326 gst_element_link (decoder, audiosink);
328 seekable = gst_element_get_static_pad (decoder, "src");
329 seekable_pads = g_list_prepend (seekable_pads, seekable);
330 rate_pads = g_list_prepend (rate_pads, seekable);
332 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
338 make_parse_pipeline (const gchar * location)
340 GstElement *pipeline;
341 GstElement *src, *parser, *fakesink;
344 pipeline = gst_pipeline_new ("app");
346 src = gst_element_factory_make_or_warn (SOURCE, "src");
347 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
348 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
349 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
350 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
352 g_object_set (G_OBJECT (src), "location", location, NULL);
354 gst_bin_add (GST_BIN (pipeline), src);
355 gst_bin_add (GST_BIN (pipeline), parser);
356 gst_bin_add (GST_BIN (pipeline), fakesink);
358 gst_element_link (src, parser);
359 gst_element_link (parser, fakesink);
361 seekable = gst_element_get_static_pad (parser, "src");
362 seekable_pads = g_list_prepend (seekable_pads, seekable);
363 rate_pads = g_list_prepend (rate_pads, seekable);
365 g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
371 make_vorbis_pipeline (const gchar * location)
373 GstElement *pipeline, *audio_bin;
374 GstElement *src, *demux, *decoder, *convert, *audiosink;
375 GstPad *pad, *seekable;
377 pipeline = gst_pipeline_new ("app");
379 src = gst_element_factory_make_or_warn (SOURCE, "src");
380 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
381 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
382 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
383 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
384 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
386 g_object_set (G_OBJECT (src), "location", location, NULL);
388 audio_bin = gst_bin_new ("a_decoder_bin");
390 gst_bin_add (GST_BIN (pipeline), src);
391 gst_bin_add (GST_BIN (pipeline), demux);
392 gst_bin_add (GST_BIN (audio_bin), decoder);
393 gst_bin_add (GST_BIN (audio_bin), convert);
394 gst_bin_add (GST_BIN (audio_bin), audiosink);
395 gst_bin_add (GST_BIN (pipeline), audio_bin);
397 gst_element_link (src, demux);
398 gst_element_link (decoder, convert);
399 gst_element_link (convert, audiosink);
401 pad = gst_element_get_static_pad (decoder, "sink");
402 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
403 gst_object_unref (pad);
405 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
408 seekable = gst_element_get_static_pad (decoder, "src");
409 seekable_pads = g_list_prepend (seekable_pads, seekable);
410 rate_pads = g_list_prepend (rate_pads, seekable);
412 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
418 make_theora_pipeline (const gchar * location)
420 GstElement *pipeline, *video_bin;
421 GstElement *src, *demux, *decoder, *convert, *videosink;
422 GstPad *pad, *seekable;
424 pipeline = gst_pipeline_new ("app");
426 src = gst_element_factory_make_or_warn (SOURCE, "src");
427 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
428 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
429 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
430 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
432 g_object_set (G_OBJECT (src), "location", location, NULL);
434 video_bin = gst_bin_new ("v_decoder_bin");
436 gst_bin_add (GST_BIN (pipeline), src);
437 gst_bin_add (GST_BIN (pipeline), demux);
438 gst_bin_add (GST_BIN (video_bin), decoder);
439 gst_bin_add (GST_BIN (video_bin), convert);
440 gst_bin_add (GST_BIN (video_bin), videosink);
441 gst_bin_add (GST_BIN (pipeline), video_bin);
443 gst_element_link (src, demux);
444 gst_element_link (decoder, convert);
445 gst_element_link (convert, videosink);
447 pad = gst_element_get_static_pad (decoder, "sink");
448 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
449 gst_object_unref (pad);
451 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_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_vorbis_theora_pipeline (const gchar * location)
466 GstElement *pipeline, *audio_bin, *video_bin;
467 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
468 GstElement *audiosink, *videosink;
469 GstElement *a_queue, *v_queue, *v_scale;
473 pipeline = gst_pipeline_new ("app");
475 src = gst_element_factory_make_or_warn (SOURCE, "src");
476 g_object_set (G_OBJECT (src), "location", location, NULL);
478 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
480 gst_bin_add (GST_BIN (pipeline), src);
481 gst_bin_add (GST_BIN (pipeline), demux);
482 gst_element_link (src, demux);
484 audio_bin = gst_bin_new ("a_decoder_bin");
485 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
486 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
487 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
488 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
490 gst_bin_add (GST_BIN (pipeline), audio_bin);
492 gst_bin_add (GST_BIN (audio_bin), a_queue);
493 gst_bin_add (GST_BIN (audio_bin), a_decoder);
494 gst_bin_add (GST_BIN (audio_bin), a_convert);
495 gst_bin_add (GST_BIN (audio_bin), audiosink);
497 gst_element_link (a_queue, a_decoder);
498 gst_element_link (a_decoder, a_convert);
499 gst_element_link (a_convert, audiosink);
501 pad = gst_element_get_static_pad (a_queue, "sink");
502 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
503 gst_object_unref (pad);
505 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
508 video_bin = gst_bin_new ("v_decoder_bin");
509 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
510 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
512 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
513 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
514 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
516 gst_bin_add (GST_BIN (pipeline), video_bin);
518 gst_bin_add (GST_BIN (video_bin), v_queue);
519 gst_bin_add (GST_BIN (video_bin), v_decoder);
520 gst_bin_add (GST_BIN (video_bin), v_convert);
521 gst_bin_add (GST_BIN (video_bin), v_scale);
522 gst_bin_add (GST_BIN (video_bin), videosink);
524 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
527 pad = gst_element_get_static_pad (v_queue, "sink");
528 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
529 gst_object_unref (pad);
531 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
534 seekable = gst_element_get_static_pad (a_decoder, "src");
535 seekable_pads = g_list_prepend (seekable_pads, seekable);
536 rate_pads = g_list_prepend (rate_pads, seekable);
538 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
545 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
547 GstElement *pipeline, *audio_bin, *video_bin;
548 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
549 GstElement *audiosink, *videosink;
550 GstElement *a_queue, *v_queue;
551 GstPad *seekable, *pad;
553 pipeline = gst_pipeline_new ("app");
555 src = gst_element_factory_make_or_warn (SOURCE, "src");
556 g_object_set (G_OBJECT (src), "location", location, NULL);
558 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
560 gst_bin_add (GST_BIN (pipeline), src);
561 gst_bin_add (GST_BIN (pipeline), demux);
562 gst_element_link (src, demux);
564 audio_bin = gst_bin_new ("a_decoder_bin");
565 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
566 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
567 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
568 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
570 gst_bin_add (GST_BIN (audio_bin), a_queue);
571 gst_bin_add (GST_BIN (audio_bin), a_decoder);
572 gst_bin_add (GST_BIN (audio_bin), a_convert);
573 gst_bin_add (GST_BIN (audio_bin), audiosink);
575 gst_element_link (a_queue, a_decoder);
576 gst_element_link (a_decoder, a_convert);
577 gst_element_link (a_convert, audiosink);
579 gst_bin_add (GST_BIN (pipeline), audio_bin);
581 pad = gst_element_get_static_pad (a_queue, "sink");
582 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
583 gst_object_unref (pad);
585 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
588 video_bin = gst_bin_new ("v_decoder_bin");
589 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
590 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
592 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
593 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
595 gst_bin_add (GST_BIN (video_bin), v_queue);
596 gst_bin_add (GST_BIN (video_bin), v_decoder);
597 gst_bin_add (GST_BIN (video_bin), v_convert);
598 gst_bin_add (GST_BIN (video_bin), videosink);
600 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
602 gst_bin_add (GST_BIN (pipeline), video_bin);
604 pad = gst_element_get_static_pad (v_queue, "sink");
605 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
606 gst_object_unref (pad);
608 setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
611 seekable = gst_element_get_static_pad (a_decoder, "src");
612 seekable_pads = g_list_prepend (seekable_pads, seekable);
613 rate_pads = g_list_prepend (rate_pads, seekable);
615 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
622 make_mp3_pipeline (const gchar * location)
624 GstElement *pipeline;
625 GstElement *src, *decoder, *osssink, *queue;
628 pipeline = gst_pipeline_new ("app");
630 src = gst_element_factory_make_or_warn (SOURCE, "src");
631 decoder = gst_element_factory_make_or_warn ("mad", "dec");
632 queue = gst_element_factory_make_or_warn ("queue", "queue");
633 osssink = gst_element_factory_make_or_warn (ASINK, "sink");
635 seekable_elements = g_list_prepend (seekable_elements, osssink);
637 g_object_set (G_OBJECT (src), "location", location, NULL);
638 //g_object_set (G_OBJECT (osssink), "fragment", 0x00180008, NULL);
640 gst_bin_add (GST_BIN (pipeline), src);
641 gst_bin_add (GST_BIN (pipeline), decoder);
642 gst_bin_add (GST_BIN (pipeline), queue);
643 gst_bin_add (GST_BIN (pipeline), osssink);
645 gst_element_link (src, decoder);
646 gst_element_link (decoder, queue);
647 gst_element_link (queue, osssink);
649 seekable = gst_element_get_static_pad (queue, "src");
650 seekable_pads = g_list_prepend (seekable_pads, seekable);
651 rate_pads = g_list_prepend (rate_pads, seekable);
653 g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
659 make_avi_pipeline (const gchar * location)
661 GstElement *pipeline, *audio_bin, *video_bin;
662 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
663 GstElement *a_queue = NULL, *v_queue = NULL;
666 pipeline = gst_pipeline_new ("app");
668 src = gst_element_factory_make_or_warn (SOURCE, "src");
669 g_object_set (G_OBJECT (src), "location", location, NULL);
671 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
672 seekable_elements = g_list_prepend (seekable_elements, demux);
674 gst_bin_add (GST_BIN (pipeline), src);
675 gst_bin_add (GST_BIN (pipeline), demux);
676 gst_element_link (src, demux);
678 audio_bin = gst_bin_new ("a_decoder_bin");
679 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
680 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
681 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
682 gst_element_link (a_decoder, a_queue);
683 gst_element_link (a_queue, audiosink);
684 gst_bin_add (GST_BIN (audio_bin), a_decoder);
685 gst_bin_add (GST_BIN (audio_bin), a_queue);
686 gst_bin_add (GST_BIN (audio_bin), audiosink);
687 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
689 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
692 seekable = gst_element_get_static_pad (a_queue, "src");
693 seekable_pads = g_list_prepend (seekable_pads, seekable);
694 rate_pads = g_list_prepend (rate_pads, seekable);
696 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
699 video_bin = gst_bin_new ("v_decoder_bin");
700 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
701 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
702 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
703 gst_element_link (v_decoder, v_queue);
704 gst_element_link (v_queue, videosink);
705 gst_bin_add (GST_BIN (video_bin), v_decoder);
706 gst_bin_add (GST_BIN (video_bin), v_queue);
707 gst_bin_add (GST_BIN (video_bin), videosink);
709 gst_element_set_state (video_bin, GST_STATE_PAUSED);
711 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
714 seekable = gst_element_get_static_pad (v_queue, "src");
715 seekable_pads = g_list_prepend (seekable_pads, seekable);
716 rate_pads = g_list_prepend (rate_pads, seekable);
718 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
725 make_mpeg_pipeline (const gchar * location)
727 GstElement *pipeline, *audio_bin, *video_bin;
728 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
729 GstElement *audiosink, *videosink;
730 GstElement *a_queue, *v_queue;
734 pipeline = gst_pipeline_new ("app");
736 src = gst_element_factory_make_or_warn (SOURCE, "src");
737 g_object_set (G_OBJECT (src), "location", location, NULL);
739 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
740 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
742 gst_bin_add (GST_BIN (pipeline), src);
743 gst_bin_add (GST_BIN (pipeline), demux);
744 gst_element_link (src, demux);
746 audio_bin = gst_bin_new ("a_decoder_bin");
747 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
748 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
749 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
750 gst_bin_add (GST_BIN (audio_bin), a_decoder);
751 gst_bin_add (GST_BIN (audio_bin), a_queue);
752 gst_bin_add (GST_BIN (audio_bin), audiosink);
754 gst_element_link (a_decoder, a_queue);
755 gst_element_link (a_queue, audiosink);
757 gst_bin_add (GST_BIN (pipeline), audio_bin);
759 pad = gst_element_get_static_pad (a_decoder, "sink");
760 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
761 gst_object_unref (pad);
763 setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
766 video_bin = gst_bin_new ("v_decoder_bin");
767 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
768 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
769 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
770 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
772 gst_bin_add (GST_BIN (video_bin), v_decoder);
773 gst_bin_add (GST_BIN (video_bin), v_queue);
774 gst_bin_add (GST_BIN (video_bin), v_filter);
775 gst_bin_add (GST_BIN (video_bin), videosink);
777 gst_element_link (v_decoder, v_queue);
778 gst_element_link (v_queue, v_filter);
779 gst_element_link (v_filter, videosink);
781 gst_bin_add (GST_BIN (pipeline), video_bin);
783 pad = gst_element_get_static_pad (v_decoder, "sink");
784 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
785 gst_object_unref (pad);
787 setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
790 seekable = gst_element_get_static_pad (v_filter, "src");
791 seekable_pads = g_list_prepend (seekable_pads, seekable);
792 rate_pads = g_list_prepend (rate_pads, seekable);
794 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
801 make_mpegnt_pipeline (const gchar * location)
803 GstElement *pipeline, *audio_bin, *video_bin;
804 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
805 GstElement *audiosink, *videosink;
809 pipeline = gst_pipeline_new ("app");
811 src = gst_element_factory_make_or_warn (SOURCE, "src");
812 g_object_set (G_OBJECT (src), "location", location, NULL);
814 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
815 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
817 seekable_elements = g_list_prepend (seekable_elements, demux);
819 gst_bin_add (GST_BIN (pipeline), src);
820 gst_bin_add (GST_BIN (pipeline), demux);
821 gst_element_link (src, demux);
823 audio_bin = gst_bin_new ("a_decoder_bin");
824 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
825 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
826 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
827 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
828 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
829 gst_element_link (a_decoder, a_queue);
830 gst_element_link (a_queue, audiosink);
831 gst_bin_add (GST_BIN (audio_bin), a_decoder);
832 gst_bin_add (GST_BIN (audio_bin), a_queue);
833 gst_bin_add (GST_BIN (audio_bin), audiosink);
835 setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
838 seekable = gst_element_get_static_pad (a_queue, "src");
839 seekable_pads = g_list_prepend (seekable_pads, seekable);
840 rate_pads = g_list_prepend (rate_pads, seekable);
842 g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
845 video_bin = gst_bin_new ("v_decoder_bin");
846 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
847 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
848 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
849 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
851 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
853 setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
856 seekable = gst_element_get_static_pad (v_decoder, "src");
857 seekable_pads = g_list_prepend (seekable_pads, seekable);
858 rate_pads = g_list_prepend (rate_pads, seekable);
860 g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
867 make_playerbin_pipeline (const gchar * location)
871 player = gst_element_factory_make ("playbin", "player");
874 g_object_set (G_OBJECT (player), "uri", location, NULL);
876 seekable_elements = g_list_prepend (seekable_elements, player);
878 /* force element seeking on this pipeline */
885 make_playerbin2_pipeline (const gchar * location)
889 player = gst_element_factory_make ("playbin2", "player");
892 g_object_set (G_OBJECT (player), "uri", location, NULL);
894 seekable_elements = g_list_prepend (seekable_elements, player);
896 /* force element seeking on this pipeline */
902 #ifndef GST_DISABLE_PARSE
904 make_parselaunch_pipeline (const gchar * description)
906 GstElement *pipeline;
907 GError *error = NULL;
909 pipeline = gst_parse_launch (description, &error);
911 seekable_elements = g_list_prepend (seekable_elements, pipeline);
922 GstElement *(*func) (const gchar * location);
926 static Pipeline pipelines[] = {
927 {"mp3", make_mp3_pipeline},
928 {"avi", make_avi_pipeline},
929 {"mpeg1", make_mpeg_pipeline},
930 {"mpegparse", make_parse_pipeline},
931 {"vorbis", make_vorbis_pipeline},
932 {"theora", make_theora_pipeline},
933 {"ogg/v/t", make_vorbis_theora_pipeline},
934 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
935 {"sid", make_sid_pipeline},
936 {"flac", make_flac_pipeline},
937 {"wav", make_wav_pipeline},
938 {"mod", make_mod_pipeline},
939 {"dv", make_dv_pipeline},
940 {"mpeg1nothreads", make_mpegnt_pipeline},
941 {"playerbin", make_playerbin_pipeline},
942 #ifndef GST_DISABLE_PARSE
943 {"parse-launch", make_parselaunch_pipeline},
945 {"playerbin2", make_playerbin2_pipeline},
949 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
951 /* ui callbacks and helpers */
954 format_value (GtkScale * scale, gdouble value)
960 real = value * duration / 100;
961 seconds = (gint64) real / GST_SECOND;
962 subseconds = (gint64) real / (GST_SECOND / 100);
964 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
965 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
971 const GstFormat format;
975 static seek_format seek_formats[] = {
976 {"tim", GST_FORMAT_TIME},
977 {"byt", GST_FORMAT_BYTES},
978 {"buf", GST_FORMAT_BUFFERS},
979 {"def", GST_FORMAT_DEFAULT},
983 G_GNUC_UNUSED static void
986 GList *walk = rate_pads;
989 GstPad *pad = GST_PAD (walk->data);
992 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
993 while (seek_formats[i].name) {
997 format = seek_formats[i].format;
999 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
1001 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
1003 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
1008 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1010 walk = g_list_next (walk);
1014 G_GNUC_UNUSED static void
1015 query_positions_elems (void)
1017 GList *walk = seekable_elements;
1020 GstElement *element = GST_ELEMENT (walk->data);
1023 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
1024 while (seek_formats[i].name) {
1025 gint64 position, total;
1028 format = seek_formats[i].format;
1030 if (gst_element_query_position (element, &format, &position) &&
1031 gst_element_query_duration (element, &format, &total)) {
1032 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1033 seek_formats[i].name, position, total);
1035 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1040 g_print (" %s\n", GST_ELEMENT_NAME (element));
1042 walk = g_list_next (walk);
1046 G_GNUC_UNUSED static void
1047 query_positions_pads (void)
1049 GList *walk = seekable_pads;
1052 GstPad *pad = GST_PAD (walk->data);
1055 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
1056 while (seek_formats[i].name) {
1058 gint64 position, total;
1060 format = seek_formats[i].format;
1062 if (gst_pad_query_position (pad, &format, &position) &&
1063 gst_pad_query_duration (pad, &format, &total)) {
1064 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
1065 seek_formats[i].name, position, total);
1067 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
1073 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1075 walk = g_list_next (walk);
1079 static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
1080 gpointer user_data);
1081 static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
1082 gpointer user_data);
1083 static void seek_cb (GtkWidget * widget);
1086 set_scale (gdouble value)
1088 g_signal_handlers_block_by_func (hscale, (void *) start_seek,
1090 g_signal_handlers_block_by_func (hscale, (void *) stop_seek,
1092 g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline);
1093 gtk_adjustment_set_value (adjustment, value);
1094 g_signal_handlers_unblock_by_func (hscale, (void *) start_seek,
1096 g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek,
1098 g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb,
1100 gtk_widget_queue_draw (hscale);
1104 update_fill (gpointer data)
1107 if (seekable_elements) {
1108 GstElement *element = GST_ELEMENT (seekable_elements->data);
1111 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
1112 if (gst_element_query (element, query)) {
1119 gst_query_parse_buffering_percent (query, &busy, &percent);
1121 if (buffering && !busy) {
1122 /* if we were buffering but not anymore, start playing */
1123 if (state == GST_STATE_PLAYING && !is_live) {
1124 fprintf (stderr, "setting pipeline to PLAYING ...\n");
1125 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1126 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1127 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id,
1130 state = GST_STATE_PAUSED;
1134 gst_query_parse_buffering_range (query, &format, &start, &stop, NULL);
1136 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
1140 fill = 100.0 * stop / GST_FORMAT_PERCENT_MAX;
1144 gtk_range_set_fill_level (GTK_RANGE (hscale), fill);
1146 gst_query_unref (query);
1153 update_scale (gpointer data)
1155 GstFormat format = GST_FORMAT_TIME;
1161 if (seekable_elements) {
1162 GstElement *element = GST_ELEMENT (seekable_elements->data);
1164 gst_element_query_position (element, &format, &position);
1165 gst_element_query_duration (element, &format, &duration);
1168 if (seekable_pads) {
1169 GstPad *pad = GST_PAD (seekable_pads->data);
1171 gst_pad_query_position (pad, &format, &position);
1172 gst_pad_query_duration (pad, &format, &duration);
1178 query_positions_elems ();
1180 query_positions_pads ();
1184 if (position >= duration)
1185 duration = position;
1188 set_scale (position * 100.0 / duration);
1194 static void do_seek (GtkWidget * widget);
1195 static void connect_bus_signals (GstElement * pipeline);
1196 static void set_update_scale (gboolean active);
1197 static void set_update_fill (gboolean active);
1200 end_scrub (GtkWidget * widget)
1202 GST_DEBUG ("end scrub, PAUSE");
1203 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1204 seek_timeout_id = 0;
1210 send_event (GstEvent * event)
1212 gboolean res = FALSE;
1215 GList *walk = seekable_pads;
1218 GstPad *seekable = GST_PAD (walk->data);
1220 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1222 gst_event_ref (event);
1223 res = gst_pad_send_event (seekable, event);
1225 walk = g_list_next (walk);
1228 GList *walk = seekable_elements;
1231 GstElement *seekable = GST_ELEMENT (walk->data);
1233 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1235 gst_event_ref (event);
1236 res = gst_element_send_event (seekable, event);
1238 walk = g_list_next (walk);
1241 gst_event_unref (event);
1246 do_seek (GtkWidget * widget)
1249 gboolean res = FALSE;
1253 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
1257 flags |= GST_SEEK_FLAG_FLUSH;
1259 flags |= GST_SEEK_FLAG_ACCURATE;
1261 flags |= GST_SEEK_FLAG_KEY_UNIT;
1263 flags |= GST_SEEK_FLAG_SEGMENT;
1266 s_event = gst_event_new_seek (rate,
1267 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET, -1);
1268 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1269 rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration));
1271 s_event = gst_event_new_seek (rate,
1272 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1273 GST_SEEK_TYPE_SET, real);
1274 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
1275 rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
1278 res = send_event (s_event);
1282 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1284 set_update_scale (TRUE);
1287 g_print ("seek failed\n");
1288 set_update_scale (TRUE);
1293 seek_cb (GtkWidget * widget)
1295 /* If the timer hasn't expired yet, then the pipeline is running */
1296 if (play_scrub && seek_timeout_id != 0) {
1297 GST_DEBUG ("do scrub seek, PAUSED");
1298 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1301 GST_DEBUG ("do seek");
1305 GST_DEBUG ("do scrub seek, PLAYING");
1306 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1308 if (seek_timeout_id == 0) {
1310 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1316 set_update_fill (gboolean active)
1318 GST_DEBUG ("fill scale is %d", active);
1323 g_timeout_add (FILL_INTERVAL, (GtkFunction) update_fill, pipeline);
1327 g_source_remove (fill_id);
1334 set_update_scale (gboolean active)
1337 GST_DEBUG ("update scale is %d", active);
1340 if (update_id == 0) {
1342 g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
1346 g_source_remove (update_id);
1353 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1355 if (event->type != GDK_BUTTON_PRESS)
1358 set_update_scale (FALSE);
1360 if (state == GST_STATE_PLAYING && flush_seek && scrub) {
1361 GST_DEBUG ("start scrub seek, PAUSE");
1362 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1365 if (changed_id == 0 && flush_seek && scrub) {
1366 changed_id = gtk_signal_connect (GTK_OBJECT (hscale),
1367 "value_changed", G_CALLBACK (seek_cb), pipeline);
1374 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1377 g_signal_handler_disconnect (GTK_OBJECT (hscale), changed_id);
1381 if (!flush_seek || !scrub) {
1382 GST_DEBUG ("do final seek");
1386 if (seek_timeout_id != 0) {
1387 g_source_remove (seek_timeout_id);
1388 seek_timeout_id = 0;
1389 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
1391 if (state == GST_STATE_PAUSED) {
1392 GST_DEBUG ("stop scrub seek, PAUSED");
1393 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1396 if (state == GST_STATE_PLAYING) {
1397 GST_DEBUG ("stop scrub seek, PLAYING");
1398 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1406 play_cb (GtkButton * button, gpointer data)
1408 GstStateChangeReturn ret;
1410 if (state != GST_STATE_PLAYING) {
1411 g_print ("PLAY pipeline\n");
1412 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1414 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1416 case GST_STATE_CHANGE_FAILURE:
1418 case GST_STATE_CHANGE_NO_PREROLL:
1424 state = GST_STATE_PLAYING;
1425 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
1431 g_print ("PLAY failed\n");
1432 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed");
1437 pause_cb (GtkButton * button, gpointer data)
1439 if (state != GST_STATE_PAUSED) {
1440 GstStateChangeReturn ret;
1442 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1443 g_print ("PAUSE pipeline\n");
1444 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1446 case GST_STATE_CHANGE_FAILURE:
1448 case GST_STATE_CHANGE_NO_PREROLL:
1455 state = GST_STATE_PAUSED;
1456 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused");
1462 g_print ("PAUSE failed\n");
1463 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed");
1468 stop_cb (GtkButton * button, gpointer data)
1470 if (state != GST_STATE_READY) {
1471 GstStateChangeReturn ret;
1473 g_print ("READY pipeline\n");
1474 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1476 ret = gst_element_set_state (pipeline, GST_STATE_READY);
1477 if (ret == GST_STATE_CHANGE_FAILURE)
1480 state = GST_STATE_READY;
1481 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
1485 set_update_scale (FALSE);
1487 set_update_fill (FALSE);
1489 if (pipeline_type == 16)
1490 clear_streams (pipeline);
1492 /* if one uses parse_launch, play, stop and play again it fails as all the
1493 * pads after the demuxer can't be reconnected
1495 if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) {
1496 gst_element_set_state (pipeline, GST_STATE_NULL);
1497 gst_object_unref (pipeline);
1499 pipeline = pipelines[pipeline_type].func (pipeline_spec);
1500 g_assert (pipeline);
1501 gst_element_set_state (pipeline, GST_STATE_READY);
1502 connect_bus_signals (pipeline);
1509 g_print ("STOP failed\n");
1510 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed");
1515 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1517 accurate_seek = gtk_toggle_button_get_active (button);
1521 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1523 keyframe_seek = gtk_toggle_button_get_active (button);
1527 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1529 loop_seek = gtk_toggle_button_get_active (button);
1530 if (state == GST_STATE_PLAYING) {
1536 flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1538 flush_seek = gtk_toggle_button_get_active (button);
1542 scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1544 scrub = gtk_toggle_button_get_active (button);
1548 play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1550 play_scrub = gtk_toggle_button_get_active (button);
1554 rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1556 gboolean res = FALSE;
1560 rate = gtk_spin_button_get_value (button);
1564 flags |= GST_SEEK_FLAG_FLUSH;
1566 flags |= GST_SEEK_FLAG_SEGMENT;
1568 flags |= GST_SEEK_FLAG_ACCURATE;
1570 flags |= GST_SEEK_FLAG_KEY_UNIT;
1573 s_event = gst_event_new_seek (rate,
1574 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position,
1575 GST_SEEK_TYPE_SET, -1);
1577 s_event = gst_event_new_seek (rate,
1578 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1579 GST_SEEK_TYPE_SET, position);
1582 GST_DEBUG ("rate changed to %lf", rate);
1584 res = send_event (s_event);
1588 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT);
1591 g_print ("seek failed\n");
1595 update_flag (GstPipeline * pipeline, gint num, gboolean state)
1599 g_object_get (pipeline, "flags", &flags, NULL);
1601 flags |= (1 << num);
1603 flags &= ~(1 << num);
1604 g_object_set (pipeline, "flags", flags, NULL);
1608 vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1612 state = gtk_toggle_button_get_active (button);
1613 update_flag (pipeline, 3, state);
1614 gtk_widget_set_sensitive (vis_combo, state);
1618 audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1622 state = gtk_toggle_button_get_active (button);
1623 update_flag (pipeline, 1, state);
1624 gtk_widget_set_sensitive (audio_combo, state);
1628 video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1632 state = gtk_toggle_button_get_active (button);
1633 update_flag (pipeline, 0, state);
1634 gtk_widget_set_sensitive (video_combo, state);
1638 text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1642 state = gtk_toggle_button_get_active (button);
1643 update_flag (pipeline, 2, state);
1644 gtk_widget_set_sensitive (text_combo, state);
1648 mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1652 mute = gtk_toggle_button_get_active (button);
1653 g_object_set (pipeline, "mute", mute, NULL);
1657 clear_streams (GstElement * pipeline)
1661 /* remove previous info */
1662 for (i = 0; i < n_video; i++)
1663 gtk_combo_box_remove_text (GTK_COMBO_BOX (video_combo), 0);
1664 for (i = 0; i < n_audio; i++)
1665 gtk_combo_box_remove_text (GTK_COMBO_BOX (audio_combo), 0);
1666 for (i = 0; i < n_text; i++)
1667 gtk_combo_box_remove_text (GTK_COMBO_BOX (text_combo), 0);
1669 n_audio = n_video = n_text = 0;
1670 gtk_widget_set_sensitive (video_combo, FALSE);
1671 gtk_widget_set_sensitive (audio_combo, FALSE);
1672 gtk_widget_set_sensitive (text_combo, FALSE);
1674 need_streams = TRUE;
1678 update_streams (GstPipeline * pipeline)
1682 if (pipeline_type == 16 && need_streams) {
1688 /* remove previous info */
1689 clear_streams (GST_ELEMENT_CAST (pipeline));
1691 /* here we get and update the different streams detected by playbin2 */
1692 g_object_get (pipeline, "n-video", &n_video, NULL);
1693 g_object_get (pipeline, "n-audio", &n_audio, NULL);
1694 g_object_get (pipeline, "n-text", &n_text, NULL);
1696 g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text);
1699 for (i = 0; i < n_video; i++) {
1700 g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags);
1701 /* find good name for the label */
1702 name = g_strdup_printf ("video %d", i + 1);
1703 gtk_combo_box_append_text (GTK_COMBO_BOX (video_combo), name);
1706 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox));
1707 gtk_widget_set_sensitive (video_combo, state && n_video > 0);
1708 gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx);
1711 for (i = 0; i < n_audio; i++) {
1712 g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags);
1713 /* find good name for the label */
1714 name = g_strdup_printf ("audio %d", i + 1);
1715 gtk_combo_box_append_text (GTK_COMBO_BOX (audio_combo), name);
1718 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox));
1719 gtk_widget_set_sensitive (audio_combo, state && n_audio > 0);
1720 gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx);
1723 for (i = 0; i < n_text; i++) {
1724 g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags);
1727 const GValue *value;
1729 /* get the language code if we can */
1730 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1731 if (value && G_VALUE_HOLDS_STRING (value)) {
1732 name = g_strdup_printf ("text %s", g_value_get_string (value));
1735 /* find good name for the label if we didn't use a tag */
1737 name = g_strdup_printf ("text %d", i + 1);
1739 gtk_combo_box_append_text (GTK_COMBO_BOX (text_combo), name);
1742 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox));
1743 gtk_widget_set_sensitive (text_combo, state && n_text > 0);
1744 gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx);
1746 need_streams = FALSE;
1751 video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1753 g_object_set (pipeline, "current-video", gtk_combo_box_get_active (combo),
1758 audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1760 g_object_set (pipeline, "current-audio", gtk_combo_box_get_active (combo),
1765 text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1767 g_object_set (pipeline, "current-text", gtk_combo_box_get_active (combo),
1772 filter_features (GstPluginFeature * feature, gpointer data)
1774 GstElementFactory *f;
1776 if (!GST_IS_ELEMENT_FACTORY (feature))
1778 f = GST_ELEMENT_FACTORY (feature);
1779 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1786 init_visualization_features (void)
1790 vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1792 list = gst_registry_feature_filter (gst_registry_get_default (),
1793 filter_features, FALSE, NULL);
1795 for (walk = list; walk; walk = g_list_next (walk)) {
1799 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1800 name = gst_element_factory_get_longname (entry.factory);
1802 g_array_append_val (vis_entries, entry);
1803 gtk_combo_box_append_text (GTK_COMBO_BOX (vis_combo), name);
1805 gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0);
1809 vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline)
1813 GstElement *element;
1815 /* get the selected index and get the factory for this index */
1816 index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo));
1817 entry = &g_array_index (vis_entries, VisEntry, index);
1818 /* create an instance of the element from the factory */
1819 element = gst_element_factory_create (entry->factory, NULL);
1823 /* set vis plugin for playbin2 */
1824 g_object_set (pipeline, "vis-plugin", element, NULL);
1828 volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline)
1832 volume = gtk_spin_button_get_value (button);
1834 g_object_set (pipeline, "volume", volume, NULL);
1838 shot_cb (GtkButton * button, gpointer data)
1843 /* convert to our desired format (RGB24) */
1844 caps = gst_caps_new_simple ("video/x-raw-rgb",
1845 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
1846 /* Note: we don't ask for a specific width/height here, so that
1847 * videoscale can adjust dimensions from a non-1/1 pixel aspect
1848 * ratio to a 1/1 pixel-aspect-ratio */
1849 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
1850 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
1851 "red_mask", G_TYPE_INT, 0xff0000,
1852 "green_mask", G_TYPE_INT, 0x00ff00,
1853 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
1855 /* convert the latest frame to the requested format */
1856 g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer);
1857 gst_caps_unref (caps);
1865 GError *error = NULL;
1867 /* get the snapshot buffer format now. We set the caps on the appsink so
1868 * that it can only be an rgb buffer. The only thing we have not specified
1869 * on the caps is the height, which is dependant on the pixel-aspect-ratio
1870 * of the source material */
1871 caps = GST_BUFFER_CAPS (buffer);
1873 g_warning ("could not get snapshot format\n");
1876 s = gst_caps_get_structure (caps, 0);
1878 /* we need to get the final caps on the buffer to get the size */
1879 res = gst_structure_get_int (s, "width", &width);
1880 res |= gst_structure_get_int (s, "height", &height);
1882 g_warning ("could not get snapshot dimension\n");
1886 /* create pixmap from buffer and save, gstreamer video buffers have a stride
1887 * that is rounded up to the nearest multiple of 4 */
1888 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
1889 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
1890 GST_ROUND_UP_4 (width * 3), NULL, NULL);
1892 /* save the pixbuf */
1893 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
1896 gst_buffer_unref (buffer);
1901 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
1903 const GstStructure *s;
1905 s = gst_message_get_structure (message);
1906 g_print ("message from \"%s\" (%s): ",
1907 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
1908 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
1912 sstr = gst_structure_to_string (s);
1913 g_print ("%s\n", sstr);
1916 g_print ("no message details\n");
1921 msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
1923 GST_DEBUG ("async done");
1924 /* when we get ASYNC_DONE we can query position, duration and other
1926 update_scale (pipeline);
1928 /* update the available streams */
1929 update_streams (pipeline);
1933 msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
1935 const GstStructure *s;
1937 s = gst_message_get_structure (message);
1939 /* We only care about state changed on the pipeline */
1940 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
1941 GstState old, new, pending;
1943 gst_message_parse_state_changed (message, &old, &new, &pending);
1945 /* When state of the pipeline changes to paused or playing we start updating scale */
1946 if (new == GST_STATE_PLAYING) {
1947 set_update_scale (TRUE);
1949 set_update_scale (FALSE);
1955 msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
1962 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
1963 gst_message_parse_segment_done (message, &format, &position);
1964 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position));
1967 /* in the segment-done callback we never flush as this would not make sense
1968 * for seamless playback. */
1970 flags = GST_SEEK_FLAG_SEGMENT;
1972 s_event = gst_event_new_seek (rate,
1973 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1974 GST_SEEK_TYPE_SET, duration);
1976 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
1977 rate, GST_TIME_ARGS (duration));
1979 res = send_event (s_event);
1981 g_print ("segment seek failed\n");
1984 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
1987 do_stream_buffering (gint percent)
1991 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
1992 bufstr = g_strdup_printf ("Buffering...%d", percent);
1993 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
1996 if (percent == 100) {
1997 /* a 100% message means buffering is done */
1999 /* if the desired state is playing, go back */
2000 if (state == GST_STATE_PLAYING) {
2001 /* no state management needed for live pipelines */
2003 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
2004 gst_element_set_state (pipeline, GST_STATE_PLAYING);
2006 gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id);
2007 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing");
2010 /* buffering busy */
2011 if (buffering == FALSE && state == GST_STATE_PLAYING) {
2012 /* we were not buffering but PLAYING, PAUSE the pipeline. */
2014 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
2015 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2023 do_download_buffering (gint percent)
2025 if (!buffering && percent < 100) {
2030 bufstr = g_strdup_printf ("Downloading...");
2031 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr);
2034 /* once we get a buffering message, we'll do the fill update */
2035 set_update_fill (TRUE);
2037 if (state == GST_STATE_PLAYING && !is_live) {
2038 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
2039 gst_element_set_state (pipeline, GST_STATE_PAUSED);
2045 msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data)
2049 gst_message_parse_buffering (message, &percent);
2051 /* get more stats */
2052 gst_message_parse_buffering_stats (message, &mode, NULL, NULL,
2056 case GST_BUFFERING_DOWNLOAD:
2057 do_download_buffering (percent);
2059 case GST_BUFFERING_LIVE:
2060 case GST_BUFFERING_TIMESHIFT:
2061 case GST_BUFFERING_STREAM:
2062 do_stream_buffering (percent);
2068 connect_bus_signals (GstElement * pipeline)
2070 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
2072 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2074 g_signal_connect (bus, "message::state-changed",
2075 (GCallback) msg_state_changed, pipeline);
2076 g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done,
2078 g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done,
2081 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
2083 g_signal_connect (bus, "message::error", (GCallback) message_received,
2085 g_signal_connect (bus, "message::warning", (GCallback) message_received,
2087 g_signal_connect (bus, "message::eos", (GCallback) message_received,
2089 g_signal_connect (bus, "message::tag", (GCallback) message_received,
2091 g_signal_connect (bus, "message::element", (GCallback) message_received,
2093 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
2095 g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering,
2098 gst_object_unref (bus);
2102 print_usage (int argc, char **argv)
2106 g_print ("usage: %s <type> <filename>\n", argv[0]);
2107 g_print (" possible types:\n");
2109 for (i = 0; i < NUM_TYPES; i++) {
2110 g_print (" %d = %s\n", i, pipelines[i].name);
2115 main (int argc, char **argv)
2117 GtkWidget *window, *hbox, *vbox, *panel, *boxes, *flagtable, *boxes2;
2118 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2119 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2120 GtkWidget *scrub_checkbox, *play_scrub_checkbox, *rate_spinbutton;
2121 GtkWidget *rate_label;
2123 GOptionEntry options[] = {
2124 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
2125 "Show pad stats", NULL},
2126 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
2127 "Seek on elements instead of pads", NULL},
2128 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
2129 "Verbose properties", NULL},
2132 GOptionContext *ctx;
2135 if (!g_thread_supported ())
2136 g_thread_init (NULL);
2138 ctx = g_option_context_new ("- test seeking in gsteamer");
2139 g_option_context_add_main_entries (ctx, options, NULL);
2140 g_option_context_add_group (ctx, gst_init_get_option_group ());
2142 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2143 g_print ("Error initializing: %s\n", err->message);
2147 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2149 gtk_init (&argc, &argv);
2152 print_usage (argc, argv);
2156 pipeline_type = atoi (argv[1]);
2158 if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) {
2159 print_usage (argc, argv);
2163 pipeline_spec = argv[2];
2165 pipeline = pipelines[pipeline_type].func (pipeline_spec);
2166 g_assert (pipeline);
2168 /* initialize gui elements ... */
2169 tips = gtk_tooltips_new ();
2170 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2171 statusbar = gtk_statusbar_new ();
2172 status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek");
2173 gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped");
2174 hbox = gtk_hbox_new (FALSE, 0);
2175 vbox = gtk_vbox_new (FALSE, 0);
2176 flagtable = gtk_table_new (4, 2, FALSE);
2177 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2179 /* media controls */
2180 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2181 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2182 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2185 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2186 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2187 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2188 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2189 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2190 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2191 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2192 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2193 rate_label = gtk_label_new ("Rate");
2195 gtk_tooltips_set_tip (tips, accurate_checkbox,
2196 "accurate position is requested, this might be considerably slower for some formats",
2198 gtk_tooltips_set_tip (tips, key_checkbox,
2199 "seek to the nearest keyframe. This might be faster but less accurate",
2201 gtk_tooltips_set_tip (tips, loop_checkbox, "loop playback", NULL);
2202 gtk_tooltips_set_tip (tips, flush_checkbox, "flush pipeline after seeking",
2204 gtk_tooltips_set_tip (tips, rate_spinbutton, "define the playback rate, "
2205 "negative value trigger reverse playback", NULL);
2206 gtk_tooltips_set_tip (tips, scrub_checkbox, "show images while seeking",
2208 gtk_tooltips_set_tip (tips, play_scrub_checkbox, "play video while seeking",
2211 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2212 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2214 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate);
2218 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
2219 hscale = gtk_hscale_new (adjustment);
2220 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
2221 #if GTK_CHECK_VERSION(2,12,0)
2222 gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE);
2223 gtk_range_set_fill_level (GTK_RANGE (hscale), 100.0);
2225 gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);
2227 gtk_signal_connect (GTK_OBJECT (hscale),
2228 "button_press_event", G_CALLBACK (start_seek), pipeline);
2229 gtk_signal_connect (GTK_OBJECT (hscale),
2230 "button_release_event", G_CALLBACK (stop_seek), pipeline);
2231 gtk_signal_connect (GTK_OBJECT (hscale),
2232 "format_value", G_CALLBACK (format_value), pipeline);
2234 if (pipeline_type == 16) {
2235 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2236 panel = gtk_hbox_new (FALSE, 0);
2237 video_combo = gtk_combo_box_new_text ();
2238 audio_combo = gtk_combo_box_new_text ();
2239 text_combo = gtk_combo_box_new_text ();
2240 gtk_widget_set_sensitive (video_combo, FALSE);
2241 gtk_widget_set_sensitive (audio_combo, FALSE);
2242 gtk_widget_set_sensitive (text_combo, FALSE);
2243 gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2);
2244 gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2);
2245 gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2);
2246 g_signal_connect (G_OBJECT (video_combo), "changed",
2247 G_CALLBACK (video_combo_cb), pipeline);
2248 g_signal_connect (G_OBJECT (audio_combo), "changed",
2249 G_CALLBACK (audio_combo_cb), pipeline);
2250 g_signal_connect (G_OBJECT (text_combo), "changed",
2251 G_CALLBACK (text_combo_cb), pipeline);
2252 /* playbin2 panel for flag checkboxes and volume/mute */
2253 boxes = gtk_hbox_new (FALSE, 0);
2254 vis_checkbox = gtk_check_button_new_with_label ("Vis");
2255 video_checkbox = gtk_check_button_new_with_label ("Video");
2256 audio_checkbox = gtk_check_button_new_with_label ("Audio");
2257 text_checkbox = gtk_check_button_new_with_label ("Text");
2258 mute_checkbox = gtk_check_button_new_with_label ("Mute");
2259 volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2260 gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0);
2261 gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2);
2262 gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2);
2263 gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2);
2264 gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2);
2265 gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2);
2266 gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2);
2267 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE);
2268 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE);
2269 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE);
2270 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE);
2271 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE);
2272 g_signal_connect (G_OBJECT (vis_checkbox), "toggled",
2273 G_CALLBACK (vis_toggle_cb), pipeline);
2274 g_signal_connect (G_OBJECT (audio_checkbox), "toggled",
2275 G_CALLBACK (audio_toggle_cb), pipeline);
2276 g_signal_connect (G_OBJECT (video_checkbox), "toggled",
2277 G_CALLBACK (video_toggle_cb), pipeline);
2278 g_signal_connect (G_OBJECT (text_checkbox), "toggled",
2279 G_CALLBACK (text_toggle_cb), pipeline);
2280 g_signal_connect (G_OBJECT (mute_checkbox), "toggled",
2281 G_CALLBACK (mute_toggle_cb), pipeline);
2282 g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed",
2283 G_CALLBACK (volume_spinbutton_changed_cb), pipeline);
2284 /* playbin2 panel for snapshot */
2285 boxes2 = gtk_hbox_new (FALSE, 0);
2286 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2287 gtk_tooltips_set_tip (tips, shot_button,
2288 "save a screenshot .png in the current directory", NULL);
2289 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2291 vis_combo = gtk_combo_box_new_text ();
2292 g_signal_connect (G_OBJECT (vis_combo), "changed",
2293 G_CALLBACK (vis_combo_cb), pipeline);
2294 gtk_widget_set_sensitive (vis_combo, FALSE);
2295 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2296 gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2);
2298 /* fill the vis combo box and the array of factories */
2299 init_visualization_features ();
2301 panel = boxes = boxes2 = NULL;
2304 /* do the packing stuff ... */
2305 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
2306 gtk_container_add (GTK_CONTAINER (window), vbox);
2307 gtk_container_add (GTK_CONTAINER (vbox), hbox);
2308 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2309 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2310 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2311 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2312 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2314 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2315 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2316 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2317 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2318 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2320 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 3, 4, 0, 1);
2321 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 3, 4, 1,
2323 if (panel && boxes && boxes2) {
2324 gtk_box_pack_start (GTK_BOX (vbox), panel, TRUE, TRUE, 2);
2325 gtk_box_pack_start (GTK_BOX (vbox), boxes, TRUE, TRUE, 2);
2326 gtk_box_pack_start (GTK_BOX (vbox), boxes2, TRUE, TRUE, 2);
2328 gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2);
2329 gtk_box_pack_start (GTK_BOX (vbox), statusbar, TRUE, TRUE, 2);
2331 /* connect things ... */
2332 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
2334 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
2336 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
2338 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2339 G_CALLBACK (accurate_toggle_cb), pipeline);
2340 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2341 G_CALLBACK (key_toggle_cb), pipeline);
2342 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2343 G_CALLBACK (loop_toggle_cb), pipeline);
2344 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2345 G_CALLBACK (flush_toggle_cb), pipeline);
2346 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2347 G_CALLBACK (scrub_toggle_cb), pipeline);
2348 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2349 G_CALLBACK (play_scrub_toggle_cb), pipeline);
2350 g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed",
2351 G_CALLBACK (rate_spinbutton_changed_cb), pipeline);
2353 g_signal_connect (G_OBJECT (window), "delete-event", gtk_main_quit, NULL);
2356 gtk_widget_show_all (window);
2359 g_signal_connect (pipeline, "deep_notify",
2360 G_CALLBACK (gst_object_default_deep_notify), NULL);
2363 connect_bus_signals (pipeline);
2366 g_print ("NULL pipeline\n");
2367 gst_element_set_state (pipeline, GST_STATE_NULL);
2369 g_print ("free pipeline\n");
2370 gst_object_unref (pipeline);