Fix is_aggregate_device and enumerate_devices

This commit is contained in:
Chun-Min Chang 2019-02-12 09:42:45 -08:00
Родитель 719ce7ec4e
Коммит 455608a90f
3 изменённых файлов: 27 добавлений и 6 удалений

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

@ -161,6 +161,7 @@ Currently it can only be built by *rust-nightly* since we use *nightly-only* ato
- *Buffer frame size* within same device may be overwritten (no matter the *AudioUnit*s are different or not) ?
- Check the input `StreamParams` parameters properly, or we will set a invalid format into `AudioUnit`.
- In fact, we should check **all** the parameters properly so we can make sure we don't mess up the streams/devices settings!
- Find a reliable way to verify `enumerate_devices`
## Issues
- Mutex: Find a replacement for [`owned_critical_section`][ocs]

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

@ -921,15 +921,17 @@ fn audiounit_create_blank_aggregate_device(plugin_id: &mut AudioObjectID, aggreg
// TODO: Check if time_id is larger than 0 ?
// assert!(time_id > 0);
let prefix = CString::new(PRIVATE_AGGREGATE_DEVICE_NAME).expect("Fail on creating a cstring as a prefix for an aggregate device");
// let device_name_string = format!("{}_{}", PRIVATE_AGGREGATE_DEVICE_NAME, time_id);
// let aggregate_device_name = cfstringref_from_string(&device_name_string);
let aggregate_device_name = CFStringCreateWithFormat(ptr::null(), ptr::null(), cfstringref_from_static_string("%s_%llx"), CString::new(PRIVATE_AGGREGATE_DEVICE_NAME).expect("Fail on creating an aggregate device name").as_ptr(), time_id);
let aggregate_device_name = CFStringCreateWithFormat(ptr::null(), ptr::null(), cfstringref_from_static_string("%s_%llx"), prefix.as_ptr(), time_id);
CFDictionaryAddValue(aggregate_device_dict, cfstringref_from_static_string(AGGREGATE_DEVICE_NAME_KEY) as *const c_void, aggregate_device_name as *const c_void);
CFRelease(aggregate_device_name as *const c_void);
// let device_uid_string = format!("org.mozilla.{}_{}", PRIVATE_AGGREGATE_DEVICE_NAME, time_id);
// let aggregate_device_UID = cfstringref_from_string(&device_uid_string);
let aggregate_device_UID = CFStringCreateWithFormat(ptr::null(), ptr::null(), cfstringref_from_static_string("org.mozilla.%s_%llx"), CString::new(PRIVATE_AGGREGATE_DEVICE_NAME).expect("Fail on creating an aggregate device uid").as_ptr(), time_id);
let aggregate_device_UID = CFStringCreateWithFormat(ptr::null(), ptr::null(), cfstringref_from_static_string("org.mozilla.%s_%llx"), prefix.as_ptr(), time_id);
CFDictionaryAddValue(aggregate_device_dict, cfstringref_from_static_string(AGGREGATE_DEVICE_UID) as *const c_void, aggregate_device_UID as *const c_void);
CFRelease(aggregate_device_UID as *const c_void);
@ -2571,11 +2573,13 @@ fn audiounit_create_device_from_hwdev(dev_info: &mut ffi::cubeb_device_info, dev
// Is it possible to have a public aggregate device ?
fn is_aggregate_device(device_info: &ffi::cubeb_device_info) -> bool
{
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=dda40d0b40a8d922649521544f260a91
assert!(!device_info.friendly_name.is_null());
let private_name_ptr = CString::new(PRIVATE_AGGREGATE_DEVICE_NAME).expect("Fail on creating a private name").as_ptr();
let private_name = CString::new(PRIVATE_AGGREGATE_DEVICE_NAME)
.expect("Fail on creating a private name");
unsafe {
libc::strncmp(device_info.friendly_name, private_name_ptr,
libc::strlen(private_name_ptr)) == 0
libc::strncmp(device_info.friendly_name, private_name.as_ptr(),
libc::strlen(private_name.as_ptr())) == 0
}
}
@ -2990,6 +2994,9 @@ impl ContextOps for AudioUnitContext {
}
}
// Remove the redundant space, set len to count.
devices.truncate(count);
let coll = unsafe { &mut *collection.as_ptr() };
if count > 0 {
let (ptr, len) = leak_vec(devices);

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

@ -5276,7 +5276,20 @@ fn test_create_device_from_hwdev_output() {
// is_aggregate_device
// ------------------------------------
// TODO
#[test]
fn test_is_aggregate_device() {
let mut aggregate_name = String::from(PRIVATE_AGGREGATE_DEVICE_NAME);
aggregate_name.push_str("_something");
let aggregate_name_cstring = CString::new(aggregate_name).unwrap();
let mut info = ffi::cubeb_device_info::default();
info.friendly_name = aggregate_name_cstring.as_ptr();
assert!(is_aggregate_device(&info));
let non_aggregate_name_cstring = CString::new("Hello World!").unwrap();
info.friendly_name = non_aggregate_name_cstring.as_ptr();
assert!(!is_aggregate_device(&info));
}
// device_destroy
// ------------------------------------