mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
added stdout-backend
This commit is contained in:
parent
880a266625
commit
383e0e9ae8
4 changed files with 42 additions and 0 deletions
|
@ -32,6 +32,7 @@ script:
|
||||||
- cargo build --no-default-features --features "with-syntex facebook"
|
- 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 portaudio-backend"
|
||||||
- cargo build --no-default-features --features "with-syntex pulseaudio-backend"
|
- cargo build --no-default-features --features "with-syntex pulseaudio-backend"
|
||||||
|
- cargo build --no-default-features --features "with-syntex stdout-backend"
|
||||||
- cargo build --no-default-features --features "with-syntex alsa-backend"
|
- cargo build --no-default-features --features "with-syntex alsa-backend"
|
||||||
- cargo build --no-default-features --features "with-syntex" --target armv7-unknown-linux-gnueabihf
|
- cargo build --no-default-features --features "with-syntex" --target armv7-unknown-linux-gnueabihf
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ nightly = ["serde_macros"]
|
||||||
|
|
||||||
with-tremor = ["tremor"]
|
with-tremor = ["tremor"]
|
||||||
facebook = ["hyper/ssl", "openssl"]
|
facebook = ["hyper/ssl", "openssl"]
|
||||||
|
stdout-backend = []
|
||||||
alsa-backend = ["alsa"]
|
alsa-backend = ["alsa"]
|
||||||
portaudio-backend = ["portaudio"]
|
portaudio-backend = ["portaudio"]
|
||||||
pulseaudio-backend= ["libpulse-sys"]
|
pulseaudio-backend= ["libpulse-sys"]
|
||||||
|
|
|
@ -54,6 +54,11 @@ fn mk_sink<S: Sink + Open + 'static>(device: Option<&str>) -> Box<Sink> {
|
||||||
Box::new(S::open(device))
|
Box::new(S::open(device))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "stdout-backend")]
|
||||||
|
mod stdout;
|
||||||
|
#[cfg(feature = "stdout-backend")]
|
||||||
|
use self::stdout::StdoutSink;
|
||||||
|
|
||||||
#[cfg(feature = "alsa-backend")]
|
#[cfg(feature = "alsa-backend")]
|
||||||
mod alsa;
|
mod alsa;
|
||||||
#[cfg(feature = "alsa-backend")]
|
#[cfg(feature = "alsa-backend")]
|
||||||
|
@ -75,6 +80,8 @@ declare_backends! {
|
||||||
(&'static str,
|
(&'static str,
|
||||||
&'static (Fn(Option<&str>) -> Box<Sink> + Sync + Send + 'static))
|
&'static (Fn(Option<&str>) -> Box<Sink> + Sync + Send + 'static))
|
||||||
] = &[
|
] = &[
|
||||||
|
#[cfg(feature = "stdout-backend")]
|
||||||
|
("stdout", &mk_sink::<StdoutSink>),
|
||||||
#[cfg(feature = "alsa-backend")]
|
#[cfg(feature = "alsa-backend")]
|
||||||
("alsa", &mk_sink::<AlsaSink>),
|
("alsa", &mk_sink::<AlsaSink>),
|
||||||
#[cfg(feature = "portaudio-backend")]
|
#[cfg(feature = "portaudio-backend")]
|
||||||
|
|
33
src/audio_backend/stdout.rs
Normal file
33
src/audio_backend/stdout.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
use super::{Open, Sink};
|
||||||
|
use std::io::{self, Write};
|
||||||
|
use std::slice;
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
|
|
||||||
|
pub struct StdoutSink;//Option<PCM>, String);
|
||||||
|
|
||||||
|
impl Open for StdoutSink {
|
||||||
|
fn open(_: Option<&str>) -> StdoutSink {
|
||||||
|
StdoutSink
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sink for StdoutSink {
|
||||||
|
fn start(&mut self) -> io::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stop(&mut self) -> io::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write(&mut self, data: &[i16]) -> io::Result<()> {
|
||||||
|
// http://stackoverflow.com/questions/30838358/writing-vecu16-to-a-file
|
||||||
|
let slice_u8: &[u8] = unsafe { slice::from_raw_parts(data.as_ptr() as *const u8, data.len() * mem::size_of::<i16>()) };
|
||||||
|
try!(io::stdout().write_all(slice_u8));
|
||||||
|
try!(io::stdout().flush());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue