seek.c 36.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;
Wim Taymans's avatar
Wim Taymans committed
12 13
static gint64 position;
static gint64 duration;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
14
static GtkAdjustment *adjustment;
15
static GtkWidget *hscale;
16
static gboolean stats = FALSE;
17 18
static gboolean elem_seek = FALSE;
static gboolean verbose = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
19 20

static guint update_id;
21 22
static guint seek_timeout_id = 0;
static gulong changed_id;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
23

24
//#define SOURCE "gnomevfssrc"
25
#define SOURCE "gnomevfssrc"
26 27
#define ASINK "alsasink"
//#define ASINK "osssink"
Wim Taymans's avatar
Wim Taymans committed
28 29 30
#define VSINK "xvimagesink"
//#define VSINK "ximagesink"
//#define VSINK "aasink"
31

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
32 33
#define UPDATE_INTERVAL 500

34 35 36 37
/* number of milliseconds to play for after a seek */
#define SCRUB_TIME 250
#define SCRUB

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
38
#define THREAD
39
#define PAD_SEEK
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
40 41 42

typedef struct
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
43 44 45
  const gchar *padname;
  GstPad *target;
  GstElement *bin;
46 47
}
dyn_link;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
48

49
static GstElement *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
50
gst_element_factory_make_or_warn (gchar * type, gchar * name)
51 52 53 54
{
  GstElement *element = gst_element_factory_make (type, name);

  if (!element) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
55
    g_warning ("Failed to create element %s of type %s", name, type);
56 57 58 59 60
  }

  return element;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
61
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
62
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
63
{
64
  dyn_link *connect = (dyn_link *) data;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
65

66 67 68 69
  if (connect->padname == NULL ||
      !strcmp (gst_pad_get_name (newpad), connect->padname)) {
    if (connect->bin)
      gst_bin_add (GST_BIN (pipeline), connect->bin);
70
    gst_pad_link (newpad, connect->target);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
71

72
    //seekable_pads = g_list_prepend (seekable_pads, newpad);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
73 74 75 76 77
    rate_pads = g_list_prepend (rate_pads, newpad);
  }
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
78 79
setup_dynamic_link (GstElement * element, const gchar * padname,
    GstPad * target, GstElement * bin)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
80
{
81
  dyn_link *connect;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
82

83
  connect = g_new0 (dyn_link, 1);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
84 85 86
  connect->padname = g_strdup (padname);
  connect->target = target;
  connect->bin = bin;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
87

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
88 89
  g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_link),
      connect);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
90 91
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
92 93
static GstElement *
make_mod_pipeline (const gchar * location)
94 95 96 97
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
98

99 100
  pipeline = gst_pipeline_new ("app");

101 102
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("modplug", "decoder");
103
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
104 105 106 107 108 109 110 111
  //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);

112 113
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
114 115 116 117 118 119 120 121 122

  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
123 124
static GstElement *
make_dv_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
125 126 127 128
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink, *videosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
129

Wim Taymans's avatar
Wim Taymans committed
130 131 132 133
  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("dvdec", "decoder");
134
  videosink = gst_element_factory_make_or_warn ("ximagesink", "v_sink");
135
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Wim Taymans's avatar
Wim Taymans committed
136 137 138 139 140 141 142 143 144
  //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);

145 146 147
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
  gst_element_link (decoder, videosink);
Wim Taymans's avatar
Wim Taymans committed
148 149 150 151 152 153 154 155 156 157 158 159

  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
160 161
static GstElement *
make_wav_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
162 163 164 165
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
166

Wim Taymans's avatar
Wim Taymans committed
167 168
  pipeline = gst_pipeline_new ("app");

169 170
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("wavparse", "decoder");
171
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
172 173 174 175 176 177 178 179
  //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);

180 181
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
Wim Taymans's avatar
Wim Taymans committed
182 183 184 185 186 187 188 189 190

  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
191 192
static GstElement *
make_flac_pipeline (const gchar * location)
193 194 195 196
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
197

198 199
  pipeline = gst_pipeline_new ("app");

200 201
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("flacdec", "decoder");
202
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
203
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
204 205 206 207 208 209 210

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

211 212
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
213 214 215 216 217 218 219 220 221

  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
222 223
static GstElement *
make_sid_pipeline (const gchar * location)
224 225 226 227
{
  GstElement *pipeline;
  GstElement *src, *decoder, *audiosink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
228

229 230
  pipeline = gst_pipeline_new ("app");

231 232
  src = gst_element_factory_make_or_warn (SOURCE, "src");
  decoder = gst_element_factory_make_or_warn ("siddec", "decoder");
233
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
234 235 236 237 238 239 240 241
  //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);

242 243
  gst_element_link (src, decoder);
  gst_element_link (decoder, audiosink);
244 245 246 247 248 249 250 251 252

  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
253 254
static GstElement *
make_parse_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
255 256 257 258
{
  GstElement *pipeline;
  GstElement *src, *parser, *fakesink;
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
259

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
260 261
  pipeline = gst_pipeline_new ("app");

262 263 264
  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
265 266
  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
267 268 269 270 271 272 273

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

274 275
  gst_element_link (src, parser);
  gst_element_link (parser, fakesink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
276 277

  seekable = gst_element_get_pad (parser, "src");
278
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
279 280 281 282 283 284
  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
285 286
static GstElement *
make_vorbis_pipeline (const gchar * location)
287
{
288 289
  GstElement *pipeline, *audio_bin;
  GstElement *src, *demux, *decoder, *convert, *audiosink;
290
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
291

292 293
  pipeline = gst_pipeline_new ("app");

294
  src = gst_element_factory_make_or_warn (SOURCE, "src");
295 296 297
  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");
298
  audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
Wim Taymans's avatar
Wim Taymans committed
299
  g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);
300 301 302

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

303 304
  audio_bin = gst_bin_new ("a_decoder_bin");

305
  gst_bin_add (GST_BIN (pipeline), src);
306 307 308 309 310
  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);
311

312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
  gst_element_link (src, demux);
  gst_element_link (decoder, convert);
  gst_element_link (convert, audiosink);

  setup_dynamic_link (demux, NULL, gst_element_get_pad (decoder, "sink"), NULL);

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

static GstElement *
make_theora_pipeline (const gchar * location)
{
  GstElement *pipeline, *video_bin;
  GstElement *src, *demux, *decoder, *convert, *videosink;
  GstElement *queue;
  GstPad *seekable;

  pipeline = gst_pipeline_new ("app");

  src = gst_element_factory_make_or_warn (SOURCE, "src");
  demux = gst_element_factory_make_or_warn ("oggdemux", "demux");
  queue = gst_element_factory_make_or_warn ("queue", "queue");
  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
341
  videosink = gst_element_factory_make_or_warn (VSINK, "sink");
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360

  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 (pipeline), queue);
  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 (queue, decoder);
  gst_element_link (decoder, convert);
  gst_element_link (convert, videosink);

  setup_dynamic_link (demux, NULL, gst_element_get_pad (queue, "sink"), NULL);
361 362 363 364 365 366 367 368 369

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

370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
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;
  GstElement *a_queue, *v_queue;
  GstPad *seekable;

  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");
394
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413

  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

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

  gst_bin_add (GST_BIN (pipeline), audio_bin);

  setup_dynamic_link (demux, NULL, gst_element_get_pad (a_queue, "sink"), NULL);

  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");
Wim Taymans's avatar
Wim Taymans committed
414
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

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

  gst_bin_add (GST_BIN (pipeline), video_bin);

  setup_dynamic_link (demux, NULL, gst_element_get_pad (v_queue, "sink"), NULL);

  seekable = gst_element_get_pad (a_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 (a_decoder, "sink"));

  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;
  GstPad *seekable;

  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");
459
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

  gst_element_link (a_queue, a_decoder);
  gst_element_link (a_decoder, a_convert);
  gst_element_link (a_convert, audiosink);

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

  gst_bin_add (GST_BIN (pipeline), audio_bin);

  setup_dynamic_link (demux, NULL, gst_element_get_pad (a_queue, "sink"), NULL);

  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
479
  videosink = gst_element_factory_make_or_warn (VSINK, "v_sink");
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
  gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);

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

  gst_bin_add (GST_BIN (pipeline), video_bin);

  setup_dynamic_link (demux, NULL, gst_element_get_pad (v_queue, "sink"), NULL);

  seekable = gst_element_get_pad (a_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 (a_decoder, "sink"));

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
500 501
static GstElement *
make_mp3_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
502 503
{
  GstElement *pipeline;
504
  GstElement *src, *decoder, *osssink, *queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
505
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
506

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
507 508
  pipeline = gst_pipeline_new ("app");

509 510 511
  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");
512
  osssink = gst_element_factory_make_or_warn (ASINK, "sink");
513

514
  seekable_elements = g_list_prepend (seekable_elements, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
515 516

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

519 520
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), decoder);
521 522
  gst_bin_add (GST_BIN (pipeline), queue);
  gst_bin_add (GST_BIN (pipeline), osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
523

524 525
  gst_element_link (src, decoder);
  gst_element_link (decoder, queue);
526
  gst_element_link (queue, osssink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
527

528 529
  seekable = gst_element_get_pad (queue, "src");
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
530 531 532 533 534 535
  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
536 537
static GstElement *
make_avi_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
538 539 540
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink;
541
  GstElement *a_queue = NULL, *v_queue = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
542
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
543

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
544 545
  pipeline = gst_pipeline_new ("app");

546
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
547 548
  g_object_set (G_OBJECT (src), "location", location, NULL);

549
  demux = gst_element_factory_make_or_warn ("avidemux", "demux");
550
  seekable_elements = g_list_prepend (seekable_elements, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
551 552 553

  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
554
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
555 556

  audio_bin = gst_bin_new ("a_decoder_bin");
557
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
558
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
559
  //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
560
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
561 562
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
563
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
564 565
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
566
  gst_element_set_state (audio_bin, GST_STATE_PAUSED);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
567

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
568
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
569
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
570 571

  seekable = gst_element_get_pad (a_queue, "src");
572
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
573
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
574 575
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
576 577

  video_bin = gst_bin_new ("v_decoder_bin");
578
  //v_decoder = gst_element_factory_make_or_warn ("identity", "v_dec");
Wim Taymans's avatar
Wim Taymans committed
579
  //v_decoder = gst_element_factory_make_or_warn ("windec", "v_dec");
Wim Taymans's avatar
Wim Taymans committed
580
  v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec");
581
  videosink = gst_element_factory_make_or_warn ("ximagesink", "v_sink");
582
  //videosink = gst_element_factory_make_or_warn ("fakesink", "v_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
583
  //g_object_set (G_OBJECT (videosink), "sync", TRUE, NULL);
584
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
Wim Taymans's avatar
Wim Taymans committed
585
  //g_object_set (G_OBJECT (v_queue), "max_level", 10, NULL);
586 587
  gst_element_link (v_decoder, v_queue);
  gst_element_link (v_queue, videosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
588
  gst_bin_add (GST_BIN (video_bin), v_decoder);
589 590
  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
591

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
594
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
595
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
596 597

  seekable = gst_element_get_pad (v_queue, "src");
598
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
599
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
600 601
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
602 603 604 605

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
606 607
static GstElement *
make_mpeg_pipeline (const gchar * location)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
608 609
{
  GstElement *pipeline, *audio_bin, *video_bin;
610 611
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
612
  GstElement *a_queue, *v_queue;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
613
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
614

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
615 616
  pipeline = gst_pipeline_new ("app");

617
  src = gst_element_factory_make_or_warn (SOURCE, "src");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
618 619
  g_object_set (G_OBJECT (src), "location", location, NULL);

620
  demux = gst_element_factory_make_or_warn ("mpegdemux", "demux");
Wim Taymans's avatar
Wim Taymans committed
621
  g_object_set (G_OBJECT (demux), "sync", FALSE, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
622

623 624
  seekable_elements = g_list_prepend (seekable_elements, demux);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
625 626
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), demux);
627
  gst_element_link (src, demux);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
628 629

  audio_bin = gst_bin_new ("a_decoder_bin");
630 631
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
632
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
633
  g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
634 635
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
636
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
637 638
  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
639

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
640
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
641
          "sink"), audio_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
642 643

  seekable = gst_element_get_pad (a_queue, "src");
644
  seekable_pads = g_list_prepend (seekable_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
645
  rate_pads = g_list_prepend (rate_pads, seekable);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
646 647
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
648 649

  video_bin = gst_bin_new ("v_decoder_bin");
650
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
Wim Taymans's avatar
Wim Taymans committed
651
  //g_object_set (G_OBJECT (video_thread), "priority", 2, NULL);
652
  v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
653
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
654
  videosink = gst_element_factory_make_or_warn ("ximagesink", "v_sink");
655
  gst_element_link_many (v_decoder, v_queue, v_filter, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
656

657
  gst_element_link (v_filter, videosink);
658 659
  gst_bin_add_many (GST_BIN (video_bin), v_decoder, NULL);
  gst_bin_add_many (GST_BIN (video_bin), v_queue, v_filter, videosink, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
660

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
661
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
662
          "sink"), video_bin);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
663 664

  seekable = gst_element_get_pad (v_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);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
667 668
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_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_mpegnt_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
675 676 677 678
{
  GstElement *pipeline, *audio_bin, *video_bin;
  GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter;
  GstElement *audiosink, *videosink;
679
  GstElement *a_queue;
Wim Taymans's avatar
Wim Taymans committed
680
  GstPad *seekable;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
681

Wim Taymans's avatar
Wim Taymans committed
682 683 684 685 686 687 688 689 690 691 692 693
  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);
694
  gst_element_link (src, demux);
Wim Taymans's avatar
Wim Taymans committed
695 696 697 698

  audio_bin = gst_bin_new ("a_decoder_bin");
  a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
  a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
699
  audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink");
Wim Taymans's avatar
Wim Taymans committed
700 701
  //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL);
  g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
702 703
  gst_element_link (a_decoder, a_queue);
  gst_element_link (a_queue, audiosink);
Wim Taymans's avatar
Wim Taymans committed
704
  gst_bin_add (GST_BIN (audio_bin), a_decoder);
705 706
  gst_bin_add (GST_BIN (audio_bin), a_queue);
  gst_bin_add (GST_BIN (audio_bin), audiosink);
Wim Taymans's avatar
Wim Taymans committed
707

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
708
  setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder,
709
          "sink"), audio_bin);
Wim Taymans's avatar
Wim Taymans committed
710 711 712 713

  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
714 715
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
716 717 718

  video_bin = gst_bin_new ("v_decoder_bin");
  v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec");
719
  v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter");
720
  videosink = gst_element_factory_make_or_warn ("ximagesink", "v_sink");
721
  gst_element_link_many (v_decoder, v_filter, videosink, NULL);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
722

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
725
  setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder,
726
          "sink"), video_bin);
Wim Taymans's avatar
Wim Taymans committed
727 728 729 730

  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
731 732
  rate_pads =
      g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink"));
Wim Taymans's avatar
Wim Taymans committed
733 734 735 736

  return pipeline;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
737 738
static GstElement *
make_playerbin_pipeline (const gchar * location)
Wim Taymans's avatar
Wim Taymans committed
739
{
740
  GstElement *player;
741 742 743 744

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

745
  g_object_set (G_OBJECT (player), "uri", location, NULL);
746 747 748 749 750 751 752

  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
753 754
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
755 756
static gchar *
format_value (GtkScale * scale, gdouble value)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
757
{
758 759 760 761 762 763 764
  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
765

766 767
  return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
      G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
768 769 770 771 772 773
}

typedef struct
{
  const gchar *name;
  const GstFormat format;
774 775
}
seek_format;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
776

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
777 778 779 780 781 782
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
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
};

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;

Wim Taymans's avatar
Wim Taymans committed
801 802
      if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format,
              &value)) {
803
        g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
804
      } else {
805
        g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
806 807 808 809 810 811 812 813 814 815 816
      }

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

    walk = g_list_next (walk);
  }
}

G_GNUC_UNUSED static void
817 818 819 820 821 822 823 824 825 826
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) {
Wim Taymans's avatar
Wim Taymans committed
827
      gint64 position, total;
828 829 830
      GstFormat format;

      format = seek_formats[i].format;
Wim Taymans's avatar
Wim Taymans committed
831 832 833 834

      if (gst_element_query_position (element, &format, &position, &total)) {
        g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
            seek_formats[i].name, position, total);
835
      } else {
Wim Taymans's avatar
Wim Taymans committed
836 837
        g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
            "*NA*");
838 839 840 841 842 843 844 845 846 847 848
      }
      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
849
{
850 851 852 853 854 855 856 857 858
  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) {
      GstFormat format;
Wim Taymans's avatar
Wim Taymans committed
859
      gint64 position, total;
860 861

      format = seek_formats[i].format;
Wim Taymans's avatar
Wim Taymans committed
862 863 864 865

      if (gst_pad_query_position (pad, &format, &position, &total)) {
        g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
            seek_formats[i].name, position, total);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
866
      } else {
Wim Taymans's avatar
Wim Taymans committed
867 868
        g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*",
            "*NA*");
869
      }
Wim Taymans's avatar
Wim Taymans committed
870

871
      i++;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
872
    }
873 874 875
    g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad));

    walk = g_list_next (walk);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
876 877 878 879
  }
}

static gboolean
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
880
update_scale (gpointer data)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
881 882
{
  GstClock *clock;
Wim Taymans's avatar
Wim Taymans committed
883
  GstFormat format;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
884

Wim Taymans's avatar
Wim Taymans committed
885
  position = 0;
886
  duration = 0;
887
  clock = gst_pipeline_get_clock (GST_PIPELINE (pipeline));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
888

Wim Taymans's avatar
Wim Taymans committed
889 890
  format = GST_FORMAT_TIME;

891 892 893
  if (elem_seek) {
    if (seekable_elements) {
      GstElement *element = GST_ELEMENT (seekable_elements->data);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
894

Wim Taymans's avatar
Wim Taymans committed
895
      gst_element_query_position (element, &format, &position, &duration);
896 897 898 899 900
    }
  } else {
    if (seekable_pads) {
      GstPad *pad = GST_PAD (seekable_pads->data);

Wim Taymans's avatar
Wim Taymans committed
901
      gst_pad_query_position (pad, &format, &position, &duration);
902
    }
903
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
904

905
  if (stats) {
906
    if (clock) {
David Schleef's avatar
David Schleef committed
907 908
      g_print ("clock:                  %13" G_GUINT64_FORMAT "  (%s)\n",
          position, gst_object_get_name (GST_OBJECT (clock)));
909 910 911 912 913 914 915
    }

    if (elem_seek) {
      query_positions_elems ();
    } else {
      query_positions_pads ();
    }
916
    query_rates ();
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
917
  }
918 919
  if (position >= duration)
    duration = position;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
920 921 922

  if (duration > 0) {
    gtk_adjustment_set_value (adjustment, position * 100.0 / duration);
923
    gtk_widget_queue_draw (hscale);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
924 925 926 927 928
  }

  return TRUE;
}

929
static void do_seek (GtkWidget * widget);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
930

931
#ifdef SCRUB
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
932
static gboolean