Rename FormatsEnumerationError to SupportedFormatsError

This more tightly associates the error with the device method on which
this might occur.
This commit is contained in:
mitchmindtree 2019-06-20 21:16:39 +02:00
parent 1275db805b
commit 0f27c1e0bb
7 changed files with 39 additions and 39 deletions

View file

@ -30,13 +30,13 @@ impl Drop for Devices {
impl Default for Devices {
fn default() -> Devices {
unsafe {
let mut hints = mem::uninitialized();
// TODO: check in which situation this can fail
check_errors(alsa::snd_device_name_hint(-1, b"pcm\0".as_ptr() as *const _, &mut hints))
.unwrap();
// TODO: check in which situation this can fail.
let card = -1; // -1 means all cards.
let iface = b"pcm\0"; // Interface identification.
let mut hints = mem::uninitialized(); // Array of device name hints.
let res = alsa::snd_device_name_hint(card, iface.as_ptr() as *const _, &mut hints);
check_errors(res).unwrap();
let hints = hints as *const *const u8;
Devices {
global_list: hints,
next_str: hints,

View file

@ -7,7 +7,7 @@ use ChannelCount;
use CreationError;
use DefaultFormatError;
use Format;
use FormatsEnumerationError;
use SupportedFormatsError;
use SampleFormat;
use SampleRate;
use StreamData;
@ -80,7 +80,7 @@ impl Device {
unsafe fn supported_formats(
&self,
stream_t: alsa::snd_pcm_stream_t,
) -> Result<VecIntoIter<SupportedFormat>, FormatsEnumerationError>
) -> Result<VecIntoIter<SupportedFormat>, SupportedFormatsError>
{
let mut handle = mem::uninitialized();
let device_name = ffi::CString::new(&self.0[..]).expect("Unable to get device name");
@ -92,10 +92,10 @@ impl Device {
alsa::SND_PCM_NONBLOCK,
) {
-2 |
-16 /* determined empirically */ => return Err(FormatsEnumerationError::DeviceNotAvailable),
-22 => return Err(FormatsEnumerationError::InvalidArgument),
-16 /* determined empirically */ => return Err(SupportedFormatsError::DeviceNotAvailable),
-22 => return Err(SupportedFormatsError::InvalidArgument),
e => if check_errors(e).is_err() {
return Err(FormatsEnumerationError::Unknown)
return Err(SupportedFormatsError::Unknown)
}
}
@ -251,13 +251,13 @@ impl Device {
Ok(output.into_iter())
}
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, FormatsEnumerationError> {
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, SupportedFormatsError> {
unsafe {
self.supported_formats(alsa::SND_PCM_STREAM_CAPTURE)
}
}
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, FormatsEnumerationError> {
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, SupportedFormatsError> {
unsafe {
self.supported_formats(alsa::SND_PCM_STREAM_PLAYBACK)
}
@ -272,15 +272,15 @@ impl Device {
{
let mut formats: Vec<_> = unsafe {
match self.supported_formats(stream_t) {
Err(FormatsEnumerationError::DeviceNotAvailable) => {
Err(SupportedFormatsError::DeviceNotAvailable) => {
return Err(DefaultFormatError::DeviceNotAvailable);
},
Err(FormatsEnumerationError::InvalidArgument) => {
Err(SupportedFormatsError::InvalidArgument) => {
// this happens sometimes when querying for input and output capabilities but
// the device supports only one
return Err(DefaultFormatError::StreamTypeNotSupported);
}
Err(FormatsEnumerationError::Unknown) => {
Err(SupportedFormatsError::Unknown) => {
return Err(DefaultFormatError::DeviceNotAvailable);
}
Ok(fmts) => fmts.collect(),
@ -940,4 +940,4 @@ unsafe fn cast_input_buffer<T>(v: &[u8]) -> &[T] {
unsafe fn cast_output_buffer<T>(v: &mut [u8]) -> &mut [T] {
debug_assert!(v.len() % std::mem::size_of::<T>() == 0);
std::slice::from_raw_parts_mut(v.as_mut_ptr() as *mut T, v.len() / std::mem::size_of::<T>())
}
}