seek.c 77.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
/* 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>
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
29 30 31 32 33
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <string.h>

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

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

42 43 44 45 46 47 48 49 50 51 52 53 54 55
/* 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"

56
#define FILL_INTERVAL 100
57 58 59 60 61 62 63 64 65 66
//#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

67 68
#define DEFAULT_VIDEO_HEIGHT 300

69

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

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

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

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

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

GList *paths = NULL, *l = NULL;
113

114 115 116 117 118 119 120 121 122
/* 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;

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

125
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
126 127 128

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
129 130 131
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
132 133
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
134

135
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
136
gst_element_factory_make_or_warn (gchar * type, gchar * name)
137 138 139 140
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
141
    g_warning ("Failed to create element %s of type %s", name, type);
142 143 144 145 146
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
147
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
148
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
149
{
150
  gchar *padname;
151
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
152

153 154 155
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
156 157
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
158
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
159

160
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
161 162
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
163
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
164 165 166
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
167 168
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
169
{
170
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
171

172
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
173 174 175
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
176

177
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
178
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
179 180
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
181 182
static GstElement *
make_mod_pipeline (const gchar * location)
183 184 185 186
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
187

188 189
  pipeline = gst_pipeline_new ("app");

190 191
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
192
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
193 194 195 196 197 198 199 200
  //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);

201 202
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
203

204
  seekable = gst_element_get_static_pad (decoder, "src");
205 206
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
207 208
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
209 210 211 212

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
213 214
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
215 216
{
  GstElement *pipeline;
217
  GstElement *src, *demux, *decoder, *audiosink, *videosink;
218
  GstElement *a_queue, *v_queue;
Wim Taymans's avatar
Wim Taymans committed
219
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
220

Wim Taymans's avatar
Wim Taymans committed
221 222 223
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
224
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
225
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
226
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
227
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
228
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
229
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
230 231 232 233

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

  gst_bin_add (GST_BIN (pipeline), src);
234
  gst_bin_add (GST_BIN (pipeline), demux);
235
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
236
  gst_bin_add (GST_BIN (pipeline), audiosink);
237
  gst_bin_add (GST_BIN (pipeline), v_queue);
238
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
239 240
  gst_bin_add (GST_BIN (pipeline), videosink);

241
  gst_element_link (src, demux);
242
  gst_element_link (a_queue, audiosink);
243 244
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
245

246 247 248 249
  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);
250

251
  seekable = gst_element_get_static_pad (decoder, "src");
252
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
253 254 255 256 257
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
258 259
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
260 261 262
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
263

Wim Taymans's avatar
Wim Taymans committed
264 265
  pipeline = gst_pipeline_new ("app");

266 267
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
268
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
269 270 271 272 273 274 275

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

276
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
277

278 279
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
280 281 282 283 284

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
285 286 287 288

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
289 290
static GstElement *
make_flac_pipeline (const gchar * location)
291 292 293 294
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
295

296 297
  pipeline = gst_pipeline_new ("app");

298 299
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
300
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
301
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
302 303 304 305 306 307 308

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

309 310
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
311

312
  seekable = gst_element_get_static_pad (decoder, "src");
313 314
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
315 316
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
317 318 319 320

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
321 322
static GstElement *
make_sid_pipeline (const gchar * location)
323 324 325 326
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
327

328 329
  pipeline = gst_pipeline_new ("app");

330 331
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
332
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
333 334 335 336 337 338 339 340
  //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);

341 342
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
343

344
  seekable = gst_element_get_static_pad (decoder, "src");
345 346
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
347 348
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
349 350 351 352

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
353 354
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
355 356 357 358
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
359

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
360 361
  pipeline = gst_pipeline_new ("app");

362 363 364
  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
365 366
  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
367 368 369 370 371 372 373

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

374 375
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
376

377
  seekable = gst_element_get_static_pad (parser, "src");
378
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
379
  rate_pads = g_list_prepend (rate_pads, seekable);
380 381
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
382 383 384 385

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
386 387
static GstElement *
make_vorbis_pipeline (const gchar * location)
388
{
389 390
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
391
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
392

393 394
  pipeline = gst_pipeline_new ("app");

395
  src = gst_element_factory_make_or_warn (SOURCE, "src");
396 397 398
  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");
399
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
400
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
401 402 403

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

404 405
  audio_bin = gst_bin_new ("a_decoder_bin");

406
  gst_bin_add (GST_BIN (pipeline), src);
407 408 409 410 411
  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);
412

413 414 415 416
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

417
  pad = gst_element_get_static_pad (decoder, "sink");
418 419 420
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

421 422
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
423

424
  seekable = gst_element_get_static_pad (decoder, "src");
425 426
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
427 428
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
429 430 431 432 433 434 435 436 437

  return pipeline;
}

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
438
  GstPad *pad, *seekable;
439 440 441 442 443 444 445

  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
446
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462

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

463
  pad = gst_element_get_static_pad (decoder, "sink");
464 465 466
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

467 468
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
469

470
  seekable = gst_element_get_static_pad (decoder, "src");
471 472
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
473 474
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
475 476 477 478

  return pipeline;
}

479 480 481 482 483 484
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;
485
  GstElement *a_queue, *v_queue, *v_scale;
486
  GstPad *seekable;
Wim Taymans's avatar
Wim Taymans committed
487
  GstPad *pad;
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503

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

506
  gst_bin_add (GST_BIN (pipeline), audio_bin);
507 508 509 510 511 512

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

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

517
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
518
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
519
  gst_object_unref (pad);
520

521 522
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
523 524 525 526 527 528

  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");
529
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
530
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
531 532

  gst_bin_add (GST_BIN (pipeline), video_bin);
533 534 535 536

  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);
537
  gst_bin_add (GST_BIN (video_bin), v_scale);
538 539
  gst_bin_add (GST_BIN (video_bin), videosink);

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

543
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
544
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
545
  gst_object_unref (pad);
546

547 548
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
549

550
  seekable = gst_element_get_static_pad (a_decoder, "src");
551 552 553
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
554 555
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
556 557 558 559 560 561 562 563 564 565 566

  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;
567
  GstPad *seekable, *pad;
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583

  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");
584
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
585 586 587 588 589 590

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

591 592 593 594
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

595 596
  gst_bin_add (GST_BIN (pipeline), audio_bin);

597
  pad = gst_element_get_static_pad (a_queue, "sink");
598 599 600
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

601 602
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
603 604 605 606 607 608

  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
609
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
610 611 612 613 614 615

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

616 617
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

618 619
  gst_bin_add (GST_BIN (pipeline), video_bin);

620
  pad = gst_element_get_static_pad (v_queue, "sink");
621 622 623
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

624 625
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
626

627
  seekable = gst_element_get_static_pad (a_decoder, "src");
628 629 630
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
631 632
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
633 634 635 636

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
637 638
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
639 640
{
  GstElement *pipeline;
641
  GstElement *src, *decoder, *osssink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
642
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
643

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
644 645
  pipeline = gst_pipeline_new ("app");

646 647 648
  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");
649
  osssink = gst_element_factory_make_or_warn (ASINK, "sink");
650

651
  seekable_elements = g_list_prepend (seekable_elements, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
652 653

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

656 657
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
658 659
  gst_bin_add (GST_BIN (pipeline), queue);
  gst_bin_add (GST_BIN (pipeline), osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
660

661 662
  gst_element_link (src, decoder);
  gst_element_link (decoder, queue);
663
  gst_element_link (queue, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
664

665
  seekable = gst_element_get_static_pad (queue, "src");
666
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
667
  rate_pads = g_list_prepend (rate_pads, seekable);
668 669
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
670 671 672 673

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
674 675
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
676 677 678
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
679
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
680
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
681

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
682 683
  pipeline = gst_pipeline_new ("app");

684
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
685 686
  g_object_set (G_OBJECT (src), "location", location, NULL);

687
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
688
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
689 690 691

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
692
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
693 694

  audio_bin = gst_bin_new ("a_decoder_bin");
695
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
696
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
697
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
698 699
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
700
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
701 702
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
703
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
704

705
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
706
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
707

708
  seekable = gst_element_get_static_pad (a_queue, "src");
709
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
710
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
711
  rate_pads =
712 713
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
714 715

  video_bin = gst_bin_new ("v_decoder_bin");
Wim Taymans's avatar
Wim Taymans committed
716
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
717
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
718
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
719 720
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
721
  gst_bin_add (GST_BIN (video_bin), v_decoder);
722 723
  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
724

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

727
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
728
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
729

730
  seekable = gst_element_get_static_pad (v_queue, "src");
731
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
732
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
733
  rate_pads =
734 735
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
736 737 738 739

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
740 741
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
742 743
{
  GstElement *pipeline, *audio_bin, *video_bin;
744 745
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
746
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
747
  GstPad *seekable;
748
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
749

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
750 751
  pipeline = gst_pipeline_new ("app");

752
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
753 754
  g_object_set (G_OBJECT (src), "location", location, NULL);

755 756
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
757

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
758 759
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
760
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
761 762

  audio_bin = gst_bin_new ("a_decoder_bin");
763 764
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
765
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
766
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
767 768
  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
769

770 771
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
772

773 774
  gst_bin_add (GST_BIN (pipeline), audio_bin);

775
  pad = gst_element_get_static_pad (a_decoder, "sink");
776 777 778
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

779
  setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
780
          "sink"), NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
781 782

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

788 789 790 791 792 793 794
  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);
795
  gst_element_link (v_filter, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
796

797
  gst_bin_add (GST_BIN (pipeline), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
798

799
  pad = gst_element_get_static_pad (v_decoder, "sink");
800 801 802
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

803
  setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,