diff --git a/src/alsa/enumerate.rs b/src/alsa/enumerate.rs index fe5cfee..3f18f57 100644 --- a/src/alsa/enumerate.rs +++ b/src/alsa/enumerate.rs @@ -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, diff --git a/src/alsa/mod.rs b/src/alsa/mod.rs index 2131aaf..22b93c8 100644 --- a/src/alsa/mod.rs +++ b/src/alsa/mod.rs @@ -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, FormatsEnumerationError> + ) -> Result, 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 { + pub fn supported_input_formats(&self) -> Result { unsafe { self.supported_formats(alsa::SND_PCM_STREAM_CAPTURE) } } - pub fn supported_output_formats(&self) -> Result { + pub fn supported_output_formats(&self) -> Result { 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(v: &[u8]) -> &[T] { unsafe fn cast_output_buffer(v: &mut [u8]) -> &mut [T] { debug_assert!(v.len() % std::mem::size_of::() == 0); std::slice::from_raw_parts_mut(v.as_mut_ptr() as *mut T, v.len() / std::mem::size_of::()) -} \ No newline at end of file +} diff --git a/src/coreaudio/mod.rs b/src/coreaudio/mod.rs index c363464..d87321e 100644 --- a/src/coreaudio/mod.rs +++ b/src/coreaudio/mod.rs @@ -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 + ) -> Result { let mut property_address = AudioObjectPropertyAddress { mSelector: kAudioDevicePropertyStreamConfiguration, @@ -212,11 +212,11 @@ impl Device { } } - pub fn supported_input_formats(&self) -> Result { + pub fn supported_input_formats(&self) -> Result { self.supported_formats(kAudioObjectPropertyScopeInput) } - pub fn supported_output_formats(&self) -> Result { + pub fn supported_output_formats(&self) -> Result { self.supported_formats(kAudioObjectPropertyScopeOutput) } diff --git a/src/emscripten/mod.rs b/src/emscripten/mod.rs index b95a5df..054a473 100644 --- a/src/emscripten/mod.rs +++ b/src/emscripten/mod.rs @@ -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 { + pub fn supported_input_formats(&self) -> Result { unimplemented!(); } #[inline] - pub fn supported_output_formats(&self) -> Result { + pub fn supported_output_formats(&self) -> Result { // 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 diff --git a/src/lib.rs b/src/lib.rs index badf130..003a623 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { + pub fn supported_input_formats(&self) -> Result { 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 { + pub fn supported_output_formats(&self) -> Result { Ok(SupportedOutputFormats(self.0.supported_output_formats()?)) } diff --git a/src/null/mod.rs b/src/null/mod.rs index 244f086..bec555f 100644 --- a/src/null/mod.rs +++ b/src/null/mod.rs @@ -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 { + pub fn supported_input_formats(&self) -> Result { unimplemented!() } #[inline] - pub fn supported_output_formats(&self) -> Result { + pub fn supported_output_formats(&self) -> Result { unimplemented!() } @@ -132,4 +132,4 @@ pub struct InputBuffer<'a, T: 'a> { pub struct OutputBuffer<'a, T: 'a> { marker: PhantomData<&'a mut T>, -} \ No newline at end of file +} diff --git a/src/wasapi/device.rs b/src/wasapi/device.rs index 9913f2a..49a852b 100644 --- a/src/wasapi/device.rs +++ b/src/wasapi/device.rs @@ -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 +) -> Result { @@ -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 { + fn supported_formats(&self) -> Result { // 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 { + pub fn supported_input_formats(&self) -> Result { 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 { + pub fn supported_output_formats(&self) -> Result { if self.data_flow() == eRender { self.supported_formats() // If it's an input device, assume no output formats.