seek.c 91.1 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 36
#include <gdk/gdk.h>
#if defined (GDK_WINDOWING_X11)
37
#include <gdk/gdkx.h>
38
#elif defined (GDK_WINDOWING_WIN32)
39 40 41
#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
static gchar *opt_audiosink_str;        /* NULL */
static gchar *opt_videosink_str;        /* NULL */
68

69
#define FILL_INTERVAL 100
70 71
//#define UPDATE_INTERVAL 500
//#define UPDATE_INTERVAL 100
72
#define UPDATE_INTERVAL 40
73 74 75 76 77 78 79

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

80 81
#define DEFAULT_VIDEO_HEIGHT 300

82 83 84
/* the state to go to when stop is pressed */
#define STOP_STATE      GST_STATE_READY

85
#define N_GRAD 1000.0
86

87
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
88
static GList *rate_pads = NULL;
89
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
90

91 92
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
93
static gboolean loop_seek = FALSE;
94
static gboolean flush_seek = TRUE;
95 96
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
97
static gboolean skip_seek = FALSE;
98
static gdouble rate = 1.0;
99

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
100
static GstElement *pipeline;
101 102
static gint pipeline_type;
static const gchar *pipeline_spec;
103 104
static gint64 position = -1;
static gint64 duration = -1;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
105
static GtkAdjustment *adjustment;
106 107
static GtkWidget *hscale, *statusbar;
static guint status_id = 0;
108
static gboolean stats = FALSE;
109 110
static gboolean elem_seek = FALSE;
static gboolean verbose = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
111

112 113
static gboolean is_live = FALSE;
static gboolean buffering = FALSE;
114 115
static GstBufferingMode mode;
static gint64 buffering_left;
116
static GstState state = GST_STATE_NULL;
117
static guint update_id = 0;
118 119
static guint seek_timeout_id = 0;
static gulong changed_id;
120
static guint fill_id = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
121

122
static gint n_video = 0, n_audio = 0, n_text = 0;
123
static gboolean need_streams = TRUE;
124
static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
125
static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
126
static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
127
static GtkWidget *skip_checkbox, *video_window, *download_checkbox;
128
static GtkWidget *buffer_checkbox, *rate_spinbutton;
Wim Taymans's avatar
Wim Taymans committed
129 130

static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
131

132
static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
Wim Taymans's avatar
Wim Taymans committed
133 134 135
static GtkWidget *shuttle_checkbox, *step_button;
static GtkWidget *shuttle_hscale;
static GtkAdjustment *shuttle_adjustment;
136 137

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

139 140 141 142 143 144 145 146 147
/* 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;

148
static void clear_streams (GstElement * pipeline);
149 150
static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
    gpointer user_dat);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
151

152
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
153 154 155

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
156 157 158
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
159 160
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
161

162
static GstElement *
163
gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
164 165 166 167
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
168
    g_warning ("Failed to create element %s of type %s", name, type);
169 170 171 172 173
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
174
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
175
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
176
{
177
  gchar *padname;
178
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
179

180 181 182
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
183 184
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
185
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
186

187
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
188 189
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
190
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
191 192 193
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
194 195
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
196
{
197
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
198

199
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
200 201 202
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
203

204
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
205
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
206 207
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
208 209
static GstElement *
make_mod_pipeline (const gchar * location)
210 211 212 213
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
214

215 216
  pipeline = gst_pipeline_new ("app");

217 218
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
219
  audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
220 221 222 223 224 225 226 227
  //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);

228 229
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
230

231
  seekable = gst_element_get_static_pad (decoder, "src");
232 233
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
234 235
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
236 237 238 239

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
240 241
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
242 243
{
  GstElement *pipeline;
244
  GstElement *src, *demux, *decoder, *audiosink, *videosink;
245
  GstElement *a_queue, *v_queue;
Wim Taymans's avatar
Wim Taymans committed
246
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
247

Wim Taymans's avatar
Wim Taymans committed
248 249 250
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
251
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
252
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
253
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
254
  videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
255
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
256
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
257 258 259 260

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

  gst_bin_add (GST_BIN (pipeline), src);
261
  gst_bin_add (GST_BIN (pipeline), demux);
262
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
263
  gst_bin_add (GST_BIN (pipeline), audiosink);
264
  gst_bin_add (GST_BIN (pipeline), v_queue);
265
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
266 267
  gst_bin_add (GST_BIN (pipeline), videosink);

268
  gst_element_link (src, demux);
269
  gst_element_link (a_queue, audiosink);
270 271
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
272

273 274 275 276
  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);
277

278
  seekable = gst_element_get_static_pad (decoder, "src");
279
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
280 281 282 283 284
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
285 286
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
287 288 289
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
290

Wim Taymans's avatar
Wim Taymans committed
291 292
  pipeline = gst_pipeline_new ("app");

293 294
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
295
  audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
Wim Taymans's avatar
Wim Taymans committed
296 297 298 299 300 301 302

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

303
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
304

305 306
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
307 308 309 310 311

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
312 313 314 315

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
316 317
static GstElement *
make_flac_pipeline (const gchar * location)
318 319 320 321
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
322

323 324
  pipeline = gst_pipeline_new ("app");

325 326
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
327
  audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
Wim Taymans's avatar
Wim Taymans committed
328
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
329 330 331 332 333 334 335

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

336 337
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
338

339
  seekable = gst_element_get_static_pad (decoder, "src");
340 341
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
342 343
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
344 345 346 347

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
348 349
static GstElement *
make_sid_pipeline (const gchar * location)
350 351 352 353
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
354

355 356
  pipeline = gst_pipeline_new ("app");

357 358
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
359
  audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
360 361 362 363 364 365 366 367
  //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);

368 369
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
370

371
  seekable = gst_element_get_static_pad (decoder, "src");
372 373
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
374 375
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
376 377 378 379

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
380 381
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
382 383 384 385
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
386

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
387 388
  pipeline = gst_pipeline_new ("app");

389 390 391
  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
392 393
  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
394 395 396 397 398 399 400

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

401 402
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
403

404
  seekable = gst_element_get_static_pad (parser, "src");
405
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
406
  rate_pads = g_list_prepend (rate_pads, seekable);
407 408
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
409 410 411 412

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
413 414
static GstElement *
make_vorbis_pipeline (const gchar * location)
415
{
416 417
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
418
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
419

420 421
  pipeline = gst_pipeline_new ("app");

422
  src = gst_element_factory_make_or_warn (SOURCE, "src");
423 424 425
  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");
426
  audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
Wim Taymans's avatar
Wim Taymans committed
427
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
428 429 430

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

431 432
  audio_bin = gst_bin_new ("a_decoder_bin");

433
  gst_bin_add (GST_BIN (pipeline), src);
434 435 436 437 438
  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);
439

440 441 442 443
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

444
  pad = gst_element_get_static_pad (decoder, "sink");
445 446 447
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

448 449
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
450

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

  return pipeline;
}

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
465
  GstPad *pad, *seekable;
466 467 468 469 470 471 472

  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");
473
  videosink = gst_element_factory_make_or_warn (opt_videosink_str, "sink");
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489

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

490
  pad = gst_element_get_static_pad (decoder, "sink");
491 492 493
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

494 495
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
496

497
  seekable = gst_element_get_static_pad (decoder, "src");
498 499
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
500 501
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
502 503 504 505

  return pipeline;
}

506 507 508 509 510 511
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;
512
  GstElement *a_queue, *v_queue, *v_scale;
513
  GstPad *seekable;
Wim Taymans's avatar
Wim Taymans committed
514
  GstPad *pad;
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530

  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");
531
  audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
532

533
  gst_bin_add (GST_BIN (pipeline), audio_bin);
534 535 536 537 538 539

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

540 541 542
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
543

544
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
545
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
546
  gst_object_unref (pad);
547

548 549
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
550 551 552 553 554 555

  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");
556
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
557
  videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
558 559

  gst_bin_add (GST_BIN (pipeline), video_bin);
560 561 562 563

  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);
564
  gst_bin_add (GST_BIN (video_bin), v_scale);
565 566
  gst_bin_add (GST_BIN (video_bin), videosink);

567 568
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
569

570
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
571
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
572
  gst_object_unref (pad);
573

574 575
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
576

577
  seekable = gst_element_get_static_pad (a_decoder, "src");
578 579 580
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
581 582
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
583 584 585 586 587 588 589 590 591 592 593

  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;
594
  GstPad *seekable, *pad;
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610

  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");
611
  audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
612 613 614 615 616 617

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

618 619 620 621
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

622 623
  gst_bin_add (GST_BIN (pipeline), audio_bin);

624
  pad = gst_element_get_static_pad (a_queue, "sink");
625 626 627
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

628 629
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
630 631 632 633 634 635

  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");
636
  videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
637 638 639 640 641 642

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

643 644
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

645 646
  gst_bin_add (GST_BIN (pipeline), video_bin);

647
  pad = gst_element_get_static_pad (v_queue, "sink");
648 649 650
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

651 652
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
653

654
  seekable = gst_element_get_static_pad (a_decoder, "src");
655 656 657
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
658 659
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
660 661 662 663

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
664 665
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
666 667
{
  GstElement *pipeline;
668
  GstElement *src, *parser, *decoder, *audiosink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
669
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
670

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
671 672
  pipeline = gst_pipeline_new ("app");

673
  src = gst_element_factory_make_or_warn (SOURCE, "src");
674
  parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
675 676
  decoder = gst_element_factory_make_or_warn ("mad", "dec");
  queue = gst_element_factory_make_or_warn ("queue", "queue");
677
  audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "sink");
678

679
  seekable_elements = g_list_prepend (seekable_elements, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
680 681

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

684
  gst_bin_add (GST_BIN (pipeline), src);
685
  gst_bin_add (GST_BIN (pipeline), parser);
686
  gst_bin_add (GST_BIN (pipeline), decoder);
687
  gst_bin_add (GST_BIN (pipeline), queue);
688
  gst_bin_add (GST_BIN (pipeline), audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
689

690 691
  gst_element_link (src, parser);
  gst_element_link (parser, decoder);
692
  gst_element_link (decoder, queue);
693
  gst_element_link (queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
694

695
  seekable = gst_element_get_static_pad (queue, "src");
696
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
697
  rate_pads = g_list_prepend (rate_pads, seekable);
698 699
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
700 701 702 703

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
704 705
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
706 707 708
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
709
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
710
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
711

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
712 713
  pipeline = gst_pipeline_new ("app");

714
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
715 716
  g_object_set (G_OBJECT (src), "location", location, NULL);

717
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
718
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
719 720 721

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
722
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
723 724

  audio_bin = gst_bin_new ("a_decoder_bin");
725
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
726
  audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
727
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
728 729
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
730
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
731 732
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
733
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
734

735
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
736
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
737

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

  video_bin = gst_bin_new ("v_decoder_bin");
Wim Taymans's avatar
Wim Taymans committed
746
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
747
  videosink = gst_element_factory_make_or_warn (opt_videosink_str, "v_sink");
748
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
749 750
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
751
  gst_bin_add (GST_BIN (video_bin), v_decoder);
752 753
  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
754

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

757
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
758
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
759

760
  seekable = gst_element_get_static_pad (v_queue, "src");
761
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
762
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
763
  rate_pads =
764 765
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
766 767 768 769

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
770 771
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
772 773
{
  GstElement *pipeline, *audio_bin, *video_bin;
774 775
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
776
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
777
  GstPad *seekable;
778
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
779

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
780 781
  pipeline = gst_pipeline_new ("app");

782
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
783 784
  g_object_set (G_OBJECT (src), "location", location, NULL);

785 786
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
787

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
788 789
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
790
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
791 792

  audio_bin = gst_bin_new ("a_decoder_bin");
793 794
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
795
  audiosink = gst_element_factory_make_or_warn (opt_audiosink_str, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
796
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
797 798
  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
799

800 801
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
802

803 804
  gst_bin_add (GST_BIN (pipeline), audio_bin);

805
  pad = gst_element_get_static_pad (a_decoder, "sink");
Wim Taymans's avatar