seek.c 89.7 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

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

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

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

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

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

static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT;
126

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

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

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

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

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

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

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

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

  return element;
}

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

175 176 177
  padname = gst_pad_get_name (newpad);

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

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

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

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

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

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

210 211
  pipeline = gst_pipeline_new ("app");

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

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

  return pipeline;
}

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

318 319
  pipeline = gst_pipeline_new ("app");

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

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

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

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

  return pipeline;
}

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

350 351
  pipeline = gst_pipeline_new ("app");

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

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

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

  return pipeline;
}

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

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

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

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

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

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

  return pipeline;
}

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

415 416
  pipeline = gst_pipeline_new ("app");

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

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

426 427
  audio_bin = gst_bin_new ("a_decoder_bin");

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

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

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

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

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

  return pipeline;
}

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

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

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

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

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

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

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

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

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

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

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