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 27, 2024
1 parent c62405d commit b3a6671
Show file tree
Hide file tree
Showing 7 changed files with 412 additions and 87 deletions.
141 changes: 59 additions & 82 deletions Cargo.lock

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

20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ 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"

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

3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fn main() {
cfg_aliases! {
wasm: { any(target_os = "wasm32") },
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: 1 addition & 3 deletions examples/enumerate_alsa.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::error::Error;

mod util;

#[cfg(os_alsa)]
fn main() -> Result<(), Box<dyn Error>> {
fn main() -> Result<(), Box<dyn std::error::Error>> {
use crate::util::enumerate::enumerate_devices;
use interflow::backends::alsa::AlsaDriver;
enumerate_devices(AlsaDriver::default())
Expand Down
14 changes: 14 additions & 0 deletions examples/enumerate_wasapi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mod util;

#[cfg(os_wasapi)]
fn main() -> Result<(), Box<dyn std::error::Error>> {
use crate::util::enumerate::enumerate_devices;
use interflow::backends::wasapi::WasapiDriver;
enumerate_devices(WasapiDriver)
}

#[cfg(not(os_wasapi))]
fn main() {
println!("WASAPI driver is not available on this platform");
}

6 changes: 5 additions & 1 deletion src/backends/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{AudioDevice, AudioDriver, AudioInputDevice, AudioOutputCallback, AudioOutputDevice, DeviceType};
use crate::{
AudioDevice, AudioDriver, AudioInputDevice, AudioOutputCallback, AudioOutputDevice, DeviceType,
};

#[cfg(os_alsa)]
pub mod alsa;
Expand Down Expand Up @@ -42,3 +44,5 @@ pub fn default_output_device() -> impl AudioOutputDevice {
#[cfg(os_alsa)]
default_output_device_from(&alsa::AlsaDriver)
}
#[cfg(os_wasapi)]
pub mod wasapi;
Loading

0 comments on commit b3a6671

Please sign in to comment.