seek.c 75.3 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>
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
29 30 31 32 33
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <string.h>

34
#ifdef HAVE_X
35
#include <gdk/gdkx.h>
36
#endif
37 38
#include <gst/interfaces/xoverlay.h>

39
GST_DEBUG_CATEGORY_STATIC (seek_debug);
40 41
#define GST_CAT_DEFAULT (seek_debug)

42 43 44 45 46 47 48 49 50 51 52 53 54 55
/* 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"

56
#define FILL_INTERVAL 100
57 58 59 60 61 62 63 64 65 66
//#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

67 68
#define DEFAULT_VIDEO_HEIGHT 300

69

70
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
71
static GList *rate_pads = NULL;
72
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
73

74 75
static gboolean accurate_seek = FALSE;
static gboolean keyframe_seek = FALSE;
76
static gboolean loop_seek = FALSE;
77
static gboolean flush_seek = TRUE;
78 79
static gboolean scrub = TRUE;
static gboolean play_scrub = FALSE;
80
static gdouble rate = 1.0;
81

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
82
static GstElement *pipeline;
83 84
static gint pipeline_type;
static const gchar *pipeline_spec;
85 86
static gint64 position = -1;
static gint64 duration = -1;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
87
static GtkAdjustment *adjustment;
88 89
static GtkWidget *hscale, *statusbar;
static guint status_id = 0;
90
static gboolean stats = FALSE;
91 92
static gboolean elem_seek = FALSE;
static gboolean verbose = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
93

94 95
static gboolean is_live = FALSE;
static gboolean buffering = FALSE;
96 97
static GstBufferingMode mode;
static gint64 buffering_left;
98
static GstState state = GST_STATE_NULL;
99
static guint update_id = 0;
100 101
static guint seek_timeout_id = 0;
static gulong changed_id;
102
static guint fill_id = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
103

104
static gint n_video = 0, n_audio = 0, n_text = 0;
105
static gboolean need_streams = TRUE;
106
static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
107
static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
108
static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
109 110 111
static GtkWidget *video_window;

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

113 114 115 116 117 118 119 120 121
/* 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;

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

124
/* pipeline construction */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
125 126 127

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
128 129 130
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
131 132
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
133

134
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
135
gst_element_factory_make_or_warn (gchar * type, gchar * name)
136 137 138 139
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
140
    g_warning ("Failed to create element %s of type %s", name, type);
141 142 143 144 145
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
146
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
147
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
148
{
149
  gchar *padname;
150
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
151

152 153 154
  padname = gst_pad_get_name (newpad);

  if (connect->padname == NULL || !strcmp (padname, connect->padname)) {
155 156
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
157
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
158

159
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
160 161
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
162
  g_free (padname);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
163 164 165
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
166 167
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
168
{
169
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
170

171
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
172 173 174
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
175

176
  g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
177
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
178 179
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
180 181
static GstElement *
make_mod_pipeline (const gchar * location)
182 183 184 185
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
186

187 188
  pipeline = gst_pipeline_new ("app");

189 190
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
191
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
192 193 194 195 196 197 198 199
  //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);

200 201
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
202

203
  seekable = gst_element_get_static_pad (decoder, "src");
204 205
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
206 207
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
208 209 210 211

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
212 213
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
214 215
{
  GstElement *pipeline;
216
  GstElement *src, *demux, *decoder, *audiosink, *videosink;
217
  GstElement *a_queue, *v_queue;
Wim Taymans's avatar
Wim Taymans committed
218
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
219

Wim Taymans's avatar
Wim Taymans committed
220 221 222
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
223
  demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer");
224
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
225
  decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder");
226
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
227
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
228
  audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink");
Wim Taymans's avatar
Wim Taymans committed
229 230 231 232

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

  gst_bin_add (GST_BIN (pipeline), src);
233
  gst_bin_add (GST_BIN (pipeline), demux);
234
  gst_bin_add (GST_BIN (pipeline), a_queue);
Wim Taymans's avatar
Wim Taymans committed
235
  gst_bin_add (GST_BIN (pipeline), audiosink);
236
  gst_bin_add (GST_BIN (pipeline), v_queue);
237
  gst_bin_add (GST_BIN (pipeline), decoder);
Wim Taymans's avatar
Wim Taymans committed
238 239
  gst_bin_add (GST_BIN (pipeline), videosink);

240
  gst_element_link (src, demux);
241
  gst_element_link (a_queue, audiosink);
242 243
  gst_element_link (v_queue, decoder);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
244

245 246 247 248
  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);
249

250
  seekable = gst_element_get_static_pad (decoder, "src");
251
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Wim Taymans's avatar
Wim Taymans committed
252 253 254 255 256
  rate_pads = g_list_prepend (rate_pads, seekable);

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
257 258
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
259 260 261
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
262

Wim Taymans's avatar
Wim Taymans committed
263 264
  pipeline = gst_pipeline_new ("app");

265 266
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
267
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
268 269 270 271 272 273 274

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

275
  gst_element_link (src, decoder);
Wim Taymans's avatar
Wim Taymans committed
276

277 278
  setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink,
          "sink"), NULL);
279 280 281 282 283

  seekable_elements = g_list_prepend (seekable_elements, audiosink);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;
Wim Taymans's avatar
Wim Taymans committed
284 285 286 287

  return pipeline;
}

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

295 296
  pipeline = gst_pipeline_new ("app");

297 298
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
299
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
300
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
301 302 303 304 305 306 307

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

308 309
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
310

311
  seekable = gst_element_get_static_pad (decoder, "src");
312 313
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
314 315
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
316 317 318 319

  return pipeline;
}

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

327 328
  pipeline = gst_pipeline_new ("app");

329 330
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
331
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
332 333 334 335 336 337 338 339
  //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);

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

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

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
352 353
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
354 355 356 357
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
358

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
359 360
  pipeline = gst_pipeline_new ("app");

361 362 363
  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
364 365
  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
366 367 368 369 370 371 372

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

373 374
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
375

376
  seekable = gst_element_get_static_pad (parser, "src");
377
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
378
  rate_pads = g_list_prepend (rate_pads, seekable);
379 380
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
381 382 383 384

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
385 386
static GstElement *
make_vorbis_pipeline (const gchar * location)
387
{
388 389
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
390
  GstPad *pad, *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
391

392 393
  pipeline = gst_pipeline_new ("app");

394
  src = gst_element_factory_make_or_warn (SOURCE, "src");
395 396 397
  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");
398
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
399
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
400 401 402

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

403 404
  audio_bin = gst_bin_new ("a_decoder_bin");

405
  gst_bin_add (GST_BIN (pipeline), src);
406 407 408 409 410
  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);
411

412 413 414 415
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

416
  pad = gst_element_get_static_pad (decoder, "sink");
417 418 419
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

420 421
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
422

423
  seekable = gst_element_get_static_pad (decoder, "src");
424 425
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
426 427
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
428 429 430 431 432 433 434 435 436

  return pipeline;
}

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
437
  GstPad *pad, *seekable;
438 439 440 441 442 443 444

  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
445
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461

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

462
  pad = gst_element_get_static_pad (decoder, "sink");
463 464 465
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

466 467
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
468

469
  seekable = gst_element_get_static_pad (decoder, "src");
470 471
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
472 473
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
474 475 476 477

  return pipeline;
}

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

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

505
  gst_bin_add (GST_BIN (pipeline), audio_bin);
506 507 508 509 510 511

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

512 513 514
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);
515

516
  pad = gst_element_get_static_pad (a_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
517
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
518
  gst_object_unref (pad);
519

520 521
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
522 523 524 525 526 527

  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");
528
  v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale");
Wim Taymans's avatar
Wim Taymans committed
529
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
530 531

  gst_bin_add (GST_BIN (pipeline), video_bin);
532 533 534 535

  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);
536
  gst_bin_add (GST_BIN (video_bin), v_scale);
537 538
  gst_bin_add (GST_BIN (video_bin), videosink);

539 540
  gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink,
      NULL);
541

542
  pad = gst_element_get_static_pad (v_queue, "sink");
Wim Taymans's avatar
Wim Taymans committed
543
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
544
  gst_object_unref (pad);
545

546 547
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
548

549
  seekable = gst_element_get_static_pad (a_decoder, "src");
550 551 552
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
553 554
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
555 556 557 558 559 560 561 562 563 564 565

  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;
566
  GstPad *seekable, *pad;
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582

  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");
583
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
584 585 586 587 588 589

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

590 591 592 593
  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

594 595
  gst_bin_add (GST_BIN (pipeline), audio_bin);

596
  pad = gst_element_get_static_pad (a_queue, "sink");
597 598 599
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

600 601
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin,
          "sink"), NULL);
602 603 604 605 606 607

  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
608
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
609 610 611 612 613 614

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

615 616
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

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

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

623 624
  setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin,
          "sink"), NULL);
625

626
  seekable = gst_element_get_static_pad (a_decoder, "src");
627 628 629
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads =
630 631
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
632 633 634 635

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
636 637
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
638 639
{
  GstElement *pipeline;
640
  GstElement *src, *decoder, *osssink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
641
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
642

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
643 644
  pipeline = gst_pipeline_new ("app");

645 646 647
  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");
648
  osssink = gst_element_factory_make_or_warn (ASINK, "sink");
649

650
  seekable_elements = g_list_prepend (seekable_elements, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
651 652

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

655 656
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
657 658
  gst_bin_add (GST_BIN (pipeline), queue);
  gst_bin_add (GST_BIN (pipeline), osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
659

660 661
  gst_element_link (src, decoder);
  gst_element_link (decoder, queue);
662
  gst_element_link (queue, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
663

664
  seekable = gst_element_get_static_pad (queue, "src");
665
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
666
  rate_pads = g_list_prepend (rate_pads, seekable);
667 668
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
669 670 671 672

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
673 674
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
675 676 677
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
678
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
679
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
680

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
681 682
  pipeline = gst_pipeline_new ("app");

683
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
684 685
  g_object_set (G_OBJECT (src), "location", location, NULL);

686
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
687
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
688 689 690

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
691
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
692 693

  audio_bin = gst_bin_new ("a_decoder_bin");
694
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
695
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
696
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
697 698
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
699
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
700 701
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
702
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
703

704
  setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder,
705
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
706

707
  seekable = gst_element_get_static_pad (a_queue, "src");
708
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
709
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
710
  rate_pads =
711 712
      g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
713 714

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

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

726
  setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder,
727
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
728

729
  seekable = gst_element_get_static_pad (v_queue, "src");
730
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
731
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
732
  rate_pads =
733 734
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
735 736 737 738

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
739 740
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
741 742
{
  GstElement *pipeline, *audio_bin, *video_bin;
743 744
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
745
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
746
  GstPad *seekable;
747
  GstPad *pad;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
748

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
749 750
  pipeline = gst_pipeline_new ("app");

751
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
752 753
  g_object_set (G_OBJECT (src), "location", location, NULL);

754 755
  //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
  demux = gst_element_factory_make_or_warn ("flupsdemux", "demux");
756

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
757 758
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
759
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
760 761

  audio_bin = gst_bin_new ("a_decoder_bin");
762 763
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
764
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
765
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
766 767
  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
768

769 770
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
771

772 773
  gst_bin_add (GST_BIN (pipeline), audio_bin);

774
  pad = gst_element_get_static_pad (a_decoder, "sink");
775 776 777
  gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

778
  setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin,
779
          "sink"), NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
780 781

  video_bin = gst_bin_new ("v_decoder_bin");
782 783
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
784
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
785
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
786

787 788 789 790 791 792 793
  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);
794
  gst_element_link (v_filter, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
795

796
  gst_bin_add (GST_BIN (pipeline), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
797

798
  pad = gst_element_get_static_pad (v_decoder, "sink");
799 800 801
  gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad));
  gst_object_unref (pad);

802
  setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin,
803 804
          "sink"), NULL);

805
  seekable = gst_element_get_static_pad (v_filter, "src");
806
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
807
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
808
  rate_pads =
809 810
      g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder,
          "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
811 812 813 814

  return pipeline;
}