gstclock.c 16.4 KB
Newer Older
1 2 3
/* GStreamer
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
 *                    2000 Wim Taymans <wtay@chello.be>
4
 *                    2004 Wim Taymans <wim@fluendo.com>
5 6
 *
 * gstclock.c: Clock subsystem for maintaining time sync
Wim Taymans's avatar
Wim Taymans committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
23

24 25 26 27 28 29 30 31 32 33 34
/**
 * SECTION:gstclock
 * @short_description: Abstract class for global clocks
 * @see_also: #GstSystemClock
 *
 * GStreamer uses a global clock to synchronise the plugins in a pipeline.
 * Different clock implementations are possible by implementing this abstract
 * base class.
 *
 * The clock time is always measured in nanoseconds and always increases. The
 * pipeline uses the clock to calculate the stream time.
35 36
 * Usually all renderers sync to the global clock using the buffer timestamps,
 * the newsegment events and the element's base time.
Wim Taymans's avatar
Wim Taymans committed
37
 *
Stefan Kost's avatar
Stefan Kost committed
38
 * The time of the clock in itself is not very useful for an application.
39
 */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
40

41
#include <time.h>
42 43

#include "gst_private.h"
44

45
#include "gstclock.h"
46
#include "gstinfo.h"
47
#include "gstutils.h"
Wim Taymans's avatar
Wim Taymans committed
48

Wim Taymans's avatar
Wim Taymans committed
49
#ifndef GST_DISABLE_TRACE
Wim Taymans's avatar
Wim Taymans committed
50
/* #define GST_WITH_ALLOC_TRACE */
Wim Taymans's avatar
Wim Taymans committed
51 52 53
#include "gsttrace.h"
static GstAllocTrace *_gst_clock_entry_trace;
#endif
Wim Taymans's avatar
Wim Taymans committed
54

55
#define DEFAULT_EVENT_DIFF	(GST_SECOND)
56 57
#define DEFAULT_MAX_DIFF	(2 * GST_SECOND)

58 59
enum
{
60 61
  ARG_0,
  ARG_STATS,
62 63
  ARG_MAX_DIFF,
  ARG_EVENT_DIFF
64 65
};

66 67
static void gst_clock_class_init (GstClockClass * klass);
static void gst_clock_init (GstClock * clock);
Wim Taymans's avatar
Wim Taymans committed
68
static void gst_clock_finalize (GObject * object);
Wim Taymans's avatar
Wim Taymans committed
69

70 71 72 73 74
static void gst_clock_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec);
static void gst_clock_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec);
static void gst_clock_update_stats (GstClock * clock);
75

76

77
static GstObjectClass *parent_class = NULL;
78

79 80
/* static guint gst_clock_signals[LAST_SIGNAL] = { 0 }; */

Wim Taymans's avatar
Wim Taymans committed
81
static GstClockID
82 83
gst_clock_entry_new (GstClock * clock, GstClockTime time,
    GstClockTime interval, GstClockEntryType type)
84 85
{
  GstClockEntry *entry;
86

87
  entry = g_malloc0 (sizeof (GstClockEntry));
Wim Taymans's avatar
Wim Taymans committed
88
#ifndef GST_DISABLE_TRACE
Wim Taymans's avatar
Wim Taymans committed
89
  gst_alloc_trace_new (_gst_clock_entry_trace, entry);
Wim Taymans's avatar
Wim Taymans committed
90
#endif
91 92
  GST_CAT_DEBUG (GST_CAT_CLOCK, "created entry %p, time %" GST_TIME_FORMAT,
      entry, GST_TIME_ARGS (time));
93

94
  gst_atomic_int_set (&entry->refcount, 1);
95 96
  entry->clock = clock;
  entry->time = time;
97
  entry->interval = interval;
98
  entry->type = type;
99
  entry->status = GST_CLOCK_BUSY;
100

101 102
  return (GstClockID) entry;
}
103

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
/**
 * gst_clock_id_ref:
 * @id: The clockid to ref
 *
 * Increase the refcount of the given clockid.
 *
 * Returns: The same #GstClockID with increased refcount.
 *
 * MT safe.
 */
GstClockID
gst_clock_id_ref (GstClockID id)
{
  g_return_val_if_fail (id != NULL, NULL);

119
  g_atomic_int_inc (&((GstClockEntry *) id)->refcount);
120 121 122 123 124 125 126 127 128 129 130 131 132 133

  return id;
}

static void
_gst_clock_id_free (GstClockID id)
{
  g_return_if_fail (id != NULL);

  GST_CAT_DEBUG (GST_CAT_CLOCK, "freed entry %p", id);

#ifndef GST_DISABLE_TRACE
  gst_alloc_trace_free (_gst_clock_entry_trace, id);
#endif
134
  g_free (id);
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
}

/**
 * gst_clock_id_unref:
 * @id: The clockid to unref
 *
 * Unref the given clockid. When the refcount reaches 0 the
 * #GstClockID will be freed.
 *
 * MT safe.
 */
void
gst_clock_id_unref (GstClockID id)
{
  gint zero;

  g_return_if_fail (id != NULL);

153
  zero = g_atomic_int_dec_and_test (&((GstClockEntry *) id)->refcount);
154 155 156 157 158 159
  /* if we ended up with the refcount at zero, free the id */
  if (zero) {
    _gst_clock_id_free (id);
  }
}

160 161 162 163 164
/**
 * gst_clock_new_single_shot_id
 * @clock: The clockid to get a single shot notification from
 * @time: the requested time
 *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
165
 * Get an ID from the given clock to trigger a single shot
166 167
 * notification at the requested time. The single shot id should be
 * unreffed after usage.
168 169
 *
 * Returns: An id that can be used to request the time notification.
170 171
 *
 * MT safe.
172 173
 */
GstClockID
174
gst_clock_new_single_shot_id (GstClock * clock, GstClockTime time)
175
{
176 177
  g_return_val_if_fail (GST_IS_CLOCK (clock), NULL);

178 179
  return gst_clock_entry_new (clock,
      time, GST_CLOCK_TIME_NONE, GST_CLOCK_ENTRY_SINGLE);
180 181 182
}

/**
Wim Taymans's avatar
Wim Taymans committed
183
 * gst_clock_new_periodic_id
184 185 186 187 188 189
 * @clock: The clockid to get a periodic notification id from
 * @start_time: the requested start time
 * @interval: the requested interval
 *
 * Get an ID from the given clock to trigger a periodic notification.
 * The periodeic notifications will be start at time start_time and
190 191
 * will then be fired with the given interval. The id should be unreffed
 * after usage.
192 193
 *
 * Returns: An id that can be used to request the time notification.
194 195
 *
 * MT safe.
196 197
 */
GstClockID
198 199
gst_clock_new_periodic_id (GstClock * clock, GstClockTime start_time,
    GstClockTime interval)
200
{
201
  g_return_val_if_fail (GST_IS_CLOCK (clock), NULL);
202
  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (start_time), NULL);
203 204
  g_return_val_if_fail (interval != 0, NULL);

205 206
  return gst_clock_entry_new (clock,
      start_time, interval, GST_CLOCK_ENTRY_PERIODIC);
207 208
}

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
/**
 * gst_clock_id_compare_func
 * @id1: A clockid
 * @id2: A clockid to compare with
 *
 * Compares the two GstClockID instances. This function can be used
 * as a GCompareFunc when sorting ids.
 *
 * Returns: negative value if a < b; zero if a = b; positive value if a > b
 *
 * MT safe.
 */
gint
gst_clock_id_compare_func (gconstpointer id1, gconstpointer id2)
{
  GstClockEntry *entry1, *entry2;

  entry1 = (GstClockEntry *) id1;
  entry2 = (GstClockEntry *) id2;

  if (GST_CLOCK_ENTRY_TIME (entry1) > GST_CLOCK_ENTRY_TIME (entry2)) {
    return 1;
  }
  if (GST_CLOCK_ENTRY_TIME (entry1) < GST_CLOCK_ENTRY_TIME (entry2)) {
    return -1;
  }

  return entry1 - entry2;
}

239 240 241 242 243 244
/**
 * gst_clock_id_get_time
 * @id: The clockid to query
 *
 * Get the time of the clock ID
 *
245 246 247
 * Returns: the time of the given clock id.
 *
 * MT safe.
248 249 250 251 252 253
 */
GstClockTime
gst_clock_id_get_time (GstClockID id)
{
  g_return_val_if_fail (id != NULL, GST_CLOCK_TIME_NONE);

254
  return GST_CLOCK_ENTRY_TIME ((GstClockEntry *) id);
255 256 257 258 259 260 261 262 263
}


/**
 * gst_clock_id_wait
 * @id: The clockid to wait on
 * @jitter: A pointer that will contain the jitter
 *
 * Perform a blocking wait on the given ID. The jitter arg can be
264
 * NULL.
265 266
 *
 * Returns: the result of the blocking wait.
267 268
 *
 * MT safe.
269 270
 */
GstClockReturn
271
gst_clock_id_wait (GstClockID id, GstClockTimeDiff * jitter)
272 273
{
  GstClockEntry *entry;
274
  GstClock *clock;
275
  GstClockReturn res;
276
  GstClockTime requested;
Wim Taymans's avatar
Wim Taymans committed
277
  GstClockClass *cclass;
278

279
  g_return_val_if_fail (id != NULL, GST_CLOCK_ERROR);
280

281 282
  entry = (GstClockEntry *) id;
  requested = GST_CLOCK_ENTRY_TIME (entry);
283

284 285 286 287 288
  if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (requested)))
    goto invalid_time;

  if (G_UNLIKELY (entry->status == GST_CLOCK_UNSCHEDULED))
    goto unscheduled;
289

290
  clock = GST_CLOCK_ENTRY_CLOCK (entry);
Wim Taymans's avatar
Wim Taymans committed
291
  cclass = GST_CLOCK_GET_CLASS (clock);
292

293
  if (G_LIKELY (cclass->wait)) {
294

295 296 297
    GST_CAT_DEBUG (GST_CAT_CLOCK, "waiting on clock entry %p", id);
    res = cclass->wait (clock, entry);
    GST_CAT_DEBUG (GST_CAT_CLOCK, "done waiting entry %p", id);
298

299
    if (jitter) {
300 301
      GstClockTime now = gst_clock_get_time (clock);

302 303
      *jitter = now - requested;
    }
304 305 306
    if (entry->type == GST_CLOCK_ENTRY_PERIODIC) {
      entry->time += entry->interval;
    }
307 308 309 310

    if (clock->stats) {
      gst_clock_update_stats (clock);
    }
311 312
  } else {
    res = GST_CLOCK_UNSUPPORTED;
313 314
  }
  return res;
315 316 317 318 319 320 321 322 323 324 325 326

  /* ERRORS */
invalid_time:
  {
    GST_CAT_DEBUG (GST_CAT_CLOCK, "invalid time requested, returning _BADTIME");
    return GST_CLOCK_BADTIME;
  }
unscheduled:
  {
    GST_CAT_DEBUG (GST_CAT_CLOCK, "entry was unscheduled return _UNSCHEDULED");
    return GST_CLOCK_UNSCHEDULED;
  }
327 328 329
}

/**
Wim Taymans's avatar
Wim Taymans committed
330 331
 * gst_clock_id_wait_async:
 * @id: a #GstClockID to wait on
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
332
 * @func: The callback function
333 334
 * @user_data: User data passed in the calback
 *
Wim Taymans's avatar
Wim Taymans committed
335
 * Register a callback on the given clockid with the given
336 337 338 339
 * function and user_data. When passing an id with an invalid
 * time to this function, the callback will be called immediatly
 * with  a time set to GST_CLOCK_TIME_NONE. The callback will
 * be called when the time of the id has been reached.
340
 *
341
 * Returns: the result of the non blocking wait.
342 343
 *
 * MT safe.
344 345 346
 */
GstClockReturn
gst_clock_id_wait_async (GstClockID id,
347
    GstClockCallback func, gpointer user_data)
348 349 350
{
  GstClockEntry *entry;
  GstClock *clock;
351
  GstClockReturn res;
Wim Taymans's avatar
Wim Taymans committed
352
  GstClockClass *cclass;
353
  GstClockTime requested;
354

355
  g_return_val_if_fail (id != NULL, GST_CLOCK_ERROR);
356
  g_return_val_if_fail (func != NULL, GST_CLOCK_ERROR);
357 358

  entry = (GstClockEntry *) id;
359 360
  requested = GST_CLOCK_ENTRY_TIME (entry);
  clock = GST_CLOCK_ENTRY_CLOCK (entry);
361

362 363 364 365 366
  if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (requested)))
    goto invalid_time;

  if (G_UNLIKELY (entry->status == GST_CLOCK_UNSCHEDULED))
    goto unscheduled;
367

Wim Taymans's avatar
Wim Taymans committed
368 369 370 371 372 373 374
  cclass = GST_CLOCK_GET_CLASS (clock);

  if (cclass->wait_async) {
    entry->func = func;
    entry->user_data = user_data;

    res = cclass->wait_async (clock, entry);
375 376
  } else {
    res = GST_CLOCK_UNSUPPORTED;
377 378 379
  }
  return res;

380 381 382 383 384 385 386 387 388 389 390 391
  /* ERRORS */
invalid_time:
  {
    (func) (clock, GST_CLOCK_TIME_NONE, id, user_data);
    GST_CAT_DEBUG (GST_CAT_CLOCK, "invalid time requested, returning _BADTIME");
    return GST_CLOCK_BADTIME;
  }
unscheduled:
  {
    GST_CAT_DEBUG (GST_CAT_CLOCK, "entry was unscheduled return _UNSCHEDULED");
    return GST_CLOCK_UNSCHEDULED;
  }
392 393
}

394
/**
Wim Taymans's avatar
Wim Taymans committed
395 396
 * gst_clock_id_unschedule:
 * @id: The id to unschedule
397
 *
398 399 400 401 402 403
 * Cancel an outstanding request with the given ID. This can either
 * be an outstanding async notification or a pending sync notification.
 * After this call, the @id cannot be used anymore to receive sync or
 * async notifications, you need to create a new GstClockID.
 *
 * MT safe.
404 405 406 407 408 409
 */
void
gst_clock_id_unschedule (GstClockID id)
{
  GstClockEntry *entry;
  GstClock *clock;
Wim Taymans's avatar
Wim Taymans committed
410
  GstClockClass *cclass;
411

412 413 414 415
  g_return_if_fail (id != NULL);

  entry = (GstClockEntry *) id;
  clock = entry->clock;
416

Wim Taymans's avatar
Wim Taymans committed
417 418 419 420
  cclass = GST_CLOCK_GET_CLASS (clock);

  if (cclass->unschedule)
    cclass->unschedule (clock, entry);
421 422
}

423 424 425 426

/**
 * GstClock abstract base class implementation
 */
427 428
GType
gst_clock_get_type (void)
Wim Taymans's avatar
Wim Taymans committed
429
{
430 431 432 433
  static GType clock_type = 0;

  if (!clock_type) {
    static const GTypeInfo clock_info = {
434
      sizeof (GstClockClass),
435 436 437 438 439
      NULL,
      NULL,
      (GClassInitFunc) gst_clock_class_init,
      NULL,
      NULL,
440
      sizeof (GstClock),
441
      0,
442 443 444
      (GInstanceInitFunc) gst_clock_init,
      NULL
    };
445

446
    clock_type = g_type_register_static (GST_TYPE_OBJECT, "GstClock",
447
        &clock_info, G_TYPE_FLAG_ABSTRACT);
448 449 450
  }
  return clock_type;
}
451

452
static void
453
gst_clock_class_init (GstClockClass * klass)
454 455 456
{
  GObjectClass *gobject_class;
  GstObjectClass *gstobject_class;
457

458 459
  gobject_class = (GObjectClass *) klass;
  gstobject_class = (GstObjectClass *) klass;
460

461
  parent_class = g_type_class_ref (GST_TYPE_OBJECT);
462

Wim Taymans's avatar
Wim Taymans committed
463 464 465
  if (!g_thread_supported ())
    g_thread_init (NULL);

Wim Taymans's avatar
Wim Taymans committed
466
#ifndef GST_DISABLE_TRACE
467 468
  _gst_clock_entry_trace =
      gst_alloc_trace_register (GST_CLOCK_ENTRY_TRACE_NAME);
Wim Taymans's avatar
Wim Taymans committed
469
#endif
470

Wim Taymans's avatar
Wim Taymans committed
471
  gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_clock_finalize);
472 473 474 475
  gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_clock_set_property);
  gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_clock_get_property);

  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STATS,
476
      g_param_spec_boolean ("stats", "Stats", "Enable clock stats",
477
          FALSE, G_PARAM_READWRITE));
Wim Taymans's avatar
Wim Taymans committed
478 479
}

480
static void
481
gst_clock_init (GstClock * clock)
Wim Taymans's avatar
Wim Taymans committed
482
{
483
  clock->adjust = 0;
484 485
  clock->last_time = 0;
  clock->entries = NULL;
486
  clock->entries_changed = g_cond_new ();
487 488
  clock->flags = 0;
  clock->stats = FALSE;
Wim Taymans's avatar
Wim Taymans committed
489 490
}

Wim Taymans's avatar
Wim Taymans committed
491
static void
Wim Taymans's avatar
Wim Taymans committed
492
gst_clock_finalize (GObject * object)
Wim Taymans's avatar
Wim Taymans committed
493 494 495
{
  GstClock *clock = GST_CLOCK (object);

496
  g_cond_free (clock->entries_changed);
Wim Taymans's avatar
Wim Taymans committed
497

Wim Taymans's avatar
Wim Taymans committed
498
  G_OBJECT_CLASS (parent_class)->finalize (object);
Wim Taymans's avatar
Wim Taymans committed
499 500
}

Wim Taymans's avatar
Wim Taymans committed
501
/**
502 503 504
 * gst_clock_set_resolution
 * @clock: The clock set the resolution on
 * @resolution: The resolution to set
Wim Taymans's avatar
Wim Taymans committed
505
 *
506 507 508
 * Set the accuracy of the clock.
 *
 * Returns: the new resolution of the clock.
Wim Taymans's avatar
Wim Taymans committed
509
 */
510
guint64
511
gst_clock_set_resolution (GstClock * clock, guint64 resolution)
Wim Taymans's avatar
Wim Taymans committed
512
{
Wim Taymans's avatar
Wim Taymans committed
513 514
  GstClockClass *cclass;

Wim Taymans's avatar
Wim Taymans committed
515 516
  g_return_val_if_fail (GST_IS_CLOCK (clock), G_GINT64_CONSTANT (0));
  g_return_val_if_fail (resolution != 0, G_GINT64_CONSTANT (0));
517

Wim Taymans's avatar
Wim Taymans committed
518 519 520
  cclass = GST_CLOCK_GET_CLASS (clock);

  if (cclass->change_resolution)
521
    clock->resolution =
522
        cclass->change_resolution (clock, clock->resolution, resolution);
523

524 525
  return clock->resolution;
}
526

527 528 529 530 531 532 533
/**
 * gst_clock_get_resolution
 * @clock: The clock get the resolution of
 *
 * Get the accuracy of the clock.
 *
 * Returns: the resolution of the clock in microseconds.
534 535
 *
 * MT safe.
536 537
 */
guint64
538
gst_clock_get_resolution (GstClock * clock)
539
{
Wim Taymans's avatar
Wim Taymans committed
540 541
  GstClockClass *cclass;

Wim Taymans's avatar
Wim Taymans committed
542
  g_return_val_if_fail (GST_IS_CLOCK (clock), G_GINT64_CONSTANT (0));
543

Wim Taymans's avatar
Wim Taymans committed
544 545 546 547
  cclass = GST_CLOCK_GET_CLASS (clock);

  if (cclass->get_resolution)
    return cclass->get_resolution (clock);
548

Wim Taymans's avatar
Wim Taymans committed
549
  return G_GINT64_CONSTANT (1);
Wim Taymans's avatar
Wim Taymans committed
550 551
}

Wim Taymans's avatar
Wim Taymans committed
552
/**
553 554 555
 * gst_clock_adjust_unlocked
 * @clock: a #GstClock to use
 * @internal: a clock time
Wim Taymans's avatar
Wim Taymans committed
556
 *
557 558
 * Converts the given @internal clock time to the real time, adjusting
 * and making sure that the returned time is increasing.
559 560
 * This function should be called with the clock LOCK held and is
 * mainly used by clock subclasses.
Wim Taymans's avatar
Wim Taymans committed
561
 *
562
 * Returns: the converted time of the clock.
563
 *
564
 * MT safe.
565
 */
566 567
GstClockTime
gst_clock_adjust_unlocked (GstClock * clock, GstClockTime internal)
568
{
569
  GstClockTime ret;
570

571 572 573 574 575 576
  ret = internal + clock->adjust;
  /* make sure the time is increasing, else return last_time */
  if ((gint64) ret < (gint64) clock->last_time) {
    ret = clock->last_time;
  } else {
    clock->last_time = ret;
577
  }
578
  return ret;
579 580
}

Wim Taymans's avatar
Wim Taymans committed
581 582
/**
 * gst_clock_get_time
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
583
 * @clock: a #GstClock to query
Wim Taymans's avatar
Wim Taymans committed
584
 *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
585
 * Gets the current time of the given clock. The time is always
Wim Taymans's avatar
Wim Taymans committed
586
 * monotonically increasing.
587
 *
588 589 590 591
 * Returns: the time of the clock. Or GST_CLOCK_TIME_NONE when
 * giving wrong input.
 *
 * MT safe.
Wim Taymans's avatar
Wim Taymans committed
592
 */
593
GstClockTime
594
gst_clock_get_time (GstClock * clock)
595
{
596
  GstClockTime ret;
597
  GstClockClass *cclass;
598

599
  g_return_val_if_fail (GST_IS_CLOCK (clock), GST_CLOCK_TIME_NONE);
600

601
  cclass = GST_CLOCK_GET_CLASS (clock);
Wim Taymans's avatar
Wim Taymans committed
602

603
  if (cclass->get_internal_time) {
604
    ret = cclass->get_internal_time (clock);
605
  } else {
606
    ret = G_GINT64_CONSTANT (0);
607
  }
608 609
  GST_CAT_DEBUG (GST_CAT_CLOCK, "internal time %" GST_TIME_FORMAT,
      GST_TIME_ARGS (ret));
610

611 612 613
  GST_LOCK (clock);
  ret = gst_clock_adjust_unlocked (clock, ret);
  GST_UNLOCK (clock);
614

615 616
  GST_CAT_DEBUG (GST_CAT_CLOCK, "adjusted time %" GST_TIME_FORMAT,
      GST_TIME_ARGS (ret));
617

618
  return ret;
619 620
}

Wim Taymans's avatar
Wim Taymans committed
621
/**
622 623 624
 * gst_clock_set_time_adjust
 * @clock: a #GstClock to adjust
 * @adjust: the adjust value
Wim Taymans's avatar
Wim Taymans committed
625
 *
626 627
 * Adjusts the current time of the clock with the adjust value.
 * A positive value moves the clock forwards and a backwards value
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
628
 * moves it backwards. Note that _get_time() always returns
629 630
 * increasing values so when you move the clock backwards, _get_time()
 * will report the previous value until the clock catches up.
Wim Taymans's avatar
Wim Taymans committed
631
 *
632
 * MT safe.
Wim Taymans's avatar
Wim Taymans committed
633
 */
634 635
void
gst_clock_set_time_adjust (GstClock * clock, GstClockTime adjust)
636
{
637
  g_return_if_fail (GST_IS_CLOCK (clock));
638

639
  GST_LOCK (clock);
640
  clock->adjust = adjust;
641 642 643 644
  GST_UNLOCK (clock);
}

static void
645
gst_clock_update_stats (GstClock * clock)
646
{
647 648
}

649
static void
650 651
gst_clock_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
652
{
653
  GstClock *clock;
654

655 656 657 658 659
  clock = GST_CLOCK (object);

  switch (prop_id) {
    case ARG_STATS:
      clock->stats = g_value_get_boolean (value);
660
      g_object_notify (object, "stats");
661 662 663 664
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
665
  }
Wim Taymans's avatar
Wim Taymans committed
666
}
667

668
static void
669 670
gst_clock_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
671
{
672
  GstClock *clock;
673

674 675 676 677 678 679 680 681 682
  clock = GST_CLOCK (object);

  switch (prop_id) {
    case ARG_STATS:
      g_value_set_boolean (value, clock->stats);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
683
  }
684
}