Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **CoreAudio**: Timestamp accuracy.
- **CoreAudio**: Segfaults when enumerating devices.
- **CoreAudio**: Undefined behavior related to null pointers and aligned reads.
- **CoreAudio**: Unnecessary microphone permission requests when using output devices only.
- **iOS**: Example by properly activating audio session.

### Removed
Expand Down
19 changes: 9 additions & 10 deletions src/host/coreaudio/macos/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn set_sample_rate(
}

fn audio_unit_from_device(device: &Device, input: bool) -> Result<AudioUnit, coreaudio::Error> {
let output_type = if is_default_device(device) && !input {
let output_type = if !input && is_default_output_device(device) {
coreaudio::audio_unit::IOType::DefaultOutput
} else {
coreaudio::audio_unit::IOType::HalOutput
Expand Down Expand Up @@ -342,13 +342,12 @@ pub struct Device {
pub(crate) audio_device_id: AudioDeviceID,
}

pub fn is_default_device(device: &Device) -> bool {
default_input_device()
.map(|d| d.audio_device_id == device.audio_device_id)
.unwrap_or(false)
|| default_output_device()
.map(|d| d.audio_device_id == device.audio_device_id)
.unwrap_or(false)
fn is_default_input_device(device: &Device) -> bool {
default_input_device().is_some_and(|d| d.audio_device_id == device.audio_device_id)
}

fn is_default_output_device(device: &Device) -> bool {
default_output_device().is_some_and(|d| d.audio_device_id == device.audio_device_id)
}

impl Device {
Expand Down Expand Up @@ -811,7 +810,7 @@ impl Device {
})?;

// Create error callback for stream - either dummy or real based on device type
let error_callback_for_stream: super::ErrorCallback = if is_default_device(self) {
let error_callback_for_stream: super::ErrorCallback = if is_default_input_device(self) {
Box::new(|_: StreamError| {})
} else {
let error_callback_clone = error_callback_disconnect.clone();
Expand Down Expand Up @@ -914,7 +913,7 @@ impl Device {
})?;

// Create error callback for stream - either dummy or real based on device type
let error_callback_for_stream: super::ErrorCallback = if is_default_device(self) {
let error_callback_for_stream: super::ErrorCallback = if is_default_output_device(self) {
Box::new(|_: StreamError| {})
} else {
let error_callback_clone = error_callback_disconnect.clone();
Expand Down