Update asio-sys to allow for having multiple handles to the same driver

ASIO has a limitation where it only supports loading a single audio
driver at a time. This fixes a common error where CPAL users would
request both the default input device and output device in separate
`load_driver` calls. Now, `load_driver` will return another handle to
the existing driver if the existing driver has the same name.
This commit is contained in:
mitchmindtree 2019-07-01 16:13:14 +02:00
parent 8b4ebeffff
commit c432f2b18d
2 changed files with 130 additions and 69 deletions

View file

@ -20,8 +20,6 @@ use super::sys;
pub struct Device {
/// The drivers for this device
pub driver: Arc<sys::Driver>,
/// The name of this device
pub name: String,
}
/// All available devices
@ -32,7 +30,7 @@ pub struct Devices {
impl PartialEq for Device {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
self.driver.name() == other.driver.name()
}
}
@ -40,13 +38,13 @@ impl Eq for Device {}
impl Hash for Device {
fn hash<H: Hasher>(&self, state: &mut H) {
self.name.hash(state);
self.driver.name().hash(state);
}
}
impl Device {
pub fn name(&self) -> Result<String, DeviceNameError> {
Ok(self.name.clone())
Ok(self.driver.name().to_string())
}
/// Gets the supported input formats.
@ -148,7 +146,7 @@ impl Iterator for Devices {
loop {
match self.drivers.next() {
Some(name) => match self.asio.load_driver(&name) {
Ok(driver) => return Some(Device { driver: Arc::new(driver), name }),
Ok(driver) => return Some(Device { driver: Arc::new(driver) }),
Err(_) => continue,
}
None => return None,