seek.c 71.7 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
#include <stdlib.h>
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
24 25 26 27 28
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <string.h>

29
GST_DEBUG_CATEGORY_STATIC (seek_debug);
30 31
#define GST_CAT_DEFAULT (seek_debug)

32 33 34 35 36 37 38 39 40 41 42 43 44 45
/* 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"

46
#define FILL_INTERVAL 100
47 48 49 50 51 52 53 54 55 56 57
//#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


58
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
59
static GList *rate_pads = NULL;
60
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
61

62 63
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
64
static gboolean loop_seek = FALSE;
65
static gboolean flush_seek = TRUE;
66 67
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
68
static gdouble rate = 1.0;
69

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

82 83
static gboolean is_live = FALSE;
static gboolean buffering = FALSE;
84 85
static GstBufferingMode mode;
static gint64 buffering_left;
86
static GstState state = GST_STATE_NULL;
87
static guint update_id = 0;
88 89
static guint seek_timeout_id = 0;
static gulong changed_id;
90
static guint fill_id = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
91

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

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

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

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

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

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

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

  return element;
}

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

137 138 139
  padname = gst_pad_get_name (newpad);

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

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

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

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

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

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

172 173
  pipeline = gst_pipeline_new ("app");

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

185 186
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
187

188
  seekable = gst_element_get_static_pad (decoder, "src");
189 190
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
191 192
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
193 194 195 196

  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_static_pad (v_queue,
          "sink"), NULL);
  setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue,
          "sink"), NULL);
234

235
  seekable = gst_element_get_static_pad (decoder, "src");
236
  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
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
264 265 266 267 268

  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
  seekable = gst_element_get_static_pad (decoder, "src");
297 298
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
299 300
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
301 302 303 304

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
305 306
static GstElement *
make_sid_pipeline (const gchar * location)
307 308 309 310
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
311

312 313
  pipeline = gst_pipeline_new ("app");

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

325 326
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
327

328
  seekable = gst_element_get_static_pad (decoder, "src");
329 330
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
331 332
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
333 334 335 336

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
337 338
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
339 340 341 342
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
343

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
344 345
  pipeline = gst_pipeline_new ("app");

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

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

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

361
  seekable = gst_element_get_static_pad (parser, "src");
362
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
363
  rate_pads = g_list_prepend (rate_pads, seekable);
364 365
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
366 367 368 369

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
370 371
static GstElement *
make_vorbis_pipeline (const gchar * location)
372
{
373 374
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
375
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
376

377 378
  pipeline = gst_pipeline_new ("app");

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

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

388 389
  audio_bin = gst_bin_new ("a_decoder_bin");

390
  gst_bin_add (GST_BIN (pipeline), src);
391 392 393 394 395
  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);
396

397 398 399 400
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

401
  pad = gst_element_get_static_pad (decoder, "sink");
402 403 404
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

405 406
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
407

408
  seekable = gst_element_get_static_pad (decoder, "src");
409 410
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
411 412
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
413 414 415 416 417 418 419 420 421

  return pipeline;
}

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
422
  GstPad *pad, *seekable;
423 424 425 426 427 428 429

  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
430
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446

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

447
  pad = gst_element_get_static_pad (decoder, "sink");
448 449 450
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

451 452
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
453

454
  seekable = gst_element_get_static_pad (decoder, "src");
455 456
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
457 458
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
459 460 461 462

  return pipeline;
}

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

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

490
  gst_bin_add (GST_BIN (pipeline), audio_bin);
491 492 493 494 495 496

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

497 498 499
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
500

501
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
502
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
503
  gst_object_unref (pad);
504

505 506
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
507 508 509 510 511 512

  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");
513
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
514
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
515 516

  gst_bin_add (GST_BIN (pipeline), video_bin);
517 518 519 520

  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);
521
  gst_bin_add (GST_BIN (video_bin), v_scale);
522 523
  gst_bin_add (GST_BIN (video_bin), videosink);

524 525
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
526

527
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
528
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
529
  gst_object_unref (pad);
530

531 532
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
533

534
  seekable = gst_element_get_static_pad (a_decoder, "src");
535 536 537
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
538 539
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
540 541 542 543 544 545 546 547 548 549 550

  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;
551
  GstPad *seekable, *pad;
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567

  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");
568
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
569 570 571 572 573 574

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

575 576 577 578
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

579 580
  gst_bin_add (GST_BIN (pipeline), audio_bin);

581
  pad = gst_element_get_static_pad (a_queue, "sink");
582 583 584
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

585 586
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
587 588 589 590 591 592

  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
593
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
594 595 596 597 598 599

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

600 601
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

602 603
  gst_bin_add (GST_BIN (pipeline), video_bin);

604
  pad = gst_element_get_static_pad (v_queue, "sink");
605 606 607
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

608 609
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
610

611
  seekable = gst_element_get_static_pad (a_decoder, "src");
612 613 614
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
615 616
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
617 618 619 620

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
621 622
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
623 624
{
  GstElement *pipeline;
625
  GstElement *src, *decoder, *osssink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
626
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
627

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
628 629
  pipeline = gst_pipeline_new ("app");

630 631 632
  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");
633
  osssink = gst_element_factory_make_or_warn (ASINK, "sink");
634

635
  seekable_elements = g_list_prepend (seekable_elements, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
636 637

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

640 641
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
642 643
  gst_bin_add (GST_BIN (pipeline), queue);
  gst_bin_add (GST_BIN (pipeline), osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
644

645 646
  gst_element_link (src, decoder);
  gst_element_link (decoder, queue);
647
  gst_element_link (queue, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
648

649
  seekable = gst_element_get_static_pad (queue, "src");
650
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
651
  rate_pads = g_list_prepend (rate_pads, seekable);
652 653
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
654 655 656 657

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
658 659
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
660 661 662
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
663
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
664
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
665

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

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

671
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
672
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
673 674 675

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

  audio_bin = gst_bin_new ("a_decoder_bin");
679
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
680
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
681
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
682 683
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
684
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
685 686
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
687
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
688

689
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
690
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
691

692
  seekable = gst_element_get_static_pad (a_queue, "src");
693
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
694
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
695
  rate_pads =
696 697
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
698 699

  video_bin = gst_bin_new ("v_decoder_bin");
Wim Taymans's avatar
Wim Taymans committed
700
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
701
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
702
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
703 704
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
705
  gst_bin_add (GST_BIN (video_bin), v_decoder);
706 707
  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
708

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

711
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
712
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
713

714
  seekable = gst_element_get_static_pad (v_queue, "src");
715
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
716
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
717
  rate_pads =
718 719
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
720 721 722 723

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
724 725
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
726 727
{
  GstElement *pipeline, *audio_bin, *video_bin;
728 729
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
730
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
731
  GstPad *seekable;
732
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
733

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
734 735
  pipeline = gst_pipeline_new ("app");

736
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
737 738
  g_object_set (G_OBJECT (src), "location", location, NULL);

739 740
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
741

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
742 743
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
744
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
745 746

  audio_bin = gst_bin_new ("a_decoder_bin");
747 748
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
749
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
750
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
751 752
  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
753

754 755
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
756

757 758
  gst_bin_add (GST_BIN (pipeline), audio_bin);

759
  pad = gst_element_get_static_pad (a_decoder, "sink");
760 761 762
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

763
  setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
764
          "sink"), NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
765 766

  video_bin = gst_bin_new ("v_decoder_bin");
767 768
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
769
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
770
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
771

772 773 774 775 776 777 778
  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);
779
  gst_element_link (v_filter, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
780

781
  gst_bin_add (GST_BIN (pipeline), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
782

783
  pad = gst_element_get_static_pad (v_decoder, "sink");
784 785 786
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

787
  setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
788 789
          "sink"), NULL);

790
  seekable = gst_element_get_static_pad (v_filter, "src");
791
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
792
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
793
  rate_pads =
794 795
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
796 797 798 799

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
800 801
static GstElement *
make_mpegnt_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
802 803 804 805
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
806
  GstElement *a_queue;
Wim Taymans's avatar
Wim Taymans committed
807
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
808

Wim Taymans's avatar
Wim Taymans committed
809 810 811 812 813 814 815 816 817 818 819 820
  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);