From 746e6c863eeb58a0dc55ed468edac3d8e85823f7 Mon Sep 17 00:00:00 2001 From: johannesd3 Date: Wed, 10 Feb 2021 23:07:59 +0100 Subject: [PATCH] Put lewton behind feature flag --- Cargo.lock | 1 + Cargo.toml | 3 ++- audio/Cargo.toml | 6 ++++-- audio/src/lib.rs | 32 ++++++++++++++++++++++---------- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94aea40b..55bc1f7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1402,6 +1402,7 @@ dependencies = [ "bit-set", "byteorder", "bytes", + "cfg-if 1.0.0", "futures", "lewton", "librespot-core", diff --git a/Cargo.toml b/Cargo.toml index 617ae086..a26db2ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,10 +75,11 @@ gstreamer-backend = ["librespot-playback/gstreamer-backend"] with-tremor = ["librespot-audio/with-tremor"] with-vorbis = ["librespot-audio/with-vorbis"] +with-lewton = ["librespot-audio/with-lewton"] # with-dns-sd = ["librespot-connect/with-dns-sd"] -default = ["rodio-backend", "apresolve"] +default = ["rodio-backend", "apresolve", "with-lewton"] [package.metadata.deb] maintainer = "librespot-org" diff --git a/audio/Cargo.toml b/audio/Cargo.toml index 96af08f2..01d81f04 100644 --- a/audio/Cargo.toml +++ b/audio/Cargo.toml @@ -15,18 +15,20 @@ aes-ctr = "0.6" bit-set = "0.5" byteorder = "1.4" bytes = "1.0" +cfg-if = "1" futures = "0.3" -lewton = "0.10" -ogg = "0.8" log = "0.4" num-bigint = "0.3" num-traits = "0.2" +ogg = "0.8" pin-project-lite = "0.2.4" tempfile = "3.1" +lewton = { version = "0.10", optional = true } librespot-tremor = { version = "0.2.0", optional = true } vorbis = { version ="0.0.14", optional = true } [features] +with-lewton = ["lewton"] with-tremor = ["librespot-tremor"] with-vorbis = ["vorbis"] diff --git a/audio/src/lib.rs b/audio/src/lib.rs index 3f22ac5d..8b3a8dfa 100644 --- a/audio/src/lib.rs +++ b/audio/src/lib.rs @@ -19,11 +19,29 @@ extern crate librespot_core; mod decrypt; mod fetch; -#[cfg(not(any(feature = "with-tremor", feature = "with-vorbis")))] -mod lewton_decoder; -#[cfg(any(feature = "with-tremor", feature = "with-vorbis"))] -mod libvorbis_decoder; +use cfg_if::cfg_if; + +#[cfg(any( + all(feature = "with-lewton", feature = "with-tremor"), + all(feature = "with-vorbis", feature = "with-tremor"), + all(feature = "with-lewton", feature = "with-vorbis") +))] +compile_error!("Cannot use two decoders at the same time."); + +cfg_if! { + if #[cfg(feature = "with-lewton")] { + mod lewton_decoder; + pub use lewton_decoder::{VorbisDecoder, VorbisError}; + } else if #[cfg(any(feature = "with-tremor", feature = "with-vorbis"))] { + mod libvorbis_decoder; + pub use crate::libvorbis_decoder::{VorbisDecoder, VorbisError}; + } else { + compile_error!("Must choose a vorbis decoder."); + } +} + mod passthrough_decoder; +pub use passthrough_decoder::{PassthroughDecoder, PassthroughError}; mod range_set; @@ -63,12 +81,6 @@ impl AudioPacket { } } -#[cfg(not(any(feature = "with-tremor", feature = "with-vorbis")))] -pub use crate::lewton_decoder::{VorbisDecoder, VorbisError}; -#[cfg(any(feature = "with-tremor", feature = "with-vorbis"))] -pub use libvorbis_decoder::{VorbisDecoder, VorbisError}; -pub use passthrough_decoder::{PassthroughDecoder, PassthroughError}; - #[derive(Debug)] pub enum AudioError { PassthroughError(PassthroughError),