diff --git a/Cargo.lock b/Cargo.lock index 575e3cbf..ab748377 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -253,6 +253,7 @@ dependencies = [ "hyper 0.11.0-a.0 (git+https://github.com/hyperium/hyper)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "libpulse-sys 0.0.0 (git+https://github.com/astro/libpulse-sys)", + "librespot-audio 0.1.0", "librespot-core 0.1.0", "librespot-metadata 0.1.0", "librespot-protocol 0.1.0", @@ -283,6 +284,21 @@ dependencies = [ "vorbis 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "librespot-audio" +version = "0.1.0" +dependencies = [ + "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "librespot-core 0.1.0", + "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "num-bigint 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.36 (git+https://github.com/awmath/rust-crypto.git?branch=avx2)", + "tempfile 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "librespot-core" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 248cbd0c..d0d0724c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,8 @@ name = "librespot" path = "src/main.rs" doc = false +[dependencies.librespot-audio] +path = "audio" [dependencies.librespot-core] path = "core" [dependencies.librespot-metadata] diff --git a/audio/Cargo.toml b/audio/Cargo.toml new file mode 100644 index 00000000..8095fd3d --- /dev/null +++ b/audio/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "librespot-audio" +version = "0.1.0" +authors = ["Paul Lietar "] + +[dependencies] +bit-set = "0.4.0" +byteorder = "1.0" +rust-crypto = { git = "https://github.com/awmath/rust-crypto.git", branch = "avx2" } +futures = "0.1.8" +log = "0.3.5" +num-bigint = "0.1.35" +num-traits = "0.1.36" +tempfile = "2.1" + +[dependencies.librespot-core] +path = "../core" diff --git a/src/audio_decrypt.rs b/audio/src/decrypt.rs similarity index 100% rename from src/audio_decrypt.rs rename to audio/src/decrypt.rs diff --git a/src/audio_file.rs b/audio/src/fetch.rs similarity index 97% rename from src/audio_file.rs rename to audio/src/fetch.rs index 1547e364..df5eeef7 100644 --- a/src/audio_file.rs +++ b/audio/src/fetch.rs @@ -3,7 +3,6 @@ use byteorder::{ByteOrder, BigEndian, WriteBytesExt}; use futures::Stream; use futures::sync::{oneshot, mpsc}; use futures::{Poll, Async, Future}; -use futures::future::{self, FutureResult}; use std::cmp::min; use std::fs; use std::io::{self, Read, Write, Seek, SeekFrom}; @@ -22,7 +21,7 @@ pub enum AudioFile { } pub enum AudioFileOpen { - Cached(FutureResult), + Cached(Option), Streaming(AudioFileOpenStreaming), } @@ -97,8 +96,8 @@ impl Future for AudioFileOpen { let file = try_ready!(open.poll()); Ok(Async::Ready(AudioFile::Streaming(file))) } - AudioFileOpen::Cached(ref mut open) => { - let file = try_ready!(open.poll()); + AudioFileOpen::Cached(ref mut file) => { + let file = file.take().unwrap(); Ok(Async::Ready(AudioFile::Cached(file))) } } @@ -129,7 +128,7 @@ impl AudioFile { if let Some(file) = cache.as_ref().and_then(|cache| cache.file(file_id)) { debug!("File {} already in cache", file_id); - return AudioFileOpen::Cached(future::ok(file)); + return AudioFileOpen::Cached(Some(file)); } debug!("Downloading file {}", file_id); @@ -247,7 +246,7 @@ impl AudioFileFetch { let complete_tx = self.complete_tx.take().unwrap(); output.seek(SeekFrom::Start(0)).unwrap(); - complete_tx.complete(output); + let _ = complete_tx.send(output); } } diff --git a/audio/src/lib.rs b/audio/src/lib.rs new file mode 100644 index 00000000..daedae44 --- /dev/null +++ b/audio/src/lib.rs @@ -0,0 +1,17 @@ +#[macro_use] extern crate log; +#[macro_use] extern crate futures; + +extern crate bit_set; +extern crate byteorder; +extern crate crypto; +extern crate num_traits; +extern crate num_bigint; +extern crate tempfile; + +extern crate librespot_core as core; + +mod fetch; +mod decrypt; + +pub use fetch::{AudioFile, AudioFileOpen}; +pub use decrypt::AudioDecrypt; diff --git a/metadata/src/lib.rs b/metadata/src/lib.rs index 283e8b5b..c6f5a5b2 100644 --- a/metadata/src/lib.rs +++ b/metadata/src/lib.rs @@ -1,11 +1,11 @@ -pub extern crate librespot_core as core; -pub extern crate librespot_protocol as protocol; - extern crate byteorder; extern crate futures; extern crate linear_map; extern crate protobuf; +extern crate librespot_core as core; +extern crate librespot_protocol as protocol; + pub mod cover; use futures::{Future, BoxFuture}; diff --git a/src/lib.rs b/src/lib.rs index 37caeed5..b2ba1816 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,6 @@ // TODO: many items from tokio-core::io have been deprecated in favour of tokio-io #![allow(deprecated)] -#[macro_use] extern crate futures; #[macro_use] extern crate log; #[macro_use] extern crate serde_json; #[macro_use] extern crate serde_derive; @@ -14,6 +13,7 @@ extern crate base64; extern crate bit_set; extern crate byteorder; extern crate crypto; +extern crate futures; extern crate getopts; extern crate hyper; extern crate linear_map; @@ -32,6 +32,7 @@ extern crate tokio_proto; extern crate url; extern crate uuid; +pub extern crate librespot_audio as audio; pub extern crate librespot_core as core; pub extern crate librespot_protocol as protocol; pub extern crate librespot_metadata as metadata; @@ -51,8 +52,6 @@ extern crate portaudio_rs; extern crate libpulse_sys; pub mod audio_backend; -pub mod audio_decrypt; -pub mod audio_file; pub mod discovery; pub mod keymaster; pub mod mixer; diff --git a/src/player.rs b/src/player.rs index f1afa9fa..6b95e16b 100644 --- a/src/player.rs +++ b/src/player.rs @@ -13,8 +13,8 @@ use core::session::Session; use core::util::{self, SpotifyId, Subfile}; use audio_backend::Sink; -use audio_decrypt::AudioDecrypt; -use audio_file::AudioFile; +use audio::AudioDecrypt; +use audio::AudioFile; use metadata::{FileFormat, Track, Metadata}; use mixer::AudioFilter;