diff --git a/cidre/src/core_audio.rs b/cidre/src/core_audio.rs index 82912476..cd598b7f 100644 --- a/cidre/src/core_audio.rs +++ b/cidre/src/core_audio.rs @@ -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; diff --git a/cidre/src/core_audio/hardware_tapping.rs b/cidre/src/core_audio/hardware_tapping.rs index 47d532ef..ac182a14 100644 --- a/cidre/src/core_audio/hardware_tapping.rs +++ b/cidre/src/core_audio/hardware_tapping.rs @@ -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"); } } @@ -48,11 +58,11 @@ impl Tap { } impl TapDesc { - pub fn create_process_tap(&self) -> os::Result { + pub fn create_process_tap(&self) -> os::Result { 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()))) } } }