interflow/backends/
mod.rs1use crate::{AudioDriver, AudioInputDevice, AudioOutputDevice, DeviceType};
9
10#[cfg(unsupported)]
11compile_error!("Unsupported platform (supports ALSA, CoreAudio, and WASAPI)");
12
13#[cfg(os_alsa)]
14pub mod alsa;
15
16#[cfg(os_coreaudio)]
17pub mod coreaudio;
18
19#[cfg(os_wasapi)]
20pub mod wasapi;
21
22#[cfg(all(os_pipewire, feature = "pipewire"))]
23pub mod pipewire;
24
25#[cfg(any(os_alsa, os_coreaudio, os_wasapi))]
41#[allow(clippy::needless_return)]
42pub fn default_driver() -> impl AudioDriver {
43 #[cfg(all(os_pipewire, feature = "pipewire"))]
44 return pipewire::driver::PipewireDriver::new().unwrap();
45 #[cfg(all(not(all(os_pipewire, feature = "pipewire")), os_alsa))]
46 return alsa::AlsaDriver;
47 #[cfg(os_coreaudio)]
48 return coreaudio::CoreAudioDriver;
49 #[cfg(os_wasapi)]
50 return wasapi::WasapiDriver;
51}
52
53pub fn default_input_device_from<Driver: AudioDriver>(driver: &Driver) -> Driver::Device
57where
58 Driver::Device: AudioInputDevice,
59{
60 driver
61 .default_device(DeviceType::PHYSICAL | DeviceType::INPUT)
62 .expect("Audio driver error")
63 .expect("No default device found")
64}
65
66#[cfg(any(feature = "pipewire", os_alsa, os_coreaudio, os_wasapi))]
72#[allow(clippy::needless_return)]
73pub fn default_input_device() -> impl AudioInputDevice {
74 #[cfg(all(os_pipewire, feature = "pipewire"))]
75 return default_input_device_from(&pipewire::driver::PipewireDriver::new().unwrap());
76 #[cfg(all(not(all(os_pipewire, feature = "pipewire")), os_alsa))]
77 return default_input_device_from(&alsa::AlsaDriver);
78 #[cfg(os_coreaudio)]
79 return default_input_device_from(&coreaudio::CoreAudioDriver);
80 #[cfg(os_wasapi)]
81 return default_input_device_from(&wasapi::WasapiDriver);
82}
83
84pub fn default_output_device_from<Driver: AudioDriver>(driver: &Driver) -> Driver::Device
88where
89 Driver::Device: AudioOutputDevice,
90{
91 driver
92 .default_device(DeviceType::PHYSICAL | DeviceType::OUTPUT)
93 .expect("Audio driver error")
94 .expect("No default device found")
95}
96
97#[cfg(any(os_alsa, os_coreaudio, os_wasapi, feature = "pipewire"))]
103#[allow(clippy::needless_return)]
104pub fn default_output_device() -> impl AudioOutputDevice {
105 #[cfg(all(os_pipewire, feature = "pipewire"))]
106 return default_output_device_from(&pipewire::driver::PipewireDriver::new().unwrap());
107 #[cfg(all(not(all(os_pipewire, feature = "pipewire")), os_alsa))]
108 return default_output_device_from(&alsa::AlsaDriver);
109 #[cfg(os_coreaudio)]
110 return default_output_device_from(&coreaudio::CoreAudioDriver);
111 #[cfg(os_wasapi)]
112 return default_output_device_from(&wasapi::WasapiDriver);
113}