seek.c 69.4 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 23 24 25
/* 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.
 */
/* FIXME: remove #if 0 code
 *
 */
26
#include <stdlib.h>
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
27 28 29 30 31
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <string.h>

32
GST_DEBUG_CATEGORY_STATIC (seek_debug);
33 34
#define GST_CAT_DEFAULT (seek_debug)

35 36 37 38 39 40 41 42 43 44 45 46 47 48
/* 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"

49
#define FILL_INTERVAL 100
50 51 52 53 54 55 56 57 58 59 60
//#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


61
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
62
static GList *rate_pads = NULL;
63
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
64

65 66
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
67
static gboolean loop_seek = FALSE;
68
static gboolean flush_seek = TRUE;
69 70
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
71
static gdouble rate = 1.0;
72

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
73
static GstElement *pipeline;
74 75
static gint pipeline_type;
static const gchar *pipeline_spec;
76 77
static gint64 position = -1;
static gint64 duration = -1;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
78
static GtkAdjustment *adjustment;
79 80
static GtkWidget *hscale, *statusbar;
static guint status_id = 0;
81
static gboolean stats = FALSE;
82 83
static gboolean elem_seek = FALSE;
static gboolean verbose = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
84

85 86
static gboolean is_live = FALSE;
static gboolean buffering = FALSE;
87
static GstState state = GST_STATE_NULL;
88
static guint update_id = 0;
89 90
static guint seek_timeout_id = 0;
static gulong changed_id;
91
static guint fill_id = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
92

93
static gint n_video = 0, n_audio = 0, n_text = 0;
94
static gboolean need_streams = TRUE;
95
static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
96
static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
97
static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
98

99 100 101 102 103 104 105 106 107
/* 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;

108
static void clear_streams (GstElement * pipeline);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
109

110
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
111 112 113

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
114 115 116
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
117 118
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
119

120
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
121
gst_element_factory_make_or_warn (gchar * type, gchar * name)
122 123 124 125
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
126
    g_warning ("Failed to create element %s of type %s", name, type);
127 128 129 130 131
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
132
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
133
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
134
{
135
  gchar *padname;
136
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
137

138 139 140
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
141 142
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
143
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
144

145
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
146 147
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
148
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
149 150 151
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
152 153
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
154
{
155
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
156

157
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
158 159 160
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
161

162
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
163
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
164 165
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
166 167
static GstElement *
make_mod_pipeline (const gchar * location)
168 169 170 171
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
172

173 174
  pipeline = gst_pipeline_new ("app");

175 176
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
177
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
178 179 180 181 182 183 184 185
  //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);

186 187
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
188 189 190 191 192 193 194 195 196

  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
197 198
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
199 200
{
  GstElement *pipeline;
201
  GstElement *src, *demux, *decoder, *audiosink, *videosink;
202
  GstElement *a_queue, *v_queue;
Wim Taymans's avatar
Wim Taymans committed
203
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
204

Wim Taymans's avatar
Wim Taymans committed
205 206 207
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
208
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
209
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
210
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
211
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
212
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
213
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
214 215 216 217

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

  gst_bin_add (GST_BIN (pipeline), src);
218
  gst_bin_add (GST_BIN (pipeline), demux);
219
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
220
  gst_bin_add (GST_BIN (pipeline), audiosink);
221
  gst_bin_add (GST_BIN (pipeline), v_queue);
222
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
223 224
  gst_bin_add (GST_BIN (pipeline), videosink);

225
  gst_element_link (src, demux);
226
  gst_element_link (a_queue, audiosink);
227 228
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
229

230 231 232 233
  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);
234

235 236
  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
237 238 239 240 241
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
242 243
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
244 245 246
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
247

Wim Taymans's avatar
Wim Taymans committed
248 249
  pipeline = gst_pipeline_new ("app");

250 251
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
252
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
253 254 255 256 257 258 259

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

260
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
261

262 263 264 265 266 267 268
  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
269 270 271 272

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
273 274
static GstElement *
make_flac_pipeline (const gchar * location)
275 276 277 278
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
279

280 281
  pipeline = gst_pipeline_new ("app");

282 283
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
284
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
285
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
286 287 288 289 290 291 292

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

293 294
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
295 296 297 298 299 300 301 302 303

  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
304 305
static GstElement *
make_sid_pipeline (const gchar * location)
306 307 308 309
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
310

311 312
  pipeline = gst_pipeline_new ("app");

313 314
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
315
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
316 317 318 319 320 321 322 323
  //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);

324 325
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
326 327 328 329 330 331 332 333 334

  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
335 336
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
337 338 339 340
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
341

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
342 343
  pipeline = gst_pipeline_new ("app");

344 345 346
  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
347 348
  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
349 350 351 352 353 354 355

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

356 357
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
358 359

  seekable = gst_element_get_pad (parser, "src");
360
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
361 362 363 364 365 366
  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
367 368
static GstElement *
make_vorbis_pipeline (const gchar * location)
369
{
370 371
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
372
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
373

374 375
  pipeline = gst_pipeline_new ("app");

376
  src = gst_element_factory_make_or_warn (SOURCE, "src");
377 378 379
  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");
380
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
381
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
382 383 384

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

385 386
  audio_bin = gst_bin_new ("a_decoder_bin");

387
  gst_bin_add (GST_BIN (pipeline), src);
388 389 390 391 392
  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);
393

394 395 396 397
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

398 399 400 401 402 403
  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);
404 405 406 407 408 409 410 411 412 413 414 415 416 417

  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;
418
  GstPad *pad, *seekable;
419 420 421 422 423 424 425

  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
426
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442

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

443 444 445 446 447 448
  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);
449 450 451 452 453 454 455 456 457

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

458 459 460 461 462 463
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;
464
  GstElement *a_queue, *v_queue, *v_scale;
465
  GstPad *seekable;
Wim Taymans's avatar
Wim Taymans committed
466
  GstPad *pad;
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482

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

485
  gst_bin_add (GST_BIN (pipeline), audio_bin);
486 487 488 489 490 491

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

492 493 494
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
495

Wim Taymans's avatar
Wim Taymans committed
496 497
  pad = gst_element_get_pad (a_queue, "sink");
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
498
  gst_object_unref (pad);
499 500 501

  setup_dynamic_link (demux, NULL, gst_element_get_pad (audio_bin, "sink"),
      NULL);
502 503 504 505 506 507

  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");
508
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
509
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
510 511

  gst_bin_add (GST_BIN (pipeline), video_bin);
512 513 514 515

  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);
516
  gst_bin_add (GST_BIN (video_bin), v_scale);
517 518
  gst_bin_add (GST_BIN (video_bin), videosink);

519 520
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
521

Wim Taymans's avatar
Wim Taymans committed
522 523
  pad = gst_element_get_pad (v_queue, "sink");
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
524
  gst_object_unref (pad);
525 526 527

  setup_dynamic_link (demux, NULL, gst_element_get_pad (video_bin, "sink"),
      NULL);
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544

  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;
545
  GstPad *seekable, *pad;
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561

  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");
562
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
563 564 565 566 567 568

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

569 570 571 572
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

573 574
  gst_bin_add (GST_BIN (pipeline), audio_bin);

575 576 577 578 579 580
  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);
581 582 583 584 585 586

  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
587
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
588 589 590 591 592 593

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

594 595
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

596 597
  gst_bin_add (GST_BIN (pipeline), video_bin);

598 599 600 601 602 603
  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);
604 605 606 607 608 609 610 611 612 613

  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
614 615
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
616 617
{
  GstElement *pipeline;
618
  GstElement *src, *decoder, *osssink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
619
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
620

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
621 622
  pipeline = gst_pipeline_new ("app");

623 624 625
  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");
626
  osssink = gst_element_factory_make_or_warn (ASINK, "sink");
627

628
  seekable_elements = g_list_prepend (seekable_elements, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
629 630

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

633 634
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
635 636
  gst_bin_add (GST_BIN (pipeline), queue);
  gst_bin_add (GST_BIN (pipeline), osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
637

638 639
  gst_element_link (src, decoder);
  gst_element_link (decoder, queue);
640
  gst_element_link (queue, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
641

642 643
  seekable = gst_element_get_pad (queue, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
644 645 646 647 648 649
  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
650 651
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
652 653 654
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
655
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
656
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
657

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
658 659
  pipeline = gst_pipeline_new ("app");

660
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
661 662
  g_object_set (G_OBJECT (src), "location", location, NULL);

663
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
664
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
665 666 667

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
668
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
669 670

  audio_bin = gst_bin_new ("a_decoder_bin");
671
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
672
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
673
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
674 675
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
676
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
677 678
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
679
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
680

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
681
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
682
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
683 684

  seekable = gst_element_get_pad (a_queue, "src");
685
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
686
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
687 688
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
689 690

  video_bin = gst_bin_new ("v_decoder_bin");
Wim Taymans's avatar
Wim Taymans committed
691
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
692
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
693
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
694 695
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
696
  gst_bin_add (GST_BIN (video_bin), v_decoder);
697 698
  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
699

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
702
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
703
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
704 705

  seekable = gst_element_get_pad (v_queue, "src");
706
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
707
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
708 709
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
710 711 712 713

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
714 715
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
716 717
{
  GstElement *pipeline, *audio_bin, *video_bin;
718 719
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
720
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
721
  GstPad *seekable;
722
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
723

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
724 725
  pipeline = gst_pipeline_new ("app");

726
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
727 728
  g_object_set (G_OBJECT (src), "location", location, NULL);

729 730
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
731

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
732 733
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
734
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
735 736

  audio_bin = gst_bin_new ("a_decoder_bin");
737 738
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
739
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
740
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
741 742
  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
743

744 745
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
746

747 748 749 750 751 752 753 754
  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
755 756

  video_bin = gst_bin_new ("v_decoder_bin");
757 758
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
759
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
760
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
761

762 763 764 765 766 767 768
  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);
769
  gst_element_link (v_filter, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
770

771
  gst_bin_add (GST_BIN (pipeline), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
772

773 774 775 776 777 778 779 780
  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");
781
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
782
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
783 784
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
785 786 787 788

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
789 790
static GstElement *
make_mpegnt_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
791 792 793 794
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
795
  GstElement *a_queue;
Wim Taymans's avatar
Wim Taymans committed
796
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
797

Wim Taymans's avatar
Wim Taymans committed
798 799 800 801 802 803 804 805 806 807 808 809
  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);
810
  gst_element_link (src, demux);
Wim Taymans's avatar
Wim Taymans committed
811 812 813 814

  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");
815
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Wim Taymans's avatar
Wim Taymans committed
816 817
  //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
818 819
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Wim Taymans's avatar
Wim Taymans committed
820
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
821 822
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
823

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
824
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
825
          "sink"), audio_bin);
Wim Taymans's avatar
Wim Taymans committed
826 827 828 829

  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
830 831
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
832 833 834

  video_bin = gst_bin_new ("v_decoder_bin");
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
835
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
836
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
837
  gst_element_link_many (v_decoder, v_filter, videosink, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
838

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
841
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
842
          "sink"), video_bin);
Wim Taymans's avatar
Wim Taymans committed
843 844 845 846

  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
847 848
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
849 850 851 852

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
853 854
static GstElement *
make_playerbin_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
855
{
856
  GstElement *player;
857 858 859 860

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

861
  g_object_set (G_OBJECT (player), "uri", location, NULL);
862 863 864 865 866 867 868

  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
869 870
}

871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
static GstElement *
make_playerbin2_pipeline (const gchar * location)
{
  GstElement *player;

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

  g_object_set (G_OBJECT (player), "uri", location, NULL);

  seekable_elements = g_list_prepend (seekable_elements, player);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;

  return player;
}

889
#ifndef GST_DISABLE_PARSE
890 891 892 893 894 895 896 897 898 899 900 901 902 903
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;
}
904
#endif
905