Rename `CreationError` to `BuildStreamError`

For clarity and to tie the name more closesly to the methods within from
which it may be returned.
This commit is contained in:
mitchmindtree 2019-06-20 21:31:15 +02:00
parent 0f27c1e0bb
commit cf84ab906f
7 changed files with 53 additions and 53 deletions

View File

@ -4,7 +4,7 @@ extern crate libc;
pub use self::enumerate::{Devices, default_input_device, default_output_device}; pub use self::enumerate::{Devices, default_input_device, default_output_device};
use ChannelCount; use ChannelCount;
use CreationError; use BuildStreamError;
use DefaultFormatError; use DefaultFormatError;
use Format; use Format;
use SupportedFormatsError; use SupportedFormatsError;
@ -644,7 +644,7 @@ impl EventLoop {
&self, &self,
device: &Device, device: &Device,
format: &Format, format: &Format,
) -> Result<StreamId, CreationError> ) -> Result<StreamId, BuildStreamError>
{ {
unsafe { unsafe {
let name = ffi::CString::new(device.0.clone()).expect("unable to clone device"); let name = ffi::CString::new(device.0.clone()).expect("unable to clone device");
@ -656,10 +656,10 @@ impl EventLoop {
alsa::SND_PCM_STREAM_CAPTURE, alsa::SND_PCM_STREAM_CAPTURE,
alsa::SND_PCM_NONBLOCK, alsa::SND_PCM_NONBLOCK,
) { ) {
-16 /* determined empirically */ => return Err(CreationError::DeviceNotAvailable), -16 /* determined empirically */ => return Err(BuildStreamError::DeviceNotAvailable),
-22 => return Err(CreationError::InvalidArgument), -22 => return Err(BuildStreamError::InvalidArgument),
e => if check_errors(e).is_err() { e => if check_errors(e).is_err() {
return Err(CreationError::Unknown); return Err(BuildStreamError::Unknown);
} }
} }
let hw_params = HwParams::alloc(); let hw_params = HwParams::alloc();
@ -708,7 +708,7 @@ impl EventLoop {
&self, &self,
device: &Device, device: &Device,
format: &Format, format: &Format,
) -> Result<StreamId, CreationError> ) -> Result<StreamId, BuildStreamError>
{ {
unsafe { unsafe {
let name = ffi::CString::new(device.0.clone()).expect("unable to clone device"); let name = ffi::CString::new(device.0.clone()).expect("unable to clone device");
@ -720,10 +720,10 @@ impl EventLoop {
alsa::SND_PCM_STREAM_PLAYBACK, alsa::SND_PCM_STREAM_PLAYBACK,
alsa::SND_PCM_NONBLOCK, alsa::SND_PCM_NONBLOCK,
) { ) {
-16 /* determined empirically */ => return Err(CreationError::DeviceNotAvailable), -16 /* determined empirically */ => return Err(BuildStreamError::DeviceNotAvailable),
-22 => return Err(CreationError::InvalidArgument), -22 => return Err(BuildStreamError::InvalidArgument),
e => if check_errors(e).is_err() { e => if check_errors(e).is_err() {
return Err(CreationError::Unknown); return Err(BuildStreamError::Unknown);
} }
} }
let hw_params = HwParams::alloc(); let hw_params = HwParams::alloc();

View File

@ -2,7 +2,7 @@ extern crate coreaudio;
extern crate core_foundation_sys; extern crate core_foundation_sys;
use ChannelCount; use ChannelCount;
use CreationError; use BuildStreamError;
use DefaultFormatError; use DefaultFormatError;
use Format; use Format;
use SupportedFormatsError; use SupportedFormatsError;
@ -338,15 +338,15 @@ struct StreamInner {
} }
// TODO need stronger error identification // TODO need stronger error identification
impl From<coreaudio::Error> for CreationError { impl From<coreaudio::Error> for BuildStreamError {
fn from(err: coreaudio::Error) -> CreationError { fn from(err: coreaudio::Error) -> BuildStreamError {
match err { match err {
coreaudio::Error::RenderCallbackBufferFormatDoesNotMatchAudioUnitStreamFormat | coreaudio::Error::RenderCallbackBufferFormatDoesNotMatchAudioUnitStreamFormat |
coreaudio::Error::NoKnownSubtype | coreaudio::Error::NoKnownSubtype |
coreaudio::Error::AudioUnit(coreaudio::error::AudioUnitError::FormatNotSupported) | coreaudio::Error::AudioUnit(coreaudio::error::AudioUnitError::FormatNotSupported) |
coreaudio::Error::AudioCodec(_) | coreaudio::Error::AudioCodec(_) |
coreaudio::Error::AudioFormat(_) => CreationError::FormatNotSupported, coreaudio::Error::AudioFormat(_) => BuildStreamError::FormatNotSupported,
_ => CreationError::DeviceNotAvailable, _ => BuildStreamError::DeviceNotAvailable,
} }
} }
} }
@ -483,7 +483,7 @@ impl EventLoop {
&self, &self,
device: &Device, device: &Device,
format: &Format, format: &Format,
) -> Result<StreamId, CreationError> ) -> Result<StreamId, BuildStreamError>
{ {
// The scope and element for working with a device's input stream. // The scope and element for working with a device's input stream.
let scope = Scope::Output; let scope = Scope::Output;
@ -555,7 +555,7 @@ impl EventLoop {
.iter() .iter()
.position(|r| r.mMinimum as u32 == sample_rate && r.mMaximum as u32 == sample_rate); .position(|r| r.mMinimum as u32 == sample_rate && r.mMaximum as u32 == sample_rate);
let range_index = match maybe_index { let range_index = match maybe_index {
None => return Err(CreationError::FormatNotSupported), None => return Err(BuildStreamError::FormatNotSupported),
Some(i) => i, Some(i) => i,
}; };
@ -700,7 +700,7 @@ impl EventLoop {
&self, &self,
device: &Device, device: &Device,
format: &Format, format: &Format,
) -> Result<StreamId, CreationError> ) -> Result<StreamId, BuildStreamError>
{ {
let mut audio_unit = audio_unit_from_device(device, false)?; let mut audio_unit = audio_unit_from_device(device, false)?;

View File

@ -8,7 +8,7 @@ use stdweb::unstable::TryInto;
use stdweb::web::TypedArray; use stdweb::web::TypedArray;
use stdweb::web::set_timeout; use stdweb::web::set_timeout;
use CreationError; use BuildStreamError;
use DefaultFormatError; use DefaultFormatError;
use Format; use Format;
use SupportedFormatsError; use SupportedFormatsError;
@ -118,12 +118,12 @@ impl EventLoop {
} }
#[inline] #[inline]
pub fn build_input_stream(&self, _: &Device, _format: &Format) -> Result<StreamId, CreationError> { pub fn build_input_stream(&self, _: &Device, _format: &Format) -> Result<StreamId, BuildStreamError> {
unimplemented!(); unimplemented!();
} }
#[inline] #[inline]
pub fn build_output_stream(&self, _: &Device, _format: &Format) -> Result<StreamId, CreationError> { pub fn build_output_stream(&self, _: &Device, _format: &Format) -> Result<StreamId, BuildStreamError> {
let stream = js!(return new AudioContext()).into_reference().unwrap(); let stream = js!(return new AudioContext()).into_reference().unwrap();
let mut streams = self.streams.lock().unwrap(); let mut streams = self.streams.lock().unwrap();

View File

@ -160,7 +160,7 @@ mod cpal_impl;
#[derive(Clone, PartialEq, Eq)] #[derive(Clone, PartialEq, Eq)]
pub struct Device(cpal_impl::Device); pub struct Device(cpal_impl::Device);
/// Collection of voices managed together. /// Collection of streams managed together.
/// ///
/// Created with the [`new`](struct.EventLoop.html#method.new) method. /// Created with the [`new`](struct.EventLoop.html#method.new) method.
pub struct EventLoop(cpal_impl::EventLoop); pub struct EventLoop(cpal_impl::EventLoop);
@ -306,9 +306,9 @@ pub enum DefaultFormatError {
StreamTypeNotSupported, StreamTypeNotSupported,
} }
/// Error that can happen when creating a `Voice`. /// Error that can happen when creating a `Stream`.
#[derive(Debug, Fail)] #[derive(Debug, Fail)]
pub enum CreationError { pub enum BuildStreamError {
/// The device no longer exists. This can happen if the device is disconnected while the /// The device no longer exists. This can happen if the device is disconnected while the
/// program is running. /// program is running.
#[fail(display = "The requested device is no longer available. For example, it has been unplugged.")] #[fail(display = "The requested device is no longer available. For example, it has been unplugged.")]
@ -435,7 +435,7 @@ impl EventLoop {
&self, &self,
device: &Device, device: &Device,
format: &Format, format: &Format,
) -> Result<StreamId, CreationError> ) -> Result<StreamId, BuildStreamError>
{ {
self.0.build_input_stream(&device.0, format).map(StreamId) self.0.build_input_stream(&device.0, format).map(StreamId)
} }
@ -451,7 +451,7 @@ impl EventLoop {
&self, &self,
device: &Device, device: &Device,
format: &Format, format: &Format,
) -> Result<StreamId, CreationError> ) -> Result<StreamId, BuildStreamError>
{ {
self.0.build_output_stream(&device.0, format).map(StreamId) self.0.build_output_stream(&device.0, format).map(StreamId)
} }

View File

@ -2,7 +2,7 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use CreationError; use BuildStreamError;
use DefaultFormatError; use DefaultFormatError;
use Format; use Format;
use SupportedFormatsError; use SupportedFormatsError;
@ -25,13 +25,13 @@ impl EventLoop {
} }
#[inline] #[inline]
pub fn build_input_stream(&self, _: &Device, _: &Format) -> Result<StreamId, CreationError> { pub fn build_input_stream(&self, _: &Device, _: &Format) -> Result<StreamId, BuildStreamError> {
Err(CreationError::DeviceNotAvailable) Err(BuildStreamError::DeviceNotAvailable)
} }
#[inline] #[inline]
pub fn build_output_stream(&self, _: &Device, _: &Format) -> Result<StreamId, CreationError> { pub fn build_output_stream(&self, _: &Device, _: &Format) -> Result<StreamId, BuildStreamError> {
Err(CreationError::DeviceNotAvailable) Err(BuildStreamError::DeviceNotAvailable)
} }
#[inline] #[inline]

View File

@ -187,7 +187,7 @@ pub unsafe fn is_format_supported(
(_, Err(ref e)) (_, Err(ref e))
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release(); (*audio_client).Release();
return Err(CreationError::DeviceNotAvailable); return Err(BuildStreamError::DeviceNotAvailable);
}, },
(_, Err(e)) => { (_, Err(e)) => {
(*audio_client).Release(); (*audio_client).Release();
@ -195,7 +195,7 @@ pub unsafe fn is_format_supported(
}, },
(winerror::S_FALSE, _) => { (winerror::S_FALSE, _) => {
(*audio_client).Release(); (*audio_client).Release();
return Err(CreationError::FormatNotSupported); return Err(BuildStreamError::FormatNotSupported);
}, },
(_, Ok(())) => (), (_, Ok(())) => (),
}; };

View File

@ -20,7 +20,7 @@ use std::sync::mpsc::{channel, Sender, Receiver};
use std::sync::atomic::AtomicUsize; use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use CreationError; use BuildStreamError;
use Format; use Format;
use SampleFormat; use SampleFormat;
use StreamData; use StreamData;
@ -114,7 +114,7 @@ impl EventLoop {
&self, &self,
device: &Device, device: &Device,
format: &Format, format: &Format,
) -> Result<StreamId, CreationError> ) -> Result<StreamId, BuildStreamError>
{ {
unsafe { unsafe {
// Making sure that COM is initialized. // Making sure that COM is initialized.
@ -124,20 +124,20 @@ impl EventLoop {
// Obtaining a `IAudioClient`. // Obtaining a `IAudioClient`.
let audio_client = match device.build_audioclient() { let audio_client = match device.build_audioclient() {
Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) =>
return Err(CreationError::DeviceNotAvailable), return Err(BuildStreamError::DeviceNotAvailable),
e => e.unwrap(), e => e.unwrap(),
}; };
// Computing the format and initializing the device. // Computing the format and initializing the device.
let waveformatex = { let waveformatex = {
let format_attempt = format_to_waveformatextensible(format) let format_attempt = format_to_waveformatextensible(format)
.ok_or(CreationError::FormatNotSupported)?; .ok_or(BuildStreamError::FormatNotSupported)?;
let share_mode = AUDCLNT_SHAREMODE_SHARED; let share_mode = AUDCLNT_SHAREMODE_SHARED;
// Ensure the format is supported. // Ensure the format is supported.
match super::device::is_format_supported(audio_client, &format_attempt.Format) { match super::device::is_format_supported(audio_client, &format_attempt.Format) {
Ok(false) => return Err(CreationError::FormatNotSupported), Ok(false) => return Err(BuildStreamError::FormatNotSupported),
Err(_) => return Err(CreationError::DeviceNotAvailable), Err(_) => return Err(BuildStreamError::DeviceNotAvailable),
_ => (), _ => (),
} }
@ -154,7 +154,7 @@ impl EventLoop {
Err(ref e) Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release(); (*audio_client).Release();
return Err(CreationError::DeviceNotAvailable); return Err(BuildStreamError::DeviceNotAvailable);
}, },
Err(e) => { Err(e) => {
(*audio_client).Release(); (*audio_client).Release();
@ -175,7 +175,7 @@ impl EventLoop {
Err(ref e) Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release(); (*audio_client).Release();
return Err(CreationError::DeviceNotAvailable); return Err(BuildStreamError::DeviceNotAvailable);
}, },
Err(e) => { Err(e) => {
(*audio_client).Release(); (*audio_client).Release();
@ -218,7 +218,7 @@ impl EventLoop {
Err(ref e) Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release(); (*audio_client).Release();
return Err(CreationError::DeviceNotAvailable); return Err(BuildStreamError::DeviceNotAvailable);
}, },
Err(e) => { Err(e) => {
(*audio_client).Release(); (*audio_client).Release();
@ -261,7 +261,7 @@ impl EventLoop {
&self, &self,
device: &Device, device: &Device,
format: &Format, format: &Format,
) -> Result<StreamId, CreationError> ) -> Result<StreamId, BuildStreamError>
{ {
unsafe { unsafe {
// Making sure that COM is initialized. // Making sure that COM is initialized.
@ -271,20 +271,20 @@ impl EventLoop {
// Obtaining a `IAudioClient`. // Obtaining a `IAudioClient`.
let audio_client = match device.build_audioclient() { let audio_client = match device.build_audioclient() {
Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) =>
return Err(CreationError::DeviceNotAvailable), return Err(BuildStreamError::DeviceNotAvailable),
e => e.unwrap(), e => e.unwrap(),
}; };
// Computing the format and initializing the device. // Computing the format and initializing the device.
let waveformatex = { let waveformatex = {
let format_attempt = format_to_waveformatextensible(format) let format_attempt = format_to_waveformatextensible(format)
.ok_or(CreationError::FormatNotSupported)?; .ok_or(BuildStreamError::FormatNotSupported)?;
let share_mode = AUDCLNT_SHAREMODE_SHARED; let share_mode = AUDCLNT_SHAREMODE_SHARED;
// Ensure the format is supported. // Ensure the format is supported.
match super::device::is_format_supported(audio_client, &format_attempt.Format) { match super::device::is_format_supported(audio_client, &format_attempt.Format) {
Ok(false) => return Err(CreationError::FormatNotSupported), Ok(false) => return Err(BuildStreamError::FormatNotSupported),
Err(_) => return Err(CreationError::DeviceNotAvailable), Err(_) => return Err(BuildStreamError::DeviceNotAvailable),
_ => (), _ => (),
} }
@ -299,7 +299,7 @@ impl EventLoop {
Err(ref e) Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release(); (*audio_client).Release();
return Err(CreationError::DeviceNotAvailable); return Err(BuildStreamError::DeviceNotAvailable);
}, },
Err(e) => { Err(e) => {
(*audio_client).Release(); (*audio_client).Release();
@ -339,7 +339,7 @@ impl EventLoop {
Err(ref e) Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release(); (*audio_client).Release();
return Err(CreationError::DeviceNotAvailable); return Err(BuildStreamError::DeviceNotAvailable);
}, },
Err(e) => { Err(e) => {
(*audio_client).Release(); (*audio_client).Release();
@ -363,7 +363,7 @@ impl EventLoop {
Err(ref e) Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release(); (*audio_client).Release();
return Err(CreationError::DeviceNotAvailable); return Err(BuildStreamError::DeviceNotAvailable);
}, },
Err(e) => { Err(e) => {
(*audio_client).Release(); (*audio_client).Release();