Skip to content

Commit

Permalink
AudioObject prop listener api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Oct 27, 2024
1 parent fd95691 commit 9558a2d
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cidre/src/core_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ mod hardware_base;
pub use hardware_base::*;

mod hardware;
pub use hardware::AudioObjPropListenerBlock;
pub use hardware::AudioObjPropListenerFn;
104 changes: 103 additions & 1 deletion cidre/src/core_audio/hardware.rs
Original file line number Diff line number Diff line change
@@ -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<T = c_void> = 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<fn(number_addresses: u32, addresses: *const AudioObjPropAddr)>;

impl core_audio::AudioObjId {
#[doc(alias = "kAudioObjectSystemObject")]
pub const SYS_OBJECT: Self = Self(1);
Expand Down Expand Up @@ -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<T>(
&self,
address: &AudioObjPropAddr,
listener: &AudioObjPropListenerFn<T>,
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<T>(
&self,
address: &AudioObjPropAddr,
listener: &AudioObjPropListenerFn<T>,
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 {
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 9558a2d

Please sign in to comment.