diff --git a/cidre/src/cf/array.rs b/cidre/src/cf/array.rs index 5096b0b5..9799085b 100644 --- a/cidre/src/cf/array.rs +++ b/cidre/src/cf/array.rs @@ -147,6 +147,18 @@ impl arc::Retain for ArrayOf { } } +impl AsRef for arc::R> { + fn as_ref(&self) -> &Self { + self + } +} + +impl AsRef>> for arc::R> { + fn as_ref(&self) -> &arc::R> { + unsafe { std::mem::transmute(self) } + } +} + pub struct ArrayOfIterator<'a, T> { array: &'a Array, index: usize, @@ -216,6 +228,11 @@ impl ArrayOfMut { pub fn push(&mut self, val: &T) { self.0.push(unsafe { transmute(val) }); } + + #[inline] + pub fn copy(&self) -> Option>> { + unsafe { std::mem::transmute(self.0.copy()) } + } } impl std::ops::Deref for ArrayOfMut { diff --git a/cidre/src/core_audio/hardware.rs b/cidre/src/core_audio/hardware.rs index cb6d5a0b..f708717a 100644 --- a/cidre/src/core_audio/hardware.rs +++ b/cidre/src/core_audio/hardware.rs @@ -1358,6 +1358,17 @@ impl AggregateDevice { self.cf_prop(&PropSelector::AGGREGATE_DEVICE_COMPOSITION.global_addr()) } + #[doc(alias = "kAudioAggregateDevicePropertyComposition")] + pub fn set_composition( + &mut self, + val: arc::R>, + ) -> os::Result { + self.set_prop( + &PropSelector::AGGREGATE_DEVICE_COMPOSITION.global_addr(), + &val, + ) + } + #[doc(alias = "kAudioAggregateDevicePropertyFullSubDeviceList")] pub fn full_sub_device_list(&self) -> os::Result>> { self.cf_prop(&PropSelector::AGGREGATE_DEVICE_FULL_SUB_DEVICE_LIST.global_addr()) @@ -1377,10 +1388,13 @@ impl AggregateDevice { } #[doc(alias = "kAudioAggregateDevicePropertyFullSubDeviceList")] - pub fn set_full_sub_device_list(&mut self, val: arc::R>) -> os::Result { + pub fn set_full_sub_device_list(&mut self, val: V) -> os::Result + where + V: AsRef>>, + { self.set_prop( &PropSelector::AGGREGATE_DEVICE_FULL_SUB_DEVICE_LIST.global_addr(), - &val, + val.as_ref(), ) } @@ -1580,10 +1594,23 @@ mod tests { agg_device.set_main_sub_device(device_uid.clone()).unwrap(); - // not is list of sub devices + // not is list of sub devices so it should be empty let main_sub_device = agg_device.main_sub_device().unwrap(); assert!(main_sub_device.is_empty()); + let composition = agg_device.composition().unwrap(); + agg_device.set_composition(composition).unwrap(); + + // add subdevice + let sub_devices = agg_device.full_sub_device_list().unwrap(); + let mut sub_devices = sub_devices.copy_mut().unwrap(); + sub_devices.push(&device_uid); + agg_device.set_full_sub_device_list(sub_devices).unwrap(); + + // now we should have main sub device + let main_sub_device = agg_device.main_sub_device().unwrap(); + assert_eq!(&main_sub_device, &device_uid); + extern "C" fn proc( _device: Device, _now: &cat::AudioTimeStamp,