7 GST_DEBUG_CATEGORY (seek_debug);
8 #define GST_CAT_DEFAULT (seek_debug)
10 static GList *seekable_pads = NULL;
11 static GList *rate_pads = NULL;
12 static GList *seekable_elements = NULL;
14 static gboolean accurate_seek = FALSE;
15 static gboolean keyframe_seek = FALSE;
16 static gboolean loop_seek = FALSE;
18 static GstElement *pipeline;
19 static gint64 position;
20 static gint64 duration;
21 static GtkAdjustment *adjustment;
22 static GtkWidget *hscale;
23 static gboolean stats = FALSE;
24 static gboolean elem_seek = FALSE;
25 static gboolean verbose = FALSE;
27 static GstState state;
28 static guint update_id = 0;
29 static guint seek_timeout_id = 0;
30 static gulong changed_id;
32 //#define SOURCE "filesrc"
33 #define SOURCE "gnomevfssrc"
34 #define ASINK "alsasink"
35 //#define ASINK "osssink"
36 #define VSINK "xvimagesink"
37 //#define VSINK "sdlvideosink"
38 //#define VSINK "ximagesink"
39 //#define VSINK "aasink"
40 //#define VSINK "cacasink"
42 //#define UPDATE_INTERVAL 500
43 #define UPDATE_INTERVAL 100
45 /* number of milliseconds to play for after a seek */
46 //#define SCRUB_TIME 250
61 gst_element_factory_make_or_warn (gchar * type, gchar * name)
63 GstElement *element = gst_element_factory_make (type, name);
66 g_warning ("Failed to create element %s of type %s", name, type);
73 dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
76 dyn_link *connect = (dyn_link *) data;
78 padname = gst_pad_get_name (newpad);
80 if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
82 gst_bin_add (GST_BIN (pipeline), connect->bin);
83 gst_pad_link (newpad, connect->target);
85 //seekable_pads = g_list_prepend (seekable_pads, newpad);
86 rate_pads = g_list_prepend (rate_pads, newpad);
92 setup_dynamic_link (GstElement * element, const gchar * padname,
93 GstPad * target, GstElement * bin)
97 connect = g_new0 (dyn_link, 1);
98 connect->padname = g_strdup (padname);
99 connect->target = target;
102 g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
107 make_mod_pipeline (const gchar * location)
109 GstElement *pipeline;
110 GstElement *src, *decoder, *audiosink;
113 pipeline = gst_pipeline_new ("app");
115 src = gst_element_factory_make_or_warn (SOURCE, "src");
116 decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
117 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
118 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
120 g_object_set (G_OBJECT (src), "location", location, NULL);
122 gst_bin_add (GST_BIN (pipeline), src);
123 gst_bin_add (GST_BIN (pipeline), decoder);
124 gst_bin_add (GST_BIN (pipeline), audiosink);
126 gst_element_link (src, decoder);
127 gst_element_link (decoder, audiosink);
129 seekable = gst_element_get_pad (decoder, "src");
130 seekable_pads = g_list_prepend (seekable_pads, seekable);
131 rate_pads = g_list_prepend (rate_pads, seekable);
132 rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));
138 make_dv_pipeline (const gchar * location)
140 GstElement *pipeline;
141 GstElement *src, *demux, *decoder, *audiosink, *videosink;
142 GstElement *a_queue, *v_queue;
145 pipeline = gst_pipeline_new ("app");
147 src = gst_element_factory_make_or_warn (SOURCE, "src");
148 demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
149 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
150 decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
151 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
152 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
153 audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
155 g_object_set (G_OBJECT (src), "location", location, NULL);
157 gst_bin_add (GST_BIN (pipeline), src);
158 gst_bin_add (GST_BIN (pipeline), demux);
159 gst_bin_add (GST_BIN (pipeline), a_queue);
160 gst_bin_add (GST_BIN (pipeline), audiosink);
161 gst_bin_add (GST_BIN (pipeline), v_queue);
162 gst_bin_add (GST_BIN (pipeline), decoder);
163 gst_bin_add (GST_BIN (pipeline), videosink);
165 gst_element_link (src, demux);
166 gst_element_link (a_queue, audiosink);
167 gst_element_link (v_queue, decoder);
168 gst_element_link (decoder, videosink);
170 setup_dynamic_link (demux, "video", gst_element_get_pad (v_queue, "sink"),
172 setup_dynamic_link (demux, "audio", gst_element_get_pad (a_queue, "sink"),
175 seekable = gst_element_get_pad (decoder, "src");
176 seekable_pads = g_list_prepend (seekable_pads, seekable);
177 rate_pads = g_list_prepend (rate_pads, seekable);
183 make_wav_pipeline (const gchar * location)
185 GstElement *pipeline;
186 GstElement *src, *decoder, *audiosink;
188 pipeline = gst_pipeline_new ("app");
190 src = gst_element_factory_make_or_warn (SOURCE, "src");
191 decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
192 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
194 g_object_set (G_OBJECT (src), "location", location, NULL);
196 gst_bin_add (GST_BIN (pipeline), src);
197 gst_bin_add (GST_BIN (pipeline), decoder);
198 gst_bin_add (GST_BIN (pipeline), audiosink);
200 gst_element_link (src, decoder);
202 setup_dynamic_link (decoder, "src", gst_element_get_pad (audiosink, "sink"),
205 seekable_elements = g_list_prepend (seekable_elements, audiosink);
207 /* force element seeking on this pipeline */
214 make_flac_pipeline (const gchar * location)
216 GstElement *pipeline;
217 GstElement *src, *decoder, *audiosink;
220 pipeline = gst_pipeline_new ("app");
222 src = gst_element_factory_make_or_warn (SOURCE, "src");
223 decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
224 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
225 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
227 g_object_set (G_OBJECT (src), "location", location, NULL);
229 gst_bin_add (GST_BIN (pipeline), src);
230 gst_bin_add (GST_BIN (pipeline), decoder);
231 gst_bin_add (GST_BIN (pipeline), audiosink);
233 gst_element_link (src, decoder);
234 gst_element_link (decoder, audiosink);
236 seekable = gst_element_get_pad (decoder, "src");
237 seekable_pads = g_list_prepend (seekable_pads, seekable);
238 rate_pads = g_list_prepend (rate_pads, seekable);
239 rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));
245 make_sid_pipeline (const gchar * location)
247 GstElement *pipeline;
248 GstElement *src, *decoder, *audiosink;
251 pipeline = gst_pipeline_new ("app");
253 src = gst_element_factory_make_or_warn (SOURCE, "src");
254 decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
255 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
256 //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
258 g_object_set (G_OBJECT (src), "location", location, NULL);
260 gst_bin_add (GST_BIN (pipeline), src);
261 gst_bin_add (GST_BIN (pipeline), decoder);
262 gst_bin_add (GST_BIN (pipeline), audiosink);
264 gst_element_link (src, decoder);
265 gst_element_link (decoder, audiosink);
267 seekable = gst_element_get_pad (decoder, "src");
268 seekable_pads = g_list_prepend (seekable_pads, seekable);
269 rate_pads = g_list_prepend (rate_pads, seekable);
270 rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));
276 make_parse_pipeline (const gchar * location)
278 GstElement *pipeline;
279 GstElement *src, *parser, *fakesink;
282 pipeline = gst_pipeline_new ("app");
284 src = gst_element_factory_make_or_warn (SOURCE, "src");
285 parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
286 fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
287 g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
288 g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
290 g_object_set (G_OBJECT (src), "location", location, NULL);
292 gst_bin_add (GST_BIN (pipeline), src);
293 gst_bin_add (GST_BIN (pipeline), parser);
294 gst_bin_add (GST_BIN (pipeline), fakesink);
296 gst_element_link (src, parser);
297 gst_element_link (parser, fakesink);
299 seekable = gst_element_get_pad (parser, "src");
300 seekable_pads = g_list_prepend (seekable_pads, seekable);
301 rate_pads = g_list_prepend (rate_pads, seekable);
302 rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (parser, "sink"));
308 make_vorbis_pipeline (const gchar * location)
310 GstElement *pipeline, *audio_bin;
311 GstElement *src, *demux, *decoder, *convert, *audiosink;
312 GstPad *pad, *seekable;
314 pipeline = gst_pipeline_new ("app");
316 src = gst_element_factory_make_or_warn (SOURCE, "src");
317 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
318 decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
319 convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
320 audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
321 g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
323 g_object_set (G_OBJECT (src), "location", location, NULL);
325 audio_bin = gst_bin_new ("a_decoder_bin");
327 gst_bin_add (GST_BIN (pipeline), src);
328 gst_bin_add (GST_BIN (pipeline), demux);
329 gst_bin_add (GST_BIN (audio_bin), decoder);
330 gst_bin_add (GST_BIN (audio_bin), convert);
331 gst_bin_add (GST_BIN (audio_bin), audiosink);
332 gst_bin_add (GST_BIN (pipeline), audio_bin);
334 gst_element_link (src, demux);
335 gst_element_link (decoder, convert);
336 gst_element_link (convert, audiosink);
338 pad = gst_element_get_pad (decoder, "sink");
339 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
340 gst_object_unref (pad);
342 setup_dynamic_link (demux, NULL, gst_element_get_pad (audio_bin, "sink"),
345 seekable = gst_element_get_pad (decoder, "src");
346 seekable_pads = g_list_prepend (seekable_pads, seekable);
347 rate_pads = g_list_prepend (rate_pads, seekable);
348 rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));
354 make_theora_pipeline (const gchar * location)
356 GstElement *pipeline, *video_bin;
357 GstElement *src, *demux, *decoder, *convert, *videosink;
358 GstPad *pad, *seekable;
360 pipeline = gst_pipeline_new ("app");
362 src = gst_element_factory_make_or_warn (SOURCE, "src");
363 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
364 decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
365 convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
366 videosink = gst_element_factory_make_or_warn (VSINK, "sink");
368 g_object_set (G_OBJECT (src), "location", location, NULL);
370 video_bin = gst_bin_new ("v_decoder_bin");
372 gst_bin_add (GST_BIN (pipeline), src);
373 gst_bin_add (GST_BIN (pipeline), demux);
374 gst_bin_add (GST_BIN (video_bin), decoder);
375 gst_bin_add (GST_BIN (video_bin), convert);
376 gst_bin_add (GST_BIN (video_bin), videosink);
377 gst_bin_add (GST_BIN (pipeline), video_bin);
379 gst_element_link (src, demux);
380 gst_element_link (decoder, convert);
381 gst_element_link (convert, videosink);
383 pad = gst_element_get_pad (decoder, "sink");
384 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
385 gst_object_unref (pad);
387 setup_dynamic_link (demux, NULL, gst_element_get_pad (video_bin, "sink"),
390 seekable = gst_element_get_pad (decoder, "src");
391 seekable_pads = g_list_prepend (seekable_pads, seekable);
392 rate_pads = g_list_prepend (rate_pads, seekable);
393 rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));
399 make_vorbis_theora_pipeline (const gchar * location)
401 GstElement *pipeline, *audio_bin, *video_bin;
402 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
403 GstElement *audiosink, *videosink;
404 GstElement *a_queue, *v_queue, *v_scale;
408 pipeline = gst_pipeline_new ("app");
410 src = gst_element_factory_make_or_warn (SOURCE, "src");
411 g_object_set (G_OBJECT (src), "location", location, NULL);
413 demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
415 gst_bin_add (GST_BIN (pipeline), src);
416 gst_bin_add (GST_BIN (pipeline), demux);
417 gst_element_link (src, demux);
419 audio_bin = gst_bin_new ("a_decoder_bin");
420 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
421 a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
422 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
423 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
425 gst_bin_add (GST_BIN (pipeline), audio_bin);
427 gst_bin_add (GST_BIN (audio_bin), a_queue);
428 gst_bin_add (GST_BIN (audio_bin), a_decoder);
429 gst_bin_add (GST_BIN (audio_bin), a_convert);
430 gst_bin_add (GST_BIN (audio_bin), audiosink);
432 gst_element_link (a_queue, a_decoder);
433 gst_element_link (a_decoder, a_convert);
434 gst_element_link (a_convert, audiosink);
436 pad = gst_element_get_pad (a_queue, "sink");
437 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
438 gst_object_unref (pad);
440 setup_dynamic_link (demux, NULL, gst_element_get_pad (audio_bin, "sink"),
443 video_bin = gst_bin_new ("v_decoder_bin");
444 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
445 v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
447 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
448 v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
449 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
451 gst_bin_add (GST_BIN (pipeline), video_bin);
453 gst_bin_add (GST_BIN (video_bin), v_queue);
454 gst_bin_add (GST_BIN (video_bin), v_decoder);
455 gst_bin_add (GST_BIN (video_bin), v_convert);
456 gst_bin_add (GST_BIN (video_bin), v_scale);
457 gst_bin_add (GST_BIN (video_bin), videosink);
459 gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
462 pad = gst_element_get_pad (v_queue, "sink");
463 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
464 gst_object_unref (pad);
466 setup_dynamic_link (demux, NULL, gst_element_get_pad (video_bin, "sink"),
469 seekable = gst_element_get_pad (a_decoder, "src");
470 seekable_pads = g_list_prepend (seekable_pads, seekable);
471 rate_pads = g_list_prepend (rate_pads, seekable);
473 g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
479 make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
481 GstElement *pipeline, *audio_bin, *video_bin;
482 GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
483 GstElement *audiosink, *videosink;
484 GstElement *a_queue, *v_queue;
485 GstPad *seekable, *pad;
487 pipeline = gst_pipeline_new ("app");
489 src = gst_element_factory_make_or_warn (SOURCE, "src");
490 g_object_set (G_OBJECT (src), "location", location, NULL);
492 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
494 gst_bin_add (GST_BIN (pipeline), src);
495 gst_bin_add (GST_BIN (pipeline), demux);
496 gst_element_link (src, demux);
498 audio_bin = gst_bin_new ("a_decoder_bin");
499 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
500 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
501 a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
502 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
504 gst_bin_add (GST_BIN (audio_bin), a_queue);
505 gst_bin_add (GST_BIN (audio_bin), a_decoder);
506 gst_bin_add (GST_BIN (audio_bin), a_convert);
507 gst_bin_add (GST_BIN (audio_bin), audiosink);
509 gst_element_link (a_queue, a_decoder);
510 gst_element_link (a_decoder, a_convert);
511 gst_element_link (a_convert, audiosink);
513 gst_bin_add (GST_BIN (pipeline), audio_bin);
515 pad = gst_element_get_pad (a_queue, "sink");
516 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
517 gst_object_unref (pad);
519 setup_dynamic_link (demux, NULL, gst_element_get_pad (audio_bin, "sink"),
522 video_bin = gst_bin_new ("v_decoder_bin");
523 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
524 v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
526 gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
527 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
529 gst_bin_add (GST_BIN (video_bin), v_queue);
530 gst_bin_add (GST_BIN (video_bin), v_decoder);
531 gst_bin_add (GST_BIN (video_bin), v_convert);
532 gst_bin_add (GST_BIN (video_bin), videosink);
534 gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
536 gst_bin_add (GST_BIN (pipeline), video_bin);
538 pad = gst_element_get_pad (v_queue, "sink");
539 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
540 gst_object_unref (pad);
542 setup_dynamic_link (demux, NULL, gst_element_get_pad (video_bin, "sink"),
545 seekable = gst_element_get_pad (a_decoder, "src");
546 seekable_pads = g_list_prepend (seekable_pads, seekable);
547 rate_pads = g_list_prepend (rate_pads, seekable);
549 g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
555 make_mp3_pipeline (const gchar * location)
557 GstElement *pipeline;
558 GstElement *src, *decoder, *osssink, *queue;
561 pipeline = gst_pipeline_new ("app");
563 src = gst_element_factory_make_or_warn (SOURCE, "src");
564 decoder = gst_element_factory_make_or_warn ("mad", "dec");
565 queue = gst_element_factory_make_or_warn ("queue", "queue");
566 osssink = gst_element_factory_make_or_warn (ASINK, "sink");
568 seekable_elements = g_list_prepend (seekable_elements, osssink);
570 g_object_set (G_OBJECT (src), "location", location, NULL);
571 //g_object_set (G_OBJECT (osssink), "fragment", 0x00180008, NULL);
573 gst_bin_add (GST_BIN (pipeline), src);
574 gst_bin_add (GST_BIN (pipeline), decoder);
575 gst_bin_add (GST_BIN (pipeline), queue);
576 gst_bin_add (GST_BIN (pipeline), osssink);
578 gst_element_link (src, decoder);
579 gst_element_link (decoder, queue);
580 gst_element_link (queue, osssink);
582 seekable = gst_element_get_pad (queue, "src");
583 seekable_pads = g_list_prepend (seekable_pads, seekable);
584 rate_pads = g_list_prepend (rate_pads, seekable);
585 rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));
591 make_avi_pipeline (const gchar * location)
593 GstElement *pipeline, *audio_bin, *video_bin;
594 GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
595 GstElement *a_queue = NULL, *v_queue = NULL;
598 pipeline = gst_pipeline_new ("app");
600 src = gst_element_factory_make_or_warn (SOURCE, "src");
601 g_object_set (G_OBJECT (src), "location", location, NULL);
603 demux = gst_element_factory_make_or_warn ("avidemux", "demux");
604 seekable_elements = g_list_prepend (seekable_elements, demux);
606 gst_bin_add (GST_BIN (pipeline), src);
607 gst_bin_add (GST_BIN (pipeline), demux);
608 gst_element_link (src, demux);
610 audio_bin = gst_bin_new ("a_decoder_bin");
611 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
612 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
613 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
614 gst_element_link (a_decoder, a_queue);
615 gst_element_link (a_queue, audiosink);
616 gst_bin_add (GST_BIN (audio_bin), a_decoder);
617 gst_bin_add (GST_BIN (audio_bin), a_queue);
618 gst_bin_add (GST_BIN (audio_bin), audiosink);
619 gst_element_set_state (audio_bin, GST_STATE_PAUSED);
621 setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
624 seekable = gst_element_get_pad (a_queue, "src");
625 seekable_pads = g_list_prepend (seekable_pads, seekable);
626 rate_pads = g_list_prepend (rate_pads, seekable);
628 g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
630 video_bin = gst_bin_new ("v_decoder_bin");
631 v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
632 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
633 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
634 gst_element_link (v_decoder, v_queue);
635 gst_element_link (v_queue, videosink);
636 gst_bin_add (GST_BIN (video_bin), v_decoder);
637 gst_bin_add (GST_BIN (video_bin), v_queue);
638 gst_bin_add (GST_BIN (video_bin), videosink);
640 gst_element_set_state (video_bin, GST_STATE_PAUSED);
642 setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
645 seekable = gst_element_get_pad (v_queue, "src");
646 seekable_pads = g_list_prepend (seekable_pads, seekable);
647 rate_pads = g_list_prepend (rate_pads, seekable);
649 g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
655 make_mpeg_pipeline (const gchar * location)
657 GstElement *pipeline, *audio_bin, *video_bin;
658 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
659 GstElement *audiosink, *videosink;
660 GstElement *a_queue, *v_queue;
664 pipeline = gst_pipeline_new ("app");
666 src = gst_element_factory_make_or_warn (SOURCE, "src");
667 g_object_set (G_OBJECT (src), "location", location, NULL);
669 //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
670 demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
672 gst_bin_add (GST_BIN (pipeline), src);
673 gst_bin_add (GST_BIN (pipeline), demux);
674 gst_element_link (src, demux);
676 audio_bin = gst_bin_new ("a_decoder_bin");
677 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
678 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
679 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
680 gst_bin_add (GST_BIN (audio_bin), a_decoder);
681 gst_bin_add (GST_BIN (audio_bin), a_queue);
682 gst_bin_add (GST_BIN (audio_bin), audiosink);
684 gst_element_link (a_decoder, a_queue);
685 gst_element_link (a_queue, audiosink);
687 gst_bin_add (GST_BIN (pipeline), audio_bin);
689 pad = gst_element_get_pad (a_decoder, "sink");
690 gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
691 gst_object_unref (pad);
693 setup_dynamic_link (demux, "audio_c0", gst_element_get_pad (audio_bin,
696 video_bin = gst_bin_new ("v_decoder_bin");
697 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
698 v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
699 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
700 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
702 gst_bin_add (GST_BIN (video_bin), v_decoder);
703 gst_bin_add (GST_BIN (video_bin), v_queue);
704 gst_bin_add (GST_BIN (video_bin), v_filter);
705 gst_bin_add (GST_BIN (video_bin), videosink);
707 gst_element_link (v_decoder, v_queue);
708 gst_element_link (v_queue, v_filter);
709 gst_element_link (v_filter, videosink);
711 gst_bin_add (GST_BIN (pipeline), video_bin);
713 pad = gst_element_get_pad (v_decoder, "sink");
714 gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
715 gst_object_unref (pad);
717 setup_dynamic_link (demux, "video_e0", gst_element_get_pad (video_bin,
720 seekable = gst_element_get_pad (v_filter, "src");
721 seekable_pads = g_list_prepend (seekable_pads, seekable);
722 rate_pads = g_list_prepend (rate_pads, seekable);
724 g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
730 make_mpegnt_pipeline (const gchar * location)
732 GstElement *pipeline, *audio_bin, *video_bin;
733 GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
734 GstElement *audiosink, *videosink;
738 pipeline = gst_pipeline_new ("app");
740 src = gst_element_factory_make_or_warn (SOURCE, "src");
741 g_object_set (G_OBJECT (src), "location", location, NULL);
743 demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
744 //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);
746 seekable_elements = g_list_prepend (seekable_elements, demux);
748 gst_bin_add (GST_BIN (pipeline), src);
749 gst_bin_add (GST_BIN (pipeline), demux);
750 gst_element_link (src, demux);
752 audio_bin = gst_bin_new ("a_decoder_bin");
753 a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
754 a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
755 audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
756 //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
757 g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
758 gst_element_link (a_decoder, a_queue);
759 gst_element_link (a_queue, audiosink);
760 gst_bin_add (GST_BIN (audio_bin), a_decoder);
761 gst_bin_add (GST_BIN (audio_bin), a_queue);
762 gst_bin_add (GST_BIN (audio_bin), audiosink);
764 setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
767 seekable = gst_element_get_pad (a_queue, "src");
768 seekable_pads = g_list_prepend (seekable_pads, seekable);
769 rate_pads = g_list_prepend (rate_pads, seekable);
771 g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
773 video_bin = gst_bin_new ("v_decoder_bin");
774 v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
775 v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
776 videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
777 gst_element_link_many (v_decoder, v_filter, videosink, NULL);
779 gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);
781 setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
784 seekable = gst_element_get_pad (v_decoder, "src");
785 seekable_pads = g_list_prepend (seekable_pads, seekable);
786 rate_pads = g_list_prepend (rate_pads, seekable);
788 g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
794 make_playerbin_pipeline (const gchar * location)
798 player = gst_element_factory_make ("playbin", "player");
801 g_object_set (G_OBJECT (player), "uri", location, NULL);
803 seekable_elements = g_list_prepend (seekable_elements, player);
805 /* force element seeking on this pipeline */
812 make_parselaunch_pipeline (const gchar * description)
814 GstElement *pipeline;
817 pipeline = gst_parse_launch (description, &error);
819 seekable_elements = g_list_prepend (seekable_elements, pipeline);
827 format_value (GtkScale * scale, gdouble value)
833 real = value * duration / 100;
834 seconds = (gint64) real / GST_SECOND;
835 subseconds = (gint64) real / (GST_SECOND / 100);
837 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
838 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
844 const GstFormat format;
848 static seek_format seek_formats[] = {
849 {"tim", GST_FORMAT_TIME},
850 {"byt", GST_FORMAT_BYTES},
851 {"buf", GST_FORMAT_BUFFERS},
852 {"def", GST_FORMAT_DEFAULT},
856 G_GNUC_UNUSED static void
859 GList *walk = rate_pads;
862 GstPad *pad = GST_PAD (walk->data);
865 g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad));
866 while (seek_formats[i].name) {
870 format = seek_formats[i].format;
872 if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
874 g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
876 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
881 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
883 walk = g_list_next (walk);
887 G_GNUC_UNUSED static void
888 query_positions_elems ()
890 GList *walk = seekable_elements;
893 GstElement *element = GST_ELEMENT (walk->data);
896 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
897 while (seek_formats[i].name) {
898 gint64 position, total;
901 format = seek_formats[i].format;
903 if (gst_element_query_position (element, &format, &position) &&
904 gst_element_query_duration (element, &format, &total)) {
905 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
906 seek_formats[i].name, position, total);
908 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
913 g_print (" %s\n", GST_ELEMENT_NAME (element));
915 walk = g_list_next (walk);
919 G_GNUC_UNUSED static void
920 query_positions_pads ()
922 GList *walk = seekable_pads;
925 GstPad *pad = GST_PAD (walk->data);
928 g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
929 while (seek_formats[i].name) {
931 gint64 position, total;
933 format = seek_formats[i].format;
935 if (gst_pad_query_position (pad, &format, &position) &&
936 gst_pad_query_duration (pad, &format, &total)) {
937 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
938 seek_formats[i].name, position, total);
940 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
946 g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
948 walk = g_list_next (walk);
953 update_scale (gpointer data)
960 format = GST_FORMAT_TIME;
963 if (seekable_elements) {
964 GstElement *element = GST_ELEMENT (seekable_elements->data);
966 gst_element_query_position (element, &format, &position);
967 gst_element_query_duration (element, &format, &duration);
971 GstPad *pad = GST_PAD (seekable_pads->data);
973 gst_pad_query_position (pad, &format, &position);
974 gst_pad_query_duration (pad, &format, &duration);
980 query_positions_elems ();
982 query_positions_pads ();
986 if (position >= duration)
990 gtk_adjustment_set_value (adjustment, position * 100.0 / duration);
991 gtk_widget_queue_draw (hscale);
997 static void do_seek (GtkWidget * widget);
1001 end_scrub (GtkWidget * widget)
1003 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1004 seek_timeout_id = 0;
1011 send_event (GstEvent * event)
1013 gboolean res = FALSE;
1016 GList *walk = seekable_pads;
1019 GstPad *seekable = GST_PAD (walk->data);
1021 GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable));
1023 gst_event_ref (event);
1024 res = gst_pad_send_event (seekable, event);
1026 walk = g_list_next (walk);
1029 GList *walk = seekable_elements;
1032 GstElement *seekable = GST_ELEMENT (walk->data);
1034 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable));
1036 gst_event_ref (event);
1037 res = gst_element_send_event (seekable, event);
1039 walk = g_list_next (walk);
1042 gst_event_unref (event);
1047 do_seek (GtkWidget * widget)
1050 gboolean res = FALSE;
1054 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
1056 flags = GST_SEEK_FLAG_FLUSH;
1058 flags |= GST_SEEK_FLAG_ACCURATE;
1060 flags |= GST_SEEK_FLAG_KEY_UNIT;
1062 flags |= GST_SEEK_FLAG_SEGMENT;
1064 s_event = gst_event_new_seek (1.0,
1065 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_NONE, 0);
1067 GST_DEBUG ("seek to %" GST_TIME_FORMAT, GST_TIME_ARGS (real));
1069 res = send_event (s_event);
1072 gst_pipeline_set_new_stream_time (GST_PIPELINE (pipeline), 0);
1073 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL,
1076 g_print ("seek failed\n");
1080 seek_cb (GtkWidget * widget)
1083 /* If the timer hasn't expired yet, then the pipeline is running */
1084 if (seek_timeout_id != 0) {
1085 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1092 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1094 if (seek_timeout_id == 0) {
1096 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget);
1102 set_update_scale (gboolean active)
1105 if (update_id == 0) {
1107 g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
1111 g_source_remove (update_id);
1118 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
1120 if (state == GST_STATE_PLAYING)
1121 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1123 set_update_scale (FALSE);
1125 if (changed_id == 0) {
1126 changed_id = gtk_signal_connect (GTK_OBJECT (hscale),
1127 "value_changed", G_CALLBACK (seek_cb), pipeline);
1134 stop_seek (GtkWidget * widget, gpointer user_data)
1136 g_signal_handler_disconnect (GTK_OBJECT (hscale), changed_id);
1138 if (seek_timeout_id != 0) {
1139 g_source_remove (seek_timeout_id);
1140 seek_timeout_id = 0;
1141 /* Still scrubbing, so the pipeline is already playing */
1143 if (state == GST_STATE_PLAYING)
1144 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1147 set_update_scale (TRUE);
1153 play_cb (GtkButton * button, gpointer data)
1155 GstStateChangeReturn ret;
1157 if (state != GST_STATE_PLAYING) {
1158 g_print ("PLAY pipeline\n");
1159 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1160 if (ret == GST_STATE_CHANGE_FAILURE)
1163 set_update_scale (TRUE);
1164 state = GST_STATE_PLAYING;
1170 g_print ("PLAY failed\n");
1175 pause_cb (GtkButton * button, gpointer data)
1177 GstStateChangeReturn ret;
1179 if (state != GST_STATE_PAUSED) {
1180 g_print ("PAUSE pipeline\n");
1181 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
1182 if (ret == GST_STATE_CHANGE_FAILURE)
1185 set_update_scale (FALSE);
1186 state = GST_STATE_PAUSED;
1192 g_print ("PAUSE failed\n");
1197 stop_cb (GtkButton * button, gpointer data)
1199 GstStateChangeReturn ret;
1201 if (state != GST_STATE_READY) {
1202 g_print ("READY pipeline\n");
1203 ret = gst_element_set_state (pipeline, GST_STATE_READY);
1204 if (ret == GST_STATE_CHANGE_FAILURE)
1207 gtk_adjustment_set_value (adjustment, 0.0);
1208 set_update_scale (FALSE);
1210 state = GST_STATE_READY;
1216 g_print ("READY failed\n");
1221 accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1223 accurate_seek = gtk_toggle_button_get_active (button);
1227 key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1229 keyframe_seek = gtk_toggle_button_get_active (button);
1233 loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline)
1235 loop_seek = gtk_toggle_button_get_active (button);
1239 segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
1247 flags |= GST_SEEK_FLAG_SEGMENT;
1249 event = gst_event_new_seek (1.0,
1250 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, 0);
1252 GST_DEBUG ("segmeent seek to start");
1254 res = send_event (event);
1256 g_print ("segment seek failed\n");
1261 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
1263 const GstStructure *s;
1265 s = gst_message_get_structure (message);
1266 g_print ("message from \"%s\" (%s): ",
1267 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
1268 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
1272 sstr = gst_structure_to_string (s);
1273 g_print ("%s\n", sstr);
1276 g_print ("no message details\n");
1284 GstElement *(*func) (const gchar * location);
1288 static Pipeline pipelines[] = {
1289 {"mp3", make_mp3_pipeline},
1290 {"avi", make_avi_pipeline},
1291 {"mpeg1", make_mpeg_pipeline},
1292 {"mpegparse", make_parse_pipeline},
1293 {"vorbis", make_vorbis_pipeline},
1294 {"theora", make_theora_pipeline},
1295 {"ogg/v/t", make_vorbis_theora_pipeline},
1296 {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
1297 {"sid", make_sid_pipeline},
1298 {"flac", make_flac_pipeline},
1299 {"wav", make_wav_pipeline},
1300 {"mod", make_mod_pipeline},
1301 {"dv", make_dv_pipeline},
1302 {"mpeg1nothreads", make_mpegnt_pipeline},
1303 {"playerbin", make_playerbin_pipeline},
1304 {"parse-launch", make_parselaunch_pipeline},
1308 #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1)
1311 print_usage (int argc, char **argv)
1315 g_print ("usage: %s <type> <filename>\n", argv[0]);
1316 g_print (" possible types:\n");
1318 for (i = 0; i < NUM_TYPES; i++) {
1319 g_print (" %d = %s\n", i, pipelines[i].name);
1324 main (int argc, char **argv)
1326 GtkWidget *window, *hbox, *vbox, *play_button, *pause_button, *stop_button;
1327 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox;
1328 GOptionEntry options[] = {
1329 {"stats", 's', 0, G_OPTION_ARG_NONE, &stats,
1330 "Show pad stats", NULL},
1331 {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek,
1332 "Seek on elements instead of pads", NULL},
1333 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
1334 "Verbose properties", NULL},
1338 GOptionContext *ctx;
1341 ctx = g_option_context_new ("seek");
1342 g_option_context_add_main_entries (ctx, options, NULL);
1343 g_option_context_add_group (ctx, gst_init_get_option_group ());
1345 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1346 g_print ("Error initializing: %s\n", err->message);
1350 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
1352 gtk_init (&argc, &argv);
1355 print_usage (argc, argv);
1359 type = atoi (argv[1]);
1361 if (type < 0 || type >= NUM_TYPES) {
1362 print_usage (argc, argv);
1366 pipeline = pipelines[type].func (argv[2]);
1367 g_assert (pipeline);
1369 /* initialize gui elements ... */
1370 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1371 hbox = gtk_hbox_new (FALSE, 0);
1372 vbox = gtk_vbox_new (FALSE, 0);
1373 play_button = gtk_button_new_with_label ("play");
1374 pause_button = gtk_button_new_with_label ("pause");
1375 stop_button = gtk_button_new_with_label ("stop");
1377 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
1378 key_checkbox = gtk_check_button_new_with_label ("Key_unit Seek");
1379 loop_checkbox = gtk_check_button_new_with_label ("Loop");
1382 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
1383 hscale = gtk_hscale_new (adjustment);
1384 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
1385 gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);
1387 gtk_signal_connect (GTK_OBJECT (hscale),
1388 "button_press_event", G_CALLBACK (start_seek), pipeline);
1389 gtk_signal_connect (GTK_OBJECT (hscale),
1390 "button_release_event", G_CALLBACK (stop_seek), pipeline);
1391 gtk_signal_connect (GTK_OBJECT (hscale),
1392 "format_value", G_CALLBACK (format_value), pipeline);
1394 /* do the packing stuff ... */
1395 gtk_window_set_default_size (GTK_WINDOW (window), 250, 96);
1396 gtk_container_add (GTK_CONTAINER (window), vbox);
1397 gtk_container_add (GTK_CONTAINER (vbox), hbox);
1398 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
1399 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
1400 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
1401 gtk_box_pack_start (GTK_BOX (hbox), accurate_checkbox, FALSE, FALSE, 2);
1402 gtk_box_pack_start (GTK_BOX (hbox), key_checkbox, FALSE, FALSE, 2);
1403 gtk_box_pack_start (GTK_BOX (hbox), loop_checkbox, FALSE, FALSE, 2);
1404 gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2);
1406 /* connect things ... */
1407 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
1409 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
1411 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
1413 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
1414 G_CALLBACK (accurate_toggle_cb), pipeline);
1415 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
1416 G_CALLBACK (key_toggle_cb), pipeline);
1417 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
1418 G_CALLBACK (loop_toggle_cb), pipeline);
1420 g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL);
1423 gtk_widget_show_all (window);
1426 g_signal_connect (pipeline, "deep_notify",
1427 G_CALLBACK (gst_object_default_deep_notify), NULL);
1432 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
1433 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
1435 // g_signal_connect (bus, "message::state-changed", (GCallback) message_received, pipeline);
1436 g_signal_connect (bus, "message::new-clock", (GCallback) message_received,
1438 g_signal_connect (bus, "message::error", (GCallback) message_received,
1440 g_signal_connect (bus, "message::warning", (GCallback) message_received,
1442 g_signal_connect (bus, "message::eos", (GCallback) message_received,
1444 g_signal_connect (bus, "message::segment-done",
1445 (GCallback) message_received, pipeline);
1446 g_signal_connect (bus, "message::segment-done", (GCallback) segment_done,
1451 g_print ("NULL pipeline\n");
1452 gst_element_set_state (pipeline, GST_STATE_NULL);
1454 g_print ("free pipeline\n");
1455 gst_object_unref (pipeline);