Browse Source

Move audio backends into seperate crate

Sasha Hilton 6 years ago
parent
commit
1fb65354b0

+ 40 - 7
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"

+ 8 - 12
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"]
+portaudio-backend = ["librespot-playback/portaudio-rs"]
+pulseaudio-backend = ["librespot-playback/libpulse-sys", "librespot-playback/libc"]
+jackaudio-backend = ["librespot-playback/jack"]
 
 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"

+ 29 - 0
playback/Cargo.toml

@@ -0,0 +1,29 @@
+[package]
+name = "librespot-playback"
+version = "0.1.0"
+authors = ["Sasha Hilton <sashahilton00@gmail.com>"]
+
+[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"]
+
+default = ["portaudio-backend"]

+ 0 - 0
src/audio_backend/alsa.rs → playback/src/audio_backend/alsa.rs


+ 0 - 0
src/audio_backend/jackaudio.rs → playback/src/audio_backend/jackaudio.rs


+ 0 - 0
src/audio_backend/mod.rs → playback/src/audio_backend/mod.rs


+ 0 - 0
src/audio_backend/pipe.rs → playback/src/audio_backend/pipe.rs


+ 0 - 0
src/audio_backend/portaudio.rs → playback/src/audio_backend/portaudio.rs


+ 0 - 0
src/audio_backend/pulseaudio.rs → playback/src/audio_backend/pulseaudio.rs


+ 26 - 0
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;

+ 0 - 0
src/mixer/mod.rs → playback/src/mixer/mod.rs


+ 0 - 0
src/mixer/softmixer.rs → playback/src/mixer/softmixer.rs


+ 0 - 0
src/player.rs → playback/src/player.rs


+ 1 - 18
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"));

+ 3 - 3
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 {

+ 5 - 5
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);
     }