pub trait CaptureBackend: Send {
// Required methods
fn native_format(&self) -> (u32, u16);
fn start(&mut self, sink: RawSink) -> Result<()>;
fn stop(&mut self);
// Provided methods
fn stop_checked(&mut self) -> Result<()> { ... }
fn poll_event(&mut self) -> Option<Event> { ... }
}Expand description
Trait implemented by OS-specific capture backends.
The facade reads the native format via native_format, configures a
Normalizer, then passes a RawSink to start to begin
capture. The backend calls sink.push(...) from its RT callback.
Pass a custom backend as Box<dyn CaptureBackend> to Stream::open.
Requirements for custom backends:
-
Never panic on the capture thread / RT callback (a panic can silently stop capture).
-
Call
RawSink::pushfrom RT callbacks in an RT-safe way (no allocation, locks, blocking, or system calls; seeRawSink::pushfor details). -
Make
start/stopidempotent: callingstartwhile running returnsOk(())without doing anything; callingstopbefore startup does nothing.
Required Methods§
Sourcefn native_format(&self) -> (u32, u16)
fn native_format(&self) -> (u32, u16)
Backend native format (sample_rate, channels).
Provided Methods§
Sourcefn stop_checked(&mut self) -> Result<()>
fn stop_checked(&mut self) -> Result<()>
Checked stop. External backends retain compatibility, but must override this to expose hidden owner failures.
Sourcefn poll_event(&mut self) -> Option<Event>
fn poll_event(&mut self) -> Option<Event>
Poll a backend notification on the control thread. Confirmed permission
denial and Event::TerminalError are terminal; the stream stops capture
and suppresses recovery.
Return promptly and return None when empty. After stop, final owner
notifications must remain pollable until drained; do not discard denial
when stopping or replacing a capture generation.
Typed error messages must be safe library-authored explanations; OS error text is
allowed, but device names, private environment diagnostics and internal call labels
are not. Legacy Event::Error strings are conservatively terminal and replaced
with a library-authored explanation at the facade boundary.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".