Skip to main content

Crate audio_clock_bsd

Crate audio_clock_bsd 

Source
Expand description

Clock synchronization and timestamp conversion for real-time audio.

This crate provides the ClockSource trait — the single contract a host application uses to map between an audio sample index and a wall-clock PTP timestamp (nanoseconds since the PTP epoch). It is the glue that lets an audio engine timestamp its samples for distributed playback (e.g. AES67/PTP-aligned streaming) or for offline alignment.

§Threading model

A ClockSource is not a real-time-thread primitive: polling an NTP daemon or a PTP hardware clock, and running the drift-compensation loop, are blocking operations. A concrete clock is intended to live on a separate thread (or be polled periodically from a worker); the cheap, allocation-free ClockSource::sample_to_ptp / ClockSource::ptp_to_sample conversions may then be called from anywhere, including the RT audio thread.

§Backends

  • NtpClock — the default fallback, anchored to the system monotonic/wall clock via std::time. Always available.
  • PtpClock — a PTPv2 (IEEE 1588-2008) interface. FreeBSD hardware PTP timestamping support is hardware-dependent, so the concrete implementation reads PTP time from an injectable PtpTimeProvider (e.g. a daemon-polling thread) and degrades to a ClockError::Unavailable stub when none is present.

§Dependency licensing

This crate depends on audio-core-bsd (BSD-2-Clause) and thiserror (MIT OR Apache-2.0). It links no system library, so it builds and tests anywhere.

Re-exports§

pub use clock::ClockAnchor;
pub use clock::ClockSource;
pub use error::ClockError;
pub use error::Result;
pub use ntp::NtpClock;
pub use ptp::PtpClock;
pub use ptp::PtpTimeProvider;

Modules§

clock
The ClockSource trait and the anchor-based sample↔timestamp conversion.
error
Crate error types and the Result alias.
ntp
NtpClock — the default system-clock fallback for ClockSource.
ptp
PtpClock — a PTPv2 (IEEE 1588-2008) ClockSource backend.