seek.c 90.6 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 40 41
#ifdef G_OS_WIN32
#include <gdk/gdkwin32.h>
#endif

42 43
#include <gst/interfaces/xoverlay.h>

44 45 46 47 48 49 50
#if (!GTK_CHECK_VERSION(2, 23, 0) || GTK_CHECK_VERSION(2, 90, 0)) && !GTK_CHECK_VERSION(2, 91, 1)
#define gtk_combo_box_text_new gtk_combo_box_new_text
#define gtk_combo_box_text_append_text gtk_combo_box_append_text
#define gtk_combo_box_text_remove gtk_combo_box_remove_text
#define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX
#endif

51
GST_DEBUG_CATEGORY_STATIC (seek_debug);
52 53
#define GST_CAT_DEFAULT (seek_debug)

54 55 56 57 58 59 60 61
#if !GTK_CHECK_VERSION (2, 17, 7)
static void
gtk_widget_get_allocation (GtkWidget * w, GtkAllocation * a)
{
  *a = w->allocation;
}
#endif

62 63
/* configuration */

64
#define SOURCE "filesrc"
65

66 67 68
#define ASINK DEFAULT_AUDIOSINK
//#define ASINK "pulsesink"
//#define ASINK "alsasink"
69
//#define ASINK "osssink"
70
//#define ASINK "directsoundsink"
71

72 73 74
#ifdef G_OS_WIN32
#define VSINK "directdrawsink"
#else
75
#define VSINK "xvimagesink"
76
#endif
77 78 79 80
//#define VSINK "sdlvideosink"
//#define VSINK "ximagesink"
//#define VSINK "aasink"
//#define VSINK "cacasink"
81 82 83
//#define VSINK "dshowvideosink"
//#define VSINK "sdlvideosink"
//#define VSINK "glimagesink"
84

85
#define FILL_INTERVAL 100
86 87
//#define UPDATE_INTERVAL 500
//#define UPDATE_INTERVAL 100
88
#define UPDATE_INTERVAL 40
89 90 91 92 93 94 95

/* 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

96 97
#define DEFAULT_VIDEO_HEIGHT 300

98 99 100
/* the state to go to when stop is pressed */
#define STOP_STATE      GST_STATE_READY

101
#define N_GRAD 1000.0
102

103
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
104
static GList *rate_pads = NULL;
105
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
106

107 108
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
109
static gboolean loop_seek = FALSE;
110
static gboolean flush_seek = TRUE;
111 112
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
113
static gboolean skip_seek = FALSE;
114
static gdouble rate = 1.0;
115

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
116
static GstElement *pipeline;
117 118
static gint pipeline_type;
static const gchar *pipeline_spec;
119 120
static gint64 position = -1;
static gint64 duration = -1;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
121
static GtkAdjustment *adjustment;
122 123
static GtkWidget *hscale, *statusbar;
static guint status_id = 0;
124
static gboolean stats = FALSE;
125 126
static gboolean elem_seek = FALSE;
static gboolean verbose = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
127

128 129
static gboolean is_live = FALSE;
static gboolean buffering = FALSE;
130 131
static GstBufferingMode mode;
static gint64 buffering_left;
132
static GstState state = GST_STATE_NULL;
133
static guint update_id = 0;
134 135
static guint seek_timeout_id = 0;
static gulong changed_id;
136
static guint fill_id = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
137

138
static gint n_video = 0, n_audio = 0, n_text = 0;
139
static gboolean need_streams = TRUE;
140
static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
141
static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
142
static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
143
static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
144
static GtkWidget *buffer_checkbox, *rate_spinbutton;
Wim Taymans's avatar
Wim Taymans committed
145 146

static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
147

148
static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
Wim Taymans's avatar
Wim Taymans committed
149 150 151
static GtkWidget *shuttle_checkbox, *step_button;
static GtkWidget *shuttle_hscale;
static GtkAdjustment *shuttle_adjustment;
152 153

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

155 156 157 158 159 160 161 162 163
/* 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;

164
static void clear_streams (GstElement * pipeline);
165 166
static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
    gpointer user_dat);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
167

168
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
169 170 171

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
172 173 174
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
175 176
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
177

178
static GstElement *
179
gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
180 181 182 183
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
184
    g_warning ("Failed to create element %s of type %s", name, type);
185 186 187 188 189
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
190
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
191
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
192
{
193
  gchar *padname;
194
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
195

196 197 198
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
199 200
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
201
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
202

203
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
204 205
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
206
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
207 208 209
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
210 211
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
212
{
213
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
214

215
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
216 217 218
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
219

220
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
221
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
222 223
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
224 225
static GstElement *
make_mod_pipeline (const gchar * location)
226 227 228 229
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
230

231 232
  pipeline = gst_pipeline_new ("app");

233 234
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
235
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
236 237 238 239 240 241 242 243
  //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);

244 245
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
246

247
  seekable = gst_element_get_static_pad (decoder, "src");
248 249
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
250 251
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
252 253 254 255

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
256 257
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
258 259
{
  GstElement *pipeline;
260
  GstElement *src, *demux, *decoder, *audiosink, *videosink;
261
  GstElement *a_queue, *v_queue;
Wim Taymans's avatar
Wim Taymans committed
262
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
263

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

  src = gst_element_factory_make_or_warn (SOURCE, "src");
267
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
268
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
269
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
270
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
271
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
272
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
273 274 275 276

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

  gst_bin_add (GST_BIN (pipeline), src);
277
  gst_bin_add (GST_BIN (pipeline), demux);
278
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
279
  gst_bin_add (GST_BIN (pipeline), audiosink);
280
  gst_bin_add (GST_BIN (pipeline), v_queue);
281
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
282 283
  gst_bin_add (GST_BIN (pipeline), videosink);

284
  gst_element_link (src, demux);
285
  gst_element_link (a_queue, audiosink);
286 287
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
288

289 290 291 292
  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);
293

294
  seekable = gst_element_get_static_pad (decoder, "src");
295
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
296 297 298 299 300
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
301 302
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
303 304 305
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
306

Wim Taymans's avatar
Wim Taymans committed
307 308
  pipeline = gst_pipeline_new ("app");

309 310
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
311
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
312 313 314 315 316 317 318

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

319
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
320

321 322
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
323 324 325 326 327

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
328 329 330 331

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
332 333
static GstElement *
make_flac_pipeline (const gchar * location)
334 335 336 337
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
338

339 340
  pipeline = gst_pipeline_new ("app");

341 342
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
343
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
344
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
345 346 347 348 349 350 351

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

352 353
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
354

355
  seekable = gst_element_get_static_pad (decoder, "src");
356 357
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
358 359
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
360 361 362 363

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
364 365
static GstElement *
make_sid_pipeline (const gchar * location)
366 367 368 369
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
370

371 372
  pipeline = gst_pipeline_new ("app");

373 374
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
375
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
376 377 378 379 380 381 382 383
  //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);

384 385
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
386

387
  seekable = gst_element_get_static_pad (decoder, "src");
388 389
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
390 391
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
392 393 394 395

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
396 397
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
398 399 400 401
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
402

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
403 404
  pipeline = gst_pipeline_new ("app");

405 406 407
  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
408 409
  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
410 411 412 413 414 415 416

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

417 418
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
419

420
  seekable = gst_element_get_static_pad (parser, "src");
421
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
422
  rate_pads = g_list_prepend (rate_pads, seekable);
423 424
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
425 426 427 428

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
429 430
static GstElement *
make_vorbis_pipeline (const gchar * location)
431
{
432 433
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
434
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
435

436 437
  pipeline = gst_pipeline_new ("app");

438
  src = gst_element_factory_make_or_warn (SOURCE, "src");
439 440 441
  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");
442
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
443
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
444 445 446

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

447 448
  audio_bin = gst_bin_new ("a_decoder_bin");

449
  gst_bin_add (GST_BIN (pipeline), src);
450 451 452 453 454
  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);
455

456 457 458 459
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

460
  pad = gst_element_get_static_pad (decoder, "sink");
461 462 463
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

464 465
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
466

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

  return pipeline;
}

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
481
  GstPad *pad, *seekable;
482 483 484 485 486 487 488

  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
489
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505

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

506
  pad = gst_element_get_static_pad (decoder, "sink");
507 508 509
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

510 511
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
512

513
  seekable = gst_element_get_static_pad (decoder, "src");
514 515
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
516 517
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
518 519 520 521

  return pipeline;
}

522 523 524 525 526 527
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;
528
  GstElement *a_queue, *v_queue, *v_scale;
529
  GstPad *seekable;
Wim Taymans's avatar
Wim Taymans committed
530
  GstPad *pad;
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546

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

549
  gst_bin_add (GST_BIN (pipeline), audio_bin);
550 551 552 553 554 555

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

556 557 558
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
559

560
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
561
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
562
  gst_object_unref (pad);
563

564 565
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
566 567 568 569 570 571

  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");
572
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
573
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
574 575

  gst_bin_add (GST_BIN (pipeline), video_bin);
576 577 578 579

  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);
580
  gst_bin_add (GST_BIN (video_bin), v_scale);
581 582
  gst_bin_add (GST_BIN (video_bin), videosink);

583 584
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
585

586
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
587
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
588
  gst_object_unref (pad);
589

590 591
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
592

593
  seekable = gst_element_get_static_pad (a_decoder, "src");
594 595 596
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
597 598
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
599 600 601 602 603 604 605 606 607 608 609

  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;
610
  GstPad *seekable, *pad;
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626

  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");
627
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
628 629 630 631 632 633

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

634 635 636 637
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

638 639
  gst_bin_add (GST_BIN (pipeline), audio_bin);

640
  pad = gst_element_get_static_pad (a_queue, "sink");
641 642 643
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

644 645
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
646 647 648 649 650 651

  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
652
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
653 654 655 656 657 658

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

659 660
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

661 662
  gst_bin_add (GST_BIN (pipeline), video_bin);

663
  pad = gst_element_get_static_pad (v_queue, "sink");
664 665 666
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

667 668
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
669

670
  seekable = gst_element_get_static_pad (a_decoder, "src");
671 672 673
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
674 675
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
676 677 678 679

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
680 681
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
682 683
{
  GstElement *pipeline;
684
  GstElement *src, *parser, *decoder, *audiosink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
685
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
686

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

689
  src = gst_element_factory_make_or_warn (SOURCE, "src");
690
  parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
691 692
  decoder = gst_element_factory_make_or_warn ("mad", "dec");
  queue = gst_element_factory_make_or_warn ("queue", "queue");
693
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
694

695
  seekable_elements = g_list_prepend (seekable_elements, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
696 697

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

700
  gst_bin_add (GST_BIN (pipeline), src);
701
  gst_bin_add (GST_BIN (pipeline), parser);
702
  gst_bin_add (GST_BIN (pipeline), decoder);
703
  gst_bin_add (GST_BIN (pipeline), queue);
704
  gst_bin_add (GST_BIN (pipeline), audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
705

706 707
  gst_element_link (src, parser);
  gst_element_link (parser, decoder);
708
  gst_element_link (decoder, queue);
709
  gst_element_link (queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
710

711
  seekable = gst_element_get_static_pad (queue, "src");
712
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
713
  rate_pads = g_list_prepend (rate_pads, seekable);
714 715
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
716 717 718 719

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
720 721
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
722 723 724
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
725
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
726
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
727

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
728 729
  pipeline = gst_pipeline_new ("app");

730
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
731 732
  g_object_set (G_OBJECT (src), "location", location, NULL);

733
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
734
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
735 736 737

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
738
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
739 740

  audio_bin = gst_bin_new ("a_decoder_bin");
741
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
742
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
743
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
744 745
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
746
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
747 748
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
749
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
750

751
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
752
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
753

754
  seekable = gst_element_get_static_pad (a_queue, "src");
755
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
756
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
757
  rate_pads =
758 759
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
760 761

  video_bin = gst_bin_new ("v_decoder_bin");
Wim Taymans's avatar
Wim Taymans committed
762
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
763
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
764
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
765 766
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
767
  gst_bin_add (GST_BIN (video_bin), v_decoder);
768 769
  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
770

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

773
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
774
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
775

776
  seekable = gst_element_get_static_pad (v_queue, "src");
777
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
778
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
779
  rate_pads =
780 781
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
782 783 784 785

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
786 787
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
788 789
{
  GstElement *pipeline, *audio_bin, *video_bin;
790 791
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
792
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
793
  GstPad *seekable;
794
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
795

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
796 797
  pipeline = gst_pipeline_new ("app");

798
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
799 800
  g_object_set (G_OBJECT (src), "location", location, NULL);

801 802
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
803

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
804 805
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
806
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
807 808

  audio_bin = gst_bin_new ("a_decoder_bin");
809 810
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
Wim Taymans's avatar