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

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

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

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

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

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

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

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

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

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

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

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

68 69
#define DEFAULT_VIDEO_HEIGHT 300

70

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

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

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

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

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

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

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

124
static void clear_streams (GstElement * pipeline);
125 126
static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
    gpointer user_dat);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
127

128
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
129 130 131

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

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

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

  return element;
}

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

156 157 158
  padname = gst_pad_get_name (newpad);

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

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

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

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

180
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
181
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
182 183
}

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

191 192
  pipeline = gst_pipeline_new ("app");

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

204 205
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
206

207
  seekable = gst_element_get_static_pad (decoder, "src");
208 209
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
210 211
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
212 213 214 215

  return pipeline;
}

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

Wim Taymans's avatar
Wim Taymans committed
224 225 226
  pipeline = gst_pipeline_new ("app");

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

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

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

244
  gst_element_link (src, demux);
245
  gst_element_link (a_queue, audiosink);
246 247
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
248

249 250 251 252
  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);
253

254
  seekable = gst_element_get_static_pad (decoder, "src");
255
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
256 257 258 259 260
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

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

Wim Taymans's avatar
Wim Taymans committed
267 268
  pipeline = gst_pipeline_new ("app");

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

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

279
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
280

281 282
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
283 284 285 286 287

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
288 289 290 291

  return pipeline;
}

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

299 300
  pipeline = gst_pipeline_new ("app");

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

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

312 313
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
314

315
  seekable = gst_element_get_static_pad (decoder, "src");
316 317
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
318 319
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
320 321 322 323

  return pipeline;
}

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

331 332
  pipeline = gst_pipeline_new ("app");

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

344 345
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
346

347
  seekable = gst_element_get_static_pad (decoder, "src");
348 349
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
350 351
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
352 353 354 355

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
363 364
  pipeline = gst_pipeline_new ("app");

365 366 367
  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
368 369
  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
370 371 372 373 374 375 376

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

377 378
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
379

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

  return pipeline;
}

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

396 397
  pipeline = gst_pipeline_new ("app");

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

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

407 408
  audio_bin = gst_bin_new ("a_decoder_bin");

409
  gst_bin_add (GST_BIN (pipeline), src);
410 411 412 413 414
  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);
415

416 417 418 419
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

420
  pad = gst_element_get_static_pad (decoder, "sink");
421 422 423
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

424 425
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
426

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

  return pipeline;
}

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

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

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

466
  pad = gst_element_get_static_pad (decoder, "sink");
467 468 469
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

470 471
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
472

473
  seekable = gst_element_get_static_pad (decoder, "src");
474 475
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
476 477
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
478 479 480 481

  return pipeline;
}

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

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

509
  gst_bin_add (GST_BIN (pipeline), audio_bin);
510 511 512 513 514 515

  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
  gst_bin_add (GST_BIN (audio_bin), a_convert);
  gst_bin_add (GST_BIN (audio_bin), audiosink);

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

520
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
521
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
522
  gst_object_unref (pad);
523

524 525
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
526 527 528 529 530 531

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

  gst_bin_add (GST_BIN (pipeline), video_bin);
536 537 538 539

  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);
540
  gst_bin_add (GST_BIN (video_bin), v_scale);
541 542
  gst_bin_add (GST_BIN (video_bin), videosink);

543 544
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
545

546
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
547
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
548
  gst_object_unref (pad);
549

550 551
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
552

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

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

  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");
587
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
588 589 590 591 592 593

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

594 595 596 597
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

598 599
  gst_bin_add (GST_BIN (pipeline), audio_bin);

600
  pad = gst_element_get_static_pad (a_queue, "sink");
601 602 603
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

604 605
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
606 607 608 609 610 611

  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
612
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
613 614 615 616 617 618

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

619 620
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

621 622
  gst_bin_add (GST_BIN (pipeline), video_bin);

623
  pad = gst_element_get_static_pad (v_queue, "sink");
624 625 626
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

627 628
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
629

630
  seekable = gst_element_get_static_pad (a_decoder, "src");
631 632 633
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
634 635
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
636 637 638 639

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
647 648
  pipeline = gst_pipeline_new ("app");

649
  src = gst_element_factory_make_or_warn (SOURCE, "src");
650
  parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
651 652
  decoder = gst_element_factory_make_or_warn ("mad", "dec");
  queue = gst_element_factory_make_or_warn ("queue", "queue");
653
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
654

655
  seekable_elements = g_list_prepend (seekable_elements, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
656 657

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

660
  gst_bin_add (GST_BIN (pipeline), src);
661
  gst_bin_add (GST_BIN (pipeline), parser);
662
  gst_bin_add (GST_BIN (pipeline), decoder);
663
  gst_bin_add (GST_BIN (pipeline), queue);
664
  gst_bin_add (GST_BIN (pipeline), audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
665

666 667
  gst_element_link (src, parser);
  gst_element_link (parser, decoder);
668
  gst_element_link (decoder, queue);
669
  gst_element_link (queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
670

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

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
688 689
  pipeline = gst_pipeline_new ("app");

690
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
691 692
  g_object_set (G_OBJECT (src), "location", location, NULL);

693
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
694
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
695 696 697

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
698
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
699 700

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

711
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
712
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
713

714
  seekable = gst_element_get_static_pad (a_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 (a_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
720 721

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

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

733
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
734
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
735

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

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
756 757
  pipeline = gst_pipeline_new ("app");

758
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
759 760
  g_object_set (G_OBJECT (src), "location", location, NULL);

761 762
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
763

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
764 765
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
766
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
767 768

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

776 777
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
778

779 780
  gst_bin_add (GST_BIN (pipeline), audio_bin);

781
  pad = gst_element_get_static_pad (a_decoder, "sink");
782 783 784
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

785
  setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
786
          "sink"), NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
787 788

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

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

803
  gst_bin_add (GST_BIN (pipeline), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
804

805
  pad = gst_element_get_static_pad (v_decoder, "sink");
806 807 808
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);