diff --git a/.github/workflows/cpal.yml b/.github/workflows/cpal.yml index 8c637b632..434bd20af 100644 --- a/.github/workflows/cpal.yml +++ b/.github/workflows/cpal.yml @@ -82,6 +82,17 @@ jobs: run: sudo apt-get install libasound2-dev - name: Install libjack run: sudo apt-get install libjack-jackd2-dev libjack-jackd2-0 + - name: Install sndio + run: | + sudo apt-get install build-essential && + git clone https://caoua.org/git/sndio && + cd sndio && + ./configure && + make && + sudo mkdir /var/run/sndiod && + sudo useradd -r -g audio -s /sbin/nologin -d /var/run/sndiod sndiod && + sudo make install && + sudo ldconfig - name: Install stable uses: actions-rs/toolchain@v1 with: @@ -98,6 +109,11 @@ jobs: with: command: test args: --all --all-features --verbose + - name: Run with jack feature + uses: actions-rs/cargo@v1 + with: + command: test + args: --all --features jack --verbose linux-check-and-test-armv7: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index e95550339..6cd83a989 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ keywords = ["audio", "sound"] [features] asio = ["asio-sys", "num-traits"] # Only available on Windows. See README for setup instructions. +linux-sndio = ["sndio-sys", "libc"] # sndio on Linux (normally this is only used on OpenBSD) [dependencies] thiserror = "1.0.2" @@ -34,6 +35,10 @@ libc = "0.2.65" parking_lot = "0.11" jack = { version = "0.6.5", optional = true } +[target.'cfg(target_os = "linux")'.dependencies] +sndio-sys = { version = "0.0.*", optional = true } +libc = { version = "0.2.65", optional = true } + [target.'cfg(target_os = "openbsd")'.dependencies] sndio-sys = "0.0.*" libc = "0.2.65" diff --git a/src/host/mod.rs b/src/host/mod.rs index cd33107c4..b8f22b6ef 100644 --- a/src/host/mod.rs +++ b/src/host/mod.rs @@ -14,7 +14,10 @@ pub(crate) mod jack; pub(crate) mod null; #[cfg(target_os = "android")] pub(crate) mod oboe; -#[cfg(target_os = "openbsd")] +#[cfg(any( + target_os = "openbsd", + all(target_os = "linux", feature = "linux-sndio") +))] pub(crate) mod sndio; #[cfg(windows)] pub(crate) mod wasapi; diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 8375f95d2..acc9554e5 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -448,30 +448,50 @@ macro_rules! impl_platform_host { // TODO: Add pulseaudio and jack here eventually. #[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] mod platform_impl { + #[cfg(not(feature = "linux-sndio"))] pub use crate::host::alsa::{ Device as AlsaDevice, Devices as AlsaDevices, Host as AlsaHost, Stream as AlsaStream, SupportedInputConfigs as AlsaSupportedInputConfigs, SupportedOutputConfigs as AlsaSupportedOutputConfigs, }; - #[cfg(feature = "jack")] + #[cfg(all(feature = "jack", not(feature = "linux-sndio")))] pub use crate::host::jack::{ Device as JackDevice, Devices as JackDevices, Host as JackHost, Stream as JackStream, SupportedInputConfigs as JackSupportedInputConfigs, SupportedOutputConfigs as JackSupportedOutputConfigs, }; - #[cfg(feature = "jack")] + #[cfg(all(feature = "jack", not(feature = "linux-sndio")))] impl_platform_host!(Jack jack "JACK", Alsa alsa "ALSA"); - #[cfg(not(feature = "jack"))] + #[cfg(all(not(feature = "jack"), not(feature = "linux-sndio")))] impl_platform_host!(Alsa alsa "ALSA"); /// The default host for the current compilation target platform. + #[cfg(not(feature = "linux-sndio"))] pub fn default_host() -> Host { AlsaHost::new() .expect("the default host should always be available") .into() } + + #[cfg(feature = "linux-sndio")] + pub use crate::host::sndio::{ + Device as SndioDevice, Devices as SndioDevices, Host as SndioHost, Stream as SndioStream, + SupportedInputConfigs as SndioSupportedInputConfigs, + SupportedOutputConfigs as SndioSupportedOutputConfigs, + }; + + #[cfg(feature = "linux-sndio")] + impl_platform_host!(Sndio sndio "sndio"); + + /// The default host for the current compilation target platform. + #[cfg(feature = "linux-sndio")] + pub fn default_host() -> Host { + SndioHost::new() + .expect("the default host should always be available") + .into() + } } #[cfg(target_os = "openbsd")]