mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Merge pull request #66 from marcust/pulse_backend_updated
Pulse backend with updated dependencies
This commit is contained in:
commit
cbce6f2ac1
7 changed files with 101 additions and 14 deletions
|
@ -10,12 +10,14 @@ addons:
|
|||
packages:
|
||||
- libprotoc-dev
|
||||
- portaudio19-dev
|
||||
- libpulse-dev
|
||||
|
||||
script:
|
||||
- cargo build --no-default-features --features "with-syntex"
|
||||
- cargo build --no-default-features --features "with-syntex with-tremor"
|
||||
- cargo build --no-default-features --features "with-syntex facebook"
|
||||
- cargo build --no-default-features --features "with-syntex portaudio-backend"
|
||||
- cargo build --no-default-features --features "with-syntex pulseaudio-backend"
|
||||
# Building without syntex only works on nightly
|
||||
- if [[ $TRAVIS_RUST_VERSION == *"nightly"* ]]; then
|
||||
cargo build --no-default-features;
|
||||
|
|
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -4,13 +4,14 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"bit-set 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clippy 0.0.54 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clippy 0.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dns-sd 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"eventual 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"json_macros 0.3.0 (git+https://github.com/plietar/json_macros)",
|
||||
"lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libpulse-sys 0.0.0 (git+https://github.com/astro/libpulse-sys)",
|
||||
"librespot-protocol 0.1.0",
|
||||
"lmdb-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -93,7 +94,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "clippy"
|
||||
version = "0.0.54"
|
||||
version = "0.0.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"regex-syntax 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -134,7 +135,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "gcc"
|
||||
version = "0.3.25"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -233,6 +234,14 @@ dependencies = [
|
|||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libpulse-sys"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/astro/libpulse-sys#3e167c0d75dae1ce3946eec7526f6afd92adda0f"
|
||||
dependencies = [
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "librespot-protocol"
|
||||
version = "0.1.0"
|
||||
|
@ -318,7 +327,7 @@ name = "ogg-sys"
|
|||
version = "0.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -329,7 +338,7 @@ version = "0.7.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"openssl-sys 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -353,7 +362,7 @@ name = "openssl-sys-extras"
|
|||
version = "0.7.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"openssl-sys 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -400,7 +409,7 @@ name = "protobuf_build"
|
|||
version = "0.1.1"
|
||||
source = "git+https://github.com/plietar/rust-protobuf-build.git#77ea08e75b66433104a035309751d48170a7aed6"
|
||||
dependencies = [
|
||||
"gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"protobuf 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -474,7 +483,7 @@ name = "rust-crypto"
|
|||
version = "0.2.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -530,7 +539,7 @@ name = "shannon-sys"
|
|||
version = "0.1.0"
|
||||
source = "git+https://github.com/plietar/rust-shannon#7000b3e49a53daaa890727ba2b2bd5a43cc4ffef"
|
||||
dependencies = [
|
||||
"gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -646,7 +655,7 @@ name = "tremor-sys"
|
|||
version = "0.1.0"
|
||||
source = "git+https://github.com/plietar/rust-tremor#5ced876f3cffb041fcf31238da7f3273178029fe"
|
||||
dependencies = [
|
||||
"gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ogg-sys 0.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -742,7 +751,7 @@ name = "vorbis-sys"
|
|||
version = "0.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ogg-sys 0.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -753,7 +762,7 @@ name = "vorbisfile-sys"
|
|||
version = "0.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ogg-sys 0.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -41,6 +41,7 @@ tremor = { git = "https://github.com/plietar/rust-tremor", optional = t
|
|||
dns-sd = { version = "~0.1.1", optional = true }
|
||||
|
||||
portaudio = { git = "https://github.com/mvdnes/portaudio-rs", optional = true }
|
||||
libpulse-sys = { git = "https://github.com/astro/libpulse-sys", optional = true }
|
||||
|
||||
json_macros = { git = "https://github.com/plietar/json_macros" }
|
||||
protobuf_macros = { git = "https://github.com/plietar/rust-protobuf-macros" }
|
||||
|
@ -61,5 +62,6 @@ with-syntex = ["syntex", "protobuf_macros/with-syntex", "json_macros/with-
|
|||
with-tremor = ["tremor"]
|
||||
facebook = ["hyper/ssl", "openssl"]
|
||||
portaudio-backend = ["portaudio"]
|
||||
pulseaudio-backend= ["libpulse-sys"]
|
||||
static-appkey = []
|
||||
default = ["with-syntex"]
|
||||
|
|
|
@ -76,6 +76,7 @@ target/release/librespot [...] --backend portaudio
|
|||
|
||||
The following backends are currently available :
|
||||
- PortAudio
|
||||
- PulseAudio (feature pulseaudio-backend, --backend pulseaudio)
|
||||
|
||||
## Development
|
||||
When developing *librespot*, it is preferable to use Rust nightly, and build it using the following :
|
||||
|
|
|
@ -57,9 +57,16 @@ fn mk_sink<S: Sink + Open + 'static>() -> Box<Sink> {
|
|||
#[cfg(feature = "portaudio-backend")]
|
||||
mod portaudio;
|
||||
|
||||
#[cfg(feature = "pulseaudio-backend")]
|
||||
mod pulseaudio;
|
||||
|
||||
|
||||
declare_backends! {
|
||||
pub const BACKENDS : &'static [(&'static str, &'static (Fn() -> Box<Sink> + Sync + Send + 'static))] = &[
|
||||
#[cfg(feature = "portaudio-backend")]
|
||||
("portaudio", &mk_sink::<self::portaudio::PortAudioSink>),
|
||||
#[cfg(feature = "pulseaudio-backend")]
|
||||
("pulseaudio", &mk_sink::<self::pulseaudio::PulseAudioSink>),
|
||||
|
||||
];
|
||||
}
|
||||
|
|
63
src/audio_backend/pulseaudio.rs
Normal file
63
src/audio_backend/pulseaudio.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
use super::{Open, Sink};
|
||||
use std::io;
|
||||
use libpulse_sys::*;
|
||||
use std::ptr::{null, null_mut};
|
||||
use std::mem::{transmute};
|
||||
use std::ffi::CString;
|
||||
|
||||
pub struct PulseAudioSink(*mut pa_simple);
|
||||
|
||||
impl Open for PulseAudioSink {
|
||||
fn open() -> PulseAudioSink {
|
||||
println!("Using PulseAudioSink");
|
||||
|
||||
let ss = pa_sample_spec {
|
||||
format: PA_SAMPLE_S16LE,
|
||||
channels: 2, // stereo
|
||||
rate: 44100
|
||||
};
|
||||
|
||||
let name = CString::new("librespot").unwrap();
|
||||
let description = CString::new("A spoty client library").unwrap();
|
||||
|
||||
let s = unsafe {
|
||||
pa_simple_new(null(), // Use the default server.
|
||||
name.as_ptr(), // Our application's name.
|
||||
PA_STREAM_PLAYBACK,
|
||||
null(), // Use the default device.
|
||||
description.as_ptr(), // Description of our stream.
|
||||
&ss, // Our sample format.
|
||||
null(), // Use default channel map
|
||||
null(), // Use default buffering attributes.
|
||||
null_mut(), // Ignore error code.
|
||||
)
|
||||
};
|
||||
assert!(s != null_mut());
|
||||
|
||||
PulseAudioSink(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl Sink for PulseAudioSink {
|
||||
fn start(&self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn stop(&self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write(&self, data: &[i16]) -> io::Result<()> {
|
||||
unsafe {
|
||||
let ptr = transmute(data.as_ptr());
|
||||
let bytes = data.len() as usize * 2;
|
||||
pa_simple_write(self.0, ptr, bytes, null_mut());
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -39,6 +39,9 @@ extern crate openssl;
|
|||
#[cfg(feature = "portaudio")]
|
||||
extern crate portaudio;
|
||||
|
||||
#[cfg(feature = "libpulse-sys")]
|
||||
extern crate libpulse_sys;
|
||||
|
||||
extern crate librespot_protocol as protocol;
|
||||
|
||||
// This doesn't play nice with syntex, so place it here
|
||||
|
|
Loading…
Reference in a new issue