seek.c 45.3 KB
Newer Older
1
#include <stdlib.h>
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
2 3 4 5 6
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <string.h>

7
GST_DEBUG_CATEGORY_STATIC (seek_debug);
8 9
#define GST_CAT_DEFAULT (seek_debug)

10
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
11
static GList *rate_pads = NULL;
12
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
13

14 15
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
16
static gboolean loop_seek = FALSE;
17
static gboolean flush_seek = TRUE;
18 19
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
20

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
21
static GstElement *pipeline;
Wim Taymans's avatar
Wim Taymans committed
22 23
static gint64 position;
static gint64 duration;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
24
static GtkAdjustment *adjustment;
25
static GtkWidget *hscale;
26
static gboolean stats = FALSE;
27 28
static gboolean elem_seek = FALSE;
static gboolean verbose = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
29

30 31
static GstState state;
static guint update_id = 0;
32 33
static guint seek_timeout_id = 0;
static gulong changed_id;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
34

Wim Taymans's avatar
Wim Taymans committed
35
//#define SOURCE "filesrc"
36
#define SOURCE "gnomevfssrc"
37 38
#define ASINK "alsasink"
//#define ASINK "osssink"
Wim Taymans's avatar
Wim Taymans committed
39
#define VSINK "xvimagesink"
40
//#define VSINK "sdlvideosink"
Wim Taymans's avatar
Wim Taymans committed
41 42
//#define VSINK "ximagesink"
//#define VSINK "aasink"
43
//#define VSINK "cacasink"
44

45
//#define UPDATE_INTERVAL 500
46 47
//#define UPDATE_INTERVAL 100
#define UPDATE_INTERVAL 10
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
48

49
/* number of milliseconds to play for after a seek */
50 51 52 53
#define SCRUB_TIME 100

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
55
#define THREAD
56
#define PAD_SEEK
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
57 58 59

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
60 61 62
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
63 64
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
65

66
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
67
gst_element_factory_make_or_warn (gchar * type, gchar * name)
68 69 70 71
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
72
    g_warning ("Failed to create element %s of type %s", name, type);
73 74 75 76 77
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
78
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
79
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
80
{
81
  gchar *padname;
82
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
83

84 85 86
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
87 88
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
89
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
90

91
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
92 93
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
94
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
95 96 97
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
98 99
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
100
{
101
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
102

103
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
104 105 106
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
107

108
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
109
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
110 111
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
112 113
static GstElement *
make_mod_pipeline (const gchar * location)
114 115 116 117
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
118

119 120
  pipeline = gst_pipeline_new ("app");

121 122
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
123
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
124 125 126 127 128 129 130 131
  //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);

132 133
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
134 135 136 137 138 139 140 141 142

  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
143 144
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
145 146
{
  GstElement *pipeline;
147
  GstElement *src, *demux, *decoder, *audiosink, *videosink;
148
  GstElement *a_queue, *v_queue;
Wim Taymans's avatar
Wim Taymans committed
149
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
150

Wim Taymans's avatar
Wim Taymans committed
151 152 153
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
154
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
155
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
156
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
157
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
158
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
159
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
160 161 162 163

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

  gst_bin_add (GST_BIN (pipeline), src);
164
  gst_bin_add (GST_BIN (pipeline), demux);
165
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
166
  gst_bin_add (GST_BIN (pipeline), audiosink);
167
  gst_bin_add (GST_BIN (pipeline), v_queue);
168
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
169 170
  gst_bin_add (GST_BIN (pipeline), videosink);

171
  gst_element_link (src, demux);
172
  gst_element_link (a_queue, audiosink);
173 174
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
175

176 177 178 179
  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);
180

181 182
  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
183 184 185 186 187
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
188 189
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
190 191 192
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
193

Wim Taymans's avatar
Wim Taymans committed
194 195
  pipeline = gst_pipeline_new ("app");

196 197
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
198
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
199 200 201 202 203 204 205

  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);

206
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
207

208 209 210 211 212 213 214
  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
215 216 217 218

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
219 220
static GstElement *
make_flac_pipeline (const gchar * location)
221 222 223 224
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
225

226 227
  pipeline = gst_pipeline_new ("app");

228 229
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
230
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
231
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
232 233 234 235 236 237 238

  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);

239 240
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
241 242 243 244 245 246 247 248 249

  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
250 251
static GstElement *
make_sid_pipeline (const gchar * location)
252 253 254 255
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
256

257 258
  pipeline = gst_pipeline_new ("app");

259 260
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
261
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
262 263 264 265 266 267 268 269
  //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);

270 271
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
272 273 274 275 276 277 278 279 280

  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
281 282
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
283 284 285 286
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
287

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
288 289
  pipeline = gst_pipeline_new ("app");

290 291 292
  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
293 294
  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
295 296 297 298 299 300 301

  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);

302 303
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
304 305

  seekable = gst_element_get_pad (parser, "src");
306
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
307 308 309 310 311 312
  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
313 314
static GstElement *
make_vorbis_pipeline (const gchar * location)
315
{
316 317
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
318
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
319

320 321
  pipeline = gst_pipeline_new ("app");

322
  src = gst_element_factory_make_or_warn (SOURCE, "src");
323 324 325
  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");
326
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
327
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
328 329 330

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

331 332
  audio_bin = gst_bin_new ("a_decoder_bin");

333
  gst_bin_add (GST_BIN (pipeline), src);
334 335 336 337 338
  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);
339

340 341 342 343
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

344 345 346 347 348 349
  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);
350 351 352 353 354 355 356 357 358 359 360 361 362 363

  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;
364
  GstPad *pad, *seekable;
365 366 367 368 369 370 371

  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
372
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388

  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);

389 390 391 392 393 394
  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);
395 396 397 398 399 400 401 402 403

  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;
}

404 405 406 407 408 409
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;
410
  GstElement *a_queue, *v_queue, *v_scale;
411
  GstPad *seekable;
Wim Taymans's avatar
Wim Taymans committed
412
  GstPad *pad;
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428

  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");
429
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
430

431
  gst_bin_add (GST_BIN (pipeline), audio_bin);
432 433 434 435 436 437

  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);

438 439 440
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
441

Wim Taymans's avatar
Wim Taymans committed
442 443
  pad = gst_element_get_pad (a_queue, "sink");
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
444
  gst_object_unref (pad);
445 446 447

  setup_dynamic_link (demux, NULL, gst_element_get_pad (audio_bin, "sink"),
      NULL);
448 449 450 451 452 453

  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");
454
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
455
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
456 457

  gst_bin_add (GST_BIN (pipeline), video_bin);
458 459 460 461

  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);
462
  gst_bin_add (GST_BIN (video_bin), v_scale);
463 464
  gst_bin_add (GST_BIN (video_bin), videosink);

465 466
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
467

Wim Taymans's avatar
Wim Taymans committed
468 469
  pad = gst_element_get_pad (v_queue, "sink");
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
470
  gst_object_unref (pad);
471 472 473

  setup_dynamic_link (demux, NULL, gst_element_get_pad (video_bin, "sink"),
      NULL);
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490

  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;
491
  GstPad *seekable, *pad;
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507

  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");
508
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
509 510 511 512 513 514

  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);

515 516 517 518
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

519 520
  gst_bin_add (GST_BIN (pipeline), audio_bin);

521 522 523 524 525 526
  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);
527 528 529 530 531 532

  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
533
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
534 535 536 537 538 539

  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);

540 541
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

542 543
  gst_bin_add (GST_BIN (pipeline), video_bin);

544 545 546 547 548 549
  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);
550 551 552 553 554 555 556 557 558 559

  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
560 561
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
562 563
{
  GstElement *pipeline;
564
  GstElement *src, *decoder, *osssink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
565
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
566

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
567 568
  pipeline = gst_pipeline_new ("app");

569 570 571
  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");
572
  osssink = gst_element_factory_make_or_warn (ASINK, "sink");
573

574
  seekable_elements = g_list_prepend (seekable_elements, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
575 576

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

579 580
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
581 582
  gst_bin_add (GST_BIN (pipeline), queue);
  gst_bin_add (GST_BIN (pipeline), osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
583

584 585
  gst_element_link (src, decoder);
  gst_element_link (decoder, queue);
586
  gst_element_link (queue, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
587

588 589
  seekable = gst_element_get_pad (queue, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
590 591 592 593 594 595
  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
596 597
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
598 599 600
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
601
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
602
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
603

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
604 605
  pipeline = gst_pipeline_new ("app");

606
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
607 608
  g_object_set (G_OBJECT (src), "location", location, NULL);

609
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
610
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
611 612 613

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
614
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
615 616

  audio_bin = gst_bin_new ("a_decoder_bin");
617
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
618
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
619
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
620 621
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
622
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
623 624
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
625
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
626

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
627
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
628
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
629 630

  seekable = gst_element_get_pad (a_queue, "src");
631
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
632
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
633 634
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
635 636

  video_bin = gst_bin_new ("v_decoder_bin");
Wim Taymans's avatar
Wim Taymans committed
637
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
638
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
639
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
640 641
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
642
  gst_bin_add (GST_BIN (video_bin), v_decoder);
643 644
  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
645

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
648
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
649
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
650 651

  seekable = gst_element_get_pad (v_queue, "src");
652
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
653
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
654 655
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
656 657 658 659

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
660 661
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
662 663
{
  GstElement *pipeline, *audio_bin, *video_bin;
664 665
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
666
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
667
  GstPad *seekable;
668
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
669

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
670 671
  pipeline = gst_pipeline_new ("app");

672
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
673 674
  g_object_set (G_OBJECT (src), "location", location, NULL);

675 676
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
677

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
678 679
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
680
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
681 682

  audio_bin = gst_bin_new ("a_decoder_bin");
683 684
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
685
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
686
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
687 688
  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
689

690 691
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
692

693 694 695 696 697 698 699 700
  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
701 702

  video_bin = gst_bin_new ("v_decoder_bin");
703 704
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
705
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
706
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
707

708 709 710 711 712 713 714
  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);
715
  gst_element_link (v_filter, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
716

717
  gst_bin_add (GST_BIN (pipeline), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
718

719 720 721 722 723 724 725 726
  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");
727
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
728
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
729 730
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
731 732 733 734

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
735 736
static GstElement *
make_mpegnt_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
737 738 739 740
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
741
  GstElement *a_queue;
Wim Taymans's avatar
Wim Taymans committed
742
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
743

Wim Taymans's avatar
Wim Taymans committed
744 745 746 747 748 749 750 751 752 753 754 755
  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);
756
  gst_element_link (src, demux);
Wim Taymans's avatar
Wim Taymans committed
757 758 759 760

  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");
761
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Wim Taymans's avatar
Wim Taymans committed
762 763
  //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
764 765
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Wim Taymans's avatar
Wim Taymans committed
766
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
767 768
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
769

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
770
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
771
          "sink"), audio_bin);
Wim Taymans's avatar
Wim Taymans committed
772 773 774 775

  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
776 777
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
778 779 780

  video_bin = gst_bin_new ("v_decoder_bin");
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
781
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
782
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
783
  gst_element_link_many (v_decoder, v_filter, videosink, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
784

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
787
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
788
          "sink"), video_bin);
Wim Taymans's avatar
Wim Taymans committed
789 790 791 792

  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
793 794
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
795 796 797 798

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
799 800
static GstElement *
make_playerbin_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
801
{
802
  GstElement *player;
803 804 805 806

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

807
  g_object_set (G_OBJECT (player), "uri", location, NULL);
808 809 810 811 812 813 814

  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
815 816
}

817
#ifndef GST_DISABLE_PARSE
818 819 820 821 822 823 824 825 826 827 828 829 830 831
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;
}
832
#endif
833

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
834 835
static gchar *
format_value (GtkScale * scale, gdouble value)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
836
{
837 838 839 840 841 842 843
  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
844

845 846
  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
847 848 849 850 851 852
}

typedef struct
{
  const gchar *name;
  const GstFormat format;
853 854
}
seek_format;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
855

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
856 857 858 859 860 861
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
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
};

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
880 881
      if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
              &value)) {