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
GST_DEBUG_CATEGORY_STATIC (seek_debug);
41 42
#define GST_CAT_DEFAULT (seek_debug)

43 44 45 46 47 48 49 50
#if !GTK_CHECK_VERSION (2, 17, 7)
static void
gtk_widget_get_allocation (GtkWidget * w, GtkAllocation * a)
{
  *a = w->allocation;
}
#endif

51 52 53 54 55 56 57 58 59 60 61 62 63 64
/* 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"

65
#define FILL_INTERVAL 100
66 67
//#define UPDATE_INTERVAL 500
//#define UPDATE_INTERVAL 100
68
#define UPDATE_INTERVAL 40
69 70 71 72 73 74 75

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

76 77
#define DEFAULT_VIDEO_HEIGHT 300

78 79 80
/* the state to go to when stop is pressed */
#define STOP_STATE      GST_STATE_READY

81
#define N_GRAD 1000.0
82

83
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
84
static GList *rate_pads = NULL;
85
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
86

87 88
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
89
static gboolean loop_seek = FALSE;
90
static gboolean flush_seek = TRUE;
91 92
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
93
static gboolean skip_seek = FALSE;
94
static gdouble rate = 1.0;
95

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

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

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

static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
127

128
static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
Wim Taymans's avatar
Wim Taymans committed
129 130 131
static GtkWidget *shuttle_checkbox, *step_button;
static GtkWidget *shuttle_hscale;
static GtkAdjustment *shuttle_adjustment;
132 133

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

135 136 137 138 139 140 141 142 143
/* 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;

144
static void clear_streams (GstElement * pipeline);
145 146
static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
    gpointer user_dat);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
147

148
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
149 150 151

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
152 153 154
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
155 156
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
157

158
static GstElement *
159
gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
160 161 162 163
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
164
    g_warning ("Failed to create element %s of type %s", name, type);
165 166 167 168 169
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
170
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
171
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
172
{
173
  gchar *padname;
174
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
175

176 177 178
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
179 180
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
181
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
182

183
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
184 185
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
186
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
187 188 189
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
190 191
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
192
{
193
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
194

195
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
196 197 198
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
199

200
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
201
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
202 203
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
204 205
static GstElement *
make_mod_pipeline (const gchar * location)
206 207 208 209
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
210

211 212
  pipeline = gst_pipeline_new ("app");

213 214
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
215
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
216 217 218 219 220 221 222 223
  //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);

224 225
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
226

227
  seekable = gst_element_get_static_pad (decoder, "src");
228 229
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
230 231
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
232 233 234 235

  return pipeline;
}

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

Wim Taymans's avatar
Wim Taymans committed
244 245 246
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
247
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
248
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
249
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
250
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
251
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
252
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
253 254 255 256

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

  gst_bin_add (GST_BIN (pipeline), src);
257
  gst_bin_add (GST_BIN (pipeline), demux);
258
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
259
  gst_bin_add (GST_BIN (pipeline), audiosink);
260
  gst_bin_add (GST_BIN (pipeline), v_queue);
261
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
262 263
  gst_bin_add (GST_BIN (pipeline), videosink);

264
  gst_element_link (src, demux);
265
  gst_element_link (a_queue, audiosink);
266 267
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
268

269 270 271 272
  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);
273

274
  seekable = gst_element_get_static_pad (decoder, "src");
275
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
276 277 278 279 280
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
281 282
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
283 284 285
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
286

Wim Taymans's avatar
Wim Taymans committed
287 288
  pipeline = gst_pipeline_new ("app");

289 290
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
291
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
292 293 294 295 296 297 298

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

299
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
300

301 302
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
303 304 305 306 307

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
308 309 310 311

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
312 313
static GstElement *
make_flac_pipeline (const gchar * location)
314 315 316 317
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
318

319 320
  pipeline = gst_pipeline_new ("app");

321 322
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
323
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
324
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
325 326 327 328 329 330 331

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

332 333
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
334

335
  seekable = gst_element_get_static_pad (decoder, "src");
336 337
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
338 339
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
340 341 342 343

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
344 345
static GstElement *
make_sid_pipeline (const gchar * location)
346 347 348 349
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
350

351 352
  pipeline = gst_pipeline_new ("app");

353 354
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
355
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
356 357 358 359 360 361 362 363
  //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);

364 365
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
366

367
  seekable = gst_element_get_static_pad (decoder, "src");
368 369
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
370 371
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
372 373 374 375

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
376 377
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
378 379 380 381
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
382

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
383 384
  pipeline = gst_pipeline_new ("app");

385 386 387
  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
388 389
  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
390 391 392 393 394 395 396

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

397 398
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
399

400
  seekable = gst_element_get_static_pad (parser, "src");
401
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
402
  rate_pads = g_list_prepend (rate_pads, seekable);
403 404
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
405 406 407 408

  return pipeline;
}

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

416 417
  pipeline = gst_pipeline_new ("app");

418
  src = gst_element_factory_make_or_warn (SOURCE, "src");
419 420 421
  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");
422
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
423
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
424 425 426

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

427 428
  audio_bin = gst_bin_new ("a_decoder_bin");

429
  gst_bin_add (GST_BIN (pipeline), src);
430 431 432 433 434
  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);
435

436 437 438 439
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

440
  pad = gst_element_get_static_pad (decoder, "sink");
441 442 443
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

444 445
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
446

447
  seekable = gst_element_get_static_pad (decoder, "src");
448 449
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
450 451
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
452 453 454 455 456 457 458 459 460

  return pipeline;
}

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
461
  GstPad *pad, *seekable;
462 463 464 465 466 467 468

  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
469
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485

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

486
  pad = gst_element_get_static_pad (decoder, "sink");
487 488 489
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

490 491
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
492

493
  seekable = gst_element_get_static_pad (decoder, "src");
494 495
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
496 497
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
498 499 500 501

  return pipeline;
}

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

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

529
  gst_bin_add (GST_BIN (pipeline), audio_bin);
530 531 532 533 534 535

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

536 537 538
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
539

540
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
541
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
542
  gst_object_unref (pad);
543

544 545
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
546 547 548 549 550 551

  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");
552
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
553
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
554 555

  gst_bin_add (GST_BIN (pipeline), video_bin);
556 557 558 559

  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);
560
  gst_bin_add (GST_BIN (video_bin), v_scale);
561 562
  gst_bin_add (GST_BIN (video_bin), videosink);

563 564
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
565

566
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
567
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
568
  gst_object_unref (pad);
569

570 571
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
572

573
  seekable = gst_element_get_static_pad (a_decoder, "src");
574 575 576
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
577 578
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
579 580 581 582 583 584 585 586 587 588 589

  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;
590
  GstPad *seekable, *pad;
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606

  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");
607
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
608 609 610 611 612 613

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

614 615 616 617
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

618 619
  gst_bin_add (GST_BIN (pipeline), audio_bin);

620
  pad = gst_element_get_static_pad (a_queue, "sink");
621 622 623
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

624 625
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
626 627 628 629 630 631

  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
632
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
633 634 635 636 637 638

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

639 640
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

641 642
  gst_bin_add (GST_BIN (pipeline), video_bin);

643
  pad = gst_element_get_static_pad (v_queue, "sink");
644 645 646
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

647 648
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
649

650
  seekable = gst_element_get_static_pad (a_decoder, "src");
651 652 653
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
654 655
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
656 657 658 659

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
660 661
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
662 663
{
  GstElement *pipeline;
664
  GstElement *src, *parser, *decoder, *audiosink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
665
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
666

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
667 668
  pipeline = gst_pipeline_new ("app");

669
  src = gst_element_factory_make_or_warn (SOURCE, "src");
670
  parser = gst_element_factory_make_or_warn ("mp3parse", "parse");
671 672
  decoder = gst_element_factory_make_or_warn ("mad", "dec");
  queue = gst_element_factory_make_or_warn ("queue", "queue");
673
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
674

675
  seekable_elements = g_list_prepend (seekable_elements, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
676 677

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

680
  gst_bin_add (GST_BIN (pipeline), src);
681
  gst_bin_add (GST_BIN (pipeline), parser);
682
  gst_bin_add (GST_BIN (pipeline), decoder);
683
  gst_bin_add (GST_BIN (pipeline), queue);
684
  gst_bin_add (GST_BIN (pipeline), audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
685

686 687
  gst_element_link (src, parser);
  gst_element_link (parser, decoder);
688
  gst_element_link (decoder, queue);
689
  gst_element_link (queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
690

691
  seekable = gst_element_get_static_pad (queue, "src");
692
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
693
  rate_pads = g_list_prepend (rate_pads, seekable);
694 695
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
696 697 698 699

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
708 709
  pipeline = gst_pipeline_new ("app");

710
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
711 712
  g_object_set (G_OBJECT (src), "location", location, NULL);

713
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
714
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
715 716 717

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
718
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
719 720

  audio_bin = gst_bin_new ("a_decoder_bin");
721
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
722
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
723
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
724 725
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
726
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
727 728
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
729
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
730

731
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
732
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
733

734
  seekable = gst_element_get_static_pad (a_queue, "src");
735
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
736
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
737
  rate_pads =
738 739
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
740 741

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

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

753
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
754
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
755

756
  seekable = gst_element_get_static_pad (v_queue, "src");
757
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
758
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
759
  rate_pads =
760 761
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
762 763 764 765

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
776 777
  pipeline = gst_pipeline_new ("app");

778
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
779 780
  g_object_set (G_OBJECT (src), "location", location, NULL);

781 782
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
783

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
784 785
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
786
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
787 788

  audio_bin = gst_bin_new ("a_decoder_bin");
789 790
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
791
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
792
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
793 794
  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
795

796 797
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
798

799 800
  gst_bin_add (GST_BIN (pipeline), audio_bin);

801
  pad = gst_element_get_static_pad (a_decoder, "sink");
802 803 804
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

805
  setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
806
          "sink"), NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
807 808

  video_bin = gst_bin_new ("v_decoder_bin");
809 810
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");