moq_audio/lib.rs
1//! Native audio capture, encoding, and decoding for Media over QUIC.
2//!
3//! Counterpart to [`moq-video`](https://crates.io/crates/moq-video) for audio
4//! tracks, and shaped the same way. Sits on top of [`moq_mux`] and [`hang`] and
5//! adds the missing piece for native callers: Rust-native Opus and uncompressed
6//! PCM codecs that turn raw samples into HANG audio tracks and back.
7//!
8//! - `capture` describes an audio source (`capture::Config`) and grabs buffers
9//! per platform: a microphone via cpal (CoreAudio / WASAPI / ALSA) everywhere,
10//! or macOS system audio via ScreenCaptureKit. `capture::Source` picks between
11//! them and `capture::devices` lists the inputs and hands back the ids it
12//! takes. Requires the `capture` feature, so these names are unlinked here:
13//! they don't exist in a default build.
14//! - [`encode`] encodes PCM and publishes it through `moq_mux::container`,
15//! registering the rendition in the `hang` catalog. Two entry points:
16//! - `encode::publish_capture` captures a microphone and publishes it
17//! (turnkey). It encodes strictly on demand: the track and catalog are
18//! advertised up front, but the device opens only while a subscriber is
19//! listening and is released when the last one leaves.
20//! - [`encode::Producer`] publishes PCM you hand it.
21//! - [`decode`] subscribes to an encoded track and decodes it back to PCM.
22//! [`decode::Consumer`] is the mirror of [`encode::Producer`].
23//! - `playback` plays decoded PCM out a speaker. `playback::Engine` owns the
24//! output device and mixes the `playback::Sink`s registered with it, so one
25//! device serves every track in a call. Requires the `playback` feature, so
26//! these names are unlinked here too.
27//! - `aec` keeps the speaker out of the microphone, which is what a conference
28//! on a laptop needs to not send itself back. `playback::Engine::canceller`
29//! builds an `aec::Canceller` from the mix it is playing and
30//! `capture::Config::aec` hands it to the microphone. Requires the `aec`
31//! feature, which implies both of the above.
32//!
33//! [`Format`] mirrors WebCodecs `AudioData.format`; the helpers convert between
34//! any supported layout and the interleaved `f32` representation libopus
35//! expects. [`Frame`] is a thin owned buffer: a timestamp and a payload. PCM
36//! layout lives on the producer / consumer via [`encode::Input`] /
37//! [`decode::Config`], not on each frame, so callers can't drift between calls.
38
39mod error;
40mod format;
41mod frame;
42mod opus;
43mod pcm;
44mod resample;
45
46#[cfg(feature = "aec")]
47pub mod aec;
48#[cfg(feature = "capture")]
49pub mod capture;
50pub mod decode;
51pub mod encode;
52
53#[cfg(feature = "playback")]
54pub mod playback;
55
56pub use error::Error;
57pub use format::Format;
58pub use frame::Frame;
59pub use resample::Resampler;