| 1 |
extern crate itertools; |
| 2 |
|
| 3 |
use self::itertools::iproduct; |
| 4 |
use super::utils::{ |
| 5 |
draining_data_callback, get_devices_info_in_scope, noop_data_callback, state_tracking_cb, |
| 6 |
test_device_channels_in_scope, test_get_default_device, test_ops_context_operation, |
| 7 |
test_ops_stream_operation, test_ops_stream_operation_on_context, Scope, StateCallbackData, |
| 8 |
}; |
| 9 |
use super::*; |
| 10 |
use std::thread; |
| 11 |
|
| 12 |
// Context Operations |
| 13 |
// ------------------------------------------------------------------------------------------------ |
| 14 |
#[test] |
| 15 |
fn test_ops_context_init_and_destroy() { |
| 16 |
test_ops_context_operation("context: init and destroy", |_context_ptr| {}); |
| 17 |
} |
| 18 |
|
| 19 |
#[test] |
| 20 |
fn test_ops_context_backend_id() { |
| 21 |
test_ops_context_operation("context: backend id", |context_ptr| { |
| 22 |
let backend = unsafe { |
| 23 |
let ptr = OPS.get_backend_id.unwrap()(context_ptr); |
| 24 |
CStr::from_ptr(ptr).to_string_lossy().into_owned() |
| 25 |
}; |
| 26 |
assert_eq!(backend, "audiounit-rust"); |
| 27 |
}); |
| 28 |
} |
| 29 |
|
| 30 |
#[test] |
| 31 |
fn test_ops_context_max_channel_count() { |
| 32 |
test_ops_context_operation("context: max channel count", |context_ptr| { |
| 33 |
let output_exists = test_get_default_device(Scope::Output).is_some(); |
| 34 |
let mut max_channel_count = 0; |
| 35 |
let r = unsafe { OPS.get_max_channel_count.unwrap()(context_ptr, &mut max_channel_count) }; |
| 36 |
if output_exists { |
| 37 |
assert_eq!(r, ffi::CUBEB_OK); |
| 38 |
assert_ne!(max_channel_count, 0); |
| 39 |
} else { |
| 40 |
assert_eq!(r, ffi::CUBEB_ERROR); |
| 41 |
assert_eq!(max_channel_count, 0); |
| 42 |
} |
| 43 |
}); |
| 44 |
} |
| 45 |
|
| 46 |
#[test] |
| 47 |
fn test_ops_context_min_latency() { |
| 48 |
test_ops_context_operation("context: min latency", |context_ptr| { |
| 49 |
let output_exists = test_get_default_device(Scope::Output).is_some(); |
| 50 |
let params = ffi::cubeb_stream_params::default(); |
| 51 |
let mut latency = u32::max_value(); |
| 52 |
let r = unsafe { OPS.get_min_latency.unwrap()(context_ptr, params, &mut latency) }; |
| 53 |
if output_exists { |
| 54 |
assert_eq!(r, ffi::CUBEB_OK); |
| 55 |
assert!(latency >= SAFE_MIN_LATENCY_FRAMES); |
| 56 |
assert!(SAFE_MAX_LATENCY_FRAMES >= latency); |
| 57 |
} else { |
| 58 |
assert_eq!(r, ffi::CUBEB_ERROR); |
| 59 |
assert_eq!(latency, u32::max_value()); |
| 60 |
} |
| 61 |
}); |
| 62 |
} |
| 63 |
|
| 64 |
#[test] |
| 65 |
fn test_ops_context_preferred_sample_rate() { |
| 66 |
test_ops_context_operation("context: preferred sample rate", |context_ptr| { |
| 67 |
let output_exists = test_get_default_device(Scope::Output).is_some(); |
| 68 |
let mut rate = u32::max_value(); |
| 69 |
let r = unsafe { OPS.get_preferred_sample_rate.unwrap()(context_ptr, &mut rate) }; |
| 70 |
if output_exists { |
| 71 |
assert_eq!(r, ffi::CUBEB_OK); |
| 72 |
assert_ne!(rate, u32::max_value()); |
| 73 |
assert_ne!(rate, 0); |
| 74 |
} else { |
| 75 |
assert_eq!(r, ffi::CUBEB_ERROR); |
| 76 |
assert_eq!(rate, u32::max_value()); |
| 77 |
} |
| 78 |
}); |
| 79 |
} |
| 80 |
|
| 81 |
#[test] |
| 82 |
fn test_ops_context_supported_input_processing_params() { |
| 83 |
test_ops_context_operation( |
| 84 |
"context: supported input processing params", |
| 85 |
|context_ptr| { |
| 86 |
let mut params = ffi::CUBEB_INPUT_PROCESSING_PARAM_NONE; |
| 87 |
let r = unsafe { |
| 88 |
OPS.get_supported_input_processing_params.unwrap()(context_ptr, &mut params) |
| 89 |
}; |
| 90 |
assert_eq!(r, ffi::CUBEB_OK); |
| 91 |
assert_eq!( |
| 92 |
params, |
| 93 |
ffi::CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION |
| 94 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION |
| 95 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_AUTOMATIC_GAIN_CONTROL |
| 96 |
); |
| 97 |
}, |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
#[test] |
| 102 |
fn test_ops_context_enumerate_devices_unknown() { |
| 103 |
test_ops_context_operation("context: enumerate devices (unknown)", |context_ptr| { |
| 104 |
let mut coll = ffi::cubeb_device_collection { |
| 105 |
device: ptr::null_mut(), |
| 106 |
count: 0, |
| 107 |
}; |
| 108 |
assert_eq!( |
| 109 |
unsafe { |
| 110 |
OPS.enumerate_devices.unwrap()( |
| 111 |
context_ptr, |
| 112 |
ffi::CUBEB_DEVICE_TYPE_UNKNOWN, |
| 113 |
&mut coll, |
| 114 |
) |
| 115 |
}, |
| 116 |
ffi::CUBEB_OK |
| 117 |
); |
| 118 |
assert_eq!(coll.count, 0); |
| 119 |
assert_eq!(coll.device, ptr::null_mut()); |
| 120 |
assert_eq!( |
| 121 |
unsafe { OPS.device_collection_destroy.unwrap()(context_ptr, &mut coll) }, |
| 122 |
ffi::CUBEB_OK |
| 123 |
); |
| 124 |
assert_eq!(coll.count, 0); |
| 125 |
assert_eq!(coll.device, ptr::null_mut()); |
| 126 |
}); |
| 127 |
} |
| 128 |
|
| 129 |
#[test] |
| 130 |
fn test_ops_context_enumerate_devices_input() { |
| 131 |
test_ops_context_operation("context: enumerate devices (input)", |context_ptr| { |
| 132 |
let having_input = test_get_default_device(Scope::Input).is_some(); |
| 133 |
let mut coll = ffi::cubeb_device_collection { |
| 134 |
device: ptr::null_mut(), |
| 135 |
count: 0, |
| 136 |
}; |
| 137 |
assert_eq!( |
| 138 |
unsafe { |
| 139 |
OPS.enumerate_devices.unwrap()(context_ptr, ffi::CUBEB_DEVICE_TYPE_INPUT, &mut coll) |
| 140 |
}, |
| 141 |
ffi::CUBEB_OK |
| 142 |
); |
| 143 |
if having_input { |
| 144 |
assert_ne!(coll.count, 0); |
| 145 |
assert_ne!(coll.device, ptr::null_mut()); |
| 146 |
} else { |
| 147 |
assert_eq!(coll.count, 0); |
| 148 |
assert_eq!(coll.device, ptr::null_mut()); |
| 149 |
} |
| 150 |
assert_eq!( |
| 151 |
unsafe { OPS.device_collection_destroy.unwrap()(context_ptr, &mut coll) }, |
| 152 |
ffi::CUBEB_OK |
| 153 |
); |
| 154 |
assert_eq!(coll.count, 0); |
| 155 |
assert_eq!(coll.device, ptr::null_mut()); |
| 156 |
}); |
| 157 |
} |
| 158 |
|
| 159 |
#[test] |
| 160 |
fn test_ops_context_enumerate_devices_output() { |
| 161 |
test_ops_context_operation("context: enumerate devices (output)", |context_ptr| { |
| 162 |
let output_exists = test_get_default_device(Scope::Output).is_some(); |
| 163 |
let mut coll = ffi::cubeb_device_collection { |
| 164 |
device: ptr::null_mut(), |
| 165 |
count: 0, |
| 166 |
}; |
| 167 |
assert_eq!( |
| 168 |
unsafe { |
| 169 |
OPS.enumerate_devices.unwrap()( |
| 170 |
context_ptr, |
| 171 |
ffi::CUBEB_DEVICE_TYPE_OUTPUT, |
| 172 |
&mut coll, |
| 173 |
) |
| 174 |
}, |
| 175 |
ffi::CUBEB_OK |
| 176 |
); |
| 177 |
if output_exists { |
| 178 |
assert_ne!(coll.count, 0); |
| 179 |
assert_ne!(coll.device, ptr::null_mut()); |
| 180 |
} else { |
| 181 |
assert_eq!(coll.count, 0); |
| 182 |
assert_eq!(coll.device, ptr::null_mut()); |
| 183 |
} |
| 184 |
assert_eq!( |
| 185 |
unsafe { OPS.device_collection_destroy.unwrap()(context_ptr, &mut coll) }, |
| 186 |
ffi::CUBEB_OK |
| 187 |
); |
| 188 |
assert_eq!(coll.count, 0); |
| 189 |
assert_eq!(coll.device, ptr::null_mut()); |
| 190 |
}); |
| 191 |
} |
| 192 |
|
| 193 |
#[test] |
| 194 |
fn test_ops_context_device_collection_destroy() { |
| 195 |
// Destroy a dummy device collection, without calling enumerate_devices to allocate memory for the device collection |
| 196 |
test_ops_context_operation("context: device collection destroy", |context_ptr| { |
| 197 |
let mut coll = ffi::cubeb_device_collection { |
| 198 |
device: ptr::null_mut(), |
| 199 |
count: 0, |
| 200 |
}; |
| 201 |
assert_eq!( |
| 202 |
unsafe { OPS.device_collection_destroy.unwrap()(context_ptr, &mut coll) }, |
| 203 |
ffi::CUBEB_OK |
| 204 |
); |
| 205 |
assert_eq!(coll.device, ptr::null_mut()); |
| 206 |
assert_eq!(coll.count, 0); |
| 207 |
}); |
| 208 |
} |
| 209 |
|
| 210 |
#[test] |
| 211 |
fn test_ops_context_register_device_collection_changed_unknown() { |
| 212 |
test_ops_context_operation( |
| 213 |
"context: register device collection changed (unknown)", |
| 214 |
|context_ptr| { |
| 215 |
assert_eq!( |
| 216 |
unsafe { |
| 217 |
OPS.register_device_collection_changed.unwrap()( |
| 218 |
context_ptr, |
| 219 |
ffi::CUBEB_DEVICE_TYPE_UNKNOWN, |
| 220 |
None, |
| 221 |
ptr::null_mut(), |
| 222 |
) |
| 223 |
}, |
| 224 |
ffi::CUBEB_ERROR_INVALID_PARAMETER |
| 225 |
); |
| 226 |
}, |
| 227 |
); |
| 228 |
} |
| 229 |
|
| 230 |
#[test] |
| 231 |
fn test_ops_context_register_device_collection_changed_twice_input() { |
| 232 |
test_ops_context_register_device_collection_changed_twice(ffi::CUBEB_DEVICE_TYPE_INPUT); |
| 233 |
} |
| 234 |
|
| 235 |
#[test] |
| 236 |
fn test_ops_context_register_device_collection_changed_twice_output() { |
| 237 |
test_ops_context_register_device_collection_changed_twice(ffi::CUBEB_DEVICE_TYPE_OUTPUT); |
| 238 |
} |
| 239 |
|
| 240 |
#[test] |
| 241 |
fn test_ops_context_register_device_collection_changed_twice_inout() { |
| 242 |
test_ops_context_register_device_collection_changed_twice( |
| 243 |
ffi::CUBEB_DEVICE_TYPE_INPUT | ffi::CUBEB_DEVICE_TYPE_OUTPUT, |
| 244 |
); |
| 245 |
} |
| 246 |
|
| 247 |
fn test_ops_context_register_device_collection_changed_twice(devtype: u32) { |
| 248 |
extern "C" fn callback(_: *mut ffi::cubeb, _: *mut c_void) {} |
| 249 |
let label_input: &'static str = "context: register device collection changed twice (input)"; |
| 250 |
let label_output: &'static str = "context: register device collection changed twice (output)"; |
| 251 |
let label_inout: &'static str = "context: register device collection changed twice (inout)"; |
| 252 |
let label = if devtype == ffi::CUBEB_DEVICE_TYPE_INPUT { |
| 253 |
label_input |
| 254 |
} else if devtype == ffi::CUBEB_DEVICE_TYPE_OUTPUT { |
| 255 |
label_output |
| 256 |
} else if devtype == ffi::CUBEB_DEVICE_TYPE_INPUT | ffi::CUBEB_DEVICE_TYPE_OUTPUT { |
| 257 |
label_inout |
| 258 |
} else { |
| 259 |
return; |
| 260 |
}; |
| 261 |
|
| 262 |
test_ops_context_operation(label, |context_ptr| { |
| 263 |
// Register a callback within the defined scope. |
| 264 |
assert_eq!( |
| 265 |
unsafe { |
| 266 |
OPS.register_device_collection_changed.unwrap()( |
| 267 |
context_ptr, |
| 268 |
devtype, |
| 269 |
Some(callback), |
| 270 |
ptr::null_mut(), |
| 271 |
) |
| 272 |
}, |
| 273 |
ffi::CUBEB_OK |
| 274 |
); |
| 275 |
|
| 276 |
assert_eq!( |
| 277 |
unsafe { |
| 278 |
OPS.register_device_collection_changed.unwrap()( |
| 279 |
context_ptr, |
| 280 |
devtype, |
| 281 |
Some(callback), |
| 282 |
ptr::null_mut(), |
| 283 |
) |
| 284 |
}, |
| 285 |
ffi::CUBEB_ERROR_INVALID_PARAMETER |
| 286 |
); |
| 287 |
// Unregister |
| 288 |
assert_eq!( |
| 289 |
unsafe { |
| 290 |
OPS.register_device_collection_changed.unwrap()( |
| 291 |
context_ptr, |
| 292 |
devtype, |
| 293 |
None, |
| 294 |
ptr::null_mut(), |
| 295 |
) |
| 296 |
}, |
| 297 |
ffi::CUBEB_OK |
| 298 |
); |
| 299 |
}); |
| 300 |
} |
| 301 |
|
| 302 |
#[test] |
| 303 |
fn test_ops_context_register_device_collection_changed() { |
| 304 |
extern "C" fn callback(_: *mut ffi::cubeb, _: *mut c_void) {} |
| 305 |
test_ops_context_operation( |
| 306 |
"context: register device collection changed", |
| 307 |
|context_ptr| { |
| 308 |
let devtypes: [ffi::cubeb_device_type; 3] = [ |
| 309 |
ffi::CUBEB_DEVICE_TYPE_INPUT, |
| 310 |
ffi::CUBEB_DEVICE_TYPE_OUTPUT, |
| 311 |
ffi::CUBEB_DEVICE_TYPE_INPUT | ffi::CUBEB_DEVICE_TYPE_OUTPUT, |
| 312 |
]; |
| 313 |
|
| 314 |
for devtype in &devtypes { |
| 315 |
// Register a callback in the defined scoped. |
| 316 |
assert_eq!( |
| 317 |
unsafe { |
| 318 |
OPS.register_device_collection_changed.unwrap()( |
| 319 |
context_ptr, |
| 320 |
*devtype, |
| 321 |
Some(callback), |
| 322 |
ptr::null_mut(), |
| 323 |
) |
| 324 |
}, |
| 325 |
ffi::CUBEB_OK |
| 326 |
); |
| 327 |
|
| 328 |
// Unregister all callbacks regardless of the scope. |
| 329 |
assert_eq!( |
| 330 |
unsafe { |
| 331 |
OPS.register_device_collection_changed.unwrap()( |
| 332 |
context_ptr, |
| 333 |
ffi::CUBEB_DEVICE_TYPE_INPUT | ffi::CUBEB_DEVICE_TYPE_OUTPUT, |
| 334 |
None, |
| 335 |
ptr::null_mut(), |
| 336 |
) |
| 337 |
}, |
| 338 |
ffi::CUBEB_OK |
| 339 |
); |
| 340 |
|
| 341 |
// Register callback in the defined scoped again. |
| 342 |
assert_eq!( |
| 343 |
unsafe { |
| 344 |
OPS.register_device_collection_changed.unwrap()( |
| 345 |
context_ptr, |
| 346 |
*devtype, |
| 347 |
Some(callback), |
| 348 |
ptr::null_mut(), |
| 349 |
) |
| 350 |
}, |
| 351 |
ffi::CUBEB_OK |
| 352 |
); |
| 353 |
|
| 354 |
// Unregister callback within the defined scope. |
| 355 |
assert_eq!( |
| 356 |
unsafe { |
| 357 |
OPS.register_device_collection_changed.unwrap()( |
| 358 |
context_ptr, |
| 359 |
*devtype, |
| 360 |
None, |
| 361 |
ptr::null_mut(), |
| 362 |
) |
| 363 |
}, |
| 364 |
ffi::CUBEB_OK |
| 365 |
); |
| 366 |
} |
| 367 |
}, |
| 368 |
); |
| 369 |
} |
| 370 |
|
| 371 |
#[test] |
| 372 |
fn test_ops_context_register_device_collection_changed_with_a_duplex_stream() { |
| 373 |
extern "C" fn callback(_: *mut ffi::cubeb, got_called_ptr: *mut c_void) { |
| 374 |
let got_called = unsafe { &mut *(got_called_ptr as *mut bool) }; |
| 375 |
*got_called = true; |
| 376 |
} |
| 377 |
|
| 378 |
test_ops_context_operation( |
| 379 |
"context: register device collection changed and create a duplex stream", |
| 380 |
|context_ptr| { |
| 381 |
let got_called = Box::new(false); |
| 382 |
let got_called_ptr = Box::into_raw(got_called); |
| 383 |
|
| 384 |
// Register a callback monitoring both input and output device collection. |
| 385 |
assert_eq!( |
| 386 |
unsafe { |
| 387 |
OPS.register_device_collection_changed.unwrap()( |
| 388 |
context_ptr, |
| 389 |
ffi::CUBEB_DEVICE_TYPE_INPUT | ffi::CUBEB_DEVICE_TYPE_OUTPUT, |
| 390 |
Some(callback), |
| 391 |
got_called_ptr as *mut c_void, |
| 392 |
) |
| 393 |
}, |
| 394 |
ffi::CUBEB_OK |
| 395 |
); |
| 396 |
|
| 397 |
// The aggregate device is very likely to be created in the system |
| 398 |
// when creating a duplex stream. We need to make sure it won't trigger |
| 399 |
// the callback. |
| 400 |
test_default_duplex_stream_operation("duplex stream", |_stream| { |
| 401 |
// Do nothing but wait for device-collection change. |
| 402 |
thread::sleep(Duration::from_millis(200)); |
| 403 |
}); |
| 404 |
|
| 405 |
// Unregister the callback. |
| 406 |
assert_eq!( |
| 407 |
unsafe { |
| 408 |
OPS.register_device_collection_changed.unwrap()( |
| 409 |
context_ptr, |
| 410 |
ffi::CUBEB_DEVICE_TYPE_INPUT | ffi::CUBEB_DEVICE_TYPE_OUTPUT, |
| 411 |
None, |
| 412 |
got_called_ptr as *mut c_void, |
| 413 |
) |
| 414 |
}, |
| 415 |
ffi::CUBEB_OK |
| 416 |
); |
| 417 |
|
| 418 |
let got_called = unsafe { Box::from_raw(got_called_ptr) }; |
| 419 |
assert!(!got_called.as_ref()); |
| 420 |
}, |
| 421 |
); |
| 422 |
} |
| 423 |
|
| 424 |
#[test] |
| 425 |
#[ignore] |
| 426 |
fn test_ops_context_register_device_collection_changed_manual() { |
| 427 |
test_ops_context_operation( |
| 428 |
"(manual) context: register device collection changed", |
| 429 |
|context_ptr| { |
| 430 |
println!("context @ {:p}", context_ptr); |
| 431 |
|
| 432 |
struct Data { |
| 433 |
context: *mut ffi::cubeb, |
| 434 |
touched: u32, // TODO: Use AtomicU32 instead |
| 435 |
} |
| 436 |
|
| 437 |
extern "C" fn input_callback(context: *mut ffi::cubeb, user: *mut c_void) { |
| 438 |
println!("input > context @ {:p}", context); |
| 439 |
let data = unsafe { &mut (*(user as *mut Data)) }; |
| 440 |
assert_eq!(context, data.context); |
| 441 |
data.touched += 1; |
| 442 |
} |
| 443 |
|
| 444 |
extern "C" fn output_callback(context: *mut ffi::cubeb, user: *mut c_void) { |
| 445 |
println!("output > context @ {:p}", context); |
| 446 |
let data = unsafe { &mut (*(user as *mut Data)) }; |
| 447 |
assert_eq!(context, data.context); |
| 448 |
data.touched += 1; |
| 449 |
} |
| 450 |
|
| 451 |
let mut data = Data { |
| 452 |
context: context_ptr, |
| 453 |
touched: 0, |
| 454 |
}; |
| 455 |
|
| 456 |
// Register a callback for input scope. |
| 457 |
assert_eq!( |
| 458 |
unsafe { |
| 459 |
OPS.register_device_collection_changed.unwrap()( |
| 460 |
context_ptr, |
| 461 |
ffi::CUBEB_DEVICE_TYPE_INPUT, |
| 462 |
Some(input_callback), |
| 463 |
&mut data as *mut Data as *mut c_void, |
| 464 |
) |
| 465 |
}, |
| 466 |
ffi::CUBEB_OK |
| 467 |
); |
| 468 |
|
| 469 |
// Register a callback for output scope. |
| 470 |
assert_eq!( |
| 471 |
unsafe { |
| 472 |
OPS.register_device_collection_changed.unwrap()( |
| 473 |
context_ptr, |
| 474 |
ffi::CUBEB_DEVICE_TYPE_OUTPUT, |
| 475 |
Some(output_callback), |
| 476 |
&mut data as *mut Data as *mut c_void, |
| 477 |
) |
| 478 |
}, |
| 479 |
ffi::CUBEB_OK |
| 480 |
); |
| 481 |
|
| 482 |
while data.touched < 2 {} |
| 483 |
}, |
| 484 |
); |
| 485 |
} |
| 486 |
|
| 487 |
#[test] |
| 488 |
fn test_ops_context_stream_init_no_stream_params() { |
| 489 |
let name = "context: stream_init with no stream params"; |
| 490 |
test_ops_context_operation(name, |context_ptr| { |
| 491 |
let mut stream: *mut ffi::cubeb_stream = ptr::null_mut(); |
| 492 |
let stream_name = CString::new(name).expect("Failed to create stream name"); |
| 493 |
assert_eq!( |
| 494 |
unsafe { |
| 495 |
OPS.stream_init.unwrap()( |
| 496 |
context_ptr, |
| 497 |
&mut stream, |
| 498 |
stream_name.as_ptr(), |
| 499 |
ptr::null_mut(), // Use default input device. |
| 500 |
ptr::null_mut(), // No input parameters. |
| 501 |
ptr::null_mut(), // Use default output device. |
| 502 |
ptr::null_mut(), // No output parameters. |
| 503 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 504 |
Some(noop_data_callback), |
| 505 |
None, // No state callback. |
| 506 |
ptr::null_mut(), // No user data pointer. |
| 507 |
) |
| 508 |
}, |
| 509 |
ffi::CUBEB_ERROR_INVALID_PARAMETER |
| 510 |
); |
| 511 |
assert!(stream.is_null()); |
| 512 |
}); |
| 513 |
} |
| 514 |
|
| 515 |
#[test] |
| 516 |
fn test_ops_context_stream_init_no_input_stream_params() { |
| 517 |
let name = "context: stream_init with no input stream params"; |
| 518 |
let input_device = test_get_default_device(Scope::Input); |
| 519 |
if input_device.is_none() { |
| 520 |
println!("No input device to perform input tests for \"{}\".", name); |
| 521 |
return; |
| 522 |
} |
| 523 |
test_ops_context_operation(name, |context_ptr| { |
| 524 |
let mut stream: *mut ffi::cubeb_stream = ptr::null_mut(); |
| 525 |
let stream_name = CString::new(name).expect("Failed to create stream name"); |
| 526 |
assert_eq!( |
| 527 |
unsafe { |
| 528 |
OPS.stream_init.unwrap()( |
| 529 |
context_ptr, |
| 530 |
&mut stream, |
| 531 |
stream_name.as_ptr(), |
| 532 |
input_device.unwrap() as ffi::cubeb_devid, |
| 533 |
ptr::null_mut(), // No input parameters. |
| 534 |
ptr::null_mut(), // Use default output device. |
| 535 |
ptr::null_mut(), // No output parameters. |
| 536 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 537 |
Some(noop_data_callback), |
| 538 |
None, // No state callback. |
| 539 |
ptr::null_mut(), // No user data pointer. |
| 540 |
) |
| 541 |
}, |
| 542 |
ffi::CUBEB_ERROR_INVALID_PARAMETER |
| 543 |
); |
| 544 |
assert!(stream.is_null()); |
| 545 |
}); |
| 546 |
} |
| 547 |
|
| 548 |
#[test] |
| 549 |
fn test_ops_context_stream_init_no_output_stream_params() { |
| 550 |
let name = "context: stream_init with no output stream params"; |
| 551 |
let output_device = test_get_default_device(Scope::Output); |
| 552 |
if output_device.is_none() { |
| 553 |
println!("No output device to perform output tests for \"{}\".", name); |
| 554 |
return; |
| 555 |
} |
| 556 |
test_ops_context_operation(name, |context_ptr| { |
| 557 |
let mut stream: *mut ffi::cubeb_stream = ptr::null_mut(); |
| 558 |
let stream_name = CString::new(name).expect("Failed to create stream name"); |
| 559 |
assert_eq!( |
| 560 |
unsafe { |
| 561 |
OPS.stream_init.unwrap()( |
| 562 |
context_ptr, |
| 563 |
&mut stream, |
| 564 |
stream_name.as_ptr(), |
| 565 |
ptr::null_mut(), // Use default input device. |
| 566 |
ptr::null_mut(), // No input parameters. |
| 567 |
output_device.unwrap() as ffi::cubeb_devid, |
| 568 |
ptr::null_mut(), // No output parameters. |
| 569 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 570 |
Some(noop_data_callback), |
| 571 |
None, // No state callback. |
| 572 |
ptr::null_mut(), // No user data pointer. |
| 573 |
) |
| 574 |
}, |
| 575 |
ffi::CUBEB_ERROR_INVALID_PARAMETER |
| 576 |
); |
| 577 |
assert!(stream.is_null()); |
| 578 |
}); |
| 579 |
} |
| 580 |
|
| 581 |
#[test] |
| 582 |
fn test_ops_context_stream_init_no_data_callback() { |
| 583 |
let name = "context: stream_init with no data callback"; |
| 584 |
test_ops_context_operation(name, |context_ptr| { |
| 585 |
let mut stream: *mut ffi::cubeb_stream = ptr::null_mut(); |
| 586 |
let stream_name = CString::new(name).expect("Failed to create stream name"); |
| 587 |
|
| 588 |
let mut output_params = ffi::cubeb_stream_params::default(); |
| 589 |
output_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 590 |
output_params.rate = 44100; |
| 591 |
output_params.channels = 2; |
| 592 |
output_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 593 |
output_params.prefs = ffi::CUBEB_STREAM_PREF_NONE; |
| 594 |
|
| 595 |
assert_eq!( |
| 596 |
unsafe { |
| 597 |
OPS.stream_init.unwrap()( |
| 598 |
context_ptr, |
| 599 |
&mut stream, |
| 600 |
stream_name.as_ptr(), |
| 601 |
ptr::null_mut(), // Use default input device. |
| 602 |
ptr::null_mut(), // No input parameters. |
| 603 |
ptr::null_mut(), // Use default output device. |
| 604 |
&mut output_params, |
| 605 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 606 |
None, // No data callback. |
| 607 |
None, // No state callback. |
| 608 |
ptr::null_mut(), // No user data pointer. |
| 609 |
) |
| 610 |
}, |
| 611 |
ffi::CUBEB_ERROR_INVALID_PARAMETER |
| 612 |
); |
| 613 |
assert!(stream.is_null()); |
| 614 |
}); |
| 615 |
} |
| 616 |
|
| 617 |
#[test] |
| 618 |
fn test_ops_context_stream_init_channel_rate_combinations() { |
| 619 |
let name = "context: stream_init with various channels and rates"; |
| 620 |
test_ops_context_operation(name, |context_ptr| { |
| 621 |
let mut stream: *mut ffi::cubeb_stream = ptr::null_mut(); |
| 622 |
let stream_name = CString::new(name).expect("Failed to create stream name"); |
| 623 |
|
| 624 |
const MAX_NUM_CHANNELS: u32 = 32; |
| 625 |
let channel_values: Vec<u32> = vec![1, 2, 3, 4, 6]; |
| 626 |
let freq_values: Vec<u32> = vec![16000, 24000, 44100, 48000]; |
| 627 |
let is_float_values: Vec<bool> = vec![false, true]; |
| 628 |
|
| 629 |
for (channels, freq, is_float) in iproduct!(channel_values, freq_values, is_float_values) { |
| 630 |
assert!(channels < MAX_NUM_CHANNELS); |
| 631 |
println!("--------------------------"); |
| 632 |
println!( |
| 633 |
"Testing {} channel(s), {} Hz, {}\n", |
| 634 |
channels, |
| 635 |
freq, |
| 636 |
if is_float { "float" } else { "short" } |
| 637 |
); |
| 638 |
|
| 639 |
let mut output_params = ffi::cubeb_stream_params::default(); |
| 640 |
output_params.format = if is_float { |
| 641 |
ffi::CUBEB_SAMPLE_FLOAT32NE |
| 642 |
} else { |
| 643 |
ffi::CUBEB_SAMPLE_S16NE |
| 644 |
}; |
| 645 |
output_params.rate = freq; |
| 646 |
output_params.channels = channels; |
| 647 |
output_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 648 |
output_params.prefs = ffi::CUBEB_STREAM_PREF_NONE; |
| 649 |
|
| 650 |
assert_eq!( |
| 651 |
unsafe { |
| 652 |
OPS.stream_init.unwrap()( |
| 653 |
context_ptr, |
| 654 |
&mut stream, |
| 655 |
stream_name.as_ptr(), |
| 656 |
ptr::null_mut(), // Use default input device. |
| 657 |
ptr::null_mut(), // No input parameters. |
| 658 |
ptr::null_mut(), // Use default output device. |
| 659 |
&mut output_params, |
| 660 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 661 |
Some(noop_data_callback), // No data callback. |
| 662 |
None, // No state callback. |
| 663 |
ptr::null_mut(), // No user data pointer. |
| 664 |
) |
| 665 |
}, |
| 666 |
ffi::CUBEB_OK |
| 667 |
); |
| 668 |
assert!(!stream.is_null()); |
| 669 |
|
| 670 |
unsafe { OPS.stream_destroy.unwrap()(stream) }; |
| 671 |
} |
| 672 |
}); |
| 673 |
} |
| 674 |
|
| 675 |
// Stream Operations |
| 676 |
// ------------------------------------------------------------------------------------------------ |
| 677 |
fn test_default_output_stream_operation_on_context_with_callback<F>( |
| 678 |
name: &'static str, |
| 679 |
context_ptr: *mut ffi::cubeb, |
| 680 |
data_callback: ffi::cubeb_data_callback, |
| 681 |
operation: F, |
| 682 |
) where |
| 683 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 684 |
{ |
| 685 |
// Make sure the parameters meet the requirements of AudioUnitContext::stream_init |
| 686 |
// (in the comments). |
| 687 |
let mut output_params = ffi::cubeb_stream_params::default(); |
| 688 |
output_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 689 |
output_params.rate = 44100; |
| 690 |
output_params.channels = 2; |
| 691 |
output_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 692 |
output_params.prefs = ffi::CUBEB_STREAM_PREF_NONE; |
| 693 |
|
| 694 |
test_ops_stream_operation_on_context( |
| 695 |
name, |
| 696 |
context_ptr, |
| 697 |
ptr::null_mut(), // Use default input device. |
| 698 |
ptr::null_mut(), // No input parameters. |
| 699 |
ptr::null_mut(), // Use default output device. |
| 700 |
&mut output_params, |
| 701 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 702 |
data_callback, |
| 703 |
None, // No state callback. |
| 704 |
ptr::null_mut(), // No user data pointer. |
| 705 |
operation, |
| 706 |
); |
| 707 |
} |
| 708 |
|
| 709 |
fn test_default_output_stream_operation_with_callback<F>( |
| 710 |
name: &'static str, |
| 711 |
data_callback: ffi::cubeb_data_callback, |
| 712 |
operation: F, |
| 713 |
) where |
| 714 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 715 |
{ |
| 716 |
test_ops_context_operation("context: default output stream operation", |context_ptr| { |
| 717 |
test_default_output_stream_operation_on_context_with_callback( |
| 718 |
name, |
| 719 |
context_ptr, |
| 720 |
data_callback, |
| 721 |
operation, |
| 722 |
); |
| 723 |
}); |
| 724 |
} |
| 725 |
|
| 726 |
fn test_default_output_stream_operation<F>(name: &'static str, operation: F) |
| 727 |
where |
| 728 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 729 |
{ |
| 730 |
test_default_output_stream_operation_with_callback(name, Some(noop_data_callback), operation); |
| 731 |
} |
| 732 |
|
| 733 |
fn test_default_duplex_stream_operation_on_context_with_callback<F>( |
| 734 |
name: &'static str, |
| 735 |
context_ptr: *mut ffi::cubeb, |
| 736 |
data_callback: ffi::cubeb_data_callback, |
| 737 |
operation: F, |
| 738 |
) where |
| 739 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 740 |
{ |
| 741 |
// Make sure the parameters meet the requirements of AudioUnitContext::stream_init |
| 742 |
// (in the comments). |
| 743 |
let mut input_params = ffi::cubeb_stream_params::default(); |
| 744 |
input_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 745 |
input_params.rate = 48000; |
| 746 |
input_params.channels = 1; |
| 747 |
input_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 748 |
input_params.prefs = ffi::CUBEB_STREAM_PREF_NONE; |
| 749 |
|
| 750 |
let mut output_params = ffi::cubeb_stream_params::default(); |
| 751 |
output_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 752 |
output_params.rate = 44100; |
| 753 |
output_params.channels = 2; |
| 754 |
output_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 755 |
output_params.prefs = ffi::CUBEB_STREAM_PREF_NONE; |
| 756 |
|
| 757 |
test_ops_stream_operation_on_context( |
| 758 |
name, |
| 759 |
context_ptr, |
| 760 |
ptr::null_mut(), // Use default input device. |
| 761 |
&mut input_params, |
| 762 |
ptr::null_mut(), // Use default output device. |
| 763 |
&mut output_params, |
| 764 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 765 |
data_callback, |
| 766 |
None, // No state callback. |
| 767 |
ptr::null_mut(), // No user data pointer. |
| 768 |
operation, |
| 769 |
); |
| 770 |
} |
| 771 |
|
| 772 |
fn test_default_duplex_stream_operation_with_callback<F>( |
| 773 |
name: &'static str, |
| 774 |
data_callback: ffi::cubeb_data_callback, |
| 775 |
operation: F, |
| 776 |
) where |
| 777 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 778 |
{ |
| 779 |
test_ops_context_operation("context: default duplex stream operation", |context_ptr| { |
| 780 |
test_default_duplex_stream_operation_on_context_with_callback( |
| 781 |
name, |
| 782 |
context_ptr, |
| 783 |
data_callback, |
| 784 |
operation, |
| 785 |
); |
| 786 |
}); |
| 787 |
} |
| 788 |
|
| 789 |
fn test_default_duplex_stream_operation<F>(name: &'static str, operation: F) |
| 790 |
where |
| 791 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 792 |
{ |
| 793 |
test_default_duplex_stream_operation_with_callback(name, Some(noop_data_callback), operation); |
| 794 |
} |
| 795 |
|
| 796 |
fn test_stereo_input_duplex_stream_operation_on_context_with_callback<F>( |
| 797 |
name: &'static str, |
| 798 |
context_ptr: *mut ffi::cubeb, |
| 799 |
data_callback: ffi::cubeb_data_callback, |
| 800 |
operation: F, |
| 801 |
) where |
| 802 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 803 |
{ |
| 804 |
let mut input_devices = get_devices_info_in_scope(Scope::Input); |
| 805 |
input_devices.retain(|d| test_device_channels_in_scope(d.id, Scope::Input).unwrap_or(0) >= 2); |
| 806 |
if input_devices.is_empty() { |
| 807 |
println!("No stereo input device present. Skipping stereo-input test."); |
| 808 |
return; |
| 809 |
} |
| 810 |
|
| 811 |
let mut input_params = ffi::cubeb_stream_params::default(); |
| 812 |
input_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 813 |
input_params.rate = 48000; |
| 814 |
input_params.channels = 2; |
| 815 |
input_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 816 |
input_params.prefs = ffi::CUBEB_STREAM_PREF_NONE; |
| 817 |
|
| 818 |
let mut output_params = ffi::cubeb_stream_params::default(); |
| 819 |
output_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 820 |
output_params.rate = 48000; |
| 821 |
output_params.channels = 2; |
| 822 |
output_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 823 |
output_params.prefs = ffi::CUBEB_STREAM_PREF_NONE; |
| 824 |
|
| 825 |
test_ops_stream_operation_on_context( |
| 826 |
name, |
| 827 |
context_ptr, |
| 828 |
input_devices[0].id as ffi::cubeb_devid, |
| 829 |
&mut input_params, |
| 830 |
ptr::null_mut(), // Use default output device. |
| 831 |
&mut output_params, |
| 832 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 833 |
data_callback, |
| 834 |
None, // No state callback. |
| 835 |
ptr::null_mut(), // No user data pointer. |
| 836 |
operation, |
| 837 |
); |
| 838 |
} |
| 839 |
|
| 840 |
fn test_stereo_input_duplex_stream_operation_with_callback<F>( |
| 841 |
name: &'static str, |
| 842 |
data_callback: ffi::cubeb_data_callback, |
| 843 |
operation: F, |
| 844 |
) where |
| 845 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 846 |
{ |
| 847 |
test_ops_context_operation( |
| 848 |
"context: stereo input duplex stream operation", |
| 849 |
|context_ptr| { |
| 850 |
test_stereo_input_duplex_stream_operation_on_context_with_callback( |
| 851 |
name, |
| 852 |
context_ptr, |
| 853 |
data_callback, |
| 854 |
operation, |
| 855 |
); |
| 856 |
}, |
| 857 |
); |
| 858 |
} |
| 859 |
|
| 860 |
fn test_stereo_input_duplex_stream_operation<F>(name: &'static str, operation: F) |
| 861 |
where |
| 862 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 863 |
{ |
| 864 |
test_stereo_input_duplex_stream_operation_with_callback( |
| 865 |
name, |
| 866 |
Some(noop_data_callback), |
| 867 |
operation, |
| 868 |
); |
| 869 |
} |
| 870 |
|
| 871 |
fn test_default_input_voice_stream_operation_on_context_with_callback<F>( |
| 872 |
name: &'static str, |
| 873 |
context_ptr: *mut ffi::cubeb, |
| 874 |
data_callback: ffi::cubeb_data_callback, |
| 875 |
operation: F, |
| 876 |
) where |
| 877 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 878 |
{ |
| 879 |
// Make sure the parameters meet the requirements of AudioUnitContext::stream_init |
| 880 |
// (in the comments). |
| 881 |
let mut input_params = ffi::cubeb_stream_params::default(); |
| 882 |
input_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 883 |
input_params.rate = 44100; |
| 884 |
input_params.channels = 1; |
| 885 |
input_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 886 |
input_params.prefs = ffi::CUBEB_STREAM_PREF_VOICE; |
| 887 |
|
| 888 |
test_ops_stream_operation_on_context( |
| 889 |
name, |
| 890 |
context_ptr, |
| 891 |
ptr::null_mut(), // Use default input device. |
| 892 |
&mut input_params, |
| 893 |
ptr::null_mut(), // Use default output device. |
| 894 |
ptr::null_mut(), // No output parameters. |
| 895 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 896 |
data_callback, |
| 897 |
None, // No state callback. |
| 898 |
ptr::null_mut(), // No user data pointer. |
| 899 |
operation, |
| 900 |
); |
| 901 |
} |
| 902 |
|
| 903 |
fn test_default_input_voice_stream_operation_on_context<F>( |
| 904 |
name: &'static str, |
| 905 |
context_ptr: *mut ffi::cubeb, |
| 906 |
operation: F, |
| 907 |
) where |
| 908 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 909 |
{ |
| 910 |
test_default_input_voice_stream_operation_on_context_with_callback( |
| 911 |
name, |
| 912 |
context_ptr, |
| 913 |
Some(noop_data_callback), |
| 914 |
operation, |
| 915 |
); |
| 916 |
} |
| 917 |
|
| 918 |
fn test_default_input_voice_stream_operation_with_callback<F>( |
| 919 |
name: &'static str, |
| 920 |
data_callback: ffi::cubeb_data_callback, |
| 921 |
operation: F, |
| 922 |
) where |
| 923 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 924 |
{ |
| 925 |
test_ops_context_operation( |
| 926 |
"context: default input voice stream operation", |
| 927 |
|context_ptr| { |
| 928 |
test_default_input_voice_stream_operation_on_context_with_callback( |
| 929 |
name, |
| 930 |
context_ptr, |
| 931 |
data_callback, |
| 932 |
operation, |
| 933 |
); |
| 934 |
}, |
| 935 |
); |
| 936 |
} |
| 937 |
|
| 938 |
fn test_default_input_voice_stream_operation<F>(name: &'static str, operation: F) |
| 939 |
where |
| 940 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 941 |
{ |
| 942 |
test_default_input_voice_stream_operation_with_callback( |
| 943 |
name, |
| 944 |
Some(noop_data_callback), |
| 945 |
operation, |
| 946 |
); |
| 947 |
} |
| 948 |
|
| 949 |
fn test_default_duplex_voice_stream_operation_on_context_with_callback<F>( |
| 950 |
name: &'static str, |
| 951 |
context_ptr: *mut ffi::cubeb, |
| 952 |
data_callback: ffi::cubeb_data_callback, |
| 953 |
operation: F, |
| 954 |
) where |
| 955 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 956 |
{ |
| 957 |
// Make sure the parameters meet the requirements of AudioUnitContext::stream_init |
| 958 |
// (in the comments). |
| 959 |
let mut input_params = ffi::cubeb_stream_params::default(); |
| 960 |
input_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 961 |
input_params.rate = 44100; |
| 962 |
input_params.channels = 1; |
| 963 |
input_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 964 |
input_params.prefs = ffi::CUBEB_STREAM_PREF_VOICE; |
| 965 |
|
| 966 |
let mut output_params = ffi::cubeb_stream_params::default(); |
| 967 |
output_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 968 |
output_params.rate = 48000; |
| 969 |
output_params.channels = 2; |
| 970 |
output_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 971 |
output_params.prefs = ffi::CUBEB_STREAM_PREF_VOICE; |
| 972 |
|
| 973 |
test_ops_stream_operation_on_context( |
| 974 |
name, |
| 975 |
context_ptr, |
| 976 |
ptr::null_mut(), // Use default input device. |
| 977 |
&mut input_params, |
| 978 |
ptr::null_mut(), // Use default output device. |
| 979 |
&mut output_params, |
| 980 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 981 |
data_callback, |
| 982 |
None, // No state callback. |
| 983 |
ptr::null_mut(), // No user data pointer. |
| 984 |
operation, |
| 985 |
); |
| 986 |
} |
| 987 |
|
| 988 |
fn test_default_duplex_voice_stream_operation_on_context<F>( |
| 989 |
name: &'static str, |
| 990 |
context_ptr: *mut ffi::cubeb, |
| 991 |
operation: F, |
| 992 |
) where |
| 993 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 994 |
{ |
| 995 |
test_default_duplex_voice_stream_operation_on_context_with_callback( |
| 996 |
name, |
| 997 |
context_ptr, |
| 998 |
Some(noop_data_callback), |
| 999 |
operation, |
| 1000 |
); |
| 1001 |
} |
| 1002 |
|
| 1003 |
fn test_default_duplex_voice_stream_operation_with_callback<F>( |
| 1004 |
name: &'static str, |
| 1005 |
data_callback: ffi::cubeb_data_callback, |
| 1006 |
operation: F, |
| 1007 |
) where |
| 1008 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 1009 |
{ |
| 1010 |
test_ops_context_operation("context: duplex voice stream operation", |context_ptr| { |
| 1011 |
test_default_duplex_voice_stream_operation_on_context_with_callback( |
| 1012 |
name, |
| 1013 |
context_ptr, |
| 1014 |
data_callback, |
| 1015 |
operation, |
| 1016 |
); |
| 1017 |
}); |
| 1018 |
} |
| 1019 |
|
| 1020 |
fn test_default_duplex_voice_stream_operation<F>(name: &'static str, operation: F) |
| 1021 |
where |
| 1022 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 1023 |
{ |
| 1024 |
test_default_duplex_voice_stream_operation_with_callback( |
| 1025 |
name, |
| 1026 |
Some(noop_data_callback), |
| 1027 |
operation, |
| 1028 |
); |
| 1029 |
} |
| 1030 |
|
| 1031 |
fn test_stereo_input_duplex_voice_stream_operation<F>(name: &'static str, operation: F) |
| 1032 |
where |
| 1033 |
F: FnOnce(*mut ffi::cubeb_stream), |
| 1034 |
{ |
| 1035 |
let mut input_devices = get_devices_info_in_scope(Scope::Input); |
| 1036 |
input_devices.retain(|d| test_device_channels_in_scope(d.id, Scope::Input).unwrap_or(0) >= 2); |
| 1037 |
if input_devices.is_empty() { |
| 1038 |
println!("No stereo input device present. Skipping stereo-input test."); |
| 1039 |
return; |
| 1040 |
} |
| 1041 |
|
| 1042 |
let mut input_params = ffi::cubeb_stream_params::default(); |
| 1043 |
input_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 1044 |
input_params.rate = 44100; |
| 1045 |
input_params.channels = 2; |
| 1046 |
input_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 1047 |
input_params.prefs = ffi::CUBEB_STREAM_PREF_VOICE; |
| 1048 |
|
| 1049 |
let mut output_params = ffi::cubeb_stream_params::default(); |
| 1050 |
output_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 1051 |
output_params.rate = 44100; |
| 1052 |
output_params.channels = 2; |
| 1053 |
output_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 1054 |
output_params.prefs = ffi::CUBEB_STREAM_PREF_VOICE; |
| 1055 |
|
| 1056 |
test_ops_stream_operation( |
| 1057 |
name, |
| 1058 |
input_devices[0].id as ffi::cubeb_devid, |
| 1059 |
&mut input_params, |
| 1060 |
ptr::null_mut(), // Use default output device. |
| 1061 |
&mut output_params, |
| 1062 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 1063 |
Some(noop_data_callback), |
| 1064 |
None, // No state callback. |
| 1065 |
ptr::null_mut(), // No user data pointer. |
| 1066 |
operation, |
| 1067 |
); |
| 1068 |
} |
| 1069 |
|
| 1070 |
#[test] |
| 1071 |
fn test_ops_stream_init_and_destroy() { |
| 1072 |
test_default_output_stream_operation("stream: init and destroy", |_stream| {}); |
| 1073 |
} |
| 1074 |
|
| 1075 |
#[test] |
| 1076 |
fn test_ops_stream_start() { |
| 1077 |
test_default_output_stream_operation("stream: start", |stream| { |
| 1078 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1079 |
}); |
| 1080 |
} |
| 1081 |
|
| 1082 |
#[test] |
| 1083 |
fn test_ops_stream_stop() { |
| 1084 |
test_default_output_stream_operation("stream: stop", |stream| { |
| 1085 |
assert_eq!(unsafe { OPS.stream_stop.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1086 |
}); |
| 1087 |
} |
| 1088 |
|
| 1089 |
#[test] |
| 1090 |
fn test_ops_stream_drain() { |
| 1091 |
test_default_output_stream_operation_with_callback( |
| 1092 |
"stream: drain", |
| 1093 |
Some(draining_data_callback), |
| 1094 |
|stream| { |
| 1095 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1096 |
thread::sleep(Duration::from_millis(10)); |
| 1097 |
}, |
| 1098 |
); |
| 1099 |
} |
| 1100 |
|
| 1101 |
#[test] |
| 1102 |
fn test_ops_stream_position() { |
| 1103 |
test_default_output_stream_operation("stream: position", |stream| { |
| 1104 |
let mut position = u64::max_value(); |
| 1105 |
assert_eq!( |
| 1106 |
unsafe { OPS.stream_get_position.unwrap()(stream, &mut position) }, |
| 1107 |
ffi::CUBEB_OK |
| 1108 |
); |
| 1109 |
assert_eq!(position, 0); |
| 1110 |
}); |
| 1111 |
} |
| 1112 |
|
| 1113 |
#[test] |
| 1114 |
fn test_ops_stream_latency() { |
| 1115 |
test_default_output_stream_operation("stream: latency", |stream| { |
| 1116 |
let mut latency = u32::max_value(); |
| 1117 |
assert_eq!( |
| 1118 |
unsafe { OPS.stream_get_latency.unwrap()(stream, &mut latency) }, |
| 1119 |
ffi::CUBEB_OK |
| 1120 |
); |
| 1121 |
assert_ne!(latency, u32::max_value()); |
| 1122 |
}); |
| 1123 |
} |
| 1124 |
|
| 1125 |
#[test] |
| 1126 |
fn test_ops_stream_set_volume() { |
| 1127 |
test_default_output_stream_operation("stream: set volume", |stream| { |
| 1128 |
assert_eq!( |
| 1129 |
unsafe { OPS.stream_set_volume.unwrap()(stream, 0.5) }, |
| 1130 |
ffi::CUBEB_OK |
| 1131 |
); |
| 1132 |
}); |
| 1133 |
} |
| 1134 |
|
| 1135 |
#[test] |
| 1136 |
fn test_ops_stream_current_device() { |
| 1137 |
test_default_output_stream_operation("stream: get current device and destroy it", |stream| { |
| 1138 |
if test_get_default_device(Scope::Input).is_none() |
| 1139 |
|| test_get_default_device(Scope::Output).is_none() |
| 1140 |
{ |
| 1141 |
println!("stream_get_current_device only works when the machine has both input and output devices"); |
| 1142 |
return; |
| 1143 |
} |
| 1144 |
|
| 1145 |
let mut device: *mut ffi::cubeb_device = ptr::null_mut(); |
| 1146 |
if unsafe { OPS.stream_get_current_device.unwrap()(stream, &mut device) } != ffi::CUBEB_OK { |
| 1147 |
// It can happen when we fail to get the device source. |
| 1148 |
println!("stream_get_current_device fails. Skip this test."); |
| 1149 |
return; |
| 1150 |
} |
| 1151 |
|
| 1152 |
assert!(!device.is_null()); |
| 1153 |
// Uncomment the below to print out the results. |
| 1154 |
// let deviceref = unsafe { DeviceRef::from_ptr(device) }; |
| 1155 |
// println!( |
| 1156 |
// "output: {}", |
| 1157 |
// deviceref.output_name().unwrap_or("(no device name)") |
| 1158 |
// ); |
| 1159 |
// println!( |
| 1160 |
// "input: {}", |
| 1161 |
// deviceref.input_name().unwrap_or("(no device name)") |
| 1162 |
// ); |
| 1163 |
assert_eq!( |
| 1164 |
unsafe { OPS.stream_device_destroy.unwrap()(stream, device) }, |
| 1165 |
ffi::CUBEB_OK |
| 1166 |
); |
| 1167 |
}); |
| 1168 |
} |
| 1169 |
|
| 1170 |
#[test] |
| 1171 |
fn test_ops_stream_device_destroy() { |
| 1172 |
test_default_output_stream_operation("stream: destroy null device", |stream| { |
| 1173 |
assert_eq!( |
| 1174 |
unsafe { OPS.stream_device_destroy.unwrap()(stream, ptr::null_mut()) }, |
| 1175 |
ffi::CUBEB_OK // It returns OK anyway. |
| 1176 |
); |
| 1177 |
}); |
| 1178 |
} |
| 1179 |
|
| 1180 |
pub extern "C" fn reiniting_and_erroring_data_callback( |
| 1181 |
stream: *mut ffi::cubeb_stream, |
| 1182 |
_user_ptr: *mut c_void, |
| 1183 |
_input_buffer: *const c_void, |
| 1184 |
output_buffer: *mut c_void, |
| 1185 |
nframes: i64, |
| 1186 |
) -> i64 { |
| 1187 |
assert!(!stream.is_null()); |
| 1188 |
|
| 1189 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1190 |
|
| 1191 |
// Feed silence data to output buffer |
| 1192 |
if !output_buffer.is_null() { |
| 1193 |
let channels = stm.core_stream_data.output_stream_params.channels(); |
| 1194 |
let samples = nframes as usize * channels as usize; |
| 1195 |
let sample_size = cubeb_sample_size(stm.core_stream_data.output_stream_params.format()); |
| 1196 |
unsafe { |
| 1197 |
ptr::write_bytes(output_buffer, 0, samples * sample_size); |
| 1198 |
} |
| 1199 |
} |
| 1200 |
|
| 1201 |
// Trigger an async reinit before the backend handles the error below. |
| 1202 |
// This scenario could happen in the backend's internal input callback. |
| 1203 |
stm.reinit_async(); |
| 1204 |
|
| 1205 |
ffi::CUBEB_ERROR.into() |
| 1206 |
} |
| 1207 |
|
| 1208 |
#[test] |
| 1209 |
fn test_ops_stream_racy_reinit() { |
| 1210 |
// Make sure the parameters meet the requirements of AudioUnitContext::stream_init |
| 1211 |
// (in the comments). |
| 1212 |
let mut input_params = ffi::cubeb_stream_params::default(); |
| 1213 |
input_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 1214 |
input_params.rate = 48000; |
| 1215 |
input_params.channels = 1; |
| 1216 |
input_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 1217 |
input_params.prefs = ffi::CUBEB_STREAM_PREF_NONE; |
| 1218 |
|
| 1219 |
let mut output_params = ffi::cubeb_stream_params::default(); |
| 1220 |
output_params.format = ffi::CUBEB_SAMPLE_FLOAT32NE; |
| 1221 |
output_params.rate = 44100; |
| 1222 |
output_params.channels = 2; |
| 1223 |
output_params.layout = ffi::CUBEB_LAYOUT_UNDEFINED; |
| 1224 |
output_params.prefs = ffi::CUBEB_STREAM_PREF_NONE; |
| 1225 |
|
| 1226 |
let mut data = StateCallbackData::default(); |
| 1227 |
test_ops_stream_operation( |
| 1228 |
"stream: racy reinit", |
| 1229 |
ptr::null_mut(), // Use default input device. |
| 1230 |
&mut input_params, |
| 1231 |
ptr::null_mut(), // Use default output device. |
| 1232 |
&mut output_params, |
| 1233 |
4096, // TODO: Get latency by get_min_latency instead ? |
| 1234 |
Some(reiniting_and_erroring_data_callback), |
| 1235 |
Some(state_tracking_cb), |
| 1236 |
&mut data as *mut StateCallbackData as *mut c_void, |
| 1237 |
|stream| { |
| 1238 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1239 |
while data.error_cnt() == 0 && data.stopped_cnt() == 0 { |
| 1240 |
thread::sleep(Duration::from_millis(1)); |
| 1241 |
} |
| 1242 |
assert_eq!(unsafe { OPS.stream_stop.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1243 |
}, |
| 1244 |
); |
| 1245 |
assert_eq!(data.started_cnt(), 1); |
| 1246 |
assert_eq!(data.stopped_cnt(), 0); |
| 1247 |
assert_eq!(data.drained_cnt(), 0); |
| 1248 |
assert_eq!(data.error_cnt(), 1); |
| 1249 |
} |
| 1250 |
|
| 1251 |
#[test] |
| 1252 |
fn test_ops_stream_register_device_changed_callback() { |
| 1253 |
extern "C" fn callback(_: *mut c_void) {} |
| 1254 |
|
| 1255 |
test_default_output_stream_operation("stream: register device changed callback", |stream| { |
| 1256 |
assert_eq!( |
| 1257 |
unsafe { OPS.stream_register_device_changed_callback.unwrap()(stream, Some(callback)) }, |
| 1258 |
ffi::CUBEB_OK |
| 1259 |
); |
| 1260 |
assert_eq!( |
| 1261 |
unsafe { OPS.stream_register_device_changed_callback.unwrap()(stream, Some(callback)) }, |
| 1262 |
ffi::CUBEB_ERROR_INVALID_PARAMETER |
| 1263 |
); |
| 1264 |
assert_eq!( |
| 1265 |
unsafe { OPS.stream_register_device_changed_callback.unwrap()(stream, None) }, |
| 1266 |
ffi::CUBEB_OK |
| 1267 |
); |
| 1268 |
}); |
| 1269 |
} |
| 1270 |
|
| 1271 |
#[test] |
| 1272 |
fn test_ops_stereo_input_duplex_stream_init_and_destroy() { |
| 1273 |
test_stereo_input_duplex_stream_operation( |
| 1274 |
"stereo-input duplex stream: init and destroy", |
| 1275 |
|_stream| {}, |
| 1276 |
); |
| 1277 |
} |
| 1278 |
|
| 1279 |
#[test] |
| 1280 |
fn test_ops_stereo_input_duplex_stream_start() { |
| 1281 |
test_stereo_input_duplex_stream_operation("stereo-input duplex stream: start", |stream| { |
| 1282 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1283 |
}); |
| 1284 |
} |
| 1285 |
|
| 1286 |
#[test] |
| 1287 |
fn test_ops_stereo_input_duplex_stream_stop() { |
| 1288 |
test_stereo_input_duplex_stream_operation("stereo-input duplex stream: stop", |stream| { |
| 1289 |
assert_eq!(unsafe { OPS.stream_stop.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1290 |
}); |
| 1291 |
} |
| 1292 |
|
| 1293 |
#[test] |
| 1294 |
fn test_ops_stereo_input_duplex_stream_drain() { |
| 1295 |
test_stereo_input_duplex_stream_operation_with_callback( |
| 1296 |
"stereo-input duplex stream: drain", |
| 1297 |
Some(draining_data_callback), |
| 1298 |
|stream| { |
| 1299 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1300 |
thread::sleep(Duration::from_millis(10)); |
| 1301 |
}, |
| 1302 |
); |
| 1303 |
} |
| 1304 |
|
| 1305 |
#[test] |
| 1306 |
fn test_ops_input_voice_stream_init_and_destroy() { |
| 1307 |
test_default_input_voice_stream_operation("input voice stream: init and destroy", |stream| { |
| 1308 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1309 |
assert_eq!( |
| 1310 |
stm.core_stream_data.using_voice_processing_unit(), |
| 1311 |
macos_kernel_major_version().unwrap() != MACOS_KERNEL_MAJOR_VERSION_MONTEREY |
| 1312 |
); |
| 1313 |
}); |
| 1314 |
} |
| 1315 |
|
| 1316 |
#[test] |
| 1317 |
fn test_ops_input_voice_stream_start() { |
| 1318 |
test_default_input_voice_stream_operation("input voice stream: start", |stream| { |
| 1319 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1320 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1321 |
assert_eq!( |
| 1322 |
stm.core_stream_data.using_voice_processing_unit(), |
| 1323 |
macos_kernel_major_version().unwrap() != MACOS_KERNEL_MAJOR_VERSION_MONTEREY |
| 1324 |
); |
| 1325 |
}); |
| 1326 |
} |
| 1327 |
|
| 1328 |
#[test] |
| 1329 |
fn test_ops_input_voice_stream_stop() { |
| 1330 |
test_default_input_voice_stream_operation("input voice stream: stop", |stream| { |
| 1331 |
assert_eq!(unsafe { OPS.stream_stop.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1332 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1333 |
assert_eq!( |
| 1334 |
stm.core_stream_data.using_voice_processing_unit(), |
| 1335 |
macos_kernel_major_version().unwrap() != MACOS_KERNEL_MAJOR_VERSION_MONTEREY |
| 1336 |
); |
| 1337 |
}); |
| 1338 |
} |
| 1339 |
|
| 1340 |
#[test] |
| 1341 |
fn test_ops_duplex_voice_stream_init_and_destroy() { |
| 1342 |
test_default_duplex_voice_stream_operation("duplex voice stream: init and destroy", |stream| { |
| 1343 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1344 |
assert_eq!( |
| 1345 |
stm.core_stream_data.using_voice_processing_unit(), |
| 1346 |
macos_kernel_major_version().unwrap() != MACOS_KERNEL_MAJOR_VERSION_MONTEREY |
| 1347 |
); |
| 1348 |
}); |
| 1349 |
} |
| 1350 |
|
| 1351 |
#[test] |
| 1352 |
fn test_ops_duplex_voice_stream_start() { |
| 1353 |
test_default_duplex_voice_stream_operation("duplex voice stream: start", |stream| { |
| 1354 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1355 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1356 |
assert_eq!( |
| 1357 |
stm.core_stream_data.using_voice_processing_unit(), |
| 1358 |
macos_kernel_major_version().unwrap() != MACOS_KERNEL_MAJOR_VERSION_MONTEREY |
| 1359 |
); |
| 1360 |
}); |
| 1361 |
} |
| 1362 |
|
| 1363 |
#[test] |
| 1364 |
fn test_ops_duplex_voice_stream_stop() { |
| 1365 |
test_default_duplex_voice_stream_operation("duplex voice stream: stop", |stream| { |
| 1366 |
assert_eq!(unsafe { OPS.stream_stop.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1367 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1368 |
assert_eq!( |
| 1369 |
stm.core_stream_data.using_voice_processing_unit(), |
| 1370 |
macos_kernel_major_version().unwrap() != MACOS_KERNEL_MAJOR_VERSION_MONTEREY |
| 1371 |
); |
| 1372 |
}); |
| 1373 |
} |
| 1374 |
|
| 1375 |
#[test] |
| 1376 |
fn test_ops_duplex_voice_stream_drain() { |
| 1377 |
test_default_duplex_voice_stream_operation_with_callback( |
| 1378 |
"duplex voice stream: drain", |
| 1379 |
Some(draining_data_callback), |
| 1380 |
|stream| { |
| 1381 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1382 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1383 |
assert_eq!( |
| 1384 |
stm.core_stream_data.using_voice_processing_unit(), |
| 1385 |
macos_kernel_major_version().unwrap() != MACOS_KERNEL_MAJOR_VERSION_MONTEREY |
| 1386 |
); |
| 1387 |
thread::sleep(Duration::from_millis(10)); |
| 1388 |
}, |
| 1389 |
); |
| 1390 |
} |
| 1391 |
|
| 1392 |
#[test] |
| 1393 |
#[ignore] |
| 1394 |
fn test_ops_timing_sensitive_multiple_voice_stream_init_and_destroy() { |
| 1395 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1396 |
// We disable VPIO on Monterey. |
| 1397 |
return; |
| 1398 |
} |
| 1399 |
let start = Instant::now(); |
| 1400 |
let mut t1 = start; |
| 1401 |
let mut t2 = start; |
| 1402 |
let mut t3 = start; |
| 1403 |
let mut t4 = start; |
| 1404 |
let mut t5 = start; |
| 1405 |
let mut t6 = start; |
| 1406 |
let mut t7 = start; |
| 1407 |
let mut t8 = start; |
| 1408 |
let mut t9 = start; |
| 1409 |
let mut t10 = start; |
| 1410 |
test_ops_context_operation("multiple duplex voice streams", |context_ptr| { |
| 1411 |
// First stream uses vpio, creates the shared vpio unit. |
| 1412 |
test_default_duplex_voice_stream_operation_on_context( |
| 1413 |
"multiple voice streams: stream 1, duplex", |
| 1414 |
context_ptr, |
| 1415 |
|stream| { |
| 1416 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1417 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1418 |
|
| 1419 |
// Two concurrent vpio streams are supported. |
| 1420 |
test_default_input_voice_stream_operation_on_context( |
| 1421 |
"multiple voice streams: stream 2, input-only", |
| 1422 |
context_ptr, |
| 1423 |
|stream| { |
| 1424 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1425 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1426 |
|
| 1427 |
// Three concurrent vpio streams are supported. |
| 1428 |
test_default_duplex_voice_stream_operation_on_context( |
| 1429 |
"multiple voice streams: stream 3, duplex", |
| 1430 |
context_ptr, |
| 1431 |
|stream| { |
| 1432 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1433 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1434 |
}, |
| 1435 |
); |
| 1436 |
}, |
| 1437 |
); |
| 1438 |
}, |
| 1439 |
); |
| 1440 |
t1 = Instant::now(); |
| 1441 |
// Fourth stream uses vpio, allows reuse of one already created. |
| 1442 |
test_default_duplex_voice_stream_operation_on_context( |
| 1443 |
"multiple voice streams: stream 4, duplex", |
| 1444 |
context_ptr, |
| 1445 |
|stream| { |
| 1446 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1447 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1448 |
t2 = Instant::now(); |
| 1449 |
|
| 1450 |
// Fifth stream uses vpio, allows reuse of one already created. |
| 1451 |
test_default_duplex_voice_stream_operation_on_context( |
| 1452 |
"multiple voice streams: stream 5, duplex", |
| 1453 |
context_ptr, |
| 1454 |
|stream| { |
| 1455 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1456 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1457 |
t3 = Instant::now(); |
| 1458 |
|
| 1459 |
// Sixth stream uses vpio, allows reuse of one already created. |
| 1460 |
test_default_input_voice_stream_operation_on_context( |
| 1461 |
"multiple voice streams: stream 6, input-only", |
| 1462 |
context_ptr, |
| 1463 |
|stream| { |
| 1464 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1465 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1466 |
t4 = Instant::now(); |
| 1467 |
|
| 1468 |
// Seventh stream uses vpio, but is created anew. |
| 1469 |
test_default_input_voice_stream_operation_on_context( |
| 1470 |
"multiple voice streams: stream 7, input-only", |
| 1471 |
context_ptr, |
| 1472 |
|stream| { |
| 1473 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1474 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1475 |
t5 = Instant::now(); |
| 1476 |
}, |
| 1477 |
); |
| 1478 |
t6 = Instant::now(); |
| 1479 |
}, |
| 1480 |
); |
| 1481 |
t7 = Instant::now(); |
| 1482 |
}, |
| 1483 |
); |
| 1484 |
t8 = Instant::now(); |
| 1485 |
}, |
| 1486 |
); |
| 1487 |
t9 = Instant::now(); |
| 1488 |
}); |
| 1489 |
t10 = Instant::now(); |
| 1490 |
|
| 1491 |
let reuse_vpio_1 = t2 - t1; |
| 1492 |
let reuse_vpio_2 = t3 - t2; |
| 1493 |
let reuse_vpio_3 = t4 - t3; |
| 1494 |
let create_standalone_vpio = t5 - t4; |
| 1495 |
assert!( |
| 1496 |
create_standalone_vpio > reuse_vpio_1 * 2, |
| 1497 |
"Failed create_standalone_vpio={}s > reuse_vpio_1={}s * 2", |
| 1498 |
create_standalone_vpio.as_secs_f32(), |
| 1499 |
reuse_vpio_1.as_secs_f32() |
| 1500 |
); |
| 1501 |
assert!( |
| 1502 |
create_standalone_vpio > reuse_vpio_2 * 2, |
| 1503 |
"Failed create_standalone_vpio={}s > reuse_vpio_2={}s * 2", |
| 1504 |
create_standalone_vpio.as_secs_f32(), |
| 1505 |
reuse_vpio_2.as_secs_f32() |
| 1506 |
); |
| 1507 |
assert!( |
| 1508 |
create_standalone_vpio > reuse_vpio_3 * 2, |
| 1509 |
"Failed create_standalone_vpio={}s > reuse_vpio_3={}s * 2", |
| 1510 |
create_standalone_vpio.as_secs_f32(), |
| 1511 |
reuse_vpio_3.as_secs_f32() |
| 1512 |
); |
| 1513 |
|
| 1514 |
let recycle_vpio_1 = t6 - t5; |
| 1515 |
let recycle_vpio_2 = t7 - t6; |
| 1516 |
let recycle_vpio_3 = t8 - t7; |
| 1517 |
let recycle_vpio_4 = t9 - t8; |
| 1518 |
let dispose_vpios = t10 - t9; |
| 1519 |
assert!( |
| 1520 |
dispose_vpios > recycle_vpio_1 * 2, |
| 1521 |
"Failed dispose_vpios={}s > recycle_vpio_1 ={}s * 2", |
| 1522 |
dispose_vpios.as_secs_f32(), |
| 1523 |
recycle_vpio_1.as_secs_f32() |
| 1524 |
); |
| 1525 |
assert!( |
| 1526 |
dispose_vpios > recycle_vpio_2 * 2, |
| 1527 |
"Failed dispose_vpios={}s > recycle_vpio_2 ={}s * 2", |
| 1528 |
dispose_vpios.as_secs_f32(), |
| 1529 |
recycle_vpio_2.as_secs_f32() |
| 1530 |
); |
| 1531 |
assert!( |
| 1532 |
dispose_vpios > recycle_vpio_3 * 2, |
| 1533 |
"Failed dispose_vpios={}s > recycle_vpio_3 ={}s * 2", |
| 1534 |
dispose_vpios.as_secs_f32(), |
| 1535 |
recycle_vpio_3.as_secs_f32() |
| 1536 |
); |
| 1537 |
assert!( |
| 1538 |
dispose_vpios > recycle_vpio_4 * 2, |
| 1539 |
"Failed dispose_vpios={}s > recycle_vpio_4 ={}s * 2", |
| 1540 |
dispose_vpios.as_secs_f32(), |
| 1541 |
recycle_vpio_4.as_secs_f32() |
| 1542 |
); |
| 1543 |
} |
| 1544 |
|
| 1545 |
#[test] |
| 1546 |
#[ignore] |
| 1547 |
fn test_ops_timing_sensitive_multiple_duplex_voice_stream_start() { |
| 1548 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1549 |
// We disable VPIO on Monterey. |
| 1550 |
return; |
| 1551 |
} |
| 1552 |
test_ops_context_operation("multiple duplex voice streams", |context_ptr| { |
| 1553 |
let start = Instant::now(); |
| 1554 |
// First stream uses vpio, creates the shared vpio unit. |
| 1555 |
test_default_duplex_voice_stream_operation_on_context( |
| 1556 |
"multiple duplex voice streams: stream 1", |
| 1557 |
context_ptr, |
| 1558 |
|stream| { |
| 1559 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1560 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1561 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1562 |
}, |
| 1563 |
); |
| 1564 |
let d1 = start.elapsed(); |
| 1565 |
// Second stream uses vpio, allows reuse of the one already created. |
| 1566 |
test_default_duplex_voice_stream_operation_on_context( |
| 1567 |
"multiple duplex voice streams: stream 2", |
| 1568 |
context_ptr, |
| 1569 |
|stream| { |
| 1570 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1571 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1572 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1573 |
}, |
| 1574 |
); |
| 1575 |
let d2 = start.elapsed() - d1; |
| 1576 |
// d1 being significantly longer than d2 is proof we reuse vpio. |
| 1577 |
assert!( |
| 1578 |
d1 > d2 * 2, |
| 1579 |
"Failed d1={}s > d2={}s * s", |
| 1580 |
d1.as_secs_f32(), |
| 1581 |
d2.as_secs_f32() |
| 1582 |
); |
| 1583 |
}); |
| 1584 |
} |
| 1585 |
|
| 1586 |
#[test] |
| 1587 |
#[ignore] |
| 1588 |
fn test_ops_timing_sensitive_multiple_duplex_voice_stream_params() { |
| 1589 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1590 |
// We disable VPIO on Monterey. |
| 1591 |
return; |
| 1592 |
} |
| 1593 |
test_ops_context_operation("multiple duplex voice streams with params", |context_ptr| { |
| 1594 |
let start = Instant::now(); |
| 1595 |
// First stream uses vpio, creates the shared vpio unit. |
| 1596 |
test_default_duplex_voice_stream_operation_on_context( |
| 1597 |
"multiple duplex voice streams: stream 1", |
| 1598 |
context_ptr, |
| 1599 |
|stream| { |
| 1600 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1601 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1602 |
assert_eq!( |
| 1603 |
unsafe { |
| 1604 |
OPS.stream_set_input_processing_params.unwrap()( |
| 1605 |
stream, |
| 1606 |
ffi::CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION |
| 1607 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION, |
| 1608 |
) |
| 1609 |
}, |
| 1610 |
ffi::CUBEB_OK |
| 1611 |
); |
| 1612 |
assert_eq!( |
| 1613 |
unsafe { OPS.stream_set_input_mute.unwrap()(stream, 1) }, |
| 1614 |
ffi::CUBEB_OK |
| 1615 |
); |
| 1616 |
}, |
| 1617 |
); |
| 1618 |
let d1 = start.elapsed(); |
| 1619 |
// Second stream uses vpio, allows reuse of the one already created. |
| 1620 |
test_default_duplex_voice_stream_operation_on_context( |
| 1621 |
"multiple duplex voice streams: stream 2", |
| 1622 |
context_ptr, |
| 1623 |
|stream| { |
| 1624 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1625 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1626 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1627 |
let queue = stm.queue.clone(); |
| 1628 |
// Test that input processing params does not carry over when reusing vpio. |
| 1629 |
let mut bypass: u32 = 0; |
| 1630 |
let r = queue |
| 1631 |
.run_sync(|| { |
| 1632 |
audio_unit_get_property( |
| 1633 |
stm.core_stream_data.input_unit, |
| 1634 |
kAUVoiceIOProperty_BypassVoiceProcessing, |
| 1635 |
kAudioUnitScope_Global, |
| 1636 |
AU_IN_BUS, |
| 1637 |
&mut bypass, |
| 1638 |
&mut mem::size_of::<u32>(), |
| 1639 |
) |
| 1640 |
}) |
| 1641 |
.unwrap(); |
| 1642 |
assert_eq!(r, NO_ERR); |
| 1643 |
assert_eq!(bypass, 1); |
| 1644 |
|
| 1645 |
// Test that input mute state does not carry over when reusing vpio. |
| 1646 |
let mut mute: u32 = 0; |
| 1647 |
let r = queue |
| 1648 |
.run_sync(|| { |
| 1649 |
audio_unit_get_property( |
| 1650 |
stm.core_stream_data.input_unit, |
| 1651 |
kAUVoiceIOProperty_MuteOutput, |
| 1652 |
kAudioUnitScope_Global, |
| 1653 |
AU_IN_BUS, |
| 1654 |
&mut mute, |
| 1655 |
&mut mem::size_of::<u32>(), |
| 1656 |
) |
| 1657 |
}) |
| 1658 |
.unwrap(); |
| 1659 |
assert_eq!(r, NO_ERR); |
| 1660 |
assert_eq!(mute, 0); |
| 1661 |
}, |
| 1662 |
); |
| 1663 |
let d2 = start.elapsed() - d1; |
| 1664 |
// d1 being significantly longer than d2 is proof we reuse vpio. |
| 1665 |
assert!( |
| 1666 |
d1 > d2 * 2, |
| 1667 |
"Failed d1={}s > d2={}s * 2", |
| 1668 |
d1.as_secs_f32(), |
| 1669 |
d2.as_secs_f32() |
| 1670 |
); |
| 1671 |
}); |
| 1672 |
} |
| 1673 |
|
| 1674 |
#[test] |
| 1675 |
fn test_ops_duplex_voice_stream_set_input_mute() { |
| 1676 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1677 |
// We disable VPIO on Monterey. |
| 1678 |
return; |
| 1679 |
} |
| 1680 |
test_default_duplex_voice_stream_operation("duplex voice stream: mute", |stream| { |
| 1681 |
assert_eq!( |
| 1682 |
unsafe { OPS.stream_set_input_mute.unwrap()(stream, 1) }, |
| 1683 |
ffi::CUBEB_OK |
| 1684 |
); |
| 1685 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1686 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1687 |
}); |
| 1688 |
} |
| 1689 |
|
| 1690 |
#[test] |
| 1691 |
fn test_ops_duplex_voice_stream_set_input_mute_before_start() { |
| 1692 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1693 |
// We disable VPIO on Monterey. |
| 1694 |
return; |
| 1695 |
} |
| 1696 |
test_default_duplex_voice_stream_operation( |
| 1697 |
"duplex voice stream: mute before start", |
| 1698 |
|stream| { |
| 1699 |
assert_eq!( |
| 1700 |
unsafe { OPS.stream_set_input_mute.unwrap()(stream, 1) }, |
| 1701 |
ffi::CUBEB_OK |
| 1702 |
); |
| 1703 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1704 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1705 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1706 |
}, |
| 1707 |
); |
| 1708 |
} |
| 1709 |
|
| 1710 |
#[test] |
| 1711 |
fn test_ops_duplex_voice_stream_set_input_mute_before_start_with_reinit() { |
| 1712 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1713 |
// We disable VPIO on Monterey. |
| 1714 |
return; |
| 1715 |
} |
| 1716 |
test_default_duplex_voice_stream_operation( |
| 1717 |
"duplex voice stream: mute before start with reinit", |
| 1718 |
|stream| { |
| 1719 |
assert_eq!( |
| 1720 |
unsafe { OPS.stream_set_input_mute.unwrap()(stream, 1) }, |
| 1721 |
ffi::CUBEB_OK |
| 1722 |
); |
| 1723 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1724 |
|
| 1725 |
// Hacky cast, but testing this here was simplest for now. |
| 1726 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1727 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1728 |
stm.reinit_async(); |
| 1729 |
let queue = stm.queue.clone(); |
| 1730 |
let mut mute_after_reinit = false; |
| 1731 |
queue.run_sync(|| { |
| 1732 |
let mut mute: u32 = 0; |
| 1733 |
let r = audio_unit_get_property( |
| 1734 |
stm.core_stream_data.input_unit, |
| 1735 |
kAUVoiceIOProperty_MuteOutput, |
| 1736 |
kAudioUnitScope_Global, |
| 1737 |
AU_IN_BUS, |
| 1738 |
&mut mute, |
| 1739 |
&mut mem::size_of::<u32>(), |
| 1740 |
); |
| 1741 |
assert_eq!(r, NO_ERR); |
| 1742 |
mute_after_reinit = mute == 1; |
| 1743 |
}); |
| 1744 |
assert_eq!(mute_after_reinit, true); |
| 1745 |
}, |
| 1746 |
); |
| 1747 |
} |
| 1748 |
|
| 1749 |
#[test] |
| 1750 |
fn test_ops_duplex_voice_stream_set_input_mute_after_start() { |
| 1751 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1752 |
// We disable VPIO on Monterey. |
| 1753 |
return; |
| 1754 |
} |
| 1755 |
test_default_duplex_voice_stream_operation("duplex voice stream: mute after start", |stream| { |
| 1756 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1757 |
assert_eq!( |
| 1758 |
unsafe { OPS.stream_set_input_mute.unwrap()(stream, 1) }, |
| 1759 |
ffi::CUBEB_OK |
| 1760 |
); |
| 1761 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1762 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1763 |
}); |
| 1764 |
} |
| 1765 |
|
| 1766 |
#[test] |
| 1767 |
fn test_ops_duplex_voice_stream_set_input_processing_params() { |
| 1768 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1769 |
// We disable VPIO on Monterey. |
| 1770 |
return; |
| 1771 |
} |
| 1772 |
test_default_duplex_voice_stream_operation("duplex voice stream: processing", |stream| { |
| 1773 |
let params: ffi::cubeb_input_processing_params = |
| 1774 |
ffi::CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION |
| 1775 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION |
| 1776 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_AUTOMATIC_GAIN_CONTROL; |
| 1777 |
assert_eq!( |
| 1778 |
unsafe { OPS.stream_set_input_processing_params.unwrap()(stream, params) }, |
| 1779 |
ffi::CUBEB_OK |
| 1780 |
); |
| 1781 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1782 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1783 |
}); |
| 1784 |
} |
| 1785 |
|
| 1786 |
#[test] |
| 1787 |
fn test_ops_duplex_voice_stream_set_input_processing_params_before_start() { |
| 1788 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1789 |
// We disable VPIO on Monterey. |
| 1790 |
return; |
| 1791 |
} |
| 1792 |
test_default_duplex_voice_stream_operation( |
| 1793 |
"duplex voice stream: processing before start", |
| 1794 |
|stream| { |
| 1795 |
let params: ffi::cubeb_input_processing_params = |
| 1796 |
ffi::CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION |
| 1797 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION |
| 1798 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_AUTOMATIC_GAIN_CONTROL; |
| 1799 |
assert_eq!( |
| 1800 |
unsafe { OPS.stream_set_input_processing_params.unwrap()(stream, params) }, |
| 1801 |
ffi::CUBEB_OK |
| 1802 |
); |
| 1803 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1804 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1805 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1806 |
}, |
| 1807 |
); |
| 1808 |
} |
| 1809 |
|
| 1810 |
#[test] |
| 1811 |
fn test_ops_duplex_voice_stream_set_input_processing_params_before_start_with_reinit() { |
| 1812 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1813 |
// We disable VPIO on Monterey. |
| 1814 |
return; |
| 1815 |
} |
| 1816 |
test_default_duplex_voice_stream_operation( |
| 1817 |
"duplex voice stream: processing before start with reinit", |
| 1818 |
|stream| { |
| 1819 |
let params: ffi::cubeb_input_processing_params = |
| 1820 |
ffi::CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION |
| 1821 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION |
| 1822 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_AUTOMATIC_GAIN_CONTROL; |
| 1823 |
assert_eq!( |
| 1824 |
unsafe { OPS.stream_set_input_processing_params.unwrap()(stream, params) }, |
| 1825 |
ffi::CUBEB_OK |
| 1826 |
); |
| 1827 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1828 |
|
| 1829 |
// Hacky cast, but testing this here was simplest for now. |
| 1830 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1831 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1832 |
stm.reinit_async(); |
| 1833 |
let queue = stm.queue.clone(); |
| 1834 |
let mut params_after_reinit: ffi::cubeb_input_processing_params = |
| 1835 |
ffi::CUBEB_INPUT_PROCESSING_PARAM_NONE; |
| 1836 |
queue.run_sync(|| { |
| 1837 |
let mut params: ffi::cubeb_input_processing_params = |
| 1838 |
ffi::CUBEB_INPUT_PROCESSING_PARAM_NONE; |
| 1839 |
let mut agc: u32 = 0; |
| 1840 |
let r = audio_unit_get_property( |
| 1841 |
stm.core_stream_data.input_unit, |
| 1842 |
kAUVoiceIOProperty_VoiceProcessingEnableAGC, |
| 1843 |
kAudioUnitScope_Global, |
| 1844 |
AU_IN_BUS, |
| 1845 |
&mut agc, |
| 1846 |
&mut mem::size_of::<u32>(), |
| 1847 |
); |
| 1848 |
assert_eq!(r, NO_ERR); |
| 1849 |
if agc == 1 { |
| 1850 |
params = params | ffi::CUBEB_INPUT_PROCESSING_PARAM_AUTOMATIC_GAIN_CONTROL; |
| 1851 |
} |
| 1852 |
let mut bypass: u32 = 0; |
| 1853 |
let r = audio_unit_get_property( |
| 1854 |
stm.core_stream_data.input_unit, |
| 1855 |
kAUVoiceIOProperty_BypassVoiceProcessing, |
| 1856 |
kAudioUnitScope_Global, |
| 1857 |
AU_IN_BUS, |
| 1858 |
&mut bypass, |
| 1859 |
&mut mem::size_of::<u32>(), |
| 1860 |
); |
| 1861 |
assert_eq!(r, NO_ERR); |
| 1862 |
if bypass == 0 { |
| 1863 |
params = params |
| 1864 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION |
| 1865 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION; |
| 1866 |
} |
| 1867 |
params_after_reinit = params; |
| 1868 |
}); |
| 1869 |
assert_eq!(params, params_after_reinit); |
| 1870 |
}, |
| 1871 |
); |
| 1872 |
} |
| 1873 |
|
| 1874 |
#[test] |
| 1875 |
fn test_ops_duplex_voice_stream_set_input_processing_params_after_start() { |
| 1876 |
if macos_kernel_major_version().unwrap() == MACOS_KERNEL_MAJOR_VERSION_MONTEREY { |
| 1877 |
// We disable VPIO on Monterey. |
| 1878 |
return; |
| 1879 |
} |
| 1880 |
test_default_duplex_voice_stream_operation( |
| 1881 |
"duplex voice stream: processing after start", |
| 1882 |
|stream| { |
| 1883 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1884 |
assert!(stm.core_stream_data.using_voice_processing_unit()); |
| 1885 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1886 |
let params: ffi::cubeb_input_processing_params = |
| 1887 |
ffi::CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION |
| 1888 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION |
| 1889 |
| ffi::CUBEB_INPUT_PROCESSING_PARAM_AUTOMATIC_GAIN_CONTROL; |
| 1890 |
assert_eq!( |
| 1891 |
unsafe { OPS.stream_set_input_processing_params.unwrap()(stream, params) }, |
| 1892 |
ffi::CUBEB_OK |
| 1893 |
); |
| 1894 |
}, |
| 1895 |
); |
| 1896 |
} |
| 1897 |
|
| 1898 |
#[test] |
| 1899 |
fn test_ops_stereo_input_duplex_voice_stream_init_and_destroy() { |
| 1900 |
test_stereo_input_duplex_voice_stream_operation( |
| 1901 |
"stereo-input duplex voice stream: init and destroy", |
| 1902 |
|stream| { |
| 1903 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1904 |
assert_eq!( |
| 1905 |
stm.core_stream_data.using_voice_processing_unit(), |
| 1906 |
macos_kernel_major_version().unwrap() != MACOS_KERNEL_MAJOR_VERSION_MONTEREY |
| 1907 |
); |
| 1908 |
}, |
| 1909 |
); |
| 1910 |
} |
| 1911 |
|
| 1912 |
#[test] |
| 1913 |
fn test_ops_stereo_input_duplex_voice_stream_start() { |
| 1914 |
test_stereo_input_duplex_voice_stream_operation( |
| 1915 |
"stereo-input duplex voice stream: start", |
| 1916 |
|stream| { |
| 1917 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1918 |
assert_eq!( |
| 1919 |
stm.core_stream_data.using_voice_processing_unit(), |
| 1920 |
macos_kernel_major_version().unwrap() != MACOS_KERNEL_MAJOR_VERSION_MONTEREY |
| 1921 |
); |
| 1922 |
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1923 |
}, |
| 1924 |
); |
| 1925 |
} |
| 1926 |
|
| 1927 |
#[test] |
| 1928 |
fn test_ops_stereo_input_duplex_voice_stream_stop() { |
| 1929 |
test_stereo_input_duplex_voice_stream_operation( |
| 1930 |
"stereo-input duplex voice stream: stop", |
| 1931 |
|stream| { |
| 1932 |
let stm = unsafe { &mut *(stream as *mut AudioUnitStream) }; |
| 1933 |
assert_eq!( |
| 1934 |
stm.core_stream_data.using_voice_processing_unit(), |
| 1935 |
macos_kernel_major_version().unwrap() != MACOS_KERNEL_MAJOR_VERSION_MONTEREY |
| 1936 |
); |
| 1937 |
assert_eq!(unsafe { OPS.stream_stop.unwrap()(stream) }, ffi::CUBEB_OK); |
| 1938 |
}, |
| 1939 |
); |
| 1940 |
} |