firewheel_graph/backend.rs
1use core::error::Error;
2
3use firewheel_core::StreamInfo;
4
5use crate::processor::FirewheelProcessor;
6
7/// A trait describing an audio backend.
8///
9/// When an instance is dropped, then it must automatically stop its
10/// corresponding audio stream.
11pub trait AudioBackend: Sized {
12 /// The configuration of the audio stream.
13 type Config;
14 /// An error when starting a new audio stream.
15 type StartStreamError: Error;
16 /// An error that has caused the audio stream to stop.
17 type StreamError: Error;
18
19 /// Return a list of the available input devices.
20 fn available_input_devices() -> Vec<DeviceInfo> {
21 Vec::new()
22 }
23 /// Return a list of the available output devices.
24 fn available_output_devices() -> Vec<DeviceInfo> {
25 Vec::new()
26 }
27
28 /// Start the audio stream with the given configuration, and return
29 /// a handle for the audio stream.
30 fn start_stream(config: Self::Config) -> Result<(Self, StreamInfo), Self::StartStreamError>;
31
32 /// Send the given processor to the audio thread for processing.
33 ///
34 /// This is called once after a successful call to `start_stream`.
35 fn set_processor(&mut self, processor: FirewheelProcessor);
36
37 /// Poll the status of the running audio stream. Return an error if the
38 /// audio stream has stopped for any reason.
39 fn poll_status(&mut self) -> Result<(), Self::StreamError>;
40}
41
42/// Information about an audio device.
43#[derive(Debug, Clone, PartialEq)]
44pub struct DeviceInfo {
45 pub name: String,
46 pub num_channels: u16,
47 pub is_default: bool,
48}