Rename `FormatsEnumerationError` to `SupportedFormatsError`
This more tightly associates the error with the device method on which this might occur.
This commit is contained in:
parent
1275db805b
commit
0f27c1e0bb
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -5,7 +5,7 @@ use ChannelCount;
|
|||
use CreationError;
|
||||
use DefaultFormatError;
|
||||
use Format;
|
||||
use FormatsEnumerationError;
|
||||
use SupportedFormatsError;
|
||||
use Sample;
|
||||
use SampleFormat;
|
||||
use SampleRate;
|
||||
|
@ -108,7 +108,7 @@ impl Device {
|
|||
fn supported_formats(
|
||||
&self,
|
||||
scope: AudioObjectPropertyScope,
|
||||
) -> Result<SupportedOutputFormats, FormatsEnumerationError>
|
||||
) -> Result<SupportedOutputFormats, SupportedFormatsError>
|
||||
{
|
||||
let mut property_address = AudioObjectPropertyAddress {
|
||||
mSelector: kAudioDevicePropertyStreamConfiguration,
|
||||
|
@ -212,11 +212,11 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedOutputFormats, FormatsEnumerationError> {
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedOutputFormats, SupportedFormatsError> {
|
||||
self.supported_formats(kAudioObjectPropertyScopeInput)
|
||||
}
|
||||
|
||||
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, FormatsEnumerationError> {
|
||||
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, SupportedFormatsError> {
|
||||
self.supported_formats(kAudioObjectPropertyScopeOutput)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use stdweb::web::set_timeout;
|
|||
use CreationError;
|
||||
use DefaultFormatError;
|
||||
use Format;
|
||||
use FormatsEnumerationError;
|
||||
use SupportedFormatsError;
|
||||
use StreamData;
|
||||
use SupportedFormat;
|
||||
use UnknownTypeOutputBuffer;
|
||||
|
@ -226,12 +226,12 @@ impl Device {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, FormatsEnumerationError> {
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, SupportedFormatsError> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, FormatsEnumerationError> {
|
||||
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, SupportedFormatsError> {
|
||||
// TODO: right now cpal's API doesn't allow flexibility here
|
||||
// "44100" and "2" (channels) have also been hard-coded in the rest of the code ; if
|
||||
// this ever becomes more flexible, don't forget to change that
|
||||
|
|
|
@ -281,7 +281,7 @@ pub struct SupportedOutputFormats(cpal_impl::SupportedOutputFormats);
|
|||
|
||||
/// Error that can happen when enumerating the list of supported formats.
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum FormatsEnumerationError {
|
||||
pub enum SupportedFormatsError {
|
||||
/// The device no longer exists. This can happen if the device is disconnected while the
|
||||
/// program is running.
|
||||
#[fail(display = "The requested device is no longer available. For example, it has been unplugged.")]
|
||||
|
@ -386,7 +386,7 @@ impl Device {
|
|||
///
|
||||
/// Can return an error if the device is no longer valid (eg. it has been disconnected).
|
||||
#[inline]
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, FormatsEnumerationError> {
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, SupportedFormatsError> {
|
||||
Ok(SupportedInputFormats(self.0.supported_input_formats()?))
|
||||
}
|
||||
|
||||
|
@ -394,7 +394,7 @@ impl Device {
|
|||
///
|
||||
/// Can return an error if the device is no longer valid (eg. it has been disconnected).
|
||||
#[inline]
|
||||
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, FormatsEnumerationError> {
|
||||
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, SupportedFormatsError> {
|
||||
Ok(SupportedOutputFormats(self.0.supported_output_formats()?))
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::marker::PhantomData;
|
|||
use CreationError;
|
||||
use DefaultFormatError;
|
||||
use Format;
|
||||
use FormatsEnumerationError;
|
||||
use SupportedFormatsError;
|
||||
use StreamData;
|
||||
use SupportedFormat;
|
||||
|
||||
|
@ -80,12 +80,12 @@ pub struct Device;
|
|||
|
||||
impl Device {
|
||||
#[inline]
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, FormatsEnumerationError> {
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, SupportedFormatsError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, FormatsEnumerationError> {
|
||||
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, SupportedFormatsError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex, MutexGuard};
|
|||
|
||||
use DefaultFormatError;
|
||||
use Format;
|
||||
use FormatsEnumerationError;
|
||||
use SupportedFormatsError;
|
||||
use SampleFormat;
|
||||
use SampleRate;
|
||||
use SupportedFormat;
|
||||
|
@ -165,7 +165,7 @@ unsafe fn data_flow_from_immendpoint(endpoint: *const IMMEndpoint) -> EDataFlow
|
|||
pub unsafe fn is_format_supported(
|
||||
client: *const IAudioClient,
|
||||
waveformatex_ptr: *const mmreg::WAVEFORMATEX,
|
||||
) -> Result<bool, FormatsEnumerationError>
|
||||
) -> Result<bool, SupportedFormatsError>
|
||||
{
|
||||
|
||||
|
||||
|
@ -213,7 +213,7 @@ pub unsafe fn is_format_supported(
|
|||
// has been found, but not an exact match) so we also treat this as unsupported.
|
||||
match (result, check_result(result)) {
|
||||
(_, Err(ref e)) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
|
||||
return Err(FormatsEnumerationError::DeviceNotAvailable);
|
||||
return Err(SupportedFormatsError::DeviceNotAvailable);
|
||||
},
|
||||
(_, Err(_)) => {
|
||||
Ok(false)
|
||||
|
@ -386,14 +386,14 @@ impl Device {
|
|||
// number of channels seems to be supported. Any more or less returns an invalid
|
||||
// parameter error. Thus we just assume that the default number of channels is the only
|
||||
// number supported.
|
||||
fn supported_formats(&self) -> Result<SupportedInputFormats, FormatsEnumerationError> {
|
||||
fn supported_formats(&self) -> Result<SupportedInputFormats, SupportedFormatsError> {
|
||||
// initializing COM because we call `CoTaskMemFree` to release the format.
|
||||
com::com_initialized();
|
||||
|
||||
// Retrieve the `IAudioClient`.
|
||||
let lock = match self.ensure_future_audio_client() {
|
||||
Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) =>
|
||||
return Err(FormatsEnumerationError::DeviceNotAvailable),
|
||||
return Err(SupportedFormatsError::DeviceNotAvailable),
|
||||
e => e.unwrap(),
|
||||
};
|
||||
let client = lock.unwrap().0;
|
||||
|
@ -403,7 +403,7 @@ impl Device {
|
|||
let mut default_waveformatex_ptr = WaveFormatExPtr(mem::uninitialized());
|
||||
match check_result((*client).GetMixFormat(&mut default_waveformatex_ptr.0)) {
|
||||
Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
|
||||
return Err(FormatsEnumerationError::DeviceNotAvailable);
|
||||
return Err(SupportedFormatsError::DeviceNotAvailable);
|
||||
},
|
||||
Err(e) => panic!("{:?}", e),
|
||||
Ok(()) => (),
|
||||
|
@ -462,7 +462,7 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, FormatsEnumerationError> {
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, SupportedFormatsError> {
|
||||
if self.data_flow() == eCapture {
|
||||
self.supported_formats()
|
||||
// If it's an output device, assume no input formats.
|
||||
|
@ -471,7 +471,7 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, FormatsEnumerationError> {
|
||||
pub fn supported_output_formats(&self) -> Result<SupportedOutputFormats, SupportedFormatsError> {
|
||||
if self.data_flow() == eRender {
|
||||
self.supported_formats()
|
||||
// If it's an input device, assume no output formats.
|
||||
|
|
Loading…
Reference in New Issue