Skip to content

Commit

Permalink
Minimize compiler flags by using nested platform_impl mods
Browse files Browse the repository at this point in the history
Also addresses some other CI errors:

- Add Host::new constructor for null backend
- Add missing DevicesError import to coreaudio backend
  • Loading branch information
mitchmindtree committed Jun 24, 2019
1 parent f7cf0c6 commit 6e9b40e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/host/coreaudio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use BuildStreamError;
use DefaultFormatError;
use Device as DeviceTrait;
use DeviceNameError;
use DevicesError;
use EventLoop as EventLoopTrait;
use Format;
use Host as HostTrait;
Expand Down
6 changes: 6 additions & 0 deletions src/host/null/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ pub struct StreamId;
pub struct SupportedInputFormats;
pub struct SupportedOutputFormats;

impl Host {
pub fn new() -> Result<Self, crate::HostUnavailable> {
Ok(Host)
}
}

impl Devices {
pub fn new() -> Result<Self, DevicesError> {
Ok(Devices)
Expand Down
63 changes: 41 additions & 22 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
//! 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.

#[doc(inline)]
pub use self::platform_impl::*;

// 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
Expand Down Expand Up @@ -412,41 +415,57 @@ macro_rules! impl_platform_host {

// TODO: Add pulseaudio and jack here eventually.
#[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"))]
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")]
impl_platform_host!(Emscripten emscripten);
mod platform_impl {
pub use crate::host::emscripten::Host as EmscriptenHost;

// TODO: Add `Asio asio` once #221 lands.
#[cfg(windows)]
impl_platform_host!(Wasapi wasapi);
/// The default host for the current compilation target platform.
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")))]
impl_platform_host!(Null null);
impl_platform_host!(Emscripten emscripten);
}

/// The default host for the current compilation target platform.
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub type DefaultHost = crate::host::alsa::Host;
// TODO: Add `Asio asio` once #221 lands.
#[cfg(windows)]
mod platform_impl {
pub use crate::host::wasapi::Host as WasapiHost;

/// The default host for the current compilation target platform.
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub type DefaultHost = crate::host::coreaudio::Host;
/// The default host for the current compilation target platform.
pub type DefaultHost = crate::host::wasapi::Host;

/// The default host for the current compilation target platform.
#[cfg(target_os = "emscripten")]
pub type DefaultHost = crate::host::emscripten::Host;
impl_platform_host!(Wasapi wasapi);
}

#[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;
mod platform_impl {
pub use crate::host::null::Host as NullHost;

/// The default host for the current compilation target platform.
#[cfg(windows)]
pub type DefaultHost = crate::host::wasapi::Host;
/// The default host for the current compilation target platform.
pub type DefaultHost = crate::host::null::Host;

impl_platform_host!(Null null);
}

/// Retrieve the default host for the system.
///
Expand Down

0 comments on commit 6e9b40e

Please sign in to comment.