diff --git a/Cargo.lock b/Cargo.lock index f73a91ad..0f21634d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -310,24 +310,19 @@ dependencies = [ name = "librespot" version = "0.1.0" dependencies = [ - "alsa 0.0.1 (git+https://github.com/plietar/rust-alsa)", "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "dns-sd 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)", - "jack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "libpulse-sys 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "librespot-audio 0.1.0", "librespot-core 0.1.0", + "librespot-discovery 0.1.0", "librespot-metadata 0.1.0", + "librespot-playback 0.1.0", "librespot-protocol 0.1.0", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "mdns 0.2.0 (git+https://github.com/plietar/rust-mdns)", "num-bigint 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "portaudio-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf_macros 0.6.0 (git+https://github.com/plietar/rust-protobuf-macros)", "rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", @@ -392,6 +387,28 @@ dependencies = [ "vergen 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "librespot-discovery" +version = "0.1.0" +dependencies = [ + "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "dns-sd 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)", + "librespot-core 0.1.0", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "mdns 0.2.0 (git+https://github.com/plietar/rust-mdns)", + "num-bigint 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.36 (git+https://github.com/awmath/rust-crypto.git?branch=avx2)", + "serde 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "librespot-metadata" version = "0.1.0" @@ -404,6 +421,22 @@ dependencies = [ "protobuf 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "librespot-playback" +version = "0.1.0" +dependencies = [ + "alsa 0.0.1 (git+https://github.com/plietar/rust-alsa)", + "futures 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "jack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libpulse-sys 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "librespot-audio 0.1.0", + "librespot-core 0.1.0", + "librespot-metadata 0.1.0", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "portaudio-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "librespot-protocol" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index e627c1f9..15e1dda1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,8 @@ path = "core" path = "discovery" [dependencies.librespot-metadata] path = "metadata" +[dependencies.librespot-playback] +path = "playback" [dependencies.librespot-protocol] path = "protocol" @@ -51,29 +53,23 @@ tokio-io = "0.1" tokio-signal = "0.1.2" url = "1.3" -alsa = { git = "https://github.com/plietar/rust-alsa", optional = true } -portaudio-rs = { version = "0.3.0", optional = true } -libpulse-sys = { version = "0.0.0", optional = true } -jack = { version = "0.5.3", optional = true } -libc = { version = "0.2", optional = true } - [build-dependencies] rand = "0.3.13" vergen = "0.1.0" protobuf_macros = { git = "https://github.com/plietar/rust-protobuf-macros", features = ["with-syntex"] } [features] -alsa-backend = ["alsa"] -portaudio-backend = ["portaudio-rs"] -pulseaudio-backend = ["libpulse-sys", "libc"] -jackaudio-backend = ["jack"] +alsa-backend = ["librespot-playback/alsa-backend"] +portaudio-backend = ["librespot-playback/portaudio-backend"] +pulseaudio-backend = ["librespot-playback/pulseaudio-backend"] +jackaudio-backend = ["librespot-playback/jackaudio-backend"] with-tremor = ["librespot-audio/with-tremor"] with-vorbis = ["librespot-audio/with-vorbis"] -with-dns-sd = ["librespot-discovery/dns-sd"] +with-dns-sd = ["librespot-discovery/with-dns-sd"] -default = ["portaudio-backend"] +default = ["librespot-playback/portaudio-backend"] [package.metadata.deb] maintainer = "librespot-org" diff --git a/playback/Cargo.toml b/playback/Cargo.toml new file mode 100644 index 00000000..96c44bec --- /dev/null +++ b/playback/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "librespot-playback" +version = "0.1.0" +authors = ["Sasha Hilton "] + +[dependencies.librespot-audio] +path = "../audio" +[dependencies.librespot-core] +path = "../core" +[dependencies.librespot-metadata] +path = "../metadata" + +[dependencies] +futures = "0.1.8" +log = "0.3.5" + +alsa = { git = "https://github.com/plietar/rust-alsa", optional = true } +portaudio-rs = { version = "0.3.0", optional = true } +libpulse-sys = { version = "0.0.0", optional = true } +jack = { version = "0.5.3", optional = true } +libc = { version = "0.2", optional = true } + +[features] +alsa-backend = ["alsa"] +portaudio-backend = ["portaudio-rs"] +pulseaudio-backend = ["libpulse-sys", "libc"] +jackaudio-backend = ["jack"] diff --git a/src/audio_backend/alsa.rs b/playback/src/audio_backend/alsa.rs similarity index 100% rename from src/audio_backend/alsa.rs rename to playback/src/audio_backend/alsa.rs diff --git a/src/audio_backend/jackaudio.rs b/playback/src/audio_backend/jackaudio.rs similarity index 100% rename from src/audio_backend/jackaudio.rs rename to playback/src/audio_backend/jackaudio.rs diff --git a/src/audio_backend/mod.rs b/playback/src/audio_backend/mod.rs similarity index 100% rename from src/audio_backend/mod.rs rename to playback/src/audio_backend/mod.rs diff --git a/src/audio_backend/pipe.rs b/playback/src/audio_backend/pipe.rs similarity index 100% rename from src/audio_backend/pipe.rs rename to playback/src/audio_backend/pipe.rs diff --git a/src/audio_backend/portaudio.rs b/playback/src/audio_backend/portaudio.rs similarity index 100% rename from src/audio_backend/portaudio.rs rename to playback/src/audio_backend/portaudio.rs diff --git a/src/audio_backend/pulseaudio.rs b/playback/src/audio_backend/pulseaudio.rs similarity index 100% rename from src/audio_backend/pulseaudio.rs rename to playback/src/audio_backend/pulseaudio.rs diff --git a/playback/src/lib.rs b/playback/src/lib.rs new file mode 100644 index 00000000..2633343b --- /dev/null +++ b/playback/src/lib.rs @@ -0,0 +1,26 @@ +#[macro_use] extern crate log; + +extern crate futures; + +#[cfg(feature = "alsa-backend")] +extern crate alsa; + +#[cfg(feature = "portaudio-rs")] +extern crate portaudio_rs; + +#[cfg(feature = "libpulse-sys")] +extern crate libpulse_sys; + +#[cfg(feature = "jackaudio-backend")] +extern crate jack; + +#[cfg(feature = "libc")] +extern crate libc; + +extern crate librespot_audio as audio; +extern crate librespot_core as core; +extern crate librespot_metadata as metadata; + +pub mod audio_backend; +pub mod mixer; +pub mod player; diff --git a/src/mixer/mod.rs b/playback/src/mixer/mod.rs similarity index 100% rename from src/mixer/mod.rs rename to playback/src/mixer/mod.rs diff --git a/src/mixer/softmixer.rs b/playback/src/mixer/softmixer.rs similarity index 100% rename from src/mixer/softmixer.rs rename to playback/src/mixer/softmixer.rs diff --git a/src/player.rs b/playback/src/player.rs similarity index 100% rename from src/player.rs rename to playback/src/player.rs diff --git a/src/lib.rs b/src/lib.rs index 2d9aad1b..1d0ee72d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,26 +17,9 @@ extern crate url; pub extern crate librespot_audio as audio; pub extern crate librespot_core as core; pub extern crate librespot_discovery as discovery; +pub extern crate librespot_playback as playback; pub extern crate librespot_protocol as protocol; pub extern crate librespot_metadata as metadata; -#[cfg(feature = "alsa-backend")] -extern crate alsa; - -#[cfg(feature = "portaudio-rs")] -extern crate portaudio_rs; - -#[cfg(feature = "libpulse-sys")] -extern crate libpulse_sys; - -#[cfg(feature = "jackaudio-backend")] -extern crate jack; - -#[cfg(feature = "libc")] -extern crate libc; - -pub mod audio_backend; -pub mod mixer; -pub mod player; include!(concat!(env!("OUT_DIR"), "/lib.rs")); diff --git a/src/main.rs b/src/main.rs index 4200fc16..2ecfb57c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,10 +24,10 @@ use librespot::core::config::{Bitrate, DeviceType, PlayerConfig, SessionConfig, use librespot::core::session::Session; use librespot::core::version; -use librespot::audio_backend::{self, Sink, BACKENDS}; +use librespot::playback::audio_backend::{self, Sink, BACKENDS}; use librespot::discovery::discovery::{discovery, DiscoveryStream}; -use librespot::mixer::{self, Mixer}; -use librespot::player::Player; +use librespot::playback::mixer::{self, Mixer}; +use librespot::playback::player::Player; use librespot::spirc::{Spirc, SpircTask}; fn usage(program: &str, opts: &getopts::Options) -> String { diff --git a/src/spirc.rs b/src/spirc.rs index f8bd53a8..59b6b841 100644 --- a/src/spirc.rs +++ b/src/spirc.rs @@ -12,8 +12,8 @@ use core::version; use protocol; use protocol::spirc::{PlayStatus, State, MessageType, Frame, DeviceState}; -use mixer::Mixer; -use player::Player; +use playback::mixer::Mixer; +use playback::player::Player; use std; use rand; @@ -132,12 +132,12 @@ fn volume_to_mixer(volume: u16) -> u16 { let mut val = std::u16::MAX; // Prevent val > std::u16::MAX due to rounding errors - if normalized_volume < 0.999 { + if normalized_volume < 0.999 { let new_volume = (normalized_volume * IDEAL_FACTOR).exp() / 1000.0; val = (new_volume * std::u16::MAX as f64) as u16; } - debug!("input volume:{} to mixer: {}", volume, val); + debug!("input volume:{} to mixer: {}", volume, val); // return the scale factor (0..0xffff) (equivalent to a voltage multiplier). val @@ -575,7 +575,7 @@ impl SpircTask { } fn handle_end_of_track(&mut self) { - self.handle_next(); + self.handle_next(); self.notify(None); }