Skip to content

Commit

Permalink
Merge pull request #327 from HEnquist/macos_aggregate_dev
Browse files Browse the repository at this point in the history
Handle the quirks of aggregate devices
  • Loading branch information
HEnquist authored Feb 20, 2024
2 parents 5cfd5f2 + 61e4aa8 commit 76aa55d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v2.0.3
Bugfixes:
- MacOS: Fix using Aggregate devices for playback.

## v2.0.2
Bugfixes:
- MacOS: Fix a segfault when reading clock source names for some capture devices.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "camilladsp"
version = "2.0.2"
version = "2.0.3"
authors = ["Henrik Enquist <[email protected]>"]
edition = "2021"
description = "A flexible tool for processing audio"
Expand Down
24 changes: 15 additions & 9 deletions src/coreaudiodevice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ use coreaudio::audio_unit::macos_helpers::{
};
use coreaudio::audio_unit::render_callback::{self, data};
use coreaudio::audio_unit::{AudioUnit, Element, Scope, StreamFormat};
use coreaudio::error::AudioCodecError;
use coreaudio::error::Error as CoreAudioError;

use coreaudio::sys::*;

use crate::CommandMessage;
Expand Down Expand Up @@ -59,8 +62,12 @@ fn take_ownership(device_id: AudioDeviceID) -> Res<pid_t> {
}

fn release_ownership(device_id: AudioDeviceID) -> Res<()> {
let device_owner_pid =
get_hogging_pid(device_id).map_err(|e| ConfigError::new(&format!("{e}")))?;
let device_owner_pid = match get_hogging_pid(device_id) {
Ok(pid) => pid,
Err(CoreAudioError::AudioCodec(AudioCodecError::UnknownProperty)) => return Ok(()),
Err(err) => return Err(ConfigError::new(&format!("{err}")).into()),
};

let camilla_pid = std::process::id() as pid_t;
if device_owner_pid == camilla_pid {
debug!("Releasing exclusive access.");
Expand Down Expand Up @@ -136,24 +143,23 @@ fn device_supports_scope(device_id: u32, input: bool) -> bool {
mElement: kAudioObjectPropertyElementWildcard,
};

let maybe_bufferlist: mem::MaybeUninit<AudioBufferList> = mem::MaybeUninit::zeroed();
let data_size = mem::size_of::<AudioBufferList>() as u32;

let data_size = 0u32;
let status = unsafe {
AudioObjectGetPropertyData(
AudioObjectGetPropertyDataSize(
device_id,
&property_address as *const _,
0,
null(),
&data_size as *const _ as *mut _,
&maybe_bufferlist as *const _ as *mut _,
)
};
if status != kAudioHardwareNoError as i32 {
return false;
}
let bufferlist = unsafe { maybe_bufferlist.assume_init() };
bufferlist.mNumberBuffers > 0
// This gives the length of the buffer list, there is no need to read the actual list.
let nbr_buffers =
(data_size - mem::size_of::<u32>() as u32) / mem::size_of::<AudioBuffer>() as u32;
nbr_buffers > 0
}

fn open_coreaudio_playback(
Expand Down

0 comments on commit 76aa55d

Please sign in to comment.