audio-clock-bsd 0.1.1

PTP/NTP clock synchronization and sample-index to timestamp conversion for real-time audio
Documentation
//! 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

#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_docs)]
#![warn(clippy::all, clippy::pedantic)]

pub mod clock;
pub mod error;
pub mod ntp;
pub mod ptp;

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