seek.c 90.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
#ifdef HAVE_X
36
#include <gdk/gdkx.h>
37
#endif
38 39
#include <gst/interfaces/xoverlay.h>

40 41 42 43 44 45 46
#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

47
GST_DEBUG_CATEGORY_STATIC (seek_debug);
48 49
#define GST_CAT_DEFAULT (seek_debug)

50 51 52 53 54 55 56 57
#if !GTK_CHECK_VERSION (2, 17, 7)
static void
gtk_widget_get_allocation (GtkWidget * w, GtkAllocation * a)
{
  *a = w->allocation;
}
#endif

58 59 60 61 62 63 64 65 66 67 68 69 70 71
/* 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"

72
#define FILL_INTERVAL 100
73 74
//#define UPDATE_INTERVAL 500
//#define UPDATE_INTERVAL 100
75
#define UPDATE_INTERVAL 40
76 77 78 79 80 81 82

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

83 84
#define DEFAULT_VIDEO_HEIGHT 300

85 86 87
/* the state to go to when stop is pressed */
#define STOP_STATE      GST_STATE_READY

88
#define N_GRAD 1000.0
89

90
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
91
static GList *rate_pads = NULL;
92
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
93

94 95
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
96
static gboolean loop_seek = FALSE;
97
static gboolean flush_seek = TRUE;
98 99
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
100
static gboolean skip_seek = FALSE;
101
static gdouble rate = 1.0;
102

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

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

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

static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
134

135
static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
Wim Taymans's avatar
Wim Taymans committed
136 137 138
static GtkWidget *shuttle_checkbox, *step_button;
static GtkWidget *shuttle_hscale;
static GtkAdjustment *shuttle_adjustment;
139 140

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

142 143 144 145 146 147 148 149 150
/* 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;

151
static void clear_streams (GstElement * pipeline);
152 153
static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
    gpointer user_dat);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
154

155
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
156 157 158

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

165
static GstElement *
166
gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
167 168 169 170
{
  GstElement *element = gst_element_factory_make (type, name);

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

  return element;
}

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

183 184 185
  padname = gst_pad_get_name (newpad);

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

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

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

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

207
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
208
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
209 210
}

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

218 219
  pipeline = gst_pipeline_new ("app");

220 221
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
222
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
223 224 225 226 227 228 229 230
  //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);

231 232
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
233

234
  seekable = gst_element_get_static_pad (decoder, "src");
235 236
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
237 238
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
239 240 241 242

  return pipeline;
}

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

Wim Taymans's avatar
Wim Taymans committed
251 252 253
  pipeline = gst_pipeline_new ("app");

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

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

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

271
  gst_element_link (src, demux);
272
  gst_element_link (a_queue, audiosink);
273 274
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
275

276 277 278 279
  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);
280

281
  seekable = gst_element_get_static_pad (decoder, "src");
282
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
283 284 285 286 287
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

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

Wim Taymans's avatar
Wim Taymans committed
294 295
  pipeline = gst_pipeline_new ("app");

296 297
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
298
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
299 300 301 302 303 304 305

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

306
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
307

308 309
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
310 311 312 313 314

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
315 316 317 318

  return pipeline;
}

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

326 327
  pipeline = gst_pipeline_new ("app");

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

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

339 340
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
341

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

  return pipeline;
}

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

358 359
  pipeline = gst_pipeline_new ("app");

360 361
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
362
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
363 364 365 366 367 368 369 370
  //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);

371 372
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
373

374
  seekable = gst_element_get_static_pad (decoder, "src");
375 376
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
377 378
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
379 380 381 382

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
390 391
  pipeline = gst_pipeline_new ("app");

392 393 394
  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
395 396
  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
397 398 399 400 401 402 403

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

404 405
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
406

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

  return pipeline;
}

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

423 424
  pipeline = gst_pipeline_new ("app");

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

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

434 435
  audio_bin = gst_bin_new ("a_decoder_bin");

436
  gst_bin_add (GST_BIN (pipeline), src);
437 438 439 440 441
  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);
442

443 444 445 446
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

447
  pad = gst_element_get_static_pad (decoder, "sink");
448 449 450
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

451 452
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
453

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

  return pipeline;
}

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

  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
476
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492

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

493
  pad = gst_element_get_static_pad (decoder, "sink");
494 495 496
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

497 498
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
499

500
  seekable = gst_element_get_static_pad (decoder, "src");
501 502
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
503 504
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
505 506 507 508

  return pipeline;
}

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

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

536
  gst_bin_add (GST_BIN (pipeline), audio_bin);
537 538 539 540 541 542

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

543 544 545
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
546

547
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
548
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
549
  gst_object_unref (pad);
550

551 552
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
553 554 555 556 557 558

  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");
559
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
560
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
561 562

  gst_bin_add (GST_BIN (pipeline), video_bin);
563 564 565 566

  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);
567
  gst_bin_add (GST_BIN (video_bin), v_scale);
568 569
  gst_bin_add (GST_BIN (video_bin), videosink);

570 571
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
572

573
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
574
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
575
  gst_object_unref (pad);
576

577 578
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
579

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

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

  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");
614
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
615 616 617 618 619 620

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

621 622 623 624
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

625 626
  gst_bin_add (GST_BIN (pipeline), audio_bin);

627
  pad = gst_element_get_static_pad (a_queue, "sink");
628 629 630
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

631 632
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
633 634 635 636 637 638

  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
639
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
640 641 642 643 644 645

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

646 647
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

648 649
  gst_bin_add (GST_BIN (pipeline), video_bin);

650
  pad = gst_element_get_static_pad (v_queue, "sink");
651 652 653
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

654 655
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
656

657
  seekable = gst_element_get_static_pad (a_decoder, "src");
658 659 660
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
661 662
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
663 664 665 666

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
674 675
  pipeline = gst_pipeline_new ("app");

676
  src = gst_element_factory_make_or_warn (SOURCE, "src");
677
  parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
678 679
  decoder = gst_element_factory_make_or_warn ("mad", "dec");
  queue = gst_element_factory_make_or_warn ("queue", "queue");
680
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
681

682
  seekable_elements = g_list_prepend (seekable_elements, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
683 684

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

687
  gst_bin_add (GST_BIN (pipeline), src);
688
  gst_bin_add (GST_BIN (pipeline), parser);
689
  gst_bin_add (GST_BIN (pipeline), decoder);
690
  gst_bin_add (GST_BIN (pipeline), queue);
691
  gst_bin_add (GST_BIN (pipeline), audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
692

693 694
  gst_element_link (src, parser);
  gst_element_link (parser, decoder);
695
  gst_element_link (decoder, queue);
696
  gst_element_link (queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
697

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

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
715 716
  pipeline = gst_pipeline_new ("app");

717
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
718 719
  g_object_set (G_OBJECT (src), "location", location, NULL);

720
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
721
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
722 723 724

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
725
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
726 727

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

738
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
739
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
740

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

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

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

760
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
761
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
762

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

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
783 784
  pipeline = gst_pipeline_new ("app");

785
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
786 787
  g_object_set (G_OBJECT (src), "location", location, NULL);

788 789
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
790

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
791 792
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
793
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
794 795

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

803 804
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
805

806 807
  gst_bin_add (GST_BIN (pipeline), audio_bin);

808
  pad = gst_element_get_static_pad (a_decoder, "sink");
809 810 811
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

812
  setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
813
          "sink"), NULL);