class ClockSynchronizer
Defined at line 29 of file ../../src/media/audio/lib/clock/clock_synchronizer.h
Maintains synchronization between two clocks. Synchronization happens in two modes, "clock
adjustment" and "MicroSRC", as detailed in //src/media/audio/mixer_service/docs/clocks.md.
A call to `Reset(mono_reset_time)` declares that the leader and follower clock are assumed to be
equivalent at the given time. From that point forward, the clocks may drift. It is the caller's
responsibility to compute a position error, then regularly call `Update(mono_time, error)` to
compute new rate adjustment parameters.
This class is not safe for concurrent use.
Public Methods
std::shared_ptr<ClockSynchronizer> Create (std::shared_ptr<Clock> leader, std::shared_ptr<Clock> follower, Mode mode)
Creates a synchronizer with the given mode.
Defined at line 36 of file ../../src/media/audio/lib/clock/clock_synchronizer.cc
Mode mode ()
Reports the mode that was set during Create.
Defined at line 55 of file ../../src/media/audio/lib/clock/clock_synchronizer.h
std::shared_ptr<Clock> follower ()
Returns the follower clock.
Defined at line 58 of file ../../src/media/audio/lib/clock/clock_synchronizer.h
std::shared_ptr<ClockSynchronizer> SelectModeAndCreate (std::shared_ptr<Clock> source, std::shared_ptr<Clock> dest)
Given two clocks representing the source and destination side of a `Mixer` node, selects the
synchronization mode to use and calls `Create`.
TODO(https://fxbug.dev/42066206): This is only for backwards compatibility with AudioCore's
mixer and can be removed after we have transitioned to the new mixer.
Defined at line 59 of file ../../src/media/audio/lib/clock/clock_synchronizer.cc
std::shared_ptr<Clock> leader ()
Returns the leader clock.
Defined at line 61 of file ../../src/media/audio/lib/clock/clock_synchronizer.h
int32_t follower_adjustment_ppm ()
Reports the follower's current adjustment in parts-per-million.
If mode is WithMicroSRC, this adjustment must be applied during SRC.
Defined at line 89 of file ../../src/media/audio/lib/clock/clock_synchronizer.cc
void Reset (zx::time mono_now)
Resets all synchronization state at the given monotonic time. This method establishes
a relationship between the leader and follower clocks as described in the class comments.
Defined at line 122 of file ../../src/media/audio/lib/clock/clock_synchronizer.cc
bool NeedsSynchronization ()
Reports whether synchronization is needed.
Returns true only if it's possible that the clocks have diverged since the last Reset.
Must call Reset at least once before this method.
Defined at line 93 of file ../../src/media/audio/lib/clock/clock_synchronizer.cc
void Update (zx::time mono_now, zx::duration follower_pos_error)
Checks if the follower clock is synchronized with the leader clock, and updates the
follower's clock rate if not. The caller is responsible for computing the follower's
position error. See class comments for more details.
There must be at least one Reset before the first Update. The sequence of Reset and
Update calls must use monotonically-increasing values for `mono_now`.
Defined at line 135 of file ../../src/media/audio/lib/clock/clock_synchronizer.cc
std::string ToDebugString ()
Collects debugging info as a string.
Defined at line 203 of file ../../src/media/audio/lib/clock/clock_synchronizer.cc
Enumerations
enum Mode
| Name | Value |
|---|---|
| WithAdjustments | 0 |
| WithMicroSRC | 1 |
Defined at line 31 of file ../../src/media/audio/lib/clock/clock_synchronizer.h