This commit is contained in:
Paul Adenot 2023-11-22 09:38:13 +01:00
Родитель 49a0c42094
Коммит 347af0022f
2 изменённых файлов: 2 добавлений и 47 удалений

Просмотреть файл

@ -2,8 +2,8 @@ use super::utils::{
test_audiounit_get_buffer_frame_size, test_audiounit_scope_is_enabled, test_create_audiounit,
test_device_channels_in_scope, test_device_in_scope, test_get_all_devices,
test_get_default_audiounit, test_get_default_device, test_get_default_raw_stream,
test_get_devices_in_scope, test_get_raw_context, test_get_source_name, ComponentSubType,
DeviceFilter, PropertyScope, Scope,
test_get_devices_in_scope, test_get_raw_context, ComponentSubType, DeviceFilter, PropertyScope,
Scope,
};
use super::*;

Просмотреть файл

@ -211,51 +211,6 @@ fn test_enable_audiounit_in_scope(
}
}
pub fn test_get_source_name(device: AudioObjectID, scope: Scope) -> Option<String> {
test_get_source_data(device, scope).map(u32_to_string)
}
pub fn test_get_source_data(device: AudioObjectID, scope: Scope) -> Option<u32> {
let address = AudioObjectPropertyAddress {
mSelector: kAudioDevicePropertyDataSource,
mScope: match scope {
Scope::Input => kAudioDevicePropertyScopeInput,
Scope::Output => kAudioDevicePropertyScopeOutput,
},
mElement: kAudioObjectPropertyElementMaster,
};
let mut size = mem::size_of::<u32>();
let mut data: u32 = 0;
let status = unsafe {
AudioObjectGetPropertyData(
device,
&address,
0,
ptr::null(),
&mut size as *mut usize as *mut u32,
&mut data as *mut u32 as *mut c_void,
)
};
// TODO: Can data be 0 when no error returns ?
if status == NO_ERR && data > 0 {
Some(data)
} else {
None
}
}
fn u32_to_string(data: u32) -> String {
// Reverse 0xWXYZ into 0xZYXW.
let mut buffer = [b'\x00'; 4]; // 4 bytes for u32.
buffer[0] = (data >> 24) as u8;
buffer[1] = (data >> 16) as u8;
buffer[2] = (data >> 8) as u8;
buffer[3] = (data) as u8;
String::from_utf8_lossy(&buffer).to_string()
}
pub enum DeviceFilter {
ExcludeCubebAggregateAndVPIO,
IncludeAll,