From a5fe4208cc7e6a21efe0d98d224be9eafc3e5332 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Tue, 12 Apr 2022 18:59:21 +0200 Subject: [PATCH] Let the OS error out and propagate the error instead of asserting --- src/backend/device_property.rs | 32 ---------------------------- src/backend/mod.rs | 2 -- src/backend/tests/api.rs | 5 ----- src/backend/tests/device_property.rs | 21 ------------------ 4 files changed, 60 deletions(-) diff --git a/src/backend/device_property.rs b/src/backend/device_property.rs index 1505392..a5c7e5c 100644 --- a/src/backend/device_property.rs +++ b/src/backend/device_property.rs @@ -4,8 +4,6 @@ pub fn get_device_uid( id: AudioDeviceID, devtype: DeviceType, ) -> std::result::Result { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::DeviceUID, devtype); let mut size = mem::size_of::(); let mut uid: CFStringRef = ptr::null(); @@ -21,8 +19,6 @@ pub fn get_device_model_uid( id: AudioDeviceID, devtype: DeviceType, ) -> std::result::Result { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::ModelUID, devtype); let mut size = mem::size_of::(); let mut uid: CFStringRef = ptr::null(); @@ -38,8 +34,6 @@ pub fn get_device_transport_type( id: AudioDeviceID, devtype: DeviceType, ) -> std::result::Result { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::TransportType, devtype); let mut size = mem::size_of::(); let mut transport: u32 = 0; @@ -55,8 +49,6 @@ pub fn get_device_source( id: AudioDeviceID, devtype: DeviceType, ) -> std::result::Result { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::DeviceSource, devtype); let mut size = mem::size_of::(); let mut source: u32 = 0; @@ -72,8 +64,6 @@ pub fn get_device_source_name( id: AudioDeviceID, devtype: DeviceType, ) -> std::result::Result { - 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::(); @@ -96,8 +86,6 @@ pub fn get_device_name( id: AudioDeviceID, devtype: DeviceType, ) -> std::result::Result { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::DeviceName, devtype); let mut size = mem::size_of::(); let mut name: CFStringRef = ptr::null(); @@ -113,8 +101,6 @@ pub fn get_device_manufacturer( id: AudioDeviceID, devtype: DeviceType, ) -> std::result::Result { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::DeviceManufacturer, devtype); let mut size = mem::size_of::(); 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 { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::DeviceBufferFrameSizeRange, devtype); let mut size = mem::size_of::(); let mut range = AudioValueRange::default(); @@ -147,8 +131,6 @@ pub fn get_device_latency( id: AudioDeviceID, devtype: DeviceType, ) -> std::result::Result { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::DeviceLatency, devtype); let mut size = mem::size_of::(); let mut latency: u32 = 0; @@ -164,8 +146,6 @@ pub fn get_device_streams( id: AudioDeviceID, devtype: DeviceType, ) -> std::result::Result, 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 { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::DeviceSampleRate, devtype); let mut size = mem::size_of::(); 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, 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 { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::DeviceStreamFormat, devtype); let mut size = mem::size_of::(); let mut format = AudioStreamBasicDescription::default(); @@ -245,8 +219,6 @@ pub fn get_device_stream_configuration( id: AudioDeviceID, devtype: DeviceType, ) -> std::result::Result, 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 { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::StreamLatency, devtype); let mut size = mem::size_of::(); let mut latency: u32 = 0; @@ -289,8 +259,6 @@ pub fn get_clock_domain( id: AudioStreamID, devtype: DeviceType, ) -> std::result::Result { - assert_ne!(id, kAudioObjectUnknown); - let address = get_property_address(Property::ClockDomain, devtype); let mut size = mem::size_of::(); let mut clock_domain: u32 = 0; diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 80b4074..34ffed5 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -1248,8 +1248,6 @@ fn get_channel_count( devid: AudioObjectID, devtype: DeviceType, ) -> std::result::Result { - assert_ne!(devid, kAudioObjectUnknown); - let buffers = get_device_stream_configuration(devid, devtype)?; let mut count = 0; for buffer in buffers { diff --git a/src/backend/tests/api.rs b/src/backend/tests/api.rs index becfbe3..706bbfc 100644 --- a/src/backend/tests/api.rs +++ b/src/backend/tests/api.rs @@ -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()); } diff --git a/src/backend/tests/device_property.rs b/src/backend/tests/device_property.rs index d8d3ef0..1dbb5e5 100644 --- a/src/backend/tests/device_property.rs +++ b/src/backend/tests/device_property.rs @@ -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()); }