in src/backend/mod.rs [1217:1270]
fn create_audiounit(device: &device_info) -> Result<AudioUnit> {
assert!(device
.flags
.intersects(device_flags::DEV_INPUT | device_flags::DEV_OUTPUT));
assert!(!device
.flags
.contains(device_flags::DEV_INPUT | device_flags::DEV_OUTPUT));
debug_assert_running_serially();
let unit = create_blank_audiounit()?;
let mut bus = AU_OUT_BUS;
if device.flags.contains(device_flags::DEV_INPUT) {
// Input only.
if let Err(e) = enable_audiounit_scope(unit, DeviceType::INPUT, true) {
cubeb_log!("Failed to enable audiounit input scope. Error: {}", e);
dispose_audio_unit(unit);
return Err(Error::error());
}
if let Err(e) = enable_audiounit_scope(unit, DeviceType::OUTPUT, false) {
cubeb_log!("Failed to disable audiounit output scope. Error: {}", e);
dispose_audio_unit(unit);
return Err(Error::error());
}
bus = AU_IN_BUS;
}
if device.flags.contains(device_flags::DEV_OUTPUT) {
// Output only.
if let Err(e) = enable_audiounit_scope(unit, DeviceType::OUTPUT, true) {
cubeb_log!("Failed to enable audiounit output scope. Error: {}", e);
dispose_audio_unit(unit);
return Err(Error::error());
}
if let Err(e) = enable_audiounit_scope(unit, DeviceType::INPUT, false) {
cubeb_log!("Failed to disable audiounit input scope. Error: {}", e);
dispose_audio_unit(unit);
return Err(Error::error());
}
bus = AU_OUT_BUS;
}
if let Err(e) = set_device_to_audiounit(unit, device.id, bus) {
cubeb_log!(
"Failed to set device {} to the created audiounit. Error: {}",
device.id,
e
);
dispose_audio_unit(unit);
return Err(Error::error());
}
Ok(unit)
}