Merge pull request #648 from kaihagseth/fix/follow-default-osx

fix: follow default output source on mac osx
This commit is contained in:
est31 2022-02-28 17:01:57 +01:00 • committed by GitHub
commit 9748543025
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -83,6 +83,7 @@ impl Iterator for Devices {
fn next(&mut self) -> Option<Device> { fn next(&mut self) -> Option<Device> {
self.0.next().map(|id| Device { self.0.next().map(|id| Device {
audio_device_id: id, audio_device_id: id,
is_default: false,
}) })
} }
} }
@ -110,7 +111,10 @@ pub fn default_input_device() -> Option<Device> {
return None; return None;
} }
let device = Device { audio_device_id }; let device = Device {
audio_device_id,
is_default: true,
};
Some(device) Some(device)
} }
@ -137,7 +141,10 @@ pub fn default_output_device() -> Option<Device> {
return None; return None;
} }
let device = Device { audio_device_id }; let device = Device {
audio_device_id,
is_default: true,
};
Some(device) Some(device)
} }

View file

@ -138,6 +138,7 @@ impl DeviceTrait for Device {
#[derive(Clone, PartialEq, Eq)] #[derive(Clone, PartialEq, Eq)]
pub struct Device { pub struct Device {
pub(crate) audio_device_id: AudioDeviceID, pub(crate) audio_device_id: AudioDeviceID,
is_default: bool,
} }
impl Device { impl Device {
@ -421,7 +422,12 @@ struct StreamInner {
} }
fn audio_unit_from_device(device: &Device, input: bool) -> Result<AudioUnit, coreaudio::Error> { fn audio_unit_from_device(device: &Device, input: bool) -> Result<AudioUnit, coreaudio::Error> {
let mut audio_unit = AudioUnit::new(coreaudio::audio_unit::IOType::HalOutput)?; let output_type = if device.is_default && !input {
coreaudio::audio_unit::IOType::DefaultOutput
} else {
coreaudio::audio_unit::IOType::HalOutput
};
let mut audio_unit = AudioUnit::new(output_type)?;
if input { if input {
// Enable input processing. // Enable input processing.