seek.c 47.5 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
static gdouble rate = 1.0;
21

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

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

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

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

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

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

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

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

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

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

  return element;
}

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

85 86 87
  padname = gst_pad_get_name (newpad);

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

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

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

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

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

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

120 121
  pipeline = gst_pipeline_new ("app");

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

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

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

  return pipeline;
}

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

227 228
  pipeline = gst_pipeline_new ("app");

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

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

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

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

258 259
  pipeline = gst_pipeline_new ("app");

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

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

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

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

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

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

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

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

321 322
  pipeline = gst_pipeline_new ("app");

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

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

332 333
  audio_bin = gst_bin_new ("a_decoder_bin");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

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

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
881 882