mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-06 03:50:06 +02:00
Update to Rust 2018
- Fix deprecated Error::cause warnings and missing dyn - Reset max_width - Add rustfmt to Travis - Run rustfmt on full codebase with `cargo fmt --all` - Add rustfmt to Travis - Complete migration to edition 2018 - Replace try! shorthand - Use explicit `dyn Trait`
This commit is contained in:
parent
be2ad9059a
commit
d26590afc5
45 changed files with 331 additions and 238 deletions
|
@ -64,7 +64,8 @@ impl Open for AlsaSink {
|
|||
}
|
||||
Some(device) => device,
|
||||
None => "default",
|
||||
}.to_string();
|
||||
}
|
||||
.to_string();
|
||||
|
||||
AlsaSink(None, name)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::{Open, Sink};
|
||||
use jack::prelude::{
|
||||
client_options, AsyncClient, AudioOutPort, AudioOutSpec, Client, JackControl, Port, ProcessHandler,
|
||||
ProcessScope,
|
||||
client_options, AsyncClient, AudioOutPort, AudioOutSpec, Client, JackControl, Port,
|
||||
ProcessHandler, ProcessScope,
|
||||
};
|
||||
use std::io;
|
||||
use std::sync::mpsc::{sync_channel, Receiver, SyncSender};
|
||||
|
@ -45,9 +45,14 @@ impl Open for JackSink {
|
|||
info!("Using jack sink!");
|
||||
|
||||
let client_name = client_name.unwrap_or("librespot".to_string());
|
||||
let (client, _status) = Client::new(&client_name[..], client_options::NO_START_SERVER).unwrap();
|
||||
let ch_r = client.register_port("out_0", AudioOutSpec::default()).unwrap();
|
||||
let ch_l = client.register_port("out_1", AudioOutSpec::default()).unwrap();
|
||||
let (client, _status) =
|
||||
Client::new(&client_name[..], client_options::NO_START_SERVER).unwrap();
|
||||
let ch_r = client
|
||||
.register_port("out_0", AudioOutSpec::default())
|
||||
.unwrap();
|
||||
let ch_l = client
|
||||
.register_port("out_1", AudioOutSpec::default())
|
||||
.unwrap();
|
||||
// buffer for samples from librespot (~10ms)
|
||||
let (tx, rx) = sync_channel(2 * 1024 * 4);
|
||||
let jack_data = JackData {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::io;
|
||||
|
||||
pub trait Open {
|
||||
fn open(Option<String>) -> Self;
|
||||
fn open(_: Option<String>) -> Self;
|
||||
}
|
||||
|
||||
pub trait Sink {
|
||||
|
@ -10,7 +10,7 @@ pub trait Sink {
|
|||
fn write(&mut self, data: &[i16]) -> io::Result<()>;
|
||||
}
|
||||
|
||||
fn mk_sink<S: Sink + Open + 'static>(device: Option<String>) -> Box<Sink> {
|
||||
fn mk_sink<S: Sink + Open + 'static>(device: Option<String>) -> Box<dyn Sink> {
|
||||
Box::new(S::open(device))
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ use self::sdl::SdlSink;
|
|||
mod pipe;
|
||||
use self::pipe::StdoutSink;
|
||||
|
||||
pub const BACKENDS: &'static [(&'static str, fn(Option<String>) -> Box<Sink>)] = &[
|
||||
pub const BACKENDS: &'static [(&'static str, fn(Option<String>) -> Box<dyn Sink>)] = &[
|
||||
#[cfg(feature = "alsa-backend")]
|
||||
("alsa", mk_sink::<AlsaSink>),
|
||||
#[cfg(feature = "portaudio-backend")]
|
||||
|
@ -62,7 +62,7 @@ pub const BACKENDS: &'static [(&'static str, fn(Option<String>) -> Box<Sink>)] =
|
|||
("pipe", mk_sink::<StdoutSink>),
|
||||
];
|
||||
|
||||
pub fn find(name: Option<String>) -> Option<fn(Option<String>) -> Box<Sink>> {
|
||||
pub fn find(name: Option<String>) -> Option<fn(Option<String>) -> Box<dyn Sink>> {
|
||||
if let Some(name) = name {
|
||||
BACKENDS
|
||||
.iter()
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::io::{self, Write};
|
|||
use std::mem;
|
||||
use std::slice;
|
||||
|
||||
pub struct StdoutSink(Box<Write>);
|
||||
pub struct StdoutSink(Box<dyn Write>);
|
||||
|
||||
impl Open for StdoutSink {
|
||||
fn open(path: Option<String>) -> StdoutSink {
|
||||
|
@ -28,7 +28,10 @@ impl Sink for StdoutSink {
|
|||
|
||||
fn write(&mut self, data: &[i16]) -> io::Result<()> {
|
||||
let data: &[u8] = unsafe {
|
||||
slice::from_raw_parts(data.as_ptr() as *const u8, data.len() * mem::size_of::<i16>())
|
||||
slice::from_raw_parts(
|
||||
data.as_ptr() as *const u8,
|
||||
data.len() * mem::size_of::<i16>(),
|
||||
)
|
||||
};
|
||||
|
||||
self.0.write_all(data)?;
|
||||
|
|
|
@ -11,7 +11,7 @@ pub struct PortAudioSink<'a>(
|
|||
StreamParameters<i16>,
|
||||
);
|
||||
|
||||
fn output_devices() -> Box<Iterator<Item = (DeviceIndex, DeviceInfo)>> {
|
||||
fn output_devices() -> Box<dyn Iterator<Item = (DeviceIndex, DeviceInfo)>> {
|
||||
let count = portaudio_rs::device::get_count().unwrap();
|
||||
let devices = (0..count)
|
||||
.filter_map(|idx| portaudio_rs::device::get_info(idx).map(|info| (idx, info)))
|
||||
|
@ -51,7 +51,8 @@ impl<'a> Open for PortAudioSink<'a> {
|
|||
}
|
||||
Some(device) => find_output(device),
|
||||
None => get_default_output_index(),
|
||||
}.expect("Could not find device");
|
||||
}
|
||||
.expect("Could not find device");
|
||||
|
||||
let info = portaudio_rs::device::get_info(device_idx);
|
||||
let latency = match info {
|
||||
|
@ -81,8 +82,9 @@ impl<'a> Sink for PortAudioSink<'a> {
|
|||
FRAMES_PER_BUFFER_UNSPECIFIED,
|
||||
StreamFlags::empty(),
|
||||
None,
|
||||
).unwrap(),
|
||||
);;
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
self.0.as_mut().unwrap().start().unwrap();
|
||||
|
|
|
@ -14,7 +14,11 @@ pub struct PulseAudioSink {
|
|||
desc: CString,
|
||||
}
|
||||
|
||||
fn call_pulseaudio<T, F, FailCheck>(f: F, fail_check: FailCheck, kind: io::ErrorKind) -> io::Result<T>
|
||||
fn call_pulseaudio<T, F, FailCheck>(
|
||||
f: F,
|
||||
fail_check: FailCheck,
|
||||
kind: io::ErrorKind,
|
||||
) -> io::Result<T>
|
||||
where
|
||||
T: Copy,
|
||||
F: Fn(*mut libc::c_int) -> T,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use super::{Open, Sink};
|
||||
extern crate rodio;
|
||||
extern crate cpal;
|
||||
use std::{io, thread, time};
|
||||
extern crate rodio;
|
||||
use std::process::exit;
|
||||
use std::{io, thread, time};
|
||||
|
||||
pub struct RodioSink {
|
||||
rodio_sink: rodio::Sink,
|
||||
|
@ -14,7 +14,7 @@ fn list_formats(ref device: &rodio::Device) {
|
|||
Err(e) => {
|
||||
warn!("Error getting default rodio::Sink format: {:?}", e);
|
||||
return;
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
let mut output_formats = match device.supported_output_formats() {
|
||||
|
@ -22,13 +22,16 @@ fn list_formats(ref device: &rodio::Device) {
|
|||
Err(e) => {
|
||||
warn!("Error getting supported rodio::Sink formats: {:?}", e);
|
||||
return;
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
if output_formats.peek().is_some() {
|
||||
debug!(" Available formats:");
|
||||
for format in output_formats {
|
||||
let s = format!("{}ch, {:?}, min {:?}, max {:?}", format.channels, format.data_type, format.min_sample_rate, format.max_sample_rate);
|
||||
let s = format!(
|
||||
"{}ch, {:?}, min {:?}, max {:?}",
|
||||
format.channels, format.data_type, format.min_sample_rate, format.max_sample_rate
|
||||
);
|
||||
if format == default_fmt {
|
||||
debug!(" (default) {}", s);
|
||||
} else {
|
||||
|
@ -79,9 +82,7 @@ impl Open for RodioSink {
|
|||
}
|
||||
let sink = rodio::Sink::new(&rodio_device);
|
||||
|
||||
RodioSink {
|
||||
rodio_sink: sink,
|
||||
}
|
||||
RodioSink { rodio_sink: sink }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue