seek.c 30.6 KB
Newer Older
1
#include <stdlib.h>
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
2 3 4 5 6
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <string.h>

7
static GList *seekable_pads = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
8
static GList *rate_pads = NULL;
9
static GList *seekable_elements = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
10 11

static GstElement *pipeline;
12
static guint64 duration;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
13
static GtkAdjustment *adjustment;
14
static gboolean stats = FALSE;
15 16
static gboolean elem_seek = FALSE;
static gboolean verbose = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
17 18 19

static guint update_id;

20 21
//#define SOURCE "gnomevfssrc"
#define SOURCE "filesrc"
22

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
23 24 25
#define UPDATE_INTERVAL 500

#define THREAD
26
#define PAD_SEEK
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
27 28 29

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
30 31 32
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
33 34
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
35

36
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
37
gst_element_factory_make_or_warn (gchar * type, gchar * name)
38 39 40 41
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
42
    g_warning ("Failed to create element %s of type %s", name, type);
43 44 45 46 47
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
48
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
49
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
50
{
51
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
52 53 54 55

  if (!strcmp (gst_pad_get_name (newpad), connect->padname)) {
    gst_element_set_state (pipeline, GST_STATE_PAUSED);
    gst_bin_add (GST_BIN (pipeline), connect->bin);
56
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
57 58
    gst_element_set_state (pipeline, GST_STATE_PLAYING);

59
    seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
60 61 62 63 64
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
65 66
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
67
{
68
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
69

70
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
71 72 73
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
74

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
75 76
  g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_link),
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
77 78
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
79 80
static GstElement *
make_mod_pipeline (const gchar * location)
81 82 83 84
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
85

86 87
  pipeline = gst_pipeline_new ("app");

88 89 90
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
  audiosink = gst_element_factory_make_or_warn ("osssink", "sink");
91 92 93 94 95 96 97 98
  //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);

99 100
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
101 102 103 104 105 106 107 108 109

  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
110 111
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
112 113 114 115
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink, *videosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
116

Wim Taymans's avatar
Wim Taymans committed
117 118 119 120
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("dvdec", "decoder");
121
  videosink = gst_element_factory_make_or_warn ("ximagesink", "v_sink");
Wim Taymans's avatar
Wim Taymans committed
122 123 124 125 126 127 128 129 130 131
  audiosink = gst_element_factory_make_or_warn ("osssink", "a_sink");
  //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);
  gst_bin_add (GST_BIN (pipeline), videosink);

132 133 134
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
135 136 137 138 139 140 141 142 143 144 145 146

  seekable = gst_element_get_pad (decoder, "video");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  seekable = gst_element_get_pad (decoder, "audio");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
147 148
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
149 150 151 152
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
153

Wim Taymans's avatar
Wim Taymans committed
154 155
  pipeline = gst_pipeline_new ("app");

156 157 158
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
  audiosink = gst_element_factory_make_or_warn ("osssink", "sink");
Wim Taymans's avatar
Wim Taymans committed
159 160 161 162 163 164 165 166
  //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);

167 168
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
Wim Taymans's avatar
Wim Taymans committed
169 170 171 172 173 174 175 176 177

  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

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

185 186
  pipeline = gst_pipeline_new ("app");

187 188 189
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
  audiosink = gst_element_factory_make_or_warn ("osssink", "sink");
Wim Taymans's avatar
Wim Taymans committed
190
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
191 192 193 194 195 196 197

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

198 199
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
200 201 202 203 204 205 206 207 208

  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

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

216 217
  pipeline = gst_pipeline_new ("app");

218 219 220
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
  audiosink = gst_element_factory_make_or_warn ("osssink", "sink");
221 222 223 224 225 226 227 228
  //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);

229 230
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
231 232 233 234 235 236 237 238 239

  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
240 241
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
242 243 244 245
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
246

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
247 248
  pipeline = gst_pipeline_new ("app");

249 250 251
  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
252 253
  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
254 255 256 257 258 259 260

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

261 262
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
263 264

  seekable = gst_element_get_pad (parser, "src");
265
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
266 267 268 269 270 271
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (parser, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
272 273
static GstElement *
make_vorbis_pipeline (const gchar * location)
274 275 276 277
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
278

279 280
  pipeline = gst_pipeline_new ("app");

281 282 283
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("vorbisfile", "decoder");
  audiosink = gst_element_factory_make_or_warn ("osssink", "sink");
Wim Taymans's avatar
Wim Taymans committed
284
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
285 286 287 288 289 290 291

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

292 293
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
294 295 296 297 298 299 300 301 302

  seekable = gst_element_get_pad (decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
303 304
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
305 306
{
  GstElement *pipeline;
307
  GstElement *src, *decoder, *osssink, *queue, *audio_thread;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
308
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
309

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
310 311
  pipeline = gst_pipeline_new ("app");

312 313 314 315
  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");
  osssink = gst_element_factory_make_or_warn ("osssink", "sink");
316 317 318 319

  audio_thread = gst_thread_new ("a_decoder_thread");

  seekable_elements = g_list_prepend (seekable_elements, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
320 321 322 323

  g_object_set (G_OBJECT (src), "location", location, NULL);
  g_object_set (G_OBJECT (osssink), "fragment", 0x00180008, NULL);

324 325 326 327 328
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
  gst_bin_add (GST_BIN (audio_thread), queue);
  gst_bin_add (GST_BIN (audio_thread), osssink);
  gst_bin_add (GST_BIN (pipeline), audio_thread);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
329

330 331 332
  gst_element_link (src, decoder);
  gst_element_link (decoder, queue);
  gst_element_link (queue, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
333

334 335
  seekable = gst_element_get_pad (queue, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
336 337 338 339 340 341
  rate_pads = g_list_prepend (rate_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
342 343
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
344 345 346
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
347 348
  GstElement *a_queue = NULL, *audio_thread = NULL, *v_queue =
      NULL, *video_thread = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
349
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
350

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
351 352
  pipeline = gst_pipeline_new ("app");

353
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
354 355
  g_object_set (G_OBJECT (src), "location", location, NULL);

356
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
357
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
358 359 360

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
361
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
362 363

  audio_bin = gst_bin_new ("a_decoder_bin");
364
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
365
  audio_thread = gst_thread_new ("a_decoder_thread");
366
  audiosink = gst_element_factory_make_or_warn ("osssink", "a_sink");
367
  //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
368
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
369 370
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
371 372 373 374
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
  gst_bin_add (GST_BIN (audio_bin), audio_thread);
  gst_bin_add (GST_BIN (audio_thread), a_queue);
  gst_bin_add (GST_BIN (audio_thread), audiosink);
Wim Taymans's avatar
Wim Taymans committed
375
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
376

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
377
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
378
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
379 380

  seekable = gst_element_get_pad (a_queue, "src");
381
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
382
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
383 384
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
385 386

  video_bin = gst_bin_new ("v_decoder_bin");
387
  //v_decoder = gst_element_factory_make_or_warn ("identity", "v_dec");
Wim Taymans's avatar
Wim Taymans committed
388
  //v_decoder = gst_element_factory_make_or_warn ("windec", "v_dec");
Wim Taymans's avatar
Wim Taymans committed
389
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
390
  video_thread = gst_thread_new ("v_decoder_thread");
391
  videosink = gst_element_factory_make_or_warn ("ximagesink", "v_sink");
392
  //videosink = gst_element_factory_make_or_warn ("fakesink", "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
393
  //g_object_set (G_OBJECT (videosink), "sync", TRUE, NULL);
394
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
Wim Taymans's avatar
Wim Taymans committed
395
  //g_object_set (G_OBJECT (v_queue), "max_level", 10, NULL);
396 397
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
398 399 400 401 402
  gst_bin_add (GST_BIN (video_bin), v_decoder);
  gst_bin_add (GST_BIN (video_bin), video_thread);
  gst_bin_add (GST_BIN (video_thread), v_queue);
  gst_bin_add (GST_BIN (video_thread), videosink);

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
405
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
406
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
407 408

  seekable = gst_element_get_pad (v_queue, "src");
409
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
410
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
411 412
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
413 414 415 416

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
417 418
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
419 420
{
  GstElement *pipeline, *audio_bin, *video_bin;
421 422
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
423 424
  GstElement *a_queue, *audio_thread, *v_queue, *video_thread;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
425

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
426 427
  pipeline = gst_pipeline_new ("app");

428
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
429 430
  g_object_set (G_OBJECT (src), "location", location, NULL);

431
  demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
Wim Taymans's avatar
Wim Taymans committed
432
  g_object_set (G_OBJECT (demux), "sync", FALSE, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
433

434 435
  seekable_elements = g_list_prepend (seekable_elements, demux);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
436 437
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
438
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
439 440

  audio_bin = gst_bin_new ("a_decoder_bin");
441
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
442
  audio_thread = gst_thread_new ("a_decoder_thread");
443 444
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
  audiosink = gst_element_factory_make_or_warn ("osssink", "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
445
  g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
446 447
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
448 449 450 451 452
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
  gst_bin_add (GST_BIN (audio_bin), audio_thread);
  gst_bin_add (GST_BIN (audio_thread), a_queue);
  gst_bin_add (GST_BIN (audio_thread), audiosink);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
453
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
454
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
455 456

  seekable = gst_element_get_pad (a_queue, "src");
457
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
458
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
459 460
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
461 462

  video_bin = gst_bin_new ("v_decoder_bin");
463
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
464
  video_thread = gst_thread_new ("v_decoder_thread");
Wim Taymans's avatar
Wim Taymans committed
465
  //g_object_set (G_OBJECT (video_thread), "priority", 2, NULL);
466
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
467 468
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
  videosink = gst_element_factory_make_or_warn ("ximagesink", "v_sink");
469
  gst_element_link_many (v_decoder, v_queue, v_filter, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
470

471
  gst_element_link (v_filter, videosink);
472
  gst_bin_add_many (GST_BIN (video_bin), v_decoder, video_thread, NULL);
473
  gst_bin_add_many (GST_BIN (video_thread), v_queue, v_filter, videosink, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
474

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
475
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
476
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
477 478

  seekable = gst_element_get_pad (v_queue, "src");
479
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
480
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
481 482
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
483 484 485 486

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
487 488
static GstElement *
make_mpegnt_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
489 490 491 492 493 494
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
  GstElement *a_queue, *audio_thread;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
495

Wim Taymans's avatar
Wim Taymans committed
496 497 498 499 500 501 502 503 504 505 506 507
  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 ("mpegdemux", "demux");
  //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL);

  seekable_elements = g_list_prepend (seekable_elements, demux);

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
508
  gst_element_link (src, demux);
Wim Taymans's avatar
Wim Taymans committed
509 510 511 512 513 514 515 516

  audio_bin = gst_bin_new ("a_decoder_bin");
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  audio_thread = gst_thread_new ("a_decoder_thread");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
  audiosink = gst_element_factory_make_or_warn ("osssink", "a_sink");
  //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
517 518
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Wim Taymans's avatar
Wim Taymans committed
519 520 521 522 523
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
  gst_bin_add (GST_BIN (audio_bin), audio_thread);
  gst_bin_add (GST_BIN (audio_thread), a_queue);
  gst_bin_add (GST_BIN (audio_thread), audiosink);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
524
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
525
          "sink"), audio_bin);
Wim Taymans's avatar
Wim Taymans committed
526 527 528 529

  seekable = gst_element_get_pad (a_queue, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
530 531
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
532 533 534

  video_bin = gst_bin_new ("v_decoder_bin");
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
535 536
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
  videosink = gst_element_factory_make_or_warn ("ximagesink", "v_sink");
537
  gst_element_link_many (v_decoder, v_filter, videosink, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
538

Wim Taymans's avatar
Wim Taymans committed
539 540
  gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
541
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
542
          "sink"), video_bin);
Wim Taymans's avatar
Wim Taymans committed
543 544 545 546

  seekable = gst_element_get_pad (v_decoder, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
547 548
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
549 550 551 552

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
553 554
static GstElement *
make_playerbin_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
555
{
556 557 558 559 560 561 562 563 564 565 566 567 568
  GstElement *player;

  player = gst_element_factory_make ("playbin", "player");
  g_assert (player);

  g_object_set (G_OBJECT (player), "uri", location, NULL);

  seekable_elements = g_list_prepend (seekable_elements, player);

  /* force element seeking on this pipeline */
  elem_seek = TRUE;

  return player;
Wim Taymans's avatar
Wim Taymans committed
569 570
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
571 572
static gchar *
format_value (GtkScale * scale, gdouble value)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
573
{
574 575 576 577 578 579 580
  gint64 real;
  gint64 seconds;
  gint64 subseconds;

  real = value * duration / 100;
  seconds = (gint64) real / GST_SECOND;
  subseconds = (gint64) real / (GST_SECOND / 100);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
581

582
  return g_strdup_printf ("%02lld:%02lld:%02lld",
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
583
      seconds / 60, seconds % 60, subseconds % 100);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
584 585 586 587 588 589
}

typedef struct
{
  const gchar *name;
  const GstFormat format;
590 591
}
seek_format;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
592

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
593 594 595 596 597 598
static seek_format seek_formats[] = {
  {"tim", GST_FORMAT_TIME},
  {"byt", GST_FORMAT_BYTES},
  {"buf", GST_FORMAT_BUFFERS},
  {"def", GST_FORMAT_DEFAULT},
  {NULL, 0},
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
};

G_GNUC_UNUSED static void
query_rates (void)
{
  GList *walk = rate_pads;

  while (walk) {
    GstPad *pad = GST_PAD (walk->data);
    gint i = 0;

    g_print ("rate/sec  %8.8s: ", GST_PAD_NAME (pad));
    while (seek_formats[i].name) {
      gint64 value;
      GstFormat format;

      format = seek_formats[i].format;

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
617
      if (gst_pad_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format, &value)) {
618
        g_print ("%s %13lld | ", seek_formats[i].name, value);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
619
      } else {
620
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
621 622 623 624 625 626 627 628 629 630 631
      }

      i++;
    }
    g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));

    walk = g_list_next (walk);
  }
}

G_GNUC_UNUSED static void
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
query_durations_elems ()
{
  GList *walk = seekable_elements;

  while (walk) {
    GstElement *element = GST_ELEMENT (walk->data);
    gint i = 0;

    g_print ("durations %8.8s: ", GST_ELEMENT_NAME (element));
    while (seek_formats[i].name) {
      gboolean res;
      gint64 value;
      GstFormat format;

      format = seek_formats[i].format;
      res = gst_element_query (element, GST_QUERY_TOTAL, &format, &value);
      if (res) {
        g_print ("%s %13lld | ", seek_formats[i].name, value);
      } else {
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
      }
      i++;
    }
    g_print (" %s\n", GST_ELEMENT_NAME (element));

    walk = g_list_next (walk);
  }
}

G_GNUC_UNUSED static void
query_durations_pads ()
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
663
{
664 665 666 667 668 669 670 671 672 673 674 675 676
  GList *walk = seekable_pads;

  while (walk) {
    GstPad *pad = GST_PAD (walk->data);
    gint i = 0;

    g_print ("durations %8.8s: ", GST_PAD_NAME (pad));
    while (seek_formats[i].name) {
      gboolean res;
      gint64 value;
      GstFormat format;

      format = seek_formats[i].format;
Wim Taymans's avatar
Wim Taymans committed
677
      res = gst_pad_query (pad, GST_QUERY_TOTAL, &format, &value);
678
      if (res) {
679
        g_print ("%s %13lld | ", seek_formats[i].name, value);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
680
      } else {
681
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
682 683
      }
      i++;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
684
    }
685
    g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
686

687
    walk = g_list_next (walk);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
688 689 690 691
  }
}

G_GNUC_UNUSED static void
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
query_positions_elems ()
{
  GList *walk = seekable_elements;

  while (walk) {
    GstElement *element = GST_ELEMENT (walk->data);
    gint i = 0;

    g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
    while (seek_formats[i].name) {
      gboolean res;
      gint64 value;
      GstFormat format;

      format = seek_formats[i].format;
      res = gst_element_query (element, GST_QUERY_POSITION, &format, &value);
      if (res) {
        g_print ("%s %13lld | ", seek_formats[i].name, value);
      } else {
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
      }
      i++;
    }
    g_print (" %s\n", GST_ELEMENT_NAME (element));

    walk = g_list_next (walk);
  }
}

G_GNUC_UNUSED static void
query_positions_pads ()
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
723
{
724 725 726 727 728 729 730 731 732 733 734 735 736
  GList *walk = seekable_pads;

  while (walk) {
    GstPad *pad = GST_PAD (walk->data);
    gint i = 0;

    g_print ("positions %8.8s: ", GST_PAD_NAME (pad));
    while (seek_formats[i].name) {
      gboolean res;
      gint64 value;
      GstFormat format;

      format = seek_formats[i].format;
Wim Taymans's avatar
Wim Taymans committed
737
      res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &value);
738
      if (res) {
739
        g_print ("%s %13lld | ", seek_formats[i].name, value);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
740
      } else {
741
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
742 743
      }
      i++;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
744
    }
745 746 747
    g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));

    walk = g_list_next (walk);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
748 749 750 751
  }
}

static gboolean
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
752
update_scale (gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
753 754
{
  GstClock *clock;
755 756
  guint64 position;
  GstFormat format = GST_FORMAT_TIME;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
757

758
  duration = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
759 760
  clock = gst_bin_get_clock (GST_BIN (pipeline));

761 762 763
  if (elem_seek) {
    if (seekable_elements) {
      GstElement *element = GST_ELEMENT (seekable_elements->data);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
764

765 766 767 768 769 770 771 772 773 774
      gst_element_query (element, GST_QUERY_TOTAL, &format, &duration);
      gst_element_query (element, GST_QUERY_POSITION, &format, &position);
    }
  } else {
    if (seekable_pads) {
      GstPad *pad = GST_PAD (seekable_pads->data);

      gst_pad_query (pad, GST_QUERY_TOTAL, &format, &duration);
      gst_pad_query (pad, GST_QUERY_POSITION, &format, &position);
    }
775
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
776

777
  if (stats) {
778 779 780 781 782 783 784 785 786 787 788 789
    if (clock) {
      g_print ("clock:                  %13llu  (%s)\n", position,
          gst_object_get_name (GST_OBJECT (clock)));
    }

    if (elem_seek) {
      query_durations_elems ();
      query_positions_elems ();
    } else {
      query_durations_pads ();
      query_positions_pads ();
    }
790
    query_rates ();
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
791 792 793 794 795 796 797 798 799 800 801 802 803 804
  }

  if (duration > 0) {
    gtk_adjustment_set_value (adjustment, position * 100.0 / duration);
  }

  return TRUE;
}

static gboolean
iterate (gpointer data)
{
  gboolean res;

805 806 807
  if (!GST_FLAG_IS_SET (GST_OBJECT (data), GST_BIN_SELF_SCHEDULABLE)) {
    res = gst_bin_iterate (GST_BIN (data));
  } else {
808
    g_usleep (500);
809 810 811
    res = gst_element_get_state (GST_ELEMENT (data)) == GST_STATE_PLAYING;
  }

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
812 813 814 815 816 817 818 819
  if (!res) {
    gtk_timeout_remove (update_id);
    g_print ("stopping iterations\n");
  }
  return res;
}

static gboolean
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
820
start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
821 822 823 824 825 826 827 828
{
  gst_element_set_state (pipeline, GST_STATE_PAUSED);
  gtk_timeout_remove (update_id);

  return FALSE;
}

static gboolean
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
829
stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
830 831 832 833
{
  gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
  gboolean res;
  GstEvent *s_event;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
834

835 836
  if (!elem_seek) {
    GList *walk = seekable_pads;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
837

838 839
    while (walk) {
      GstPad *seekable = GST_PAD (walk->data);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
840

841 842 843 844 845
      g_print ("seek to %lld on pad %s:%s\n", real,
          GST_DEBUG_PAD_NAME (seekable));
      s_event =
          gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET |
          GST_SEEK_FLAG_FLUSH, real);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
846

847
      res = gst_pad_send_event (seekable, s_event);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
848

849 850 851 852
      walk = g_list_next (walk);
    }
  } else {
    GList *walk = seekable_elements;
853

854 855
    while (walk) {
      GstElement *seekable = GST_ELEMENT (walk->data);
856

857 858 859 860 861
      g_print ("seek to %lld on element %s\n", real,
          gst_element_get_name (seekable));
      s_event =
          gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET |
          GST_SEEK_FLAG_FLUSH, real);
862

863
      res = gst_element_send_event (seekable, s_event);
864

865 866
      walk = g_list_next (walk);
    }
867
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
868 869 870

  gst_element_set_state (pipeline, GST_STATE_PLAYING);
  gtk_idle_add ((GtkFunction) iterate, pipeline);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
871 872
  update_id =
      gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
873 874 875 876 877 878 879

  return FALSE;
}

static void
play_cb (GtkButton * button, gpointer data)
{
880 881 882
  if (gst_element_get_state (pipeline) != GST_STATE_PLAYING) {
    gst_element_set_state (pipeline, GST_STATE_PLAYING);
    gtk_idle_add ((GtkFunction) iterate, pipeline);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
883
    update_id =
884
        gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
885
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
886 887 888 889 890
}

static void
pause_cb (GtkButton * button, gpointer data)
{
891 892 893 894
  if (gst_element_get_state (pipeline) != GST_STATE_PAUSED) {
    gst_element_set_state (pipeline, GST_STATE_PAUSED);
    gtk_timeout_remove (update_id);
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
895 896 897 898 899
}

static void
stop_cb (GtkButton * button, gpointer data)
{
900 901
  if (gst_element_get_state (pipeline) != GST_STATE_READY) {
    gst_element_set_state (pipeline, GST_STATE_READY);
Wim Taymans's avatar
Wim Taymans committed
902
    gtk_adjustment_set_value (adjustment, 0.0);
903 904
    gtk_timeout_remove (update_id);
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
905 906
}

Wim Taymans's avatar
Wim Taymans committed
907 908 909
typedef struct
{
  gchar *name;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
910
  GstElement *(*func) (const gchar * location);
911 912
}
Pipeline;
Wim Taymans's avatar
Wim Taymans committed
913 914

static Pipeline pipelines[] = {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
915 916 917 918 919 920 921 922 923 924 925 926 927
  {"mp3", make_mp3_pipeline},
  {"avi", make_avi_pipeline},
  {"mpeg1", make_mpeg_pipeline},
  {"mpegparse", make_parse_pipeline},
  {"vorbis", make_vorbis_pipeline},
  {"sid", make_sid_pipeline},
  {"flac", make_flac_pipeline},
  {"wav", make_wav_pipeline},
  {"mod", make_mod_pipeline},
  {"dv", make_dv_pipeline},
  {"mpeg1nothreads", make_mpegnt_pipeline},
  {"playerbin", make_playerbin_pipeline},
  {NULL, NULL},
Wim Taymans's avatar
Wim Taymans committed
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
};

#define NUM_TYPES	((sizeof (pipelines) / sizeof (Pipeline)) - 1)

static void
print_usage (int argc, char **argv)
{
  gint i;

  g_print ("usage: %s <type> <filename>\n", argv[0]);
  g_print ("   possible types:\n");

  for (i = 0; i < NUM_TYPES; i++) {
    g_print ("     %d = %s\n", i, pipelines[i].name);
  }
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
945 946 947
int
main (int argc, char **argv)
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
948 949
  GtkWidget *window, *hbox, *vbox,
      *play_button, *pause_button, *stop_button, *hscale;
950
  struct poptOption options[] = {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
951
    {"stats", 's', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &stats, 0,
952
        "Show pad stats", NULL},
953 954 955 956
    {"elem", 'e', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &elem_seek, 0,
        "Seek on elements instead of pads", NULL},
    {"verbose", 'v', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &verbose, 0,
        "Verbose properties", NULL},
957 958
    POPT_TABLEEND
  };
Wim Taymans's avatar
Wim Taymans committed
959
  gint type;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
960

961
  gst_init_with_popt_table (&argc, &argv, options);