1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! 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.
//!
//! [`audio-core-bsd`]: https://crates.io/crates/audio-core-bsd
//! [`thiserror`]: https://crates.io/crates/thiserror
pub use ;
pub use ;
pub use NtpClock;
pub use ;