pub trait AudioSource: MaybeSend {
// Required methods
fn format(&self) -> AudioFormat;
fn next_chunk<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<AudioChunk>, AudioError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
A source of audio flowing into a pipeline (device capture, file,
network, or a mock).
Carries MaybeSend like every capability interface: Send on native so a
per-session pump task is spawnable on a multi-threaded executor (a WebRTC
server runs one source per call), vacuous on wasm32 where Send cannot
be satisfied. It is MaybeSend, not MaybeSendSync: next_chunk takes
&mut self, so the future needs to move self, never share it. A
backend whose native handle is !Send (cpal’s Stream) keeps that handle
off the struct — behind a stream-owning thread — rather than leaking
?Send here.
Required Methods§
Sourcefn format(&self) -> AudioFormat
fn format(&self) -> AudioFormat
The format of the chunks this source yields. Fixed for the source’s life.
Sourcefn next_chunk<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<AudioChunk>, AudioError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn next_chunk<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<AudioChunk>, AudioError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Await the next chunk.
Three outcomes, kept distinct so a live device can report failure without being mistaken for a clean end of stream:
Ok(Some(chunk))— a chunk of audio.Ok(None)— the source is gracefully exhausted (e.g. a file or mock ran out); there will be no more chunks.Err(_)— the source failed (e.g. the capture device dropped out).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".