gstclock.c 16.2 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.
 */
23 24 25 26 27 28 29 30 31 32 33 34 35 36
/**
 * 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.
 * Usually all renderers sync to the global clock so that the clock is always 
 * a good measure of the current playback time in the pipeline.
 */
37
#include <time.h>
38 39

#include "gst_private.h"
40

41
#include "gstclock.h"
42
#include "gstinfo.h"
43
#include "gstutils.h"
Wim Taymans's avatar
Wim Taymans committed
44

Wim Taymans's avatar
Wim Taymans committed
45
#ifndef GST_DISABLE_TRACE
Wim Taymans's avatar
Wim Taymans committed
46
/* #define GST_WITH_ALLOC_TRACE */
Wim Taymans's avatar
Wim Taymans committed
47 48 49
#include "gsttrace.h"
static GstAllocTrace *_gst_clock_entry_trace;
#endif
Wim Taymans's avatar
Wim Taymans committed
50

51
#define DEFAULT_EVENT_DIFF	(GST_SECOND)
52 53
#define DEFAULT_MAX_DIFF	(2 * GST_SECOND)

54 55
enum
{
56 57
  ARG_0,
  ARG_STATS,
58 59
  ARG_MAX_DIFF,
  ARG_EVENT_DIFF
60 61
};

62 63
static void gst_clock_class_init (GstClockClass * klass);
static void gst_clock_init (GstClock * clock);
Wim Taymans's avatar
Wim Taymans committed
64
static void gst_clock_finalize (GObject * object);
Wim Taymans's avatar
Wim Taymans committed
65

66 67 68 69 70
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);
71

72

73
static GstObjectClass *parent_class = NULL;
74

75 76
/* static guint gst_clock_signals[LAST_SIGNAL] = { 0 }; */

Wim Taymans's avatar
Wim Taymans committed
77
static GstClockID
78 79
gst_clock_entry_new (GstClock * clock, GstClockTime time,
    GstClockTime interval, GstClockEntryType type)
80 81
{
  GstClockEntry *entry;
82

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

90
  gst_atomic_int_set (&entry->refcount, 1);
91 92
  entry->clock = clock;
  entry->time = time;
93
  entry->interval = interval;
94
  entry->type = type;
95
  entry->status = GST_CLOCK_BUSY;
96

97 98
  return (GstClockID) entry;
}
99

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
/**
 * 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);

115
  g_atomic_int_inc (&((GstClockEntry *) id)->refcount);
116 117 118 119 120 121 122 123 124 125 126 127 128 129

  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
130
  g_free (id);
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
}

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

149
  zero = g_atomic_int_dec_and_test (&((GstClockEntry *) id)->refcount);
150 151 152 153 154 155
  /* if we ended up with the refcount at zero, free the id */
  if (zero) {
    _gst_clock_id_free (id);
  }
}

156 157 158 159 160
/**
 * 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
161
 * Get an ID from the given clock to trigger a single shot
162 163
 * notification at the requested time. The single shot id should be
 * unreffed after usage.
164 165
 *
 * Returns: An id that can be used to request the time notification.
166 167
 *
 * MT safe.
168 169
 */
GstClockID
170
gst_clock_new_single_shot_id (GstClock * clock, GstClockTime time)
171
{
172 173
  g_return_val_if_fail (GST_IS_CLOCK (clock), NULL);

174 175
  return gst_clock_entry_new (clock,
      time, GST_CLOCK_TIME_NONE, GST_CLOCK_ENTRY_SINGLE);
176 177 178
}

/**
Wim Taymans's avatar
Wim Taymans committed
179
 * gst_clock_new_periodic_id
180 181 182 183 184 185
 * @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
186 187
 * will then be fired with the given interval. The id should be unreffed
 * after usage.
188 189
 *
 * Returns: An id that can be used to request the time notification.
190 191
 *
 * MT safe.
192 193
 */
GstClockID
194 195
gst_clock_new_periodic_id (GstClock * clock, GstClockTime start_time,
    GstClockTime interval)
196
{
197
  g_return_val_if_fail (GST_IS_CLOCK (clock), NULL);
198
  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (start_time), NULL);
199 200
  g_return_val_if_fail (interval != 0, NULL);

201 202
  return gst_clock_entry_new (clock,
      start_time, interval, GST_CLOCK_ENTRY_PERIODIC);
203 204
}

205 206 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
/**
 * 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;
}

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

250
  return GST_CLOCK_ENTRY_TIME ((GstClockEntry *) id);
251 252 253 254 255 256 257 258 259
}


/**
 * 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
260
 * NULL.
261 262
 *
 * Returns: the result of the blocking wait.
263 264
 *
 * MT safe.
265 266
 */
GstClockReturn
267
gst_clock_id_wait (GstClockID id, GstClockTimeDiff * jitter)
268 269
{
  GstClockEntry *entry;
270
  GstClock *clock;
271
  GstClockReturn res;
272
  GstClockTime requested;
Wim Taymans's avatar
Wim Taymans committed
273
  GstClockClass *cclass;
274

275
  g_return_val_if_fail (id != NULL, GST_CLOCK_ERROR);
276

277 278
  entry = (GstClockEntry *) id;
  requested = GST_CLOCK_ENTRY_TIME (entry);
279

280 281 282 283 284
  if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (requested)))
    goto invalid_time;

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

286
  clock = GST_CLOCK_ENTRY_CLOCK (entry);
Wim Taymans's avatar
Wim Taymans committed
287
  cclass = GST_CLOCK_GET_CLASS (clock);
288

289
  if (G_LIKELY (cclass->wait)) {
290

291 292 293
    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);
294

295
    if (jitter) {
296 297
      GstClockTime now = gst_clock_get_time (clock);

298 299
      *jitter = now - requested;
    }
300 301 302
    if (entry->type == GST_CLOCK_ENTRY_PERIODIC) {
      entry->time += entry->interval;
    }
303 304 305 306

    if (clock->stats) {
      gst_clock_update_stats (clock);
    }
307 308
  } else {
    res = GST_CLOCK_UNSUPPORTED;
309 310
  }
  return res;
311 312 313 314 315 316 317 318 319 320 321 322

  /* 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;
  }
323 324 325
}

/**
Wim Taymans's avatar
Wim Taymans committed
326 327
 * gst_clock_id_wait_async:
 * @id: a #GstClockID to wait on
328 329 330
 * @func: The callback function 
 * @user_data: User data passed in the calback
 *
Wim Taymans's avatar
Wim Taymans committed
331
 * Register a callback on the given clockid with the given
332 333 334 335
 * 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.
336
 *
337
 * Returns: the result of the non blocking wait.
338 339
 *
 * MT safe.
340 341 342
 */
GstClockReturn
gst_clock_id_wait_async (GstClockID id,
343
    GstClockCallback func, gpointer user_data)
344 345 346
{
  GstClockEntry *entry;
  GstClock *clock;
347
  GstClockReturn res;
Wim Taymans's avatar
Wim Taymans committed
348
  GstClockClass *cclass;
349
  GstClockTime requested;
350

351
  g_return_val_if_fail (id != NULL, GST_CLOCK_ERROR);
352
  g_return_val_if_fail (func != NULL, GST_CLOCK_ERROR);
353 354

  entry = (GstClockEntry *) id;
355 356
  requested = GST_CLOCK_ENTRY_TIME (entry);
  clock = GST_CLOCK_ENTRY_CLOCK (entry);
357

358 359 360 361 362
  if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (requested)))
    goto invalid_time;

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

Wim Taymans's avatar
Wim Taymans committed
364 365 366 367 368 369 370
  cclass = GST_CLOCK_GET_CLASS (clock);

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

    res = cclass->wait_async (clock, entry);
371 372
  } else {
    res = GST_CLOCK_UNSUPPORTED;
373 374 375
  }
  return res;

376 377 378 379 380 381 382 383 384 385 386 387
  /* 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;
  }
388 389
}

390
/**
Wim Taymans's avatar
Wim Taymans committed
391 392
 * gst_clock_id_unschedule:
 * @id: The id to unschedule
393
 *
394 395 396 397 398 399
 * 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.
400 401 402 403 404 405
 */
void
gst_clock_id_unschedule (GstClockID id)
{
  GstClockEntry *entry;
  GstClock *clock;
Wim Taymans's avatar
Wim Taymans committed
406
  GstClockClass *cclass;
407

408 409 410 411
  g_return_if_fail (id != NULL);

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

Wim Taymans's avatar
Wim Taymans committed
413 414 415 416
  cclass = GST_CLOCK_GET_CLASS (clock);

  if (cclass->unschedule)
    cclass->unschedule (clock, entry);
417 418
}

419 420 421 422

/**
 * GstClock abstract base class implementation
 */
423 424
GType
gst_clock_get_type (void)
Wim Taymans's avatar
Wim Taymans committed
425
{
426 427 428 429
  static GType clock_type = 0;

  if (!clock_type) {
    static const GTypeInfo clock_info = {
430
      sizeof (GstClockClass),
431 432 433 434 435
      NULL,
      NULL,
      (GClassInitFunc) gst_clock_class_init,
      NULL,
      NULL,
436
      sizeof (GstClock),
437
      0,
438 439 440
      (GInstanceInitFunc) gst_clock_init,
      NULL
    };
441

442
    clock_type = g_type_register_static (GST_TYPE_OBJECT, "GstClock",
443
        &clock_info, G_TYPE_FLAG_ABSTRACT);
444 445 446
  }
  return clock_type;
}
447

448
static void
449
gst_clock_class_init (GstClockClass * klass)
450 451 452
{
  GObjectClass *gobject_class;
  GstObjectClass *gstobject_class;
453

454 455
  gobject_class = (GObjectClass *) klass;
  gstobject_class = (GstObjectClass *) klass;
456

457
  parent_class = g_type_class_ref (GST_TYPE_OBJECT);
458

Wim Taymans's avatar
Wim Taymans committed
459 460 461
  if (!g_thread_supported ())
    g_thread_init (NULL);

Wim Taymans's avatar
Wim Taymans committed
462
#ifndef GST_DISABLE_TRACE
463 464
  _gst_clock_entry_trace =
      gst_alloc_trace_register (GST_CLOCK_ENTRY_TRACE_NAME);
Wim Taymans's avatar
Wim Taymans committed
465
#endif
466

Wim Taymans's avatar
Wim Taymans committed
467
  gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_clock_finalize);
468 469 470 471
  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,
472
      g_param_spec_boolean ("stats", "Stats", "Enable clock stats",
473
          FALSE, G_PARAM_READWRITE));
Wim Taymans's avatar
Wim Taymans committed
474 475
}

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

Wim Taymans's avatar
Wim Taymans committed
487
static void
Wim Taymans's avatar
Wim Taymans committed
488
gst_clock_finalize (GObject * object)
Wim Taymans's avatar
Wim Taymans committed
489 490 491
{
  GstClock *clock = GST_CLOCK (object);

492
  g_cond_free (clock->entries_changed);
Wim Taymans's avatar
Wim Taymans committed
493

Wim Taymans's avatar
Wim Taymans committed
494
  G_OBJECT_CLASS (parent_class)->finalize (object);
Wim Taymans's avatar
Wim Taymans committed
495 496
}

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

Wim Taymans's avatar
Wim Taymans committed
511 512
  g_return_val_if_fail (GST_IS_CLOCK (clock), G_GINT64_CONSTANT (0));
  g_return_val_if_fail (resolution != 0, G_GINT64_CONSTANT (0));
513

Wim Taymans's avatar
Wim Taymans committed
514 515 516
  cclass = GST_CLOCK_GET_CLASS (clock);

  if (cclass->change_resolution)
517
    clock->resolution =
518
        cclass->change_resolution (clock, clock->resolution, resolution);
519

520 521
  return clock->resolution;
}
522

523 524 525 526 527 528 529
/**
 * 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.
530 531
 *
 * MT safe.
532 533
 */
guint64
534
gst_clock_get_resolution (GstClock * clock)
535
{
Wim Taymans's avatar
Wim Taymans committed
536 537
  GstClockClass *cclass;

Wim Taymans's avatar
Wim Taymans committed
538
  g_return_val_if_fail (GST_IS_CLOCK (clock), G_GINT64_CONSTANT (0));
539

Wim Taymans's avatar
Wim Taymans committed
540 541 542 543
  cclass = GST_CLOCK_GET_CLASS (clock);

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

Wim Taymans's avatar
Wim Taymans committed
545
  return G_GINT64_CONSTANT (1);
Wim Taymans's avatar
Wim Taymans committed
546 547
}

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

566 567 568 569 570 571
  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;
572
  }
573
  return ret;
574 575
}

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

594
  g_return_val_if_fail (GST_IS_CLOCK (clock), GST_CLOCK_TIME_NONE);
595

596
  cclass = GST_CLOCK_GET_CLASS (clock);
Wim Taymans's avatar
Wim Taymans committed
597

598
  if (cclass->get_internal_time) {
599
    ret = cclass->get_internal_time (clock);
600
  } else {
601
    ret = G_GINT64_CONSTANT (0);
602
  }
603 604
  GST_CAT_DEBUG (GST_CAT_CLOCK, "internal time %" GST_TIME_FORMAT,
      GST_TIME_ARGS (ret));
605

606 607 608
  GST_LOCK (clock);
  ret = gst_clock_adjust_unlocked (clock, ret);
  GST_UNLOCK (clock);
609

610 611
  GST_CAT_DEBUG (GST_CAT_CLOCK, "adjusted time %" GST_TIME_FORMAT,
      GST_TIME_ARGS (ret));
612

613
  return ret;
614 615
}

Wim Taymans's avatar
Wim Taymans committed
616
/**
617 618 619
 * gst_clock_set_time_adjust
 * @clock: a #GstClock to adjust
 * @adjust: the adjust value
Wim Taymans's avatar
Wim Taymans committed
620
 *
621 622 623 624 625
 * Adjusts the current time of the clock with the adjust value.
 * A positive value moves the clock forwards and a backwards value
 * moves it backwards. Note that _get_time() always returns 
 * 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
626
 *
627
 * MT safe.
Wim Taymans's avatar
Wim Taymans committed
628
 */
629 630
void
gst_clock_set_time_adjust (GstClock * clock, GstClockTime adjust)
631
{
632
  g_return_if_fail (GST_IS_CLOCK (clock));
633

634
  GST_LOCK (clock);
635
  clock->adjust = adjust;
636 637 638 639
  GST_UNLOCK (clock);
}

static void
640
gst_clock_update_stats (GstClock * clock)
641
{
642 643
}

644
static void
645 646
gst_clock_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
647
{
648
  GstClock *clock;
649

650 651 652 653 654
  clock = GST_CLOCK (object);

  switch (prop_id) {
    case ARG_STATS:
      clock->stats = g_value_get_boolean (value);
655
      g_object_notify (object, "stats");
656 657 658 659
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
660
  }
Wim Taymans's avatar
Wim Taymans committed
661
}
662

663
static void
664 665
gst_clock_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
666
{
667
  GstClock *clock;
668

669 670 671 672 673 674 675 676 677
  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;
678
  }
679
}