seek.c 75.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* GStreamer
 *
 * seek.c: seeking sample application
 *
 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
 *               2006 Stefan Kost <ensonic@users.sf.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
23
#include <stdlib.h>
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
24 25 26 27 28
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <string.h>

29 30 31 32
#include <X11/Xlib.h>
#include <gdk/gdkx.h>
#include <gst/interfaces/xoverlay.h>

33
GST_DEBUG_CATEGORY_STATIC (seek_debug);
34 35
#define GST_CAT_DEFAULT (seek_debug)

36 37 38 39 40 41 42 43 44 45 46 47 48 49
/* 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"

50
#define FILL_INTERVAL 100
51 52 53 54 55 56 57 58 59 60
//#define UPDATE_INTERVAL 500
//#define UPDATE_INTERVAL 100
#define UPDATE_INTERVAL 10

/* number of milliseconds to play for after a seek */
#define SCRUB_TIME 100

/* timeout for gst_element_get_state() after a seek */
#define SEEK_TIMEOUT 40 * GST_MSECOND

61 62
#define DEFAULT_VIDEO_HEIGHT 300

63

64
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
65
static GList *rate_pads = NULL;
66
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
67

68 69
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
70
static gboolean loop_seek = FALSE;
71
static gboolean flush_seek = TRUE;
72 73
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
74
static gdouble rate = 1.0;
75

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
76
static GstElement *pipeline;
77 78
static gint pipeline_type;
static const gchar *pipeline_spec;
79 80
static gint64 position = -1;
static gint64 duration = -1;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
81
static GtkAdjustment *adjustment;
82 83
static GtkWidget *hscale, *statusbar;
static guint status_id = 0;
84
static gboolean stats = FALSE;
85 86
static gboolean elem_seek = FALSE;
static gboolean verbose = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
87

88 89
static gboolean is_live = FALSE;
static gboolean buffering = FALSE;
90 91
static GstBufferingMode mode;
static gint64 buffering_left;
92
static GstState state = GST_STATE_NULL;
93
static guint update_id = 0;
94 95
static guint seek_timeout_id = 0;
static gulong changed_id;
96
static guint fill_id = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
97

98
static gint n_video = 0, n_audio = 0, n_text = 0;
99
static gboolean need_streams = TRUE;
100
static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
101
static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
102
static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
103 104 105 106
static GtkWidget *video_window;
static guint embed_xid = 0;

GList *paths = NULL, *l = NULL;
107

108 109 110 111 112 113 114 115 116
/* 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;

117
static void clear_streams (GstElement * pipeline);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
118

119
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
120 121 122

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
123 124 125
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
126 127
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
128

129
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
130
gst_element_factory_make_or_warn (gchar * type, gchar * name)
131 132 133 134
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
135
    g_warning ("Failed to create element %s of type %s", name, type);
136 137 138 139 140
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
141
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
142
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
143
{
144
  gchar *padname;
145
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
146

147 148 149
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
150 151
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
152
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
153

154
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
155 156
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
157
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
158 159 160
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
161 162
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
163
{
164
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
165

166
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
167 168 169
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
170

171
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
172
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
173 174
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
175 176
static GstElement *
make_mod_pipeline (const gchar * location)
177 178 179 180
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
181

182 183
  pipeline = gst_pipeline_new ("app");

184 185
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
186
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
187 188 189 190 191 192 193 194
  //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);

195 196
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
197

198
  seekable = gst_element_get_static_pad (decoder, "src");
199 200
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
201 202
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
203 204 205 206

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
207 208
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
209 210
{
  GstElement *pipeline;
211
  GstElement *src, *demux, *decoder, *audiosink, *videosink;
212
  GstElement *a_queue, *v_queue;
Wim Taymans's avatar
Wim Taymans committed
213
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
214

Wim Taymans's avatar
Wim Taymans committed
215 216 217
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
218
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
219
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
220
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
221
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
222
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
223
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
224 225 226 227

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

  gst_bin_add (GST_BIN (pipeline), src);
228
  gst_bin_add (GST_BIN (pipeline), demux);
229
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
230
  gst_bin_add (GST_BIN (pipeline), audiosink);
231
  gst_bin_add (GST_BIN (pipeline), v_queue);
232
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
233 234
  gst_bin_add (GST_BIN (pipeline), videosink);

235
  gst_element_link (src, demux);
236
  gst_element_link (a_queue, audiosink);
237 238
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
239

240 241 242 243
  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);
244

245
  seekable = gst_element_get_static_pad (decoder, "src");
246
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
247 248 249 250 251
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
252 253
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
254 255 256
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
257

Wim Taymans's avatar
Wim Taymans committed
258 259
  pipeline = gst_pipeline_new ("app");

260 261
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
262
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
263 264 265 266 267 268 269

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

270
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
271

272 273
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
274 275 276 277 278

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
279 280 281 282

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
283 284
static GstElement *
make_flac_pipeline (const gchar * location)
285 286 287 288
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
289

290 291
  pipeline = gst_pipeline_new ("app");

292 293
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
294
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
295
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
296 297 298 299 300 301 302

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

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
  gst_bin_add (GST_BIN (pipeline), audiosink);

303 304
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
305

306
  seekable = gst_element_get_static_pad (decoder, "src");
307 308
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
309 310
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
311 312 313 314

  return pipeline;
}

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

322 323
  pipeline = gst_pipeline_new ("app");

324 325
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
326
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
327 328 329 330 331 332 333 334
  //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);

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

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

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
347 348
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
349 350 351 352
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
353

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
354 355
  pipeline = gst_pipeline_new ("app");

356 357 358
  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
359 360
  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
361 362 363 364 365 366 367

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

368 369
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
370

371
  seekable = gst_element_get_static_pad (parser, "src");
372
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
373
  rate_pads = g_list_prepend (rate_pads, seekable);
374 375
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
376 377 378 379

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
380 381
static GstElement *
make_vorbis_pipeline (const gchar * location)
382
{
383 384
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
385
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
386

387 388
  pipeline = gst_pipeline_new ("app");

389
  src = gst_element_factory_make_or_warn (SOURCE, "src");
390 391 392
  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");
393
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
394
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
395 396 397

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

398 399
  audio_bin = gst_bin_new ("a_decoder_bin");

400
  gst_bin_add (GST_BIN (pipeline), src);
401 402 403 404 405
  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);
406

407 408 409 410
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

411
  pad = gst_element_get_static_pad (decoder, "sink");
412 413 414
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

415 416
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
417

418
  seekable = gst_element_get_static_pad (decoder, "src");
419 420
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
421 422
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
423 424 425 426 427 428 429 430 431

  return pipeline;
}

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
432
  GstPad *pad, *seekable;
433 434 435 436 437 438 439

  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
440
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456

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

457
  pad = gst_element_get_static_pad (decoder, "sink");
458 459 460
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

461 462
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
463

464
  seekable = gst_element_get_static_pad (decoder, "src");
465 466
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
467 468
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
469 470 471 472

  return pipeline;
}

473 474 475 476 477 478
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;
479
  GstElement *a_queue, *v_queue, *v_scale;
480
  GstPad *seekable;
Wim Taymans's avatar
Wim Taymans committed
481
  GstPad *pad;
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497

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

500
  gst_bin_add (GST_BIN (pipeline), audio_bin);
501 502 503 504 505 506

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

507 508 509
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
510

511
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
512
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
513
  gst_object_unref (pad);
514

515 516
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
517 518 519 520 521 522

  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");
523
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
524
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
525 526

  gst_bin_add (GST_BIN (pipeline), video_bin);
527 528 529 530

  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);
531
  gst_bin_add (GST_BIN (video_bin), v_scale);
532 533
  gst_bin_add (GST_BIN (video_bin), videosink);

534 535
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
536

537
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
538
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
539
  gst_object_unref (pad);
540

541 542
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
543

544
  seekable = gst_element_get_static_pad (a_decoder, "src");
545 546 547
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
548 549
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
550 551 552 553 554 555 556 557 558 559 560

  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;
561
  GstPad *seekable, *pad;
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577

  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");
578
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
579 580 581 582 583 584

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

585 586 587 588
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

589 590
  gst_bin_add (GST_BIN (pipeline), audio_bin);

591
  pad = gst_element_get_static_pad (a_queue, "sink");
592 593 594
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

595 596
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
597 598 599 600 601 602

  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
603
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
604 605 606 607 608 609

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

610 611
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

612 613
  gst_bin_add (GST_BIN (pipeline), video_bin);

614
  pad = gst_element_get_static_pad (v_queue, "sink");
615 616 617
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

618 619
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
620

621
  seekable = gst_element_get_static_pad (a_decoder, "src");
622 623 624
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
625 626
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
627 628 629 630

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
631 632
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
633 634
{
  GstElement *pipeline;
635
  GstElement *src, *decoder, *osssink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
636
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
637

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
638 639
  pipeline = gst_pipeline_new ("app");

640 641 642
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("mad", "dec");
  queue = gst_element_factory_make_or_warn ("queue", "queue");
643
  osssink = gst_element_factory_make_or_warn (ASINK, "sink");
644

645
  seekable_elements = g_list_prepend (seekable_elements, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
646 647

  g_object_set (G_OBJECT (src), "location", location, NULL);
648
  //g_object_set (G_OBJECT (osssink), "fragment", 0x00180008, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
649

650 651
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
652 653
  gst_bin_add (GST_BIN (pipeline), queue);
  gst_bin_add (GST_BIN (pipeline), osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
654

655 656
  gst_element_link (src, decoder);
  gst_element_link (decoder, queue);
657
  gst_element_link (queue, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
658

659
  seekable = gst_element_get_static_pad (queue, "src");
660
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
661
  rate_pads = g_list_prepend (rate_pads, seekable);
662 663
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
664 665 666 667

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
668 669
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
670 671 672
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
673
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
674
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
675

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
676 677
  pipeline = gst_pipeline_new ("app");

678
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
679 680
  g_object_set (G_OBJECT (src), "location", location, NULL);

681
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
682
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
683 684 685

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
686
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
687 688

  audio_bin = gst_bin_new ("a_decoder_bin");
689
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
690
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
691
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
692 693
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
694
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
695 696
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
697
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
698

699
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
700
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
701

702
  seekable = gst_element_get_static_pad (a_queue, "src");
703
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
704
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
705
  rate_pads =
706 707
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
708 709

  video_bin = gst_bin_new ("v_decoder_bin");
Wim Taymans's avatar
Wim Taymans committed
710
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
711
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
712
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
713 714
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
715
  gst_bin_add (GST_BIN (video_bin), v_decoder);
716 717
  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
718

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

721
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
722
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
723

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

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
734 735
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
736 737
{
  GstElement *pipeline, *audio_bin, *video_bin;
738 739
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
740
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
741
  GstPad *seekable;
742
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
743

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
744 745
  pipeline = gst_pipeline_new ("app");

746
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
747 748
  g_object_set (G_OBJECT (src), "location", location, NULL);

749 750
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
751

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
752 753
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
754
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
755 756

  audio_bin = gst_bin_new ("a_decoder_bin");
757 758
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
759
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
760
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
761 762
  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
763

764 765
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
766

767 768
  gst_bin_add (GST_BIN (pipeline), audio_bin);

769
  pad = gst_element_get_static_pad (a_decoder, "sink");
770 771 772
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

773
  setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
774
          "sink"), NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
775 776

  video_bin = gst_bin_new ("v_decoder_bin");
777 778
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
779
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
780
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
781

782 783 784 785 786 787 788
  gst_bin_add (GST_BIN (video_bin), v_decoder);
  gst_bin_add (GST_BIN (video_bin), v_queue);
  gst_bin_add (GST_BIN (video_bin), v_filter);
  gst_bin_add (GST_BIN (video_bin), videosink);

  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, v_filter);
789
  gst_element_link (v_filter, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
790

791
  gst_bin_add (GST_BIN (pipeline), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
792

793
  pad = gst_element_get_static_pad (v_decoder, "sink");
794 795 796
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

797
  setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
798 799
          "sink"), NULL);

800
  seekable = gst_element_get_static_pad (v_filter, "src");
801
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
802
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
803
  rate_pads =
804 805
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
806 807 808 809

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
810 811
static GstElement *
make_mpegnt_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
812 813 814 815
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
816
  GstElement *a_queue;