class Clock

Defined at line 23 of file ../../src/media/audio/lib/clock/clock.h

Abstract base class for clocks in the audio system.

All methods are safe to call from any thread.

Public Members

static const uint32_t kMonotonicDomain
static const uint32_t kExternalDomain

Public Methods

std::string_view name ()

Reports the clock's name, used for debugging only.

Names are not guaranteed to be unique. Use `koid` where a unique identifier is needed.

zx_koid_t koid ()

Reports the clock's koid.

This must uniquely indentify the clock, even if the clock is not backed by a zx::clock.

uint32_t domain ()

Reports the clock's domain. If two clocks have the same clock domain, their clock rates are

identical (although their positions may be offset by an arbitrary amount). There are two

special values:

* kMonotonicDomain means the hardware is operating at the same rate as the system montonic

clock.

* kExternalDomain means the hardware is operating at an unknown rate and is not synchronized

with any known clock, not even with other clocks in domain kExternalDomain.

For clock objects that represent real hardware, the domain typically comes from a system-wide

entity such as a global clock tree. For clock objects created in software, the domain is

typically either kMonotonicDomain or kExternalDomain.

bool adjustable ()

Reports whether this clock can be adjusted via calls to `SetRate`.

zx::time now ()

Reports the current time.

ToClockMonoSnapshot to_clock_mono_snapshot ()

Returns a function that translates from this clock's local time, a.k.a. "reference time", to

the system monotonic time, along with a generation counter that is incremented each time the

`to_clock_mono` function changes.

void SetRate (int32_t rate_adjust_ppm)

Adjusts the clock's rate. The adjustment is given in parts-per-million relate to the system

monotonic rate. This parameter has the same constraints as the `rate_adjust` parameter of

`zx_clock_update`. Specifically, the rate must be within the range:

[ZX_CLOCK_UPDATE_MIN_RATE_ADJUST, ZX_CLOCK_UPDATE_MAX_RATE_ADJUST].

It is illegal to call `SetRate` unless the clock is adjustable.

std::optional<zx::clock> DuplicateZxClockReadOnly ()

Duplicates the underlying zx::clock without ZX_RIGHTS_WRITE, or std::nullopt if there is no

underlying zx::clock or it cannot be duplicated.

TODO(https://fxbug.dev/42066206): This is needed by old audio_core code only. It's used by FIDL

GetReferenceClock implementations which won't be present in the mixer service. Once all uses

are removed, this can be deleted.

void ~Clock ()

Defined at line 28 of file ../../src/media/audio/lib/clock/clock.h

media::TimelineFunction to_clock_mono ()

Shorthand for to_clock_mono_snapshot().timeline_function.

Defined at line 90 of file ../../src/media/audio/lib/clock/clock.h

int32_t rate_adjustment_ppm ()

Returns the current clock rate adjustment as integral parts-per-million, rounded. A zx::clock

specifies rate adjustment as parts-per-million, but our Clock object's underlying TimelineRate

is capable of higher precision, so we use a utility function that rounds to nearest integer.

Defined at line 95 of file ../../src/media/audio/lib/clock/clock.h

zx::time ReferenceTimeFromMonotonicTime (zx::time mono_time)

Returns the reference time equivalent to the given system monotonic time.

Defined at line 100 of file ../../src/media/audio/lib/clock/clock.h

zx::time MonotonicTimeFromReferenceTime (zx::time ref_time)

Returns the system monotonic time equivalent to the given reference time.

Defined at line 105 of file ../../src/media/audio/lib/clock/clock.h

bool IdenticalToMonotonicClock ()

Reports if this clock is currently identical to the system monotonic clock.

Defined at line 110 of file ../../src/media/audio/lib/clock/clock.h

int32_t TimelineRateToRateAdjustmentPpm (const media::TimelineRate & rate)

Converts a TimelineRate to parts-per-million, rounded.

Defined at line 117 of file ../../src/media/audio/lib/clock/clock.h

int32_t ClampZxClockPpm (int32_t ppm)

Clamps an integer rate, expressed in parts-per-million, to the range allowed by

`zx_clock_update`.

Defined at line 130 of file ../../src/media/audio/lib/clock/clock.h

int32_t ClampDoubleToZxClockPpm (double val)

Converts a rational number to parts-per-million, then clamp to range allowed by

`zx_clock_update`.

Defined at line 137 of file ../../src/media/audio/lib/clock/clock.h

Records