Let the OS error out and propagate the error instead of asserting

This commit is contained in:
Paul Adenot 2022-04-12 18:59:21 +02:00
Родитель 38896988d7
Коммит a5fe4208cc
4 изменённых файлов: 0 добавлений и 60 удалений

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

@ -4,8 +4,6 @@ pub fn get_device_uid(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<StringRef, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceUID, devtype);
let mut size = mem::size_of::<CFStringRef>();
let mut uid: CFStringRef = ptr::null();
@ -21,8 +19,6 @@ pub fn get_device_model_uid(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<StringRef, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::ModelUID, devtype);
let mut size = mem::size_of::<CFStringRef>();
let mut uid: CFStringRef = ptr::null();
@ -38,8 +34,6 @@ pub fn get_device_transport_type(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<u32, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::TransportType, devtype);
let mut size = mem::size_of::<u32>();
let mut transport: u32 = 0;
@ -55,8 +49,6 @@ pub fn get_device_source(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<u32, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceSource, devtype);
let mut size = mem::size_of::<u32>();
let mut source: u32 = 0;
@ -72,8 +64,6 @@ pub fn get_device_source_name(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<StringRef, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let mut source: u32 = get_device_source(id, devtype)?;
let address = get_property_address(Property::DeviceSourceName, devtype);
let mut size = mem::size_of::<AudioValueTranslation>();
@ -96,8 +86,6 @@ pub fn get_device_name(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<StringRef, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceName, devtype);
let mut size = mem::size_of::<CFStringRef>();
let mut name: CFStringRef = ptr::null();
@ -113,8 +101,6 @@ pub fn get_device_manufacturer(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<StringRef, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceManufacturer, devtype);
let mut size = mem::size_of::<CFStringRef>();
let mut manufacturer: CFStringRef = ptr::null();
@ -130,8 +116,6 @@ pub fn get_device_buffer_frame_size_range(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<AudioValueRange, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceBufferFrameSizeRange, devtype);
let mut size = mem::size_of::<AudioValueRange>();
let mut range = AudioValueRange::default();
@ -147,8 +131,6 @@ pub fn get_device_latency(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<u32, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceLatency, devtype);
let mut size = mem::size_of::<u32>();
let mut latency: u32 = 0;
@ -164,8 +146,6 @@ pub fn get_device_streams(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<Vec<AudioStreamID>, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceStreams, devtype);
let mut size: usize = 0;
@ -187,8 +167,6 @@ pub fn get_device_sample_rate(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<f64, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceSampleRate, devtype);
let mut size = mem::size_of::<f64>();
let mut rate: f64 = 0.0;
@ -204,8 +182,6 @@ pub fn get_ranges_of_device_sample_rate(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<Vec<AudioValueRange>, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceSampleRates, devtype);
let mut size: usize = 0;
@ -227,8 +203,6 @@ pub fn get_device_stream_format(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<AudioStreamBasicDescription, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceStreamFormat, devtype);
let mut size = mem::size_of::<AudioStreamBasicDescription>();
let mut format = AudioStreamBasicDescription::default();
@ -245,8 +219,6 @@ pub fn get_device_stream_configuration(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<Vec<AudioBuffer>, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::DeviceStreamConfiguration, devtype);
let mut size: usize = 0;
let err = audio_object_get_property_data_size(id, &address, &mut size);
@ -272,8 +244,6 @@ pub fn get_stream_latency(
id: AudioStreamID,
devtype: DeviceType,
) -> std::result::Result<u32, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::StreamLatency, devtype);
let mut size = mem::size_of::<u32>();
let mut latency: u32 = 0;
@ -289,8 +259,6 @@ pub fn get_clock_domain(
id: AudioStreamID,
devtype: DeviceType,
) -> std::result::Result<u32, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::ClockDomain, devtype);
let mut size = mem::size_of::<u32>();
let mut clock_domain: u32 = 0;

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

@ -1248,8 +1248,6 @@ fn get_channel_count(
devid: AudioObjectID,
devtype: DeviceType,
) -> std::result::Result<u32, OSStatus> {
assert_ne!(devid, kAudioObjectUnknown);
let buffers = get_device_stream_configuration(devid, devtype)?;
let mut count = 0;
for buffer in buffers {

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

@ -1044,7 +1044,6 @@ fn test_get_channel_count_of_output_for_a_input_only_deivce() {
}
#[test]
#[should_panic]
fn test_get_channel_count_of_unknown_device() {
assert!(get_channel_count(kAudioObjectUnknown, DeviceType::OUTPUT).is_err());
}
@ -1221,7 +1220,6 @@ fn test_get_same_group_id_for_builtin_device_pairs() {
}
#[test]
#[should_panic]
fn test_get_device_group_id_by_unknown_device() {
assert!(get_device_group_id(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -1246,7 +1244,6 @@ fn test_get_device_label() {
}
#[test]
#[should_panic]
fn test_get_device_label_by_unknown_device() {
assert!(get_device_label(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -1271,7 +1268,6 @@ fn test_get_device_global_uid() {
}
#[test]
#[should_panic]
fn test_get_device_global_uid_by_unknwon_device() {
// Unknown device.
assert!(get_device_global_uid(kAudioObjectUnknown).is_err());
@ -1370,7 +1366,6 @@ fn test_create_cubeb_device_info() {
}
#[test]
#[should_panic]
fn test_create_device_info_by_unknown_device() {
assert!(create_cubeb_device_info(kAudioObjectUnknown, DeviceType::OUTPUT).is_err());
}

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

@ -20,13 +20,6 @@ fn test_get_device_uid() {
}
}
#[test]
#[should_panic]
fn test_get_device_uid_by_unknwon_device() {
// Unknown device.
assert!(get_device_uid(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
// get_device_model_uid
// ------------------------------------
// Some devices (e.g., AirPods) fail to get model uid.
@ -52,7 +45,6 @@ fn test_get_device_model_uid() {
}
#[test]
#[should_panic]
fn test_get_device_model_uid_by_unknown_device() {
assert!(get_device_model_uid(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -89,7 +81,6 @@ fn test_get_device_transport_type() {
}
#[test]
#[should_panic]
fn test_get_device_transport_type_by_unknown_device() {
assert!(get_device_transport_type(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -127,7 +118,6 @@ fn test_get_device_source() {
}
#[test]
#[should_panic]
fn test_get_device_source_by_unknown_device() {
assert!(get_device_source(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -156,7 +146,6 @@ fn test_get_device_source_name() {
}
#[test]
#[should_panic]
fn test_get_device_source_name_by_unknown_device() {
assert!(get_device_source_name(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -181,7 +170,6 @@ fn test_get_device_name() {
}
#[test]
#[should_panic]
fn test_get_device_name_by_unknown_device() {
assert!(get_device_name(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -214,7 +202,6 @@ fn test_get_device_manufacturer() {
}
#[test]
#[should_panic]
fn test_get_device_manufacturer_by_unknown_device() {
assert!(get_device_manufacturer(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -245,7 +232,6 @@ fn test_get_device_buffer_frame_size_range() {
}
#[test]
#[should_panic]
fn test_get_device_buffer_frame_size_range_by_unknown_device() {
assert!(get_device_buffer_frame_size_range(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -270,7 +256,6 @@ fn test_get_device_latency() {
}
#[test]
#[should_panic]
fn test_get_device_latency_by_unknown_device() {
assert!(get_device_latency(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -295,7 +280,6 @@ fn test_get_device_streams() {
}
#[test]
#[should_panic]
fn test_get_device_streams_by_unknown_device() {
assert!(get_device_streams(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -320,7 +304,6 @@ fn test_get_device_sample_rate() {
}
#[test]
#[should_panic]
fn test_get_device_sample_rate_by_unknown_device() {
assert!(get_device_sample_rate(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -345,7 +328,6 @@ fn test_get_ranges_of_device_sample_rate() {
}
#[test]
#[should_panic]
fn test_get_ranges_of_device_sample_rate_by_unknown_device() {
assert!(get_ranges_of_device_sample_rate(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -370,7 +352,6 @@ fn test_get_device_stream_format() {
}
#[test]
#[should_panic]
fn test_get_device_stream_format_by_unknown_device() {
assert!(get_device_stream_format(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -395,7 +376,6 @@ fn test_get_device_stream_configuration() {
}
#[test]
#[should_panic]
fn test_get_device_stream_configuration_by_unknown_device() {
assert!(get_device_stream_configuration(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
@ -426,7 +406,6 @@ fn test_get_stream_latency() {
}
#[test]
#[should_panic]
fn test_get_stream_latency_by_unknown_device() {
assert!(get_stream_latency(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}