seek.c 50.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* GStreamer
 *
 * seek.c: seeking sample application
 *
 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
 *               2006 Stefan Kost <ensonic@users.sf.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
/* FIXME: remove #if 0 code
 * FIXME: is the flush_seek part after sending the seek still needed?
 *
 */
27
#include <stdlib.h>
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
28
29
30
31
32
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <string.h>

33
GST_DEBUG_CATEGORY_STATIC (seek_debug);
34
35
#define GST_CAT_DEFAULT (seek_debug)

36
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
37
static GList *rate_pads = NULL;
38
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
39

40
41
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
42
static gboolean loop_seek = FALSE;
43
static gboolean flush_seek = TRUE;
44
45
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
46
static gdouble rate = 1.0;
47

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
48
static GstElement *pipeline;
49
50
static gint64 position = -1;
static gint64 duration = -1;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
51
static GtkAdjustment *adjustment;
52
static GtkWidget *hscale;
53
static gboolean stats = FALSE;
54
55
static gboolean elem_seek = FALSE;
static gboolean verbose = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
56

57
static GstState state = GST_STATE_NULL;
58
static guint update_id = 0;
59
60
static guint seek_timeout_id = 0;
static gulong changed_id;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
61

Wim Taymans's avatar
Wim Taymans committed
62
//#define SOURCE "filesrc"
63
#define SOURCE "gnomevfssrc"
64
65
#define ASINK "alsasink"
//#define ASINK "osssink"
Wim Taymans's avatar
Wim Taymans committed
66
#define VSINK "xvimagesink"
67
//#define VSINK "sdlvideosink"
Wim Taymans's avatar
Wim Taymans committed
68
69
//#define VSINK "ximagesink"
//#define VSINK "aasink"
70
//#define VSINK "cacasink"
71

72
//#define UPDATE_INTERVAL 500
73
74
//#define UPDATE_INTERVAL 100
#define UPDATE_INTERVAL 10
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
75

76
/* number of milliseconds to play for after a seek */
77
78
79
80
#define SCRUB_TIME 100

/* seek timeout */
#define SEEK_TIMEOUT 40 * GST_MSECOND
81

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
82
#define THREAD
83
#define PAD_SEEK
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
84
85
86

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
87
88
89
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
90
91
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
92

93
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
94
gst_element_factory_make_or_warn (gchar * type, gchar * name)
95
96
97
98
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
99
    g_warning ("Failed to create element %s of type %s", name, type);
100
101
102
103
104
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
105
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
106
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
107
{
108
  gchar *padname;
109
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
110

111
112
113
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
114
115
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
116
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
117

118
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
119
120
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
121
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
122
123
124
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
125
126
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
127
{
128
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
129

130
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
131
132
133
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
134

135
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
136
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
137
138
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
139
140
static GstElement *
make_mod_pipeline (const gchar * location)
141
142
143
144
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
145

146
147
  pipeline = gst_pipeline_new ("app");

148
149
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
150
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
151
152
153
154
155
156
157
158
  //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);

  g_object_set (G_OBJECT (src), "location", location, NULL);

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
  gst_bin_add (GST_BIN (pipeline), audiosink);

159
160
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
161
162
163
164
165
166
167
168
169

  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
170
171
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
172
173
{
  GstElement *pipeline;
174
  GstElement *src, *demux, *decoder, *audiosink, *videosink;
175
  GstElement *a_queue, *v_queue;
Wim Taymans's avatar
Wim Taymans committed
176
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
177

Wim Taymans's avatar
Wim Taymans committed
178
179
180
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
181
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
182
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
183
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
184
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
185
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
186
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
187
188
189
190

  g_object_set (G_OBJECT (src), "location", location, NULL);

  gst_bin_add (GST_BIN (pipeline), src);
191
  gst_bin_add (GST_BIN (pipeline), demux);
192
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
193
  gst_bin_add (GST_BIN (pipeline), audiosink);
194
  gst_bin_add (GST_BIN (pipeline), v_queue);
195
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
196
197
  gst_bin_add (GST_BIN (pipeline), videosink);

198
  gst_element_link (src, demux);
199
  gst_element_link (a_queue, audiosink);
200
201
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
202

203
204
205
206
  setup_dynamic_link (demux, "video", gst_element_get_pad (v_queue, "sink"),
      NULL);
  setup_dynamic_link (demux, "audio", gst_element_get_pad (a_queue, "sink"),
      NULL);
207

208
209
  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
210
211
212
213
214
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
215
216
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
217
218
219
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
220

Wim Taymans's avatar
Wim Taymans committed
221
222
  pipeline = gst_pipeline_new ("app");

223
224
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
225
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
226
227
228
229
230
231
232

  g_object_set (G_OBJECT (src), "location", location, NULL);

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
  gst_bin_add (GST_BIN (pipeline), audiosink);

233
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
234

235
236
237
238
239
240
241
  setup_dynamic_link (decoder, "src", gst_element_get_pad (audiosink, "sink"),
      NULL);

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
242
243
244
245

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
246
247
static GstElement *
make_flac_pipeline (const gchar * location)
248
249
250
251
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
252

253
254
  pipeline = gst_pipeline_new ("app");

255
256
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
257
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
258
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
259
260
261
262
263
264
265

  g_object_set (G_OBJECT (src), "location", location, NULL);

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
  gst_bin_add (GST_BIN (pipeline), audiosink);

266
267
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
268
269
270
271
272
273
274
275
276

  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
277
278
static GstElement *
make_sid_pipeline (const gchar * location)
279
280
281
282
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
283

284
285
  pipeline = gst_pipeline_new ("app");

286
287
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
288
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
289
290
291
292
293
294
295
296
  //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);

  g_object_set (G_OBJECT (src), "location", location, NULL);

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
  gst_bin_add (GST_BIN (pipeline), audiosink);

297
298
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
299
300
301
302
303
304
305
306
307

  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
308
309
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
310
311
312
313
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
314

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
315
316
  pipeline = gst_pipeline_new ("app");

317
318
319
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  parser = gst_element_factory_make_or_warn ("mpegparse", "parse");
  fakesink = gst_element_factory_make_or_warn ("fakesink", "sink");
Wim Taymans's avatar
Wim Taymans committed
320
321
  g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL);
  g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
322
323
324
325
326
327
328

  g_object_set (G_OBJECT (src), "location", location, NULL);

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), parser);
  gst_bin_add (GST_BIN (pipeline), fakesink);

329
330
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
331
332

  seekable = gst_element_get_pad (parser, "src");
333
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
334
335
336
337
338
339
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (parser, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
340
341
static GstElement *
make_vorbis_pipeline (const gchar * location)
342
{
343
344
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
345
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
346

347
348
  pipeline = gst_pipeline_new ("app");

349
  src = gst_element_factory_make_or_warn (SOURCE, "src");
350
351
352
  demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
  decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder");
  convert = gst_element_factory_make_or_warn ("audioconvert", "convert");
353
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
354
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
355
356
357

  g_object_set (G_OBJECT (src), "location", location, NULL);

358
359
  audio_bin = gst_bin_new ("a_decoder_bin");

360
  gst_bin_add (GST_BIN (pipeline), src);
361
362
363
364
365
  gst_bin_add (GST_BIN (pipeline), demux);
  gst_bin_add (GST_BIN (audio_bin), decoder);
  gst_bin_add (GST_BIN (audio_bin), convert);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
  gst_bin_add (GST_BIN (pipeline), audio_bin);
366

367
368
369
370
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

371
372
373
374
375
376
  pad = gst_element_get_pad (decoder, "sink");
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

  setup_dynamic_link (demux, NULL, gst_element_get_pad (audio_bin, "sink"),
      NULL);
377
378
379
380
381
382
383
384
385
386
387
388
389
390

  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
391
  GstPad *pad, *seekable;
392
393
394
395
396
397
398

  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
  demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
  decoder = gst_element_factory_make_or_warn ("theoradec", "decoder");
  convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert");
Wim Taymans's avatar
Wim Taymans committed
399
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415

  g_object_set (G_OBJECT (src), "location", location, NULL);

  video_bin = gst_bin_new ("v_decoder_bin");

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
  gst_bin_add (GST_BIN (video_bin), decoder);
  gst_bin_add (GST_BIN (video_bin), convert);
  gst_bin_add (GST_BIN (video_bin), videosink);
  gst_bin_add (GST_BIN (pipeline), video_bin);

  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, videosink);

416
417
418
419
420
421
  pad = gst_element_get_pad (decoder, "sink");
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

  setup_dynamic_link (demux, NULL, gst_element_get_pad (video_bin, "sink"),
      NULL);
422
423
424
425
426
427
428
429
430

  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

431
432
433
434
435
436
static GstElement *
make_vorbis_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
  GstElement *audiosink, *videosink;
437
  GstElement *a_queue, *v_queue, *v_scale;
438
  GstPad *seekable;
Wim Taymans's avatar
Wim Taymans committed
439
  GstPad *pad;
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455

  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
  g_object_set (G_OBJECT (src), "location", location, NULL);

  demux = gst_element_factory_make_or_warn ("oggdemux", "demux");

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
  gst_element_link (src, demux);

  audio_bin = gst_bin_new ("a_decoder_bin");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
  a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec");
  a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
456
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
457

458
  gst_bin_add (GST_BIN (pipeline), audio_bin);
459
460
461
462
463
464

  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
  gst_bin_add (GST_BIN (audio_bin), a_convert);
  gst_bin_add (GST_BIN (audio_bin), audiosink);

465
466
467
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
468

Wim Taymans's avatar
Wim Taymans committed
469
470
  pad = gst_element_get_pad (a_queue, "sink");
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
471
  gst_object_unref (pad);
472
473
474

  setup_dynamic_link (demux, NULL, gst_element_get_pad (audio_bin, "sink"),
      NULL);
475
476
477
478
479
480

  video_bin = gst_bin_new ("v_decoder_bin");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
  v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec");
  v_convert =
      gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
481
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
482
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
483
484

  gst_bin_add (GST_BIN (pipeline), video_bin);
485
486
487
488

  gst_bin_add (GST_BIN (video_bin), v_queue);
  gst_bin_add (GST_BIN (video_bin), v_decoder);
  gst_bin_add (GST_BIN (video_bin), v_convert);
489
  gst_bin_add (GST_BIN (video_bin), v_scale);
490
491
  gst_bin_add (GST_BIN (video_bin), videosink);

492
493
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
494

Wim Taymans's avatar
Wim Taymans committed
495
496
  pad = gst_element_get_pad (v_queue, "sink");
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
497
  gst_object_unref (pad);
498
499
500

  setup_dynamic_link (demux, NULL, gst_element_get_pad (video_bin, "sink"),
      NULL);
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

  seekable = gst_element_get_pad (a_decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));

  return pipeline;
}

static GstElement *
make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
  GstElement *audiosink, *videosink;
  GstElement *a_queue, *v_queue;
518
  GstPad *seekable, *pad;
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534

  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
  g_object_set (G_OBJECT (src), "location", location, NULL);

  demux = gst_element_factory_make_or_warn ("avidemux", "demux");

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
  gst_element_link (src, demux);

  audio_bin = gst_bin_new ("a_decoder_bin");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
535
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
536
537
538
539
540
541

  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
  gst_bin_add (GST_BIN (audio_bin), a_convert);
  gst_bin_add (GST_BIN (audio_bin), audiosink);

542
543
544
545
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

546
547
  gst_bin_add (GST_BIN (pipeline), audio_bin);

548
549
550
551
552
553
  pad = gst_element_get_pad (a_queue, "sink");
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

  setup_dynamic_link (demux, NULL, gst_element_get_pad (audio_bin, "sink"),
      NULL);
554
555
556
557
558
559

  video_bin = gst_bin_new ("v_decoder_bin");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
  v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
  v_convert =
      gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
Wim Taymans's avatar
Wim Taymans committed
560
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
561
562
563
564
565
566

  gst_bin_add (GST_BIN (video_bin), v_queue);
  gst_bin_add (GST_BIN (video_bin), v_decoder);
  gst_bin_add (GST_BIN (video_bin), v_convert);
  gst_bin_add (GST_BIN (video_bin), videosink);

567
568
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

569
570
  gst_bin_add (GST_BIN (pipeline), video_bin);

571
572
573
574
575
576
  pad = gst_element_get_pad (v_queue, "sink");
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

  setup_dynamic_link (demux, NULL, gst_element_get_pad (video_bin, "sink"),
      NULL);
577
578
579
580
581
582
583
584
585
586

  seekable = gst_element_get_pad (a_decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
587
588
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
589
590
{
  GstElement *pipeline;
591
  GstElement *src, *decoder, *osssink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
592
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
593

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
594
595
  pipeline = gst_pipeline_new ("app");

596
597
598
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("mad", "dec");
  queue = gst_element_factory_make_or_warn ("queue", "queue");
599
  osssink = gst_element_factory_make_or_warn (ASINK, "sink");
600

601
  seekable_elements = g_list_prepend (seekable_elements, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
602
603

  g_object_set (G_OBJECT (src), "location", location, NULL);
604
  //g_object_set (G_OBJECT (osssink), "fragment", 0x00180008, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
605

606
607
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
608
609
  gst_bin_add (GST_BIN (pipeline), queue);
  gst_bin_add (GST_BIN (pipeline), osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
610

611
612
  gst_element_link (src, decoder);
  gst_element_link (decoder, queue);
613
  gst_element_link (queue, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
614

615
616
  seekable = gst_element_get_pad (queue, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
617
618
619
620
621
622
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
623
624
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
625
626
627
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
628
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
629
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
630

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
631
632
  pipeline = gst_pipeline_new ("app");

633
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
634
635
  g_object_set (G_OBJECT (src), "location", location, NULL);

636
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
637
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
638
639
640

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
641
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
642
643

  audio_bin = gst_bin_new ("a_decoder_bin");
644
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
645
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
646
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
647
648
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
649
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
650
651
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
652
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
653

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
654
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
655
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
656
657

  seekable = gst_element_get_pad (a_queue, "src");
658
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
659
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
660
661
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
662
663

  video_bin = gst_bin_new ("v_decoder_bin");
Wim Taymans's avatar
Wim Taymans committed
664
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
665
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
666
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
667
668
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
669
  gst_bin_add (GST_BIN (video_bin), v_decoder);
670
671
  gst_bin_add (GST_BIN (video_bin), v_queue);
  gst_bin_add (GST_BIN (video_bin), videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
672

Wim Taymans's avatar
Wim Taymans committed
673
  gst_element_set_state (video_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
674

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
675
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
676
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
677
678

  seekable = gst_element_get_pad (v_queue, "src");
679
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
680
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
681
682
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
683
684
685
686

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
687
688
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
689
690
{
  GstElement *pipeline, *audio_bin, *video_bin;
691
692
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
693
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
694
  GstPad *seekable;
695
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
696

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
697
698
  pipeline = gst_pipeline_new ("app");

699
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
700
701
  g_object_set (G_OBJECT (src), "location", location, NULL);

702
703
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
704

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
705
706
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
707
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
708
709

  audio_bin = gst_bin_new ("a_decoder_bin");
710
711
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
712
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
713
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
714
715
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
716

717
718
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
719

720
721
722
723
724
725
726
727
  gst_bin_add (GST_BIN (pipeline), audio_bin);

  pad = gst_element_get_pad (a_decoder, "sink");
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

  setup_dynamic_link (demux, "audio_c0", gst_element_get_pad (audio_bin,
          "sink"), NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
728
729

  video_bin = gst_bin_new ("v_decoder_bin");
730
731
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
732
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
733
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
734

735
736
737
738
739
740
741
  gst_bin_add (GST_BIN (video_bin), v_decoder);
  gst_bin_add (GST_BIN (video_bin), v_queue);
  gst_bin_add (GST_BIN (video_bin), v_filter);
  gst_bin_add (GST_BIN (video_bin), videosink);

  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, v_filter);
742
  gst_element_link (v_filter, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
743

744
  gst_bin_add (GST_BIN (pipeline), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
745

746
747
748
749
750
751
752
753
  pad = gst_element_get_pad (v_decoder, "sink");
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

  setup_dynamic_link (demux, "video_e0", gst_element_get_pad (video_bin,
          "sink"), NULL);

  seekable = gst_element_get_pad (v_filter, "src");
754
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
755
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
756
757
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
758
759
760
761

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
762
763
static GstElement *
make_mpegnt_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
764
765
766
767
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
768
  GstElement *a_queue;
Wim Taymans's avatar
Wim Taymans committed
769
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
770

Wim Taymans's avatar
Wim Taymans committed
771
772
773
774
775
776
777
778
779
780
781
782
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
  g_object_set (G_OBJECT (src), "location", location, NULL);

  demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);

  seekable_elements = g_list_prepend (seekable_elements, demux);

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
783
  gst_element_link (src, demux);
Wim Taymans's avatar
Wim Taymans committed
784
785
786
787

  audio_bin = gst_bin_new ("a_decoder_bin");
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
788
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Wim Taymans's avatar
Wim Taymans committed
789
790
  //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
791
792
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Wim Taymans's avatar
Wim Taymans committed
793
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
794
795
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
796

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
797
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
798
          "sink"), audio_bin);
Wim Taymans's avatar
Wim Taymans committed
799
800
801
802

  seekable = gst_element_get_pad (a_queue, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
803
804
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
805
806
807

  video_bin = gst_bin_new ("v_decoder_bin");
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
808
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
809
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
810
  gst_element_link_many (v_decoder, v_filter, videosink, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
811

Wim Taymans's avatar
Wim Taymans committed
812
813
  gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
814
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
815
          "sink"), video_bin);
Wim Taymans's avatar
Wim Taymans committed
816
817
818
819

  seekable = gst_element_get_pad (v_decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
820
821
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
822
823
824
825

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
826
827
static GstElement *
make_playerbin_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
828
{
829
  GstElement *player;
830
831
832
833

  player = gst_element_factory_make ("playbin", "player");
  g_assert (player);

834
  g_object_set (G_OBJECT (player), "uri", location, NULL);
835
836
837
838
839
840
841

  seekable_elements = g_list_prepend (seekable_elements, player);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;

  return player;
Wim Taymans's avatar
Wim Taymans committed
842
843
}

844
#ifndef GST_DISABLE_PARSE
845
846
847
848
849
850
851
852
853
854
855
856
857
858
static GstElement *
make_parselaunch_pipeline (const gchar * description)
{
  GstElement *pipeline;
  GError *error;

  pipeline = gst_parse_launch (description, &error);

  seekable_elements = g_list_prepend (seekable_elements, pipeline);

  elem_seek = TRUE;

  return pipeline;
}
859
#endif
860

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
861
862
static gchar *
format_value (GtkScale * scale, gdouble value)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
863
{
864
865
866
867
868
869
870
  gint64 real;
  gint64 seconds;
  gint64 subseconds;

  real = value * duration / 100;
  seconds = (gint64) real / GST_SECOND;
  subseconds = (gint64) real / (GST_SECOND / 100);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
871

872
873
  return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
      G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
874
875
876
877
878
879
}

typedef struct
{
  const gchar *name;
  const GstFormat format;
880
881
}
seek_format;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
882

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
883
884
885
886
887
888
static seek_format seek_formats[] = {
  {"tim", GST_FORMAT_TIME},
  {"byt", GST_FORMAT_BYTES},
  {"buf", GST_FORMAT_BUFFERS},
  {"def", GST_FORMAT_DEFAULT},
  {NULL, 0},
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
};

G_GNUC_UNUSED static void
query_rates (void)
{
  GList *walk = rate_pads;

  while (walk) {
    GstPad *pad = GST_PAD (walk->data);
    gint i = 0;

    g_print ("rate/sec  %8.8s: ", GST_PAD_NAME (pad));
    while (seek_formats[i].name) {
      gint64 value;
      GstFormat format;

      format = seek_formats[i].format;

Wim Taymans's avatar
Wim Taymans committed
907
908
      if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
              &value)) {
909
        g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
910
      } else {
911
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
912
913
914
915
916
917
918
919
920
921
922
      }

      i++;
    }
    g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));

    walk = g_list_next (walk);
  }
}

G_GNUC_UNUSED static void
923
924
925
926
927
928
929
930
931
932
query_positions_elems ()
{
  GList *walk = seekable_elements;

  while (walk) {
    GstElement *element = GST_ELEMENT (walk->data);
    gint i = 0;

    g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
    while (seek_formats[i].name) {
Wim Taymans's avatar
Wim Taymans committed
933
      gint64 position, total;
934
935
936
      GstFormat format;

      format = seek_formats[i].format;
Wim Taymans's avatar
Wim Taymans committed
937

Wim Taymans's avatar
Wim Taymans committed
938
939
      if (gst_element_query_position (element, &format, &position) &&
          gst_element_query_duration (element, &format, &total)) {
Wim Taymans's avatar
Wim Taymans committed
940
941
        g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
            seek_formats[i].name, position, total);
942
      } else {
Wim Taymans's avatar
Wim Taymans committed
943
944
        g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
            "*NA*");
945
946
947
948
949
950
951
952
953
954
955
      }
      i++;
    }
    g_print (" %s\n", GST_ELEMENT_NAME (element));

    walk = g_list_next (walk);
  }
}

G_GNUC_UNUSED static void
query_positions_pads ()
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
956
{
957
958
959
960
961
962
963
964
965
  GList *walk = seekable_pads;

  while (walk) {
    GstPad *pad = GST_PAD (walk->data);
    gint i = 0;

    g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
    while (seek_formats[i].name) {
      GstFormat format;
Wim Taymans's avatar
Wim Taymans committed
966
      gint64 position, total;
967
968

      format = seek_formats[i].format;
Wim Taymans's avatar
Wim Taymans committed
969

Wim Taymans's avatar
Wim Taymans committed
970
971
      if (gst_pad_query_position (pad, &format, &position) &&
          gst_pad_query_duration (pad, &format, &total)) {
Wim Taymans's avatar
Wim Taymans committed
972
973
        g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
            seek_formats[i].name, position, total);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
974
      } else {
Wim Taymans's avatar
Wim Taymans committed
975
976
        g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
            "*NA*");
977
      }
Wim Taymans's avatar
Wim Taymans committed
978

979
      i++;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
980
    }
981
982
983
    g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));

    walk = g_list_next (walk);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
984
985
986
  }
}

987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
static gboolean start_seek (GtkWidget * widget, GdkEventButton * event,
    gpointer user_data);
static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event,
    gpointer user_data);

static void
set_scale (gdouble value)
{
  g_signal_handlers_block_by_func (hscale, start_seek, pipeline);
  g_signal_handlers_block_by_func (hscale, stop_seek, pipeline);
  gtk_adjustment_set_value (adjustment, value);
  g_signal_handlers_unblock_by_func (hscale, start_seek, pipeline);
  g_signal_handlers_unblock_by_func (hscale, stop_seek, pipeline);
  gtk_widget_queue_draw (hscale);
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1003
static gboolean
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1004
update_scale (gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1005
{
1006
  GstFormat format = GST_FORMAT_TIME;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1007

Wim Taymans's avatar
Wim Taymans committed
1008
  position = 0;
1009
  duration = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1010

1011
1012
1013
  if (elem_seek) {
    if (seekable_elements) {
      GstElement *element = GST_ELEMENT (seekable_elements->data);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1014

Wim Taymans's avatar
Wim Taymans committed
1015
1016
      gst_element_query_position (element, &format, &position);
      gst_element_query_duration (element, &format, &duration);
1017
1018
1019
1020
1021
    }
  } else {
    if (seekable_pads) {
      GstPad *pad = GST_PAD (seekable_pads->data);

Wim Taymans's avatar
Wim Taymans committed
1022
1023
      gst_pad_query_position (pad, &format,