Skip to content

Commit

Permalink
Implement device enumeration for WASAPI driver backend
Browse files Browse the repository at this point in the history
  • Loading branch information
geom3trik committed Jul 25, 2024
1 parent a99b773 commit 04e1b68
Show file tree
Hide file tree
Showing 9 changed files with 485 additions and 8 deletions.
129 changes: 129 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ cfg_aliases = "0.2.1"
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd"))'.dependencies]
alsa = "0.9.0"

[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.58.0", features = [
"Win32_Media_Audio",
"Win32_Foundation",
"Win32_Devices_Properties",
"Win32_Media_KernelStreaming",
"Win32_System_Com_StructuredStorage",
"Win32_System_Threading",
"Win32_Security",
"Win32_System_SystemServices",
"Win32_System_Variant",
"Win32_Media_Multimedia",
"Win32_UI_Shell_PropertiesSystem"
]}

[[example]]
name = "enumerate_alsa"
path = "examples/enumerate_alsa.rs"



3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ fn main() {
// Setup cfg aliases
cfg_aliases! {
os_alsa: { any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd",
target_os = "netbsd") }
target_os = "netbsd") },
os_wasapi: { target_os = "windows" }
}
}
4 changes: 2 additions & 2 deletions examples/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ pub fn enumerate_devices<Driver: AudioDriver>(driver: Driver) -> Result<(), Box<
for device_type in [DeviceType::Input, DeviceType::Output, DeviceType::Duplex] {
eprint!("\t{device_type:?}:\t");
if let Some(device) = driver.default_device(device_type)? {
eprintln!("{}", device.name());
eprintln!("{}", device.name().unwrap());
} else {
eprintln!("None");
}
}

eprintln!("All devices");
for device in driver.list_devices()? {
eprintln!("\t{} ({:?})", device.name(), device.device_type());
eprintln!("\t{} ({:?})", device.name().unwrap(), device.device_type());
}
Ok(())
}
1 change: 1 addition & 0 deletions examples/enumerate_alsa.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(os_alsa)]
use std::error::Error;
use interflow::{AudioDevice, AudioDriver};
use interflow::backends::alsa::AlsaDriver;
Expand Down
8 changes: 4 additions & 4 deletions src/backends/alsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ impl fmt::Debug for AlsaDevice {
impl AudioDevice for AlsaDevice {
type Error = Infallible;

fn name(&self) -> Cow<str> {
Cow::Borrowed(self.name.as_str())
fn name(&self) -> Option<Cow<str>> {
Some(Cow::Borrowed(self.name.as_str()))
}

fn device_type(&self) -> DeviceType {
Expand Down Expand Up @@ -146,15 +146,15 @@ mod tests {
for device_type in [DeviceType::Input, DeviceType::Output, DeviceType::Duplex] {
eprint!("\t{device_type:?}:\t");
if let Some(device) = driver.default_device(device_type).unwrap() {
eprintln!("{}", device.name());
eprintln!("{}", device.name().unwrap());
} else {
eprintln!("None");
}
}

eprintln!("All devices :");
for device in driver.list_devices().unwrap() {
eprintln!("\t{} ({:?})", device.name(), device.device_type());
eprintln!("\t{} ({:?})", device.name().unwrap(), device.device_type());
}
}
}
3 changes: 3 additions & 0 deletions src/backends/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#[cfg(os_alsa)]
pub mod alsa;

#[cfg(target_os = "windows")]
pub mod wasapi;
Loading

0 comments on commit 04e1b68

Please sign in to comment.