seek.c 43.7 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
static gboolean scrub = FALSE;
19

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

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

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

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

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

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

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

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

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

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

  return element;
}

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

83 84 85
  padname = gst_pad_get_name (newpad);

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

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

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

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

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

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

118 119
  pipeline = gst_pipeline_new ("app");

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

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

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

  return pipeline;
}

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

225 226
  pipeline = gst_pipeline_new ("app");

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

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

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

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

256 257
  pipeline = gst_pipeline_new ("app");

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

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

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

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

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

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

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

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

319 320
  pipeline = gst_pipeline_new ("app");

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

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

330 331
  audio_bin = gst_bin_new ("a_decoder_bin");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

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

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
879 880
      if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
              &value)) {
881
        g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);