extern crate winapi; use BackendSpecificError; use BuildStreamError; use DefaultFormatError; use DeviceNameError; use DevicesError; use Format; use PlayStreamError; use PauseStreamError; use StreamDataResult; use SupportedFormatsError; use self::winapi::um::winnt::HRESULT; use std::io::Error as IoError; use traits::{DeviceTrait, EventLoopTrait, HostTrait, StreamIdTrait}; pub use self::device::{Device, Devices, SupportedInputFormats, SupportedOutputFormats, default_input_device, default_output_device}; pub use self::stream::{EventLoop, StreamId}; mod com; mod device; mod stream; /// The WASAPI host, the default windows host type. #[derive(Debug)] pub struct Host; impl Host { pub fn new() -> Result { Ok(Host) } } impl HostTrait for Host { type Devices = Devices; type Device = Device; type EventLoop = EventLoop; fn is_available() -> bool { // Assume WASAPI is always available on windows. true } fn devices(&self) -> Result { Devices::new() } fn default_input_device(&self) -> Option { default_input_device() } fn default_output_device(&self) -> Option { default_output_device() } fn event_loop(&self) -> Self::EventLoop { EventLoop::new() } } impl DeviceTrait for Device { type SupportedInputFormats = SupportedInputFormats; type SupportedOutputFormats = SupportedOutputFormats; fn name(&self) -> Result { Device::name(self) } fn supported_input_formats(&self) -> Result { Device::supported_input_formats(self) } fn supported_output_formats(&self) -> Result { Device::supported_output_formats(self) } fn default_input_format(&self) -> Result { Device::default_input_format(self) } fn default_output_format(&self) -> Result { Device::default_output_format(self) } } impl EventLoopTrait for EventLoop { type Device = Device; type StreamId = StreamId; fn build_input_stream( &self, device: &Self::Device, format: &Format, ) -> Result { EventLoop::build_input_stream(self, device, format) } fn build_output_stream( &self, device: &Self::Device, format: &Format, ) -> Result { EventLoop::build_output_stream(self, device, format) } fn play_stream(&self, stream: Self::StreamId) -> Result<(), PlayStreamError> { EventLoop::play_stream(self, stream) } fn pause_stream(&self, stream: Self::StreamId) -> Result<(), PauseStreamError> { EventLoop::pause_stream(self, stream) } fn destroy_stream(&self, stream: Self::StreamId) { EventLoop::destroy_stream(self, stream) } fn run(&self, callback: F) -> ! where F: FnMut(Self::StreamId, StreamDataResult) + Send, { EventLoop::run(self, callback) } } impl StreamIdTrait for StreamId {} #[inline] fn check_result(result: HRESULT) -> Result<(), IoError> { if result < 0 { Err(IoError::from_raw_os_error(result)) } else { Ok(()) } } fn check_result_backend_specific(result: HRESULT) -> Result<(), BackendSpecificError> { match check_result(result) { Ok(()) => Ok(()), Err(err) => { let description = format!("{}", err); return Err(BackendSpecificError { description }); } } }