weirdnet-streaming 0.1.0

Streaming for Weirdnet: live and recorded audio streams over weirdnet-net with per-listener queues, clocks and remote routing, a follow-transport protocol (start, stop, locate, tempo, beacon), and loop-positioned streams with alignment for record-along.
Documentation
//! Streaming for Weirdnet: audio streams between nodes, the transport that keeps them together, and the loop-positioned streams
//! apps record along with.
//!
//! **Streams** (the core, moved here from `weirdnet-audio-stream`)
//!
//! * A [`Publisher`] sends [`Frame`]s of one stream to any number of listeners. It never blocks: each listener has its own
//!   bounded queue and an [`Overflow`] policy, so a slow listener never slows the others.
//! * A late live listener starts at the next key frame; a [`MemorySource`] holds a recorded stream that listeners can seek in.
//! * Frames are codec-agnostic: the crate moves bytes and a [`CodecId`] and never decodes. Raw PCM needs no codec
//!   ([`StreamInfo::pcm_f32`]). Streams and frames carry optional opaque app metadata that the crate never reads.
//! * [`net`] serves a [`Hub`] of streams over weirdnet-net streams, with an authoriser per subscription, and
//!   [`net::Subscriber`] connects to one, with [`Stats`] on arrival delay, jitter and loss.
//! * [`clock`]: another node's clock offset by request and reply, and its drift by a line fit.
//! * `remote` (feature `route`): a weirdnet-audio-route executor carrying connections between a weirdnet-audio-engine router
//!   and other nodes, with resampling, drift following and measured delay, and a [`remote::PeerTable`] to tell it where nodes are.
//!
//! **Transport**
//!
//! * [`transport`]: the follow-transport protocol (`Prepare`, `Ready`, `Start`, `Stop`, `Locate`, `Tempo`, `Beacon`), the
//!   [`transport::SessionClock`] an instance learns from a master's messages, and the [`transport::Follower`] that turns them
//!   into engine actions on the right audio block. It is a plain message type: the app chooses how to carry it.
//!
//! **Loop-positioned streams (record-along)**
//!
//! * [`stage`]: stream and frame metadata saying where on the sender's loop each frame belongs, and [`stage::Grid`] to turn that
//!   into the listener's own frames at any sample rate.
//! * [`align`]: where a collaborator's audio plays on your loop (recorded exact, live bar-aligned or immediate).
//! * [`bus`]: the audio-thread side, a tap and a mix that never lock or allocate in the render callback.
//! * [`listen`] and [`along`]: the network side, listen-along (a master out as a stream) and record-along (a dry stream and take,
//!   and playing a collaborator's aligned to your loop).
//! * [`clocked`]: a manual sink on its own clock, to run without a device or to inject drift in tests.
#![forbid(unsafe_code)]
#![warn(missing_docs)]

pub mod align;
pub mod along;
pub mod bus;
pub mod clock;
pub mod clocked;
mod hub;
pub mod listen;
pub mod net;
#[cfg(feature = "route")]
pub mod remote;
mod source;
pub mod stage;
mod stats;
pub mod transport;
mod types;
pub mod wire;

pub use hub::{Listener, ListenerInfo, Publisher};
pub use net::{AllowAll, Hub, StreamAuth};
pub use source::{FrameSource, MemorySource, Recording};
pub use stats::Stats;
pub use types::{
    BufferPolicy, CodecId, Frame, Overflow, PCM_F32LE, PCM_S16LE, Start, StreamError, StreamEvent, StreamId, StreamInfo, StreamKind, SubscribeOptions,
};

/// Locks `m`, taking the data from a poisoned lock (a panic elsewhere must not stop the audio side).
pub(crate) fn lock<T>(m: &std::sync::Mutex<T>) -> std::sync::MutexGuard<'_, T> {
    m.lock().unwrap_or_else(|e| e.into_inner())
}