Added error handling for unknown ALSA device errors (#1)
Instead of taking the easy way out and killing the whole program by panicking, device enumeration and stream creation will now report the error variant 'Unknown'
This commit is contained in:
parent
c2d606176a
commit
5cb45bfd7e
2 changed files with 43 additions and 3 deletions
|
|
@ -92,7 +92,10 @@ impl Device {
|
|||
) {
|
||||
-2 |
|
||||
-16 /* determined empirically */ => return Err(FormatsEnumerationError::DeviceNotAvailable),
|
||||
e => check_errors(e).expect("device not available")
|
||||
-22 => return Err(FormatsEnumerationError::InvalidArgument),
|
||||
e => if check_errors(e).is_err() {
|
||||
return Err(FormatsEnumerationError::Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
let hw_params = HwParams::alloc();
|
||||
|
|
@ -271,6 +274,14 @@ impl Device {
|
|||
Err(FormatsEnumerationError::DeviceNotAvailable) => {
|
||||
return Err(DefaultFormatError::DeviceNotAvailable);
|
||||
},
|
||||
Err(FormatsEnumerationError::InvalidArgument) => {
|
||||
// this happens sometimes when querying for input and output capabilities but
|
||||
// the device supports only one
|
||||
return Err(DefaultFormatError::StreamTypeNotSupported);
|
||||
}
|
||||
Err(FormatsEnumerationError::Unknown) => {
|
||||
return Err(DefaultFormatError::DeviceNotAvailable);
|
||||
}
|
||||
Ok(fmts) => fmts.collect(),
|
||||
}
|
||||
};
|
||||
|
|
@ -633,7 +644,10 @@ impl EventLoop {
|
|||
alsa::SND_PCM_NONBLOCK,
|
||||
) {
|
||||
-16 /* determined empirically */ => return Err(CreationError::DeviceNotAvailable),
|
||||
e => check_errors(e).expect("Device unavailable")
|
||||
-22 => return Err(CreationError::InvalidArgument),
|
||||
e => if check_errors(e).is_err() {
|
||||
return Err(CreationError::Unknown);
|
||||
}
|
||||
}
|
||||
let hw_params = HwParams::alloc();
|
||||
|
||||
|
|
@ -693,7 +707,10 @@ impl EventLoop {
|
|||
alsa::SND_PCM_NONBLOCK,
|
||||
) {
|
||||
-16 /* determined empirically */ => return Err(CreationError::DeviceNotAvailable),
|
||||
e => check_errors(e).expect("Device unavailable")
|
||||
-22 => return Err(CreationError::InvalidArgument),
|
||||
e => if check_errors(e).is_err() {
|
||||
return Err(CreationError::Unknown);
|
||||
}
|
||||
}
|
||||
let hw_params = HwParams::alloc();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue