Skip to content

Commit 9ec3241

Browse files
authored
fix(macos): avoid mic permission for output-only streams (#1070)
1 parent 5236586 commit 9ec3241

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7171
- **CoreAudio**: Timestamp accuracy.
7272
- **CoreAudio**: Segfaults when enumerating devices.
7373
- **CoreAudio**: Undefined behavior related to null pointers and aligned reads.
74+
- **CoreAudio**: Unnecessary microphone permission requests when using output devices only.
7475
- **iOS**: Example by properly activating audio session.
7576

7677
### Removed

src/host/coreaudio/macos/device.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn set_sample_rate(
204204
}
205205

206206
fn audio_unit_from_device(device: &Device, input: bool) -> Result<AudioUnit, coreaudio::Error> {
207-
let output_type = if is_default_device(device) && !input {
207+
let output_type = if !input && is_default_output_device(device) {
208208
coreaudio::audio_unit::IOType::DefaultOutput
209209
} else {
210210
coreaudio::audio_unit::IOType::HalOutput
@@ -342,13 +342,12 @@ pub struct Device {
342342
pub(crate) audio_device_id: AudioDeviceID,
343343
}
344344

345-
pub fn is_default_device(device: &Device) -> bool {
346-
default_input_device()
347-
.map(|d| d.audio_device_id == device.audio_device_id)
348-
.unwrap_or(false)
349-
|| default_output_device()
350-
.map(|d| d.audio_device_id == device.audio_device_id)
351-
.unwrap_or(false)
345+
fn is_default_input_device(device: &Device) -> bool {
346+
default_input_device().is_some_and(|d| d.audio_device_id == device.audio_device_id)
347+
}
348+
349+
fn is_default_output_device(device: &Device) -> bool {
350+
default_output_device().is_some_and(|d| d.audio_device_id == device.audio_device_id)
352351
}
353352

354353
impl Device {
@@ -811,7 +810,7 @@ impl Device {
811810
})?;
812811

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

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

0 commit comments

Comments
 (0)