Skip to main content

Crate moq_audio

Crate moq_audio 

Source
Expand description

Native audio capture, encoding, and decoding for Media over QUIC.

Counterpart to moq-video for audio tracks, and shaped the same way. Sits on top of [moq_mux] and [hang] and adds the missing piece for native callers: Rust-native Opus and uncompressed PCM codecs that turn raw samples into HANG audio tracks and back, plus AAC-LC, which is what the gateways (RTMP, SRT, HLS, gstreamer) publish. AAC decodes in software and encodes only through a platform encoder.

  • capture describes an audio source (capture::Config) and grabs buffers per platform: a microphone via cpal (CoreAudio / WASAPI / ALSA) everywhere, or macOS system audio via ScreenCaptureKit. capture::Source picks between them and capture::devices lists the inputs and hands back the ids it takes. Open capture::Producer once, give each bus or encoder a consumer, and drive its run alongside them. Requires the capture feature: they don’t exist in a default build.
  • encode encodes PCM and publishes it through moq_mux::container, registering the rendition in the hang catalog. Two entry points:
    • encode::publish_capture publishes an already-open capture consumer, returning a Publication that reports its state and level, and the Driver that encodes. Its rendition is registered before processing samples. Capture keeps running while raw audio waits for a subscriber, then encodes that history and continues live. Set encode::Capture::retain to false to encode continuously instead.
    • encode::Producer publishes PCM you hand it.
  • decode subscribes to an encoded track and decodes it back to PCM. decode::Consumer is the mirror of encode::Producer. It reads AAC-LC too, since a broadcast that came in through a gateway is AAC rather than one of the codecs we encode in software.
  • playback plays decoded PCM out a speaker. playback::Engine owns the output device and mixes the playback::Sinks registered with it, so one device serves every track in a call. Requires the playback feature, so these names are unlinked here too.
  • bus mixes any number of PCM sources, each with its own gain, mute, pan, sync delay, and meter, into several mixes advanced on the caller’s own clock: a studio’s program audio and its return feeds.
  • aec keeps the speaker out of the microphone, which is what a conference on a laptop needs to not send itself back. aec::Processor processes PCM supplied by any audio stack without enabling device features. With both capture and playback, playback::Engine::canceller wires it to capture::Config::aec.

Format mirrors WebCodecs AudioData.format; the helpers convert between any supported layout and the interleaved f32 representation libopus expects. Frame is a thin owned buffer: a timestamp, a payload, and the Activity it was decoded from, which is how a caller tells coded audio from the frames an Opus sender withholds while its input is silent. PCM layout lives on the producer / consumer via encode::Input / decode::Output, not on each frame, so callers can’t drift between calls.

Modules§

aec
Acoustic echo cancellation: keep the speaker out of the microphone.
bus
Route PCM sources into several mixes, advanced on the caller’s clock.
capture
Audio capture: a microphone via cpal (pure-Rust: CoreAudio / WASAPI / ALSA), or macOS system audio via ScreenCaptureKit.
decode
Subscribe to an encoded audio track and decode it to raw PCM.
encode
Encode raw PCM and publish it as a moq audio track.
playback
Play decoded PCM out a speaker, via cpal (CoreAudio / WASAPI / ALSA).

Structs§

Frame
One unit of raw PCM crossing the codec boundary: what encode::Producer::write takes and what decode::Read::Frame carries.
Level
How loud a stretch of audio was, for drawing a meter.

Enums§

Activity
Whether a packet carried coded audio, or none at all.
Error
Errors returned by moq-audio.
Format
Raw PCM sample format.
Layout
Speaker meaning and interleaving order for PCM channels.