diff --git a/cidre/src/core_audio.rs b/cidre/src/core_audio.rs index c8ff7509..a630dfb5 100644 --- a/cidre/src/core_audio.rs +++ b/cidre/src/core_audio.rs @@ -2,3 +2,5 @@ mod hardware_base; pub use hardware_base::*; mod hardware; +pub use hardware::AudioObjPropListenerBlock; +pub use hardware::AudioObjPropListenerFn; diff --git a/cidre/src/core_audio/hardware.rs b/cidre/src/core_audio/hardware.rs index 13def7fd..36d1b487 100644 --- a/cidre/src/core_audio/hardware.rs +++ b/cidre/src/core_audio/hardware.rs @@ -1,11 +1,23 @@ use std::ffi::c_void; -use crate::{arc, at::AudioBufListN, cf, core_audio, os}; +use crate::{arc, at::AudioBufListN, blocks, cf, core_audio, dispatch, os}; use super::{ AudioObjId, AudioObjPropAddr, AudioObjPropElement, AudioObjPropScope, AudioObjPropSelector, }; +#[doc(alias = "AudioObjectPropertyListenerProc")] +pub type AudioObjPropListenerFn = extern "C-unwind" fn( + obj_id: core_audio::AudioObjId, + number_addresses: u32, + addresses: *const AudioObjPropAddr, + client_data: *mut T, +) -> os::Status; + +#[doc(alias = "AudioObjectPropertyListenerBlock")] +pub type AudioObjPropListenerBlock = + blocks::EscBlock; + impl core_audio::AudioObjId { #[doc(alias = "kAudioObjectSystemObject")] pub const SYS_OBJECT: Self = Self(1); @@ -169,9 +181,71 @@ impl core_audio::AudioObjId { } } + #[doc(alias = "AudioObjectShow")] pub fn show(&self) { unsafe { AudioObjectShow(*self) } } + + #[doc(alias = "AudioObjectAddPropertyListener")] + pub fn add_prop_listener( + &self, + address: &AudioObjPropAddr, + listener: &AudioObjPropListenerFn, + client_data: *mut T, + ) -> os::Result { + unsafe { + AudioObjectAddPropertyListener( + *self, + address, + std::mem::transmute(listener), + client_data.cast(), + ) + .result() + } + } + + #[doc(alias = "AudioObjectRemovePropertyListener")] + pub fn remove_prop_listener( + &self, + address: &AudioObjPropAddr, + listener: &AudioObjPropListenerFn, + client_data: *mut T, + ) -> os::Result { + unsafe { + AudioObjectRemovePropertyListener( + *self, + address, + std::mem::transmute(listener), + client_data.cast(), + ) + .result() + } + } + + #[doc(alias = "AudioObjectAddPropertyListenerBlock")] + pub fn add_prop_listener_block( + &self, + address: &AudioObjPropAddr, + dispatch_queue: Option<&dispatch::Queue>, + listener: &mut AudioObjPropListenerBlock, + ) -> os::Result { + unsafe { + AudioObjectAddPropertyListenerBlock(*self, address, dispatch_queue, listener).result() + } + } + + #[doc(alias = "AudioObjectRemovePropertyListenerBlock")] + pub fn remove_prop_listener_block( + &self, + address: &AudioObjPropAddr, + dispatch_queue: Option<&dispatch::Queue>, + listener: &mut AudioObjPropListenerBlock, + ) -> os::Result { + unsafe { + AudioObjectRemovePropertyListenerBlock(*self, address, dispatch_queue, listener) + .result() + } + } } impl core_audio::AudioObjPropSelector { @@ -740,6 +814,34 @@ extern "C-unwind" { data_size: *mut u32, ) -> os::Status; + fn AudioObjectAddPropertyListener( + objectId: AudioObjId, + address: *const AudioObjPropAddr, + listener: AudioObjPropListenerFn, + client_data: *mut c_void, + ) -> os::Status; + + fn AudioObjectRemovePropertyListener( + objectId: AudioObjId, + address: *const AudioObjPropAddr, + listener: AudioObjPropListenerFn, + client_data: *mut c_void, + ) -> os::Status; + + fn AudioObjectAddPropertyListenerBlock( + objectId: AudioObjId, + address: *const AudioObjPropAddr, + dispatch_queue: Option<&dispatch::Queue>, + listener: *mut AudioObjPropListenerBlock, + ) -> os::Status; + + fn AudioObjectRemovePropertyListenerBlock( + objectId: AudioObjId, + address: *const AudioObjPropAddr, + dispatch_queue: Option<&dispatch::Queue>, + listener: *mut AudioObjPropListenerBlock, + ) -> os::Status; + } #[cfg(test)]