Skip to content

Commit

Permalink
Tune core audio Tap api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 26, 2024
1 parent ff8bf1e commit b467414
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cidre/src/core_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ pub use tap_description::TapMuteBehavior;

#[cfg(feature = "macos_14_2")]
pub mod hardware_tapping;
#[cfg(feature = "macos_14_2")]
pub use hardware_tapping::Tap;
#[cfg(feature = "macos_14_2")]
pub use hardware_tapping::TapGuard;
18 changes: 14 additions & 4 deletions cidre/src/core_audio/hardware_tapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ use crate::{
#[repr(transparent)]
pub struct Tap(Obj);

impl Drop for Tap {
pub struct TapGuard(Tap);

impl std::ops::Deref for TapGuard {
type Target = Tap;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl Drop for TapGuard {
fn drop(&mut self) {
let res = unsafe { AudioHardwareDestroyProcessTap(self.0) };
let res = unsafe { AudioHardwareDestroyProcessTap(self.0 .0) };
debug_assert!(res.is_ok(), "Failed to destroy process tap");
}
}
Expand Down Expand Up @@ -48,11 +58,11 @@ impl Tap {
}

impl TapDesc {
pub fn create_process_tap(&self) -> os::Result<Tap> {
pub fn create_process_tap(&self) -> os::Result<TapGuard> {
let mut res = std::mem::MaybeUninit::uninit();
unsafe {
AudioHardwareCreateProcessTap(self, res.as_mut_ptr()).result()?;
Ok(Tap(res.assume_init()))
Ok(TapGuard(Tap(res.assume_init())))
}
}
}
Expand Down

0 comments on commit b467414

Please # to comment.