Skip to main content

weirdnet_streaming/
lib.rs

1//! Streaming for Weirdnet: audio streams between nodes, the transport that keeps them together, and the loop-positioned streams
2//! apps record along with.
3//!
4//! **Streams** (the core, moved here from `weirdnet-audio-stream`)
5//!
6//! * A [`Publisher`] sends [`Frame`]s of one stream to any number of listeners. It never blocks: each listener has its own
7//!   bounded queue and an [`Overflow`] policy, so a slow listener never slows the others.
8//! * A late live listener starts at the next key frame; a [`MemorySource`] holds a recorded stream that listeners can seek in.
9//! * Frames are codec-agnostic: the crate moves bytes and a [`CodecId`] and never decodes. Raw PCM needs no codec
10//!   ([`StreamInfo::pcm_f32`]). Streams and frames carry optional opaque app metadata that the crate never reads.
11//! * [`net`] serves a [`Hub`] of streams over weirdnet-net streams, with an authoriser per subscription, and
12//!   [`net::Subscriber`] connects to one, with [`Stats`] on arrival delay, jitter and loss.
13//! * [`clock`]: another node's clock offset by request and reply, and its drift by a line fit.
14//! * `remote` (feature `route`): a weirdnet-audio-route executor carrying connections between a weirdnet-audio-engine router
15//!   and other nodes, with resampling, drift following and measured delay, and a [`remote::PeerTable`] to tell it where nodes are.
16//!
17//! **Transport**
18//!
19//! * [`transport`]: the follow-transport protocol (`Prepare`, `Ready`, `Start`, `Stop`, `Locate`, `Tempo`, `Beacon`), the
20//!   [`transport::SessionClock`] an instance learns from a master's messages, and the [`transport::Follower`] that turns them
21//!   into engine actions on the right audio block. It is a plain message type: the app chooses how to carry it.
22//!
23//! **Loop-positioned streams (record-along)**
24//!
25//! * [`stage`]: stream and frame metadata saying where on the sender's loop each frame belongs, and [`stage::Grid`] to turn that
26//!   into the listener's own frames at any sample rate.
27//! * [`align`]: where a collaborator's audio plays on your loop (recorded exact, live bar-aligned or immediate).
28//! * [`bus`]: the audio-thread side, a tap and a mix that never lock or allocate in the render callback.
29//! * [`listen`] and [`along`]: the network side, listen-along (a master out as a stream) and record-along (a dry stream and take,
30//!   and playing a collaborator's aligned to your loop).
31//! * [`clocked`]: a manual sink on its own clock, to run without a device or to inject drift in tests.
32#![forbid(unsafe_code)]
33#![warn(missing_docs)]
34
35pub mod align;
36pub mod along;
37pub mod bus;
38pub mod clock;
39pub mod clocked;
40mod hub;
41pub mod listen;
42pub mod net;
43#[cfg(feature = "route")]
44pub mod remote;
45mod source;
46pub mod stage;
47mod stats;
48pub mod transport;
49mod types;
50pub mod wire;
51
52pub use hub::{Listener, ListenerInfo, Publisher};
53pub use net::{AllowAll, Hub, StreamAuth};
54pub use source::{FrameSource, MemorySource, Recording};
55pub use stats::Stats;
56pub use types::{
57    BufferPolicy, CodecId, Frame, Overflow, PCM_F32LE, PCM_S16LE, Start, StreamError, StreamEvent, StreamId, StreamInfo, StreamKind, SubscribeOptions,
58};
59
60/// Locks `m`, taking the data from a poisoned lock (a panic elsewhere must not stop the audio side).
61pub(crate) fn lock<T>(m: &std::sync::Mutex<T>) -> std::sync::MutexGuard<'_, T> {
62    m.lock().unwrap_or_else(|e| e.into_inner())
63}