Minimize compiler flags by using nested platform_impl mods

Also addresses some other CI errors:

- Add Host::new constructor for null backend
- Add missing DevicesError import to coreaudio backend
This commit is contained in:
mitchmindtree 2019-06-24 22:49:18 +02:00
parent f7cf0c65b8
commit 6e9b40e225
3 changed files with 49 additions and 23 deletions

View File

@ -7,6 +7,7 @@ use BuildStreamError;
use DefaultFormatError; use DefaultFormatError;
use Device as DeviceTrait; use Device as DeviceTrait;
use DeviceNameError; use DeviceNameError;
use DevicesError;
use EventLoop as EventLoopTrait; use EventLoop as EventLoopTrait;
use Format; use Format;
use Host as HostTrait; use Host as HostTrait;

View File

@ -31,6 +31,12 @@ pub struct StreamId;
pub struct SupportedInputFormats; pub struct SupportedInputFormats;
pub struct SupportedOutputFormats; pub struct SupportedOutputFormats;
impl Host {
pub fn new() -> Result<Self, crate::HostUnavailable> {
Ok(Host)
}
}
impl Devices { impl Devices {
pub fn new() -> Result<Self, DevicesError> { pub fn new() -> Result<Self, DevicesError> {
Ok(Devices) Ok(Devices)

View File

@ -4,6 +4,9 @@
//! type and its associated `EventLoop`, `Device`, `StreamId` and other associated types. These //! type and its associated `EventLoop`, `Device`, `StreamId` and other associated types. These
//! types are useful in the case that users require switching between audio host APIs at runtime. //! types are useful in the case that users require switching between audio host APIs at runtime.
#[doc(inline)]
pub use self::platform_impl::*;
// A macro to assist with implementing a platform's dynamically dispatched `Host` type. // A macro to assist with implementing a platform's dynamically dispatched `Host` type.
// //
// These dynamically dispatched types are necessary to allow for users to switch between hosts at // These dynamically dispatched types are necessary to allow for users to switch between hosts at
@ -412,41 +415,57 @@ macro_rules! impl_platform_host {
// TODO: Add pulseaudio and jack here eventually. // TODO: Add pulseaudio and jack here eventually.
#[cfg(any(target_os = "linux", target_os = "freebsd"))] #[cfg(any(target_os = "linux", target_os = "freebsd"))]
impl_platform_host!(Alsa alsa); mod platform_impl {
pub use crate::host::alsa::Host as AlsaHost;
/// The default host for the current compilation target platform.
pub type DefaultHost = crate::host::alsa::Host;
impl_platform_host!(Alsa alsa);
}
#[cfg(any(target_os = "macos", target_os = "ios"))] #[cfg(any(target_os = "macos", target_os = "ios"))]
impl_platform_host!(CoreAudio coreaudio); mod platform_impl {
pub use crate::host::coreaudio::Host as CoreAudioHost;
/// The default host for the current compilation target platform.
pub type DefaultHost = crate::host::coreaudio::Host;
impl_platform_host!(CoreAudio coreaudio);
}
#[cfg(target_os = "emscripten")] #[cfg(target_os = "emscripten")]
impl_platform_host!(Emscripten emscripten); mod platform_impl {
pub use crate::host::emscripten::Host as EmscriptenHost;
/// The default host for the current compilation target platform.
pub type DefaultHost = crate::host::emscripten::Host;
impl_platform_host!(Emscripten emscripten);
}
// TODO: Add `Asio asio` once #221 lands. // TODO: Add `Asio asio` once #221 lands.
#[cfg(windows)] #[cfg(windows)]
impl_platform_host!(Wasapi wasapi); mod platform_impl {
pub use crate::host::wasapi::Host as WasapiHost;
/// The default host for the current compilation target platform.
pub type DefaultHost = crate::host::wasapi::Host;
impl_platform_host!(Wasapi wasapi);
}
#[cfg(not(any(windows, target_os = "linux", target_os = "freebsd", target_os = "macos", #[cfg(not(any(windows, target_os = "linux", target_os = "freebsd", target_os = "macos",
target_os = "ios", target_os = "emscripten")))] target_os = "ios", target_os = "emscripten")))]
impl_platform_host!(Null null); mod platform_impl {
pub use crate::host::null::Host as NullHost;
/// The default host for the current compilation target platform. /// The default host for the current compilation target platform.
#[cfg(any(target_os = "linux", target_os = "freebsd"))] pub type DefaultHost = crate::host::null::Host;
pub type DefaultHost = crate::host::alsa::Host;
/// The default host for the current compilation target platform. impl_platform_host!(Null null);
#[cfg(any(target_os = "macos", target_os = "ios"))] }
pub type DefaultHost = crate::host::coreaudio::Host;
/// The default host for the current compilation target platform.
#[cfg(target_os = "emscripten")]
pub type DefaultHost = crate::host::emscripten::Host;
#[cfg(not(any(windows, target_os = "linux", target_os = "freebsd", target_os = "macos",
target_os = "ios", target_os = "emscripten")))]
pub type DefaultHost = crate::host::null::Host;
/// The default host for the current compilation target platform.
#[cfg(windows)]
pub type DefaultHost = crate::host::wasapi::Host;
/// Retrieve the default host for the system. /// Retrieve the default host for the system.
/// ///