Skip to main content

CaptureBackend

Trait CaptureBackend 

Source
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::push from RT callbacks in an RT-safe way (no allocation, locks, blocking, or system calls; see RawSink::push for details).

  • Make start / stop idempotent: calling start while running returns Ok(()) without doing anything; calling stop before startup does nothing.

Required Methods§

Source

fn native_format(&self) -> (u32, u16)

Backend native format (sample_rate, channels).

Source

fn start(&mut self, sink: RawSink) -> Result<()>

Start sending raw frames to the given sink.

Source

fn stop(&mut self)

Stop capture.

Provided Methods§

Source

fn stop_checked(&mut self) -> Result<()>

Checked stop. External backends retain compatibility, but must override this to expose hidden owner failures.

Source

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".

Implementors§