seek.c 42.8 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 8 9
GST_DEBUG_CATEGORY (seek_debug);
#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

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

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

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

43 44
//#define UPDATE_INTERVAL 500
#define UPDATE_INTERVAL 100
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
45

46
/* number of milliseconds to play for after a seek */
Wim Taymans's avatar
Wim Taymans committed
47 48
//#define SCRUB_TIME 250
//#define SCRUB
49

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
50
#define THREAD
51
#define PAD_SEEK
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
52 53 54

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
55 56 57
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
58 59
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
60

61
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
62
gst_element_factory_make_or_warn (gchar * type, gchar * name)
63 64 65 66
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
67
    g_warning ("Failed to create element %s of type %s", name, type);
68 69 70 71 72
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
73
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
74
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
75
{
76
  gchar *padname;
77
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
78

79 80 81
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
82 83
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
84
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
85

86
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
87 88
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
89
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
90 91 92
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
93 94
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
95
{
96
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
97

98
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
99 100 101
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
102

103
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
104
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
105 106
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
107 108
static GstElement *
make_mod_pipeline (const gchar * location)
109 110 111 112
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
113

114 115
  pipeline = gst_pipeline_new ("app");

116 117
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
118
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
119 120 121 122 123 124 125 126
  //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);

127 128
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
129 130 131 132 133 134 135 136 137

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

Wim Taymans's avatar
Wim Taymans committed
146 147 148
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
149
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
150
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
151
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
152
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
153
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
154
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
155 156 157 158

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

  gst_bin_add (GST_BIN (pipeline), src);
159
  gst_bin_add (GST_BIN (pipeline), demux);
160
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
161
  gst_bin_add (GST_BIN (pipeline), audiosink);
162
  gst_bin_add (GST_BIN (pipeline), v_queue);
163
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
164 165
  gst_bin_add (GST_BIN (pipeline), videosink);

166
  gst_element_link (src, demux);
167
  gst_element_link (a_queue, audiosink);
168 169
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
170

171 172 173 174
  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);
175

176 177
  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
178 179 180 181 182
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
183 184
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
185 186 187
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
188

Wim Taymans's avatar
Wim Taymans committed
189 190
  pipeline = gst_pipeline_new ("app");

191 192
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
193
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
194 195 196 197 198 199 200

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

201
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
202

203 204 205 206 207 208 209
  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
210 211 212 213

  return pipeline;
}

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

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 ("flacdec", "decoder");
225
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
226
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
227 228 229 230 231 232 233

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

234 235
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
236 237 238 239 240 241 242 243 244

  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
245 246
static GstElement *
make_sid_pipeline (const gchar * location)
247 248 249 250
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
251

252 253
  pipeline = gst_pipeline_new ("app");

254 255
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
256
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
257 258 259 260 261 262 263 264
  //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);

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

  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
276 277
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
278 279 280 281
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
282

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
283 284
  pipeline = gst_pipeline_new ("app");

285 286 287
  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
288 289
  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
290 291 292 293 294 295 296

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

297 298
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
299 300

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

315 316
  pipeline = gst_pipeline_new ("app");

317
  src = gst_element_factory_make_or_warn (SOURCE, "src");
318 319 320
  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");
321
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
322
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
323 324 325

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

326 327
  audio_bin = gst_bin_new ("a_decoder_bin");

328
  gst_bin_add (GST_BIN (pipeline), src);
329 330 331 332 333
  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);
334

335 336 337 338
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

339 340 341 342 343 344
  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);
345 346 347 348 349 350 351 352 353 354 355 356 357 358

  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;
359
  GstPad *pad, *seekable;
360 361 362 363 364 365 366

  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
367
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383

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

384 385 386 387 388 389
  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);
390 391 392 393 394 395 396 397 398

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

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

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

426
  gst_bin_add (GST_BIN (pipeline), audio_bin);
427 428 429 430 431 432

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

433 434 435
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
436

Wim Taymans's avatar
Wim Taymans committed
437 438
  pad = gst_element_get_pad (a_queue, "sink");
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
439
  gst_object_unref (pad);
440 441 442

  setup_dynamic_link (demux, NULL, gst_element_get_pad (audio_bin, "sink"),
      NULL);
443 444 445 446 447 448

  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");
449
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
450
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
451 452

  gst_bin_add (GST_BIN (pipeline), video_bin);
453 454 455 456

  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);
457
  gst_bin_add (GST_BIN (video_bin), v_scale);
458 459
  gst_bin_add (GST_BIN (video_bin), videosink);

460 461
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
462

Wim Taymans's avatar
Wim Taymans committed
463 464
  pad = gst_element_get_pad (v_queue, "sink");
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
465
  gst_object_unref (pad);
466 467 468

  setup_dynamic_link (demux, NULL, gst_element_get_pad (video_bin, "sink"),
      NULL);
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485

  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;
486
  GstPad *seekable, *pad;
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502

  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");
503
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
504 505 506 507 508 509

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

510 511 512 513
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

514 515
  gst_bin_add (GST_BIN (pipeline), audio_bin);

516 517 518 519 520 521
  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);
522 523 524 525 526 527

  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
528
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
529 530 531 532 533 534

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

535 536
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

537 538
  gst_bin_add (GST_BIN (pipeline), video_bin);

539 540 541 542 543 544
  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);
545 546 547 548 549 550 551 552 553 554

  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
555 556
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
557 558
{
  GstElement *pipeline;
559
  GstElement *src, *decoder, *osssink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
560
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
561

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
562 563
  pipeline = gst_pipeline_new ("app");

564 565 566
  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");
567
  osssink = gst_element_factory_make_or_warn (ASINK, "sink");
568

569
  seekable_elements = g_list_prepend (seekable_elements, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
570 571

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

574 575
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
576 577
  gst_bin_add (GST_BIN (pipeline), queue);
  gst_bin_add (GST_BIN (pipeline), osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
578

579 580
  gst_element_link (src, decoder);
  gst_element_link (decoder, queue);
581
  gst_element_link (queue, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
582

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
599 600
  pipeline = gst_pipeline_new ("app");

601
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
602 603
  g_object_set (G_OBJECT (src), "location", location, NULL);

604
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
605
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
606 607 608

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
609
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
610 611

  audio_bin = gst_bin_new ("a_decoder_bin");
612
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
613
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
614
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
615 616
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
617
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
618 619
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
620
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
621

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
622
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
623
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
624 625

  seekable = gst_element_get_pad (a_queue, "src");
626
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
627
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
628 629
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
630 631

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

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
643
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
644
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
645 646

  seekable = gst_element_get_pad (v_queue, "src");
647
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
648
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
649 650
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
651 652 653 654

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
655 656
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
657 658
{
  GstElement *pipeline, *audio_bin, *video_bin;
659 660
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
661
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
662
  GstPad *seekable;
663
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
664

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
665 666
  pipeline = gst_pipeline_new ("app");

667
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
668 669
  g_object_set (G_OBJECT (src), "location", location, NULL);

670 671
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
672

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
673 674
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
675
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
676 677

  audio_bin = gst_bin_new ("a_decoder_bin");
678 679
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
680
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
681
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
682 683
  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
684

685 686
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
687

688 689 690 691 692 693 694 695
  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
696 697

  video_bin = gst_bin_new ("v_decoder_bin");
698 699
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
700
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
701
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
702

703 704 705 706 707 708 709
  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);
710
  gst_element_link (v_filter, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
711

712
  gst_bin_add (GST_BIN (pipeline), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
713

714 715 716 717 718 719 720 721
  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");
722
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
723
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
724 725
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
726 727 728 729

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
730 731
static GstElement *
make_mpegnt_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
732 733 734 735
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
736
  GstElement *a_queue;
Wim Taymans's avatar
Wim Taymans committed
737
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
738

Wim Taymans's avatar
Wim Taymans committed
739 740 741 742 743 744 745 746 747 748 749 750
  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);
751
  gst_element_link (src, demux);
Wim Taymans's avatar
Wim Taymans committed
752 753 754 755

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
765
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
766
          "sink"), audio_bin);
Wim Taymans's avatar
Wim Taymans committed
767 768 769 770

  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
771 772
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
773 774 775

  video_bin = gst_bin_new ("v_decoder_bin");
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
776
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
777
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
778
  gst_element_link_many (v_decoder, v_filter, videosink, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
779

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
782
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
783
          "sink"), video_bin);
Wim Taymans's avatar
Wim Taymans committed
784 785 786 787

  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
788 789
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
790 791 792 793

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
794 795
static GstElement *
make_playerbin_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
796
{
797
  GstElement *player;
798 799 800 801

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

802
  g_object_set (G_OBJECT (player), "uri", location, NULL);
803 804 805 806 807 808 809

  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
810 811
}

812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
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;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
827 828
static gchar *
format_value (GtkScale * scale, gdouble value)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
829
{
830 831 832 833 834 835 836
  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
837

838 839
  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
840 841 842 843 844 845
}

typedef struct
{
  const gchar *name;
  const GstFormat format;
846 847
}
seek_format;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
848

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
849 850 851 852 853 854
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
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
};

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
873 874
      if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
              &value)) {
875
        g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
876
      } else {
877
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
878 879 880 881 882 883 884 885 886 887 888
      }

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

    walk = g_list_next (walk);
  }
}

G_GNUC_UNUSED static void