seek.c 87.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 72
/* the state to go to when stop is pressed */
#define STOP_STATE      GST_STATE_READY

73

74
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
75
static GList *rate_pads = NULL;
76
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
77

78 79
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
80
static gboolean loop_seek = FALSE;
81
static gboolean flush_seek = TRUE;
82 83
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
84
static gboolean skip_seek = FALSE;
85
static gdouble rate = 1.0;
86

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

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

109
static gint n_video = 0, n_audio = 0, n_text = 0;
110
static gboolean need_streams = TRUE;
111
static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
112
static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
113
static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
114
static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
115
static GtkWidget *buffer_checkbox, *rate_spinbutton;
Wim Taymans's avatar
Wim Taymans committed
116 117

static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
118

119
static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
Wim Taymans's avatar
Wim Taymans committed
120 121 122
static GtkWidget *shuttle_checkbox, *step_button;
static GtkWidget *shuttle_hscale;
static GtkAdjustment *shuttle_adjustment;
123 124

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

126 127 128 129 130 131 132 133 134
/* 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;

135
static void clear_streams (GstElement * pipeline);
136 137
static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
    gpointer user_dat);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
138

139
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
140 141 142

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
143 144 145
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
146 147
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
148

149
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
150
gst_element_factory_make_or_warn (gchar * type, gchar * name)
151 152 153 154
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
155
    g_warning ("Failed to create element %s of type %s", name, type);
156 157 158 159 160
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
161
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
162
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
163
{
164
  gchar *padname;
165
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
166

167 168 169
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
170 171
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
172
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
173

174
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
175 176
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
177
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
178 179 180
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
181 182
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
183
{
184
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
185

186
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
187 188 189
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
190

191
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
192
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
193 194
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
195 196
static GstElement *
make_mod_pipeline (const gchar * location)
197 198 199 200
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
201

202 203
  pipeline = gst_pipeline_new ("app");

204 205
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
206
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
207 208 209 210 211 212 213 214
  //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);

215 216
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
217

218
  seekable = gst_element_get_static_pad (decoder, "src");
219 220
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
221 222
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
223 224 225 226

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
227 228
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
229 230
{
  GstElement *pipeline;
231
  GstElement *src, *demux, *decoder, *audiosink, *videosink;
232
  GstElement *a_queue, *v_queue;
Wim Taymans's avatar
Wim Taymans committed
233
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
234

Wim Taymans's avatar
Wim Taymans committed
235 236 237
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
238
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
239
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
240
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
241
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
242
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
243
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
244 245 246 247

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

  gst_bin_add (GST_BIN (pipeline), src);
248
  gst_bin_add (GST_BIN (pipeline), demux);
249
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
250
  gst_bin_add (GST_BIN (pipeline), audiosink);
251
  gst_bin_add (GST_BIN (pipeline), v_queue);
252
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
253 254
  gst_bin_add (GST_BIN (pipeline), videosink);

255
  gst_element_link (src, demux);
256
  gst_element_link (a_queue, audiosink);
257 258
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
259

260 261 262 263
  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);
264

265
  seekable = gst_element_get_static_pad (decoder, "src");
266
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
267 268 269 270 271
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
272 273
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
274 275 276
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
277

Wim Taymans's avatar
Wim Taymans committed
278 279
  pipeline = gst_pipeline_new ("app");

280 281
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
282
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
283 284 285 286 287 288 289

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

290
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
291

292 293
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
294 295 296 297 298

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
299 300 301 302

  return pipeline;
}

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

310 311
  pipeline = gst_pipeline_new ("app");

312 313
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
314
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
315
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
316 317 318 319 320 321 322

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

323 324
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
325

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

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
335 336
static GstElement *
make_sid_pipeline (const gchar * location)
337 338 339 340
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
341

342 343
  pipeline = gst_pipeline_new ("app");

344 345
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
346
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
347 348 349 350 351 352 353 354
  //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);

355 356
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
357

358
  seekable = gst_element_get_static_pad (decoder, "src");
359 360
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
361 362
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
363 364 365 366

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
367 368
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
369 370 371 372
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
373

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
374 375
  pipeline = gst_pipeline_new ("app");

376 377 378
  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
379 380
  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
381 382 383 384 385 386 387

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

388 389
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
390

391
  seekable = gst_element_get_static_pad (parser, "src");
392
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
393
  rate_pads = g_list_prepend (rate_pads, seekable);
394 395
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
396 397 398 399

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
400 401
static GstElement *
make_vorbis_pipeline (const gchar * location)
402
{
403 404
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
405
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
406

407 408
  pipeline = gst_pipeline_new ("app");

409
  src = gst_element_factory_make_or_warn (SOURCE, "src");
410 411 412
  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");
413
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
414
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
415 416 417

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

418 419
  audio_bin = gst_bin_new ("a_decoder_bin");

420
  gst_bin_add (GST_BIN (pipeline), src);
421 422 423 424 425
  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);
426

427 428 429 430
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

431
  pad = gst_element_get_static_pad (decoder, "sink");
432 433 434
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

435 436
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
437

438
  seekable = gst_element_get_static_pad (decoder, "src");
439 440
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
441 442
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
443 444 445 446 447 448 449 450 451

  return pipeline;
}

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
452
  GstPad *pad, *seekable;
453 454 455 456 457 458 459

  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
460
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476

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

477
  pad = gst_element_get_static_pad (decoder, "sink");
478 479 480
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

481 482
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
483

484
  seekable = gst_element_get_static_pad (decoder, "src");
485 486
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
487 488
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
489 490 491 492

  return pipeline;
}

493 494 495 496 497 498
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;
499
  GstElement *a_queue, *v_queue, *v_scale;
500
  GstPad *seekable;
Wim Taymans's avatar
Wim Taymans committed
501
  GstPad *pad;
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517

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

520
  gst_bin_add (GST_BIN (pipeline), audio_bin);
521 522 523 524 525 526

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

527 528 529
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
530

531
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
532
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
533
  gst_object_unref (pad);
534

535 536
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
537 538 539 540 541 542

  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");
543
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
544
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
545 546

  gst_bin_add (GST_BIN (pipeline), video_bin);
547 548 549 550

  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);
551
  gst_bin_add (GST_BIN (video_bin), v_scale);
552 553
  gst_bin_add (GST_BIN (video_bin), videosink);

554 555
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
556

557
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
558
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
559
  gst_object_unref (pad);
560

561 562
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
563

564
  seekable = gst_element_get_static_pad (a_decoder, "src");
565 566 567
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
568 569
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
570 571 572 573 574 575 576 577 578 579 580

  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;
581
  GstPad *seekable, *pad;
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597

  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");
598
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
599 600 601 602 603 604

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

605 606 607 608
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

609 610
  gst_bin_add (GST_BIN (pipeline), audio_bin);

611
  pad = gst_element_get_static_pad (a_queue, "sink");
612 613 614
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

615 616
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
617 618 619 620 621 622

  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
623
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
624 625 626 627 628 629

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

630 631
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

632 633
  gst_bin_add (GST_BIN (pipeline), video_bin);

634
  pad = gst_element_get_static_pad (v_queue, "sink");
635 636 637
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

638 639
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
640

641
  seekable = gst_element_get_static_pad (a_decoder, "src");
642 643 644
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
645 646
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
647 648 649 650

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
651 652
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
653 654
{
  GstElement *pipeline;
655
  GstElement *src, *parser, *decoder, *audiosink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
656
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
657

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

660
  src = gst_element_factory_make_or_warn (SOURCE, "src");
661
  parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
662 663
  decoder = gst_element_factory_make_or_warn ("mad", "dec");
  queue = gst_element_factory_make_or_warn ("queue", "queue");
664
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
665

666
  seekable_elements = g_list_prepend (seekable_elements, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
667 668

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

671
  gst_bin_add (GST_BIN (pipeline), src);
672
  gst_bin_add (GST_BIN (pipeline), parser);
673
  gst_bin_add (GST_BIN (pipeline), decoder);
674
  gst_bin_add (GST_BIN (pipeline), queue);
675
  gst_bin_add (GST_BIN (pipeline), audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
676

677 678
  gst_element_link (src, parser);
  gst_element_link (parser, decoder);
679
  gst_element_link (decoder, queue);
680
  gst_element_link (queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
681

682
  seekable = gst_element_get_static_pad (queue, "src");
683
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
684
  rate_pads = g_list_prepend (rate_pads, seekable);
685 686
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
687 688 689 690

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
691 692
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
693 694 695
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
696
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
697
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
698

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
699 700
  pipeline = gst_pipeline_new ("app");

701
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
702 703
  g_object_set (G_OBJECT (src), "location", location, NULL);

704
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
705
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
706 707 708

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
709
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
710 711

  audio_bin = gst_bin_new ("a_decoder_bin");
712
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
713
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
714
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
715 716
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
717
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
718 719
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
720
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
721

722
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
723
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
724

725
  seekable = gst_element_get_static_pad (a_queue, "src");
726
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
727
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
728
  rate_pads =
729 730
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
731 732

  video_bin = gst_bin_new ("v_decoder_bin");
Wim Taymans's avatar
Wim Taymans committed
733
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
734
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
735
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
736 737
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
738
  gst_bin_add (GST_BIN (video_bin), v_decoder);
739 740
  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
741

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

744
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
745
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
746

747
  seekable = gst_element_get_static_pad (v_queue, "src");
748
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
749
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
750
  rate_pads =
751 752
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
753 754 755 756

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
757 758
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
759 760
{
  GstElement *pipeline, *audio_bin, *video_bin;
761 762
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
763
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
764
  GstPad *seekable;
765
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
766

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
767 768
  pipeline = gst_pipeline_new ("app");

769
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
770 771
  g_object_set (G_OBJECT (src), "location", location, NULL);

772 773
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
774

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
775 776
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
777
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
778 779

  audio_bin = gst_bin_new ("a_decoder_bin");
780 781
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
782
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
783
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
784 785
  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
786

787 788
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
789

790 791
  gst_bin_add (GST_BIN (pipeline), audio_bin);

792
  pad = gst_element_get_static_pad (a_decoder, "sink");
793 794 795
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

796
  setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
797
          "sink"), NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
798 799

  video_bin = gst_bin_new ("v_decoder_bin");
800 801
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
802
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
803
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
804

805 806 807 808 809 810 811
  gst_bin_add (GST_BIN (video_bin), v_decoder);
  gst_bin_add (GST_BIN (