Struct ClockSync

Source
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

Source

pub fn new() -> Self

Create a new clock synchronization instance.

Source

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.

Source

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.

Source

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.

Source

pub fn elapsed_micros(&self) -> u64

Get the time elapsed since clock creation in microseconds.

Source

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 sent
  • server_receive_time - Server timestamp when ping was received
  • server_send_time - Server timestamp when pong was sent
  • client_receive_time - Client timestamp when pong was received
§Returns

Clock offset in microseconds (positive = client ahead, negative = client behind)

Trait Implementations§

Source§

impl Default for ClockSync

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V