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};
use ChannelCount;
use CreationError;
use BuildStreamError;
use DefaultFormatError;
use Format;
use SupportedFormatsError;
@ -644,7 +644,7 @@ impl EventLoop {
&self,
device: &Device,
format: &Format,
) -> Result<StreamId, CreationError>
) -> Result<StreamId, BuildStreamError>
{
unsafe {
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_NONBLOCK,
) {
-16 /* determined empirically */ => return Err(CreationError::DeviceNotAvailable),
-22 => return Err(CreationError::InvalidArgument),
-16 /* determined empirically */ => return Err(BuildStreamError::DeviceNotAvailable),
-22 => return Err(BuildStreamError::InvalidArgument),
e => if check_errors(e).is_err() {
return Err(CreationError::Unknown);
return Err(BuildStreamError::Unknown);
}
}
let hw_params = HwParams::alloc();
@ -708,7 +708,7 @@ impl EventLoop {
&self,
device: &Device,
format: &Format,
) -> Result<StreamId, CreationError>
) -> Result<StreamId, BuildStreamError>
{
unsafe {
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_NONBLOCK,
) {
-16 /* determined empirically */ => return Err(CreationError::DeviceNotAvailable),
-22 => return Err(CreationError::InvalidArgument),
-16 /* determined empirically */ => return Err(BuildStreamError::DeviceNotAvailable),
-22 => return Err(BuildStreamError::InvalidArgument),
e => if check_errors(e).is_err() {
return Err(CreationError::Unknown);
return Err(BuildStreamError::Unknown);
}
}
let hw_params = HwParams::alloc();

View File

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

View File

@ -160,7 +160,7 @@ mod cpal_impl;
#[derive(Clone, PartialEq, Eq)]
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.
pub struct EventLoop(cpal_impl::EventLoop);
@ -306,9 +306,9 @@ pub enum DefaultFormatError {
StreamTypeNotSupported,
}
/// Error that can happen when creating a `Voice`.
/// Error that can happen when creating a `Stream`.
#[derive(Debug, Fail)]
pub enum CreationError {
pub enum BuildStreamError {
/// 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.")]
@ -435,7 +435,7 @@ impl EventLoop {
&self,
device: &Device,
format: &Format,
) -> Result<StreamId, CreationError>
) -> Result<StreamId, BuildStreamError>
{
self.0.build_input_stream(&device.0, format).map(StreamId)
}
@ -451,7 +451,7 @@ impl EventLoop {
&self,
device: &Device,
format: &Format,
) -> Result<StreamId, CreationError>
) -> Result<StreamId, BuildStreamError>
{
self.0.build_output_stream(&device.0, format).map(StreamId)
}

View File

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

View File

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

View File

@ -20,7 +20,7 @@ use std::sync::mpsc::{channel, Sender, Receiver};
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use CreationError;
use BuildStreamError;
use Format;
use SampleFormat;
use StreamData;
@ -114,7 +114,7 @@ impl EventLoop {
&self,
device: &Device,
format: &Format,
) -> Result<StreamId, CreationError>
) -> Result<StreamId, BuildStreamError>
{
unsafe {
// Making sure that COM is initialized.
@ -124,20 +124,20 @@ impl EventLoop {
// Obtaining a `IAudioClient`.
let audio_client = match device.build_audioclient() {
Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) =>
return Err(CreationError::DeviceNotAvailable),
return Err(BuildStreamError::DeviceNotAvailable),
e => e.unwrap(),
};
// Computing the format and initializing the device.
let waveformatex = {
let format_attempt = format_to_waveformatextensible(format)
.ok_or(CreationError::FormatNotSupported)?;
.ok_or(BuildStreamError::FormatNotSupported)?;
let share_mode = AUDCLNT_SHAREMODE_SHARED;
// Ensure the format is supported.
match super::device::is_format_supported(audio_client, &format_attempt.Format) {
Ok(false) => return Err(CreationError::FormatNotSupported),
Err(_) => return Err(CreationError::DeviceNotAvailable),
Ok(false) => return Err(BuildStreamError::FormatNotSupported),
Err(_) => return Err(BuildStreamError::DeviceNotAvailable),
_ => (),
}
@ -154,7 +154,7 @@ impl EventLoop {
Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release();
return Err(CreationError::DeviceNotAvailable);
return Err(BuildStreamError::DeviceNotAvailable);
},
Err(e) => {
(*audio_client).Release();
@ -175,7 +175,7 @@ impl EventLoop {
Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release();
return Err(CreationError::DeviceNotAvailable);
return Err(BuildStreamError::DeviceNotAvailable);
},
Err(e) => {
(*audio_client).Release();
@ -218,7 +218,7 @@ impl EventLoop {
Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release();
return Err(CreationError::DeviceNotAvailable);
return Err(BuildStreamError::DeviceNotAvailable);
},
Err(e) => {
(*audio_client).Release();
@ -261,7 +261,7 @@ impl EventLoop {
&self,
device: &Device,
format: &Format,
) -> Result<StreamId, CreationError>
) -> Result<StreamId, BuildStreamError>
{
unsafe {
// Making sure that COM is initialized.
@ -271,20 +271,20 @@ impl EventLoop {
// Obtaining a `IAudioClient`.
let audio_client = match device.build_audioclient() {
Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) =>
return Err(CreationError::DeviceNotAvailable),
return Err(BuildStreamError::DeviceNotAvailable),
e => e.unwrap(),
};
// Computing the format and initializing the device.
let waveformatex = {
let format_attempt = format_to_waveformatextensible(format)
.ok_or(CreationError::FormatNotSupported)?;
.ok_or(BuildStreamError::FormatNotSupported)?;
let share_mode = AUDCLNT_SHAREMODE_SHARED;
// Ensure the format is supported.
match super::device::is_format_supported(audio_client, &format_attempt.Format) {
Ok(false) => return Err(CreationError::FormatNotSupported),
Err(_) => return Err(CreationError::DeviceNotAvailable),
Ok(false) => return Err(BuildStreamError::FormatNotSupported),
Err(_) => return Err(BuildStreamError::DeviceNotAvailable),
_ => (),
}
@ -299,7 +299,7 @@ impl EventLoop {
Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release();
return Err(CreationError::DeviceNotAvailable);
return Err(BuildStreamError::DeviceNotAvailable);
},
Err(e) => {
(*audio_client).Release();
@ -339,7 +339,7 @@ impl EventLoop {
Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release();
return Err(CreationError::DeviceNotAvailable);
return Err(BuildStreamError::DeviceNotAvailable);
},
Err(e) => {
(*audio_client).Release();
@ -363,7 +363,7 @@ impl EventLoop {
Err(ref e)
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
(*audio_client).Release();
return Err(CreationError::DeviceNotAvailable);
return Err(BuildStreamError::DeviceNotAvailable);
},
Err(e) => {
(*audio_client).Release();
@ -529,7 +529,7 @@ impl EventLoop {
if hresult == AUDCLNT_S_BUFFER_EMPTY { continue; }
debug_assert!(!buffer.is_null());
let buffer_len = frames_available as usize
let buffer_len = frames_available as usize
* stream.bytes_per_frame as usize / sample_size;
// Simplify the capture callback sample format branches.
@ -568,9 +568,9 @@ impl EventLoop {
&mut buffer as *mut *mut _,
);
// FIXME: can return `AUDCLNT_E_DEVICE_INVALIDATED`
check_result(hresult).unwrap();
check_result(hresult).unwrap();
debug_assert!(!buffer.is_null());
let buffer_len = frames_available as usize
let buffer_len = frames_available as usize
* stream.bytes_per_frame as usize / sample_size;
// Simplify the render callback sample format branches.
@ -594,7 +594,7 @@ impl EventLoop {
Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => (),
e => e.unwrap(),
};
}}
}}
}
match stream.sample_format {