Skip to content

Commit

Permalink
continue on core audio
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jan 14, 2025
1 parent a1484e9 commit 3c9e493
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
17 changes: 17 additions & 0 deletions cidre/src/cf/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ impl<T> arc::Retain for ArrayOf<T> {
}
}

impl<T: arc::Retain> AsRef<Self> for arc::R<ArrayOf<T>> {
fn as_ref(&self) -> &Self {
self
}
}

impl<T: arc::Retain> AsRef<arc::R<ArrayOf<T>>> for arc::R<ArrayOfMut<T>> {
fn as_ref(&self) -> &arc::R<ArrayOf<T>> {
unsafe { std::mem::transmute(self) }
}
}

pub struct ArrayOfIterator<'a, T> {
array: &'a Array,
index: usize,
Expand Down Expand Up @@ -216,6 +228,11 @@ impl<T: Retain> ArrayOfMut<T> {
pub fn push(&mut self, val: &T) {
self.0.push(unsafe { transmute(val) });
}

#[inline]
pub fn copy(&self) -> Option<arc::R<ArrayOf<T>>> {
unsafe { std::mem::transmute(self.0.copy()) }
}
}

impl<T> std::ops::Deref for ArrayOfMut<T> {
Expand Down
33 changes: 30 additions & 3 deletions cidre/src/core_audio/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<cf::DictionaryOf<cf::String, cf::Type>>,
) -> os::Result {
self.set_prop(
&PropSelector::AGGREGATE_DEVICE_COMPOSITION.global_addr(),
&val,
)
}

#[doc(alias = "kAudioAggregateDevicePropertyFullSubDeviceList")]
pub fn full_sub_device_list(&self) -> os::Result<arc::R<cf::ArrayOf<cf::String>>> {
self.cf_prop(&PropSelector::AGGREGATE_DEVICE_FULL_SUB_DEVICE_LIST.global_addr())
Expand All @@ -1377,10 +1388,13 @@ impl AggregateDevice {
}

#[doc(alias = "kAudioAggregateDevicePropertyFullSubDeviceList")]
pub fn set_full_sub_device_list(&mut self, val: arc::R<cf::ArrayOf<cf::String>>) -> os::Result {
pub fn set_full_sub_device_list<V>(&mut self, val: V) -> os::Result
where
V: AsRef<arc::R<cf::ArrayOf<cf::String>>>,
{
self.set_prop(
&PropSelector::AGGREGATE_DEVICE_FULL_SUB_DEVICE_LIST.global_addr(),
&val,
val.as_ref(),
)
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3c9e493

Please # to comment.