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

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

28
#include <stdlib.h>
29
#include <math.h>
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
30 31 32 33 34
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <string.h>

35
#ifdef HAVE_X
36
#include <gdk/gdkx.h>
37
#endif
38 39
#include <gst/interfaces/xoverlay.h>

40
GST_DEBUG_CATEGORY_STATIC (seek_debug);
41 42
#define GST_CAT_DEFAULT (seek_debug)

43 44 45 46 47 48 49 50 51 52 53 54 55 56
/* configuration */

//#define SOURCE "filesrc"
#define SOURCE "gnomevfssrc"

#define ASINK "alsasink"
//#define ASINK "osssink"

#define VSINK "xvimagesink"
//#define VSINK "sdlvideosink"
//#define VSINK "ximagesink"
//#define VSINK "aasink"
//#define VSINK "cacasink"

57
#define FILL_INTERVAL 100
58 59 60 61 62 63 64 65 66 67
//#define UPDATE_INTERVAL 500
//#define UPDATE_INTERVAL 100
#define UPDATE_INTERVAL 10

/* number of milliseconds to play for after a seek */
#define SCRUB_TIME 100

/* timeout for gst_element_get_state() after a seek */
#define SEEK_TIMEOUT 40 * GST_MSECOND

68 69
#define DEFAULT_VIDEO_HEIGHT 300

70

71
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
72
static GList *rate_pads = NULL;
73
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
74

75 76
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
77
static gboolean loop_seek = FALSE;
78
static gboolean flush_seek = TRUE;
79 80
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
81
static gboolean skip_seek = FALSE;
82
static gdouble rate = 1.0;
83

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
84
static GstElement *pipeline;
85 86
static gint pipeline_type;
static const gchar *pipeline_spec;
87 88
static gint64 position = -1;
static gint64 duration = -1;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
89
static GtkAdjustment *adjustment;
90 91
static GtkWidget *hscale, *statusbar;
static guint status_id = 0;
92
static gboolean stats = FALSE;
93 94
static gboolean elem_seek = FALSE;
static gboolean verbose = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
95

96 97
static gboolean is_live = FALSE;
static gboolean buffering = FALSE;
98 99
static GstBufferingMode mode;
static gint64 buffering_left;
100
static GstState state = GST_STATE_NULL;
101
static guint update_id = 0;
102 103
static guint seek_timeout_id = 0;
static gulong changed_id;
104
static guint fill_id = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
105

106
static gint n_video = 0, n_audio = 0, n_text = 0;
107
static gboolean need_streams = TRUE;
108
static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
109
static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
110
static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
111
static GtkWidget *skip_checkbox, *video_window;
112

113 114 115 116
static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
static GtkWidget *step_flush_checkbox, *step_button;

static GList *paths = NULL, *l = NULL;
117

118 119 120 121 122 123 124 125 126
/* we keep an array of the visualisation entries so that we can easily switch
 * with the combo box index. */
typedef struct
{
  GstElementFactory *factory;
} VisEntry;

static GArray *vis_entries;

127
static void clear_streams (GstElement * pipeline);
128 129
static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
    gpointer user_dat);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
130

131
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
132 133 134

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
135 136 137
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
138 139
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
140

141
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
142
gst_element_factory_make_or_warn (gchar * type, gchar * name)
143 144 145 146
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
147
    g_warning ("Failed to create element %s of type %s", name, type);
148 149 150 151 152
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
153
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
154
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
155
{
156
  gchar *padname;
157
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
158

159 160 161
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
162 163
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
164
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
165

166
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
167 168
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
169
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
170 171 172
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
173 174
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
175
{
176
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
177

178
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
179 180 181
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
182

183
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
184
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
185 186
}

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

194 195
  pipeline = gst_pipeline_new ("app");

196 197
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
198
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
199 200 201 202 203 204 205 206
  //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);

207 208
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
209

210
  seekable = gst_element_get_static_pad (decoder, "src");
211 212
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
213 214
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
215 216 217 218

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
219 220
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
221 222
{
  GstElement *pipeline;
223
  GstElement *src, *demux, *decoder, *audiosink, *videosink;
224
  GstElement *a_queue, *v_queue;
Wim Taymans's avatar
Wim Taymans committed
225
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
226

Wim Taymans's avatar
Wim Taymans committed
227 228 229
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
230
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
231
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
232
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
233
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
234
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
235
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
236 237 238 239

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

  gst_bin_add (GST_BIN (pipeline), src);
240
  gst_bin_add (GST_BIN (pipeline), demux);
241
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
242
  gst_bin_add (GST_BIN (pipeline), audiosink);
243
  gst_bin_add (GST_BIN (pipeline), v_queue);
244
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
245 246
  gst_bin_add (GST_BIN (pipeline), videosink);

247
  gst_element_link (src, demux);
248
  gst_element_link (a_queue, audiosink);
249 250
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
251

252 253 254 255
  setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue,
          "sink"), NULL);
  setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
          "sink"), NULL);
256

257
  seekable = gst_element_get_static_pad (decoder, "src");
258
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
259 260 261 262 263
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
264 265
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
266 267 268
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
269

Wim Taymans's avatar
Wim Taymans committed
270 271
  pipeline = gst_pipeline_new ("app");

272 273
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
274
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
275 276 277 278 279 280 281

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

282
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
283

284 285
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
286 287 288 289 290

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
291 292 293 294

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
295 296
static GstElement *
make_flac_pipeline (const gchar * location)
297 298 299 300
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
301

302 303
  pipeline = gst_pipeline_new ("app");

304 305
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
306
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
307
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
308 309 310 311 312 313 314

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

315 316
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
317

318
  seekable = gst_element_get_static_pad (decoder, "src");
319 320
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
321 322
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
323 324 325 326

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
327 328
static GstElement *
make_sid_pipeline (const gchar * location)
329 330 331 332
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
333

334 335
  pipeline = gst_pipeline_new ("app");

336 337
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
338
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
339 340 341 342 343 344 345 346
  //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);

347 348
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
349

350
  seekable = gst_element_get_static_pad (decoder, "src");
351 352
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
353 354
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
355 356 357 358

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
359 360
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
361 362 363 364
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
365

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
366 367
  pipeline = gst_pipeline_new ("app");

368 369 370
  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
371 372
  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
373 374 375 376 377 378 379

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

380 381
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
382

383
  seekable = gst_element_get_static_pad (parser, "src");
384
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
385
  rate_pads = g_list_prepend (rate_pads, seekable);
386 387
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
388 389 390 391

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
392 393
static GstElement *
make_vorbis_pipeline (const gchar * location)
394
{
395 396
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
397
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
398

399 400
  pipeline = gst_pipeline_new ("app");

401
  src = gst_element_factory_make_or_warn (SOURCE, "src");
402 403 404
  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");
405
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
406
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
407 408 409

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

410 411
  audio_bin = gst_bin_new ("a_decoder_bin");

412
  gst_bin_add (GST_BIN (pipeline), src);
413 414 415 416 417
  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);
418

419 420 421 422
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

423
  pad = gst_element_get_static_pad (decoder, "sink");
424 425 426
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

427 428
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
429

430
  seekable = gst_element_get_static_pad (decoder, "src");
431 432
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
433 434
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
435 436 437 438 439 440 441 442 443

  return pipeline;
}

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
444
  GstPad *pad, *seekable;
445 446 447 448 449 450 451

  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
452
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468

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

469
  pad = gst_element_get_static_pad (decoder, "sink");
470 471 472
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

473 474
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
475

476
  seekable = gst_element_get_static_pad (decoder, "src");
477 478
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
479 480
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
481 482 483 484

  return pipeline;
}

485 486 487 488 489 490
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;
491
  GstElement *a_queue, *v_queue, *v_scale;
492
  GstPad *seekable;
Wim Taymans's avatar
Wim Taymans committed
493
  GstPad *pad;
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509

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

512
  gst_bin_add (GST_BIN (pipeline), audio_bin);
513 514 515 516 517 518

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

519 520 521
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
522

523
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
524
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
525
  gst_object_unref (pad);
526

527 528
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
529 530 531 532 533 534

  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");
535
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
536
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
537 538

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

  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);
543
  gst_bin_add (GST_BIN (video_bin), v_scale);
544 545
  gst_bin_add (GST_BIN (video_bin), videosink);

546 547
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
548

549
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
550
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
551
  gst_object_unref (pad);
552

553 554
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
555

556
  seekable = gst_element_get_static_pad (a_decoder, "src");
557 558 559
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
560 561
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
562 563 564 565 566 567 568 569 570 571 572

  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;
573
  GstPad *seekable, *pad;
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589

  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");
590
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
591 592 593 594 595 596

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

597 598 599 600
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

601 602
  gst_bin_add (GST_BIN (pipeline), audio_bin);

603
  pad = gst_element_get_static_pad (a_queue, "sink");
604 605 606
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

607 608
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
609 610 611 612 613 614

  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
615
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
616 617 618 619 620 621

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

622 623
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

624 625
  gst_bin_add (GST_BIN (pipeline), video_bin);

626
  pad = gst_element_get_static_pad (v_queue, "sink");
627 628 629
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

630 631
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
632

633
  seekable = gst_element_get_static_pad (a_decoder, "src");
634 635 636
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
637 638
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
639 640 641 642

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
643 644
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
645 646
{
  GstElement *pipeline;
647
  GstElement *src, *parser, *decoder, *audiosink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
648
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
649

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
650 651
  pipeline = gst_pipeline_new ("app");

652
  src = gst_element_factory_make_or_warn (SOURCE, "src");
653
  parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
654 655
  decoder = gst_element_factory_make_or_warn ("mad", "dec");
  queue = gst_element_factory_make_or_warn ("queue", "queue");
656
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
657

658
  seekable_elements = g_list_prepend (seekable_elements, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
659 660

  g_object_set (G_OBJECT (src), "location", location, NULL);
661
  //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
662

663
  gst_bin_add (GST_BIN (pipeline), src);
664
  gst_bin_add (GST_BIN (pipeline), parser);
665
  gst_bin_add (GST_BIN (pipeline), decoder);
666
  gst_bin_add (GST_BIN (pipeline), queue);
667
  gst_bin_add (GST_BIN (pipeline), audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
668

669 670
  gst_element_link (src, parser);
  gst_element_link (parser, decoder);
671
  gst_element_link (decoder, queue);
672
  gst_element_link (queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
673

674
  seekable = gst_element_get_static_pad (queue, "src");
675
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
676
  rate_pads = g_list_prepend (rate_pads, seekable);
677 678
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
679 680 681 682

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
683 684
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
685 686 687
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
688
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
689
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
690

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
691 692
  pipeline = gst_pipeline_new ("app");

693
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
694 695
  g_object_set (G_OBJECT (src), "location", location, NULL);

696
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
697
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
698 699 700

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
701
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
702 703

  audio_bin = gst_bin_new ("a_decoder_bin");
704
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
705
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
706
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
707 708
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
709
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
710 711
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
712
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
713

714
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
715
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
716

717
  seekable = gst_element_get_static_pad (a_queue, "src");
718
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
719
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
720
  rate_pads =
721 722
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
723 724

  video_bin = gst_bin_new ("v_decoder_bin");
Wim Taymans's avatar
Wim Taymans committed
725
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
726
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
727
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
728 729
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
730
  gst_bin_add (GST_BIN (video_bin), v_decoder);
731 732
  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
733

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

736
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
737
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
738

739
  seekable = gst_element_get_static_pad (v_queue, "src");
740
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
741
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
742
  rate_pads =
743 744
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
745 746 747 748

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
749 750
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
751 752
{
  GstElement *pipeline, *audio_bin, *video_bin;
753 754
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
755
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
756
  GstPad *seekable;
757
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
758

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
759 760
  pipeline = gst_pipeline_new ("app");

761
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
762 763
  g_object_set (G_OBJECT (src), "location", location, NULL);

764 765
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
766

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
767 768
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
769
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
770 771

  audio_bin = gst_bin_new ("a_decoder_bin");
772 773
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
774
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
775
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
776 777
  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
778

779 780
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
781

782 783
  gst_bin_add (GST_BIN (pipeline), audio_bin);

784
  pad = gst_element_get_static_pad (a_decoder, "sink");
785 786 787
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

788
  setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
789
          "sink"), NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
790 791

  video_bin = gst_bin_new ("v_decoder_bin");
792 793
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
794
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
795
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
796

797 798 799 800 801 802 803
  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);
804
  gst_element_link (v_filter, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
805

806
  gst_bin_add (GST_BIN (pipeline), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
807

808
  pad = gst_element_get_static_pad (v_decoder, "sink");