pub struct ClockSync { /* private fields */ }Expand description
Clock synchronization state for a node.
Manages the mapping between local time and synchronized network time. Thread-safe for reading the current time from the audio thread.
Implementations§
Source§impl ClockSync
impl ClockSync
Sourcepub fn now(&self) -> SyncedTimestamp
pub fn now(&self) -> SyncedTimestamp
Get the current synchronized timestamp.
This reads the system clock and converts to microseconds since start.
§Realtime Safety
This method is NOT realtime-safe as it calls Instant::elapsed() which
may invoke a system call. For audio thread use, call tick()
from a non-audio thread and use cached_now() from
the audio thread.
Sourcepub fn tick(&self)
pub fn tick(&self)
Update the cached current time.
Call this periodically (e.g., at the start of each audio buffer) to update the cached time value.
§Realtime Safety
This method is NOT realtime-safe as it calls now()
internally. Call this from your main thread or audio device callback
thread, then use cached_now() from the audio
processing code.
Sourcepub fn cached_now(&self) -> SyncedTimestamp
pub fn cached_now(&self) -> SyncedTimestamp
Get the cached current time.
Faster than now() as it avoids a system call, but may be slightly stale.
Use for non-critical timing within the audio thread.
Sourcepub fn elapsed_micros(&self) -> u64
pub fn elapsed_micros(&self) -> u64
Get the time elapsed since clock creation in microseconds.
Sourcepub fn calculate_offset(
client_send_time: u64,
server_receive_time: u64,
server_send_time: u64,
client_receive_time: u64,
) -> i64
pub fn calculate_offset( client_send_time: u64, server_receive_time: u64, server_send_time: u64, client_receive_time: u64, ) -> i64
Calculate client clock offset based on ping/pong exchange.
Uses NTP-style offset calculation to determine the difference between client and server clocks.
§Arguments
client_send_time- Client timestamp when ping was sentserver_receive_time- Server timestamp when ping was receivedserver_send_time- Server timestamp when pong was sentclient_receive_time- Client timestamp when pong was received
§Returns
Clock offset in microseconds (positive = client ahead, negative = client behind)