Skip to main content

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//!
24//! [`Format`] mirrors WebCodecs `AudioData.format`; the helpers convert between
25//! any supported layout and the interleaved `f32` representation libopus
26//! expects. [`Frame`] is a thin owned buffer: a timestamp and a payload. PCM
27//! layout lives on the producer / consumer via [`encode::Input`] /
28//! [`decode::Config`], not on each frame, so callers can't drift between calls.
29
30mod error;
31mod format;
32mod frame;
33mod opus;
34mod pcm;
35mod resample;
36
37#[cfg(feature = "capture")]
38pub mod capture;
39pub mod decode;
40pub mod encode;
41
42pub use error::Error;
43pub use format::Format;
44pub use frame::Frame;
45pub use resample::Resampler;