seek.c 27.8 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;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
15 16 17

static guint update_id;

18 19
//#define SOURCE "gnomevfssrc"
#define SOURCE "filesrc"
20

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
21 22 23
#define UPDATE_INTERVAL 500

#define THREAD
24
#define PAD_SEEK
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
25 26 27

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

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

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

  return element;
}

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

  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);
54
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
55 56
    gst_element_set_state (pipeline, GST_STATE_PLAYING);

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

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

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

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

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

84 85
  pipeline = gst_pipeline_new ("app");

86 87 88
  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");
89 90 91 92 93 94 95 96
  //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);

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

  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
108 109
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
110 111 112 113
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink, *videosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
114

Wim Taymans's avatar
Wim Taymans committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("dvdec", "decoder");
  videosink = gst_element_factory_make_or_warn ("xvideosink", "v_sink");
  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);

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

  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
145 146
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
147 148 149 150
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
151

Wim Taymans's avatar
Wim Taymans committed
152 153
  pipeline = gst_pipeline_new ("app");

154 155 156
  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
157 158 159 160 161 162 163 164
  //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);

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

  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
176 177
static GstElement *
make_flac_pipeline (const gchar * location)
178 179 180 181
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
182

183 184
  pipeline = gst_pipeline_new ("app");

185 186 187
  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
188
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
189 190 191 192 193 194 195

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

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

  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
207 208
static GstElement *
make_sid_pipeline (const gchar * location)
209 210 211 212
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
213

214 215
  pipeline = gst_pipeline_new ("app");

216 217 218
  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");
219 220 221 222 223 224 225 226
  //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);

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

  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
238 239
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
240 241 242 243
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
244

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
245 246
  pipeline = gst_pipeline_new ("app");

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

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

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

  seekable = gst_element_get_pad (parser, "src");
263
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
264 265 266 267 268 269
  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
270 271
static GstElement *
make_vorbis_pipeline (const gchar * location)
272 273 274 275
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
276

277 278
  pipeline = gst_pipeline_new ("app");

279 280 281
  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
282
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
283 284 285 286 287 288 289

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

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

  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
301 302
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
303 304
{
  GstElement *pipeline;
305
  GstElement *src, *decoder, *osssink, *queue, *audio_thread;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
306
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
307

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
308 309
  pipeline = gst_pipeline_new ("app");

310 311 312 313
  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");
314 315 316 317

  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
318 319 320 321

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

322 323 324 325 326
  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
327

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

332 333
  seekable = gst_element_get_pad (queue, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
334 335 336 337 338 339
  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
340 341
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
342 343 344
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
345 346
  GstElement *a_queue = NULL, *audio_thread = NULL, *v_queue =
      NULL, *video_thread = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
347
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
348

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
349 350
  pipeline = gst_pipeline_new ("app");

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

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

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

  audio_bin = gst_bin_new ("a_decoder_bin");
362
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
363
  audio_thread = gst_thread_new ("a_decoder_thread");
364
  audiosink = gst_element_factory_make_or_warn ("osssink", "a_sink");
365
  //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
366
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
367 368
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
369 370 371 372
  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
373
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
374

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

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

  video_bin = gst_bin_new ("v_decoder_bin");
385
  //v_decoder = gst_element_factory_make_or_warn ("identity", "v_dec");
Wim Taymans's avatar
Wim Taymans committed
386
  //v_decoder = gst_element_factory_make_or_warn ("windec", "v_dec");
Wim Taymans's avatar
Wim Taymans committed
387
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
388
  video_thread = gst_thread_new ("v_decoder_thread");
389 390
  videosink = gst_element_factory_make_or_warn ("xvideosink", "v_sink");
  //videosink = gst_element_factory_make_or_warn ("fakesink", "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
391
  //g_object_set (G_OBJECT (videosink), "sync", TRUE, NULL);
392
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
Wim Taymans's avatar
Wim Taymans committed
393
  //g_object_set (G_OBJECT (v_queue), "max_level", 10, NULL);
394 395
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
396 397 398 399 400
  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
401
  gst_element_set_state (video_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
402

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

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

  return pipeline;
}

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
424 425
  pipeline = gst_pipeline_new ("app");

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

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

432 433
  seekable_elements = g_list_prepend (seekable_elements, demux);

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

  audio_bin = gst_bin_new ("a_decoder_bin");
439
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
440
  audio_thread = gst_thread_new ("a_decoder_thread");
441 442
  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
443
  g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
444 445
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
446 447 448 449 450
  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
451
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
452
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
453 454

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

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

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

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

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

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
485 486
static GstElement *
make_mpegnt_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
487 488 489 490 491 492
{
  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
493

Wim Taymans's avatar
Wim Taymans committed
494 495 496 497 498 499 500 501 502 503 504 505
  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);
506
  gst_element_link (src, demux);
Wim Taymans's avatar
Wim Taymans committed
507 508 509 510 511 512 513 514

  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);
515 516
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Wim Taymans's avatar
Wim Taymans committed
517 518 519 520 521
  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
522
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
523
          "sink"), audio_bin);
Wim Taymans's avatar
Wim Taymans committed
524 525 526 527

  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
528 529
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
530 531 532 533 534

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

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

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

  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
545 546
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
547 548 549 550

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
551 552
static GstElement *
make_playerbin_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
553 554 555 556
{
  return NULL;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
557 558
static gchar *
format_value (GtkScale * scale, gdouble value)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
559
{
560 561 562 563 564 565 566
  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
567

568
  return g_strdup_printf ("%02lld:%02lld:%02lld",
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
569
      seconds / 60, seconds % 60, subseconds % 100);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
570 571 572 573 574 575
}

typedef struct
{
  const gchar *name;
  const GstFormat format;
576 577
}
seek_format;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
578

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
579 580 581 582 583 584
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
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
};

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
603
      if (gst_pad_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format, &value)) {
604
        g_print ("%s %13lld | ", seek_formats[i].name, value);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
605
      } else {
606
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
607 608 609 610 611 612 613 614 615 616 617
      }

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

    walk = g_list_next (walk);
  }
}

G_GNUC_UNUSED static void
618
query_durations ()
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
619
{
620 621 622 623 624 625 626 627 628 629 630 631 632
  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
633
      res = gst_pad_query (pad, GST_QUERY_TOTAL, &format, &value);
634
      if (res) {
635
        g_print ("%s %13lld | ", seek_formats[i].name, value);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
636
      } else {
637
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
638 639
      }
      i++;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
640
    }
641
    g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
642

643
    walk = g_list_next (walk);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
644 645 646 647
  }
}

G_GNUC_UNUSED static void
648
query_positions ()
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
649
{
650 651 652 653 654 655 656 657 658 659 660 661 662
  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
663
      res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &value);
664
      if (res) {
665
        g_print ("%s %13lld | ", seek_formats[i].name, value);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
666
      } else {
667
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
668 669
      }
      i++;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
670
    }
671 672 673
    g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));

    walk = g_list_next (walk);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
674 675 676 677
  }
}

static gboolean
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
678
update_scale (gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
679 680
{
  GstClock *clock;
681 682
  guint64 position;
  GstFormat format = GST_FORMAT_TIME;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
683

684
  duration = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
685 686
  clock = gst_bin_get_clock (GST_BIN (pipeline));

687 688
  if (seekable_pads) {
    GstPad *pad = GST_PAD (seekable_pads->data);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
689

Wim Taymans's avatar
Wim Taymans committed
690
    gst_pad_query (pad, GST_QUERY_TOTAL, &format, &duration);
691 692
  }
  position = gst_clock_get_time (clock);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
693

694
  if (stats) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
695
    g_print ("clock:                  %13llu  (%s)\n", position,
696
        gst_object_get_name (GST_OBJECT (clock)));
697 698 699
    query_durations ();
    query_positions ();
    query_rates ();
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
  }

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

  return TRUE;
}

static gboolean
iterate (gpointer data)
{
  gboolean res;

  res = gst_bin_iterate (GST_BIN (data));
  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
723
start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
724 725 726 727 728 729 730 731
{
  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
732
stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
733 734 735 736
{
  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
737

738 739
#ifdef PAD_SEEK
  GList *walk = seekable_pads;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
740 741 742 743

  while (walk) {
    GstPad *seekable = GST_PAD (walk->data);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
744
    g_print ("seek to %lld on pad %s:%s\n", real,
745
        GST_DEBUG_PAD_NAME (seekable));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
746
    s_event =
747 748
        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
749 750 751 752 753

    res = gst_pad_send_event (seekable, s_event);

    walk = g_list_next (walk);
  }
754 755 756 757 758 759
#else
  GList *walk = seekable_elements;

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
760
    g_print ("seek to %lld on element %s\n", real,
761
        gst_element_get_name (seekable));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
762
    s_event =
763 764
        gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET |
        GST_SEEK_FLAG_FLUSH, real);
765 766 767 768 769 770

    res = gst_element_send_event (seekable, s_event);

    walk = g_list_next (walk);
  }
#endif
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
771 772 773

  gst_element_set_state (pipeline, GST_STATE_PLAYING);
  gtk_idle_add ((GtkFunction) iterate, pipeline);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
774 775
  update_id =
      gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
776 777 778 779 780 781 782

  return FALSE;
}

static void
play_cb (GtkButton * button, gpointer data)
{
783 784 785
  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
786
    update_id =
787
        gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
788
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
789 790 791 792 793
}

static void
pause_cb (GtkButton * button, gpointer data)
{
794 795 796 797
  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
798 799 800 801 802
}

static void
stop_cb (GtkButton * button, gpointer data)
{
803 804 805 806
  if (gst_element_get_state (pipeline) != GST_STATE_READY) {
    gst_element_set_state (pipeline, GST_STATE_READY);
    gtk_timeout_remove (update_id);
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
807 808
}

Wim Taymans's avatar
Wim Taymans committed
809 810 811
typedef struct
{
  gchar *name;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
812
  GstElement *(*func) (const gchar * location);
813 814
}
Pipeline;
Wim Taymans's avatar
Wim Taymans committed
815 816

static Pipeline pipelines[] = {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
817 818 819 820 821 822 823 824 825 826 827 828 829
  {"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
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
};

#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
847 848 849
int
main (int argc, char **argv)
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
850 851
  GtkWidget *window, *hbox, *vbox,
      *play_button, *pause_button, *stop_button, *hscale;
852
  struct poptOption options[] = {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
853
    {"stats", 's', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &stats, 0,
854
        "Show pad stats", NULL},
855 856
    POPT_TABLEEND
  };
Wim Taymans's avatar
Wim Taymans committed
857
  gint type;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
858

859
  gst_init_with_popt_table (&argc, &argv, options);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
860 861 862
  gtk_init (&argc, &argv);

  if (argc != 3) {
Wim Taymans's avatar
Wim Taymans committed
863 864 865 866 867 868 869 870
    print_usage (argc, argv);
    exit (-1);
  }

  type = atoi (argv[1]);

  if (type < 0 || type >= NUM_TYPES) {
    print_usage (argc, argv);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
871 872 873
    exit (-1);
  }

Wim Taymans's avatar
Wim Taymans committed
874 875
  pipeline = pipelines[type].func (argv[2]);
  g_assert (pipeline);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
876 877 878 879 880 881 882 883 884

  /* initialize gui elements ... */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  hbox = gtk_hbox_new (FALSE, 0);
  vbox = gtk_vbox_new (FALSE, 0);
  play_button = gtk_button_new_with_label ("play");
  pause_button = gtk_button_new_with_label ("pause");
  stop_button = gtk_button_new_with_label ("stop");

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
885 886
  adjustment =
      GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
887 888 889 890
  hscale = gtk_hscale_new (adjustment);
  gtk_scale_set_digits (GTK_SCALE (hscale), 2);
  gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
891 892 893 894 895 896
  gtk_signal_connect (GTK_OBJECT (hscale),
      "button_press_event", G_CALLBACK (start_seek), pipeline);
  gtk_signal_connect (GTK_OBJECT (hscale),
      "button_release_event", G_CALLBACK (stop_seek), pipeline);
  gtk_signal_connect (GTK_OBJECT (hscale),
      "format_value", G_CALLBACK (format_value), pipeline);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
897 898 899 900 901 902 903 904 905 906 907

  /* do the packing stuff ... */
  gtk_window_set_default_size (GTK_WINDOW (window), 96, 96);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_container_add (GTK_CONTAINER (vbox), hbox);
  gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
  gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
  gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
  gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2);

  /* connect things ... */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
908 909 910 911 912 913
  g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
      pipeline);
  g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
      pipeline);
  g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
      pipeline);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
914 915 916 917 918
  g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL);

  /* show the gui. */
  gtk_widget_show_all (window);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
919 920 921 922
  g_signal_connect (pipeline, "deep_notify",
      G_CALLBACK (gst_element_default_deep_notify), NULL);
  g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error),
      NULL);
Wim Taymans's avatar
Wim Taymans committed
923

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
924 925
  gtk_main ();

Wim Taymans's avatar
Wim Taymans committed
926 927
  gst_element_set_state (pipeline, GST_STATE_NULL);

928 929
  //gst_object_unref (GST_OBJECT (pipeline));

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
930 931 932 933
  //g_mem_chunk_info();

  return 0;
}