1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 01:39:28 +02:00

Format according to rustfmt

This commit is contained in:
Sasha Hilton 2018-02-26 02:50:41 +01:00
parent c3745a958a
commit 237ef1e4f9
22 changed files with 502 additions and 360 deletions

View file

@ -7,8 +7,9 @@ use std::ops::Add;
use core::audio_key::AudioKey;
const AUDIO_AESIV: &'static [u8] = &[0x72, 0xe0, 0x67, 0xfb, 0xdd, 0xcb, 0xcf, 0x77, 0xeb, 0xe8,
0xbc, 0x64, 0x3f, 0x63, 0x0d, 0x93];
const AUDIO_AESIV: &'static [u8] = &[
0x72, 0xe0, 0x67, 0xfb, 0xdd, 0xcb, 0xcf, 0x77, 0xeb, 0xe8, 0xbc, 0x64, 0x3f, 0x63, 0x0d, 0x93
];
pub struct AudioDecrypt<T: io::Read> {
cipher: Box<SynchronousStreamCipher + 'static>,
@ -44,8 +45,8 @@ impl<T: io::Read + io::Seek> io::Seek for AudioDecrypt<T> {
let skip = newpos % 16;
let iv = BigUint::from_bytes_be(AUDIO_AESIV)
.add(BigUint::from_u64(newpos / 16).unwrap())
.to_bytes_be();
.add(BigUint::from_u64(newpos / 16).unwrap())
.to_bytes_be();
self.cipher = aes::ctr(aes::KeySize::KeySize128, &self.key.0, &iv);
let buf = vec![0u8; skip as usize];

View file

@ -1,11 +1,11 @@
use bit_set::BitSet;
use byteorder::{ByteOrder, BigEndian, WriteBytesExt};
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use futures::{Async, Future, Poll};
use futures::Stream;
use futures::sync::{oneshot, mpsc};
use futures::{Poll, Async, Future};
use futures::sync::{mpsc, oneshot};
use std::cmp::min;
use std::fs;
use std::io::{self, Read, Write, Seek, SeekFrom};
use std::io::{self, Read, Seek, SeekFrom, Write};
use std::sync::{Arc, Condvar, Mutex};
use tempfile::NamedTempFile;
@ -71,7 +71,12 @@ impl AudioFileOpenStreaming {
let (seek_tx, seek_rx) = mpsc::unbounded();
let fetcher = AudioFileFetch::new(
self.session.clone(), shared.clone(), data_rx, write_file, seek_rx, complete_tx
self.session.clone(),
shared.clone(),
data_rx,
write_file,
seek_rx,
complete_tx,
);
self.session.spawn(move |_| fetcher);
@ -148,14 +153,16 @@ impl AudioFile {
let session_ = session.clone();
session.spawn(move |_| {
complete_rx.map(move |mut file| {
if let Some(cache) = session_.cache() {
cache.save_file(file_id, &mut file);
debug!("File {} complete, saving to cache", file_id);
} else {
debug!("File {} complete", file_id);
}
}).or_else(|oneshot::Canceled| Ok(()))
complete_rx
.map(move |mut file| {
if let Some(cache) = session_.cache() {
cache.save_file(file_id, &mut file);
debug!("File {} complete, saving to cache", file_id);
} else {
debug!("File {} complete", file_id);
}
})
.or_else(|oneshot::Canceled| Ok(()))
});
AudioFileOpen::Streaming(open)
@ -200,11 +207,14 @@ struct AudioFileFetch {
}
impl AudioFileFetch {
fn new(session: Session, shared: Arc<AudioFileShared>,
data_rx: ChannelData, output: NamedTempFile,
seek_rx: mpsc::UnboundedReceiver<u64>,
complete_tx: oneshot::Sender<NamedTempFile>) -> AudioFileFetch
{
fn new(
session: Session,
shared: Arc<AudioFileShared>,
data_rx: ChannelData,
output: NamedTempFile,
seek_rx: mpsc::UnboundedReceiver<u64>,
complete_tx: oneshot::Sender<NamedTempFile>,
) -> AudioFileFetch {
AudioFileFetch {
session: session,
shared: shared,
@ -233,8 +243,11 @@ impl AudioFileFetch {
let offset = self.index * CHUNK_SIZE;
self.output.as_mut().unwrap()
.seek(SeekFrom::Start(offset as u64)).unwrap();
self.output
.as_mut()
.unwrap()
.seek(SeekFrom::Start(offset as u64))
.unwrap();
let (_headers, data) = request_chunk(&self.session, self.shared.file_id, self.index).split();
self.data_rx = data;
@ -275,13 +288,20 @@ impl Future for AudioFileFetch {
Ok(Async::Ready(Some(data))) => {
progress = true;
self.output.as_mut().unwrap()
.write_all(data.as_ref()).unwrap();
self.output
.as_mut()
.unwrap()
.write_all(data.as_ref())
.unwrap();
}
Ok(Async::Ready(None)) => {
Ok(Async::Ready(None)) => {
progress = true;
trace!("chunk {} / {} complete", self.index, self.shared.chunk_count);
trace!(
"chunk {} / {} complete",
self.index,
self.shared.chunk_count
);
let full = {
let mut bitmap = self.shared.bitmap.lock().unwrap();
@ -303,7 +323,7 @@ impl Future for AudioFileFetch {
Err(ChannelError) => {
warn!("error from channel");
return Ok(Async::Ready(()));
},
}
}
if !progress {

View file

@ -2,16 +2,17 @@ extern crate lewton;
use self::lewton::inside_ogg::OggStreamReader;
use std::io::{Read, Seek};
use std::fmt;
use std::error;
use std::fmt;
use std::io::{Read, Seek};
pub struct VorbisDecoder<R: Read + Seek>(OggStreamReader<R>);
pub struct VorbisPacket(Vec<i16>);
pub struct VorbisError(lewton::VorbisError);
impl <R> VorbisDecoder<R>
where R: Read + Seek
impl<R> VorbisDecoder<R>
where
R: Read + Seek,
{
pub fn new(input: R) -> Result<VorbisDecoder<R>, VorbisError> {
Ok(VorbisDecoder(OggStreamReader::new(input)?))

View file

@ -1,27 +1,29 @@
#[macro_use] extern crate log;
#[macro_use] extern crate futures;
#[macro_use]
extern crate futures;
#[macro_use]
extern crate log;
extern crate bit_set;
extern crate byteorder;
extern crate crypto;
extern crate num_traits;
extern crate num_bigint;
extern crate num_traits;
extern crate tempfile;
extern crate librespot_core as core;
mod fetch;
mod decrypt;
mod fetch;
#[cfg(not(any(feature = "with-tremor", feature = "with-vorbis")))]
mod lewton_decoder;
#[cfg(any(feature = "with-tremor", feature = "with-vorbis"))]
mod libvorbis_decoder;
pub use fetch::{AudioFile, AudioFileOpen};
pub use decrypt::AudioDecrypt;
pub use fetch::{AudioFile, AudioFileOpen};
#[cfg(not(any(feature = "with-tremor", feature = "with-vorbis")))]
pub use lewton_decoder::{VorbisDecoder, VorbisPacket, VorbisError};
pub use lewton_decoder::{VorbisDecoder, VorbisError, VorbisPacket};
#[cfg(any(feature = "with-tremor", feature = "with-vorbis"))]
pub use libvorbis_decoder::{VorbisDecoder, VorbisPacket, VorbisError};
pub use libvorbis_decoder::{VorbisDecoder, VorbisError, VorbisPacket};

View file

@ -1,16 +1,19 @@
#[cfg(not(feature = "with-tremor"))] extern crate vorbis;
#[cfg(feature = "with-tremor")] extern crate tremor as vorbis;
#[cfg(feature = "with-tremor")]
extern crate tremor as vorbis;
#[cfg(not(feature = "with-tremor"))]
extern crate vorbis;
use std::io::{Read, Seek};
use std::fmt;
use std::error;
use std::fmt;
use std::io::{Read, Seek};
pub struct VorbisDecoder<R: Read + Seek>(vorbis::Decoder<R>);
pub struct VorbisPacket(vorbis::Packet);
pub struct VorbisError(vorbis::VorbisError);
impl <R> VorbisDecoder<R>
where R: Read + Seek
impl<R> VorbisDecoder<R>
where
R: Read + Seek,
{
pub fn new(input: R) -> Result<VorbisDecoder<R>, VorbisError> {
Ok(VorbisDecoder(vorbis::Decoder::new(input)?))