Rerun rustfmt on full codebase

This commit is contained in:
marcelbuesing 2020-01-17 18:11:07 +01:00
parent d26590afc5
commit 38d82f2dc2
No known key found for this signature in database
GPG key ID: 5E8C5624159F80BB
10 changed files with 99 additions and 44 deletions

View file

@ -446,7 +446,7 @@ impl AudioFile {
channel_tx: None, channel_tx: None,
stream_shared: None, stream_shared: None,
file_size: file.metadata().unwrap().len() as usize, file_size: file.metadata().unwrap().len() as usize,
} };
} }
} }
} }
@ -514,7 +514,10 @@ impl AudioFileFetchDataReceiver {
request_length: usize, request_length: usize,
request_sent_time: Instant, request_sent_time: Instant,
) -> AudioFileFetchDataReceiver { ) -> AudioFileFetchDataReceiver {
let measure_ping_time = shared.number_of_open_requests.load(atomic::Ordering::SeqCst) == 0; let measure_ping_time = shared
.number_of_open_requests
.load(atomic::Ordering::SeqCst)
== 0;
shared shared
.number_of_open_requests .number_of_open_requests
@ -562,7 +565,8 @@ impl Future for AudioFileFetchDataReceiver {
if let Some(request_sent_time) = self.request_sent_time { if let Some(request_sent_time) = self.request_sent_time {
let duration = Instant::now() - request_sent_time; let duration = Instant::now() - request_sent_time;
let duration_ms: u64; let duration_ms: u64;
if 0.001 * (duration.as_millis() as f64) > MAXIMUM_ASSUMED_PING_TIME_SECONDS if 0.001 * (duration.as_millis() as f64)
> MAXIMUM_ASSUMED_PING_TIME_SECONDS
{ {
duration_ms = (MAXIMUM_ASSUMED_PING_TIME_SECONDS * 1000.0) as u64; duration_ms = (MAXIMUM_ASSUMED_PING_TIME_SECONDS * 1000.0) as u64;
} else { } else {
@ -714,8 +718,13 @@ impl AudioFileFetch {
ranges_to_request.subtract_range_set(&download_status.requested); ranges_to_request.subtract_range_set(&download_status.requested);
for range in ranges_to_request.iter() { for range in ranges_to_request.iter() {
let (_headers, data) = let (_headers, data) = request_range(
request_range(&self.session, self.shared.file_id, range.start, range.length).split(); &self.session,
self.shared.file_id,
range.start,
range.length,
)
.split();
download_status.requested.add_range(range); download_status.requested.add_range(range);
@ -749,7 +758,10 @@ impl AudioFileFetch {
// download data from after the current read position first // download data from after the current read position first
let mut tail_end = RangeSet::new(); let mut tail_end = RangeSet::new();
let read_position = self.shared.read_position.load(atomic::Ordering::Relaxed); let read_position = self.shared.read_position.load(atomic::Ordering::Relaxed);
tail_end.add_range(&Range::new(read_position, self.shared.file_size - read_position)); tail_end.add_range(&Range::new(
read_position,
self.shared.file_size - read_position,
));
let tail_end = tail_end.intersection(&missing_data); let tail_end = tail_end.intersection(&missing_data);
if !tail_end.is_empty() { if !tail_end.is_empty() {
@ -794,8 +806,9 @@ impl AudioFileFetch {
let ping_time_ms: usize = match self.network_response_times_ms.len() { let ping_time_ms: usize = match self.network_response_times_ms.len() {
1 => self.network_response_times_ms[0] as usize, 1 => self.network_response_times_ms[0] as usize,
2 => { 2 => {
((self.network_response_times_ms[0] + self.network_response_times_ms[1]) / 2) ((self.network_response_times_ms[0]
as usize + self.network_response_times_ms[1])
/ 2) as usize
} }
3 => { 3 => {
let mut times = self.network_response_times_ms.clone(); let mut times = self.network_response_times_ms.clone();
@ -863,10 +876,12 @@ impl AudioFileFetch {
self.download_range(request.start, request.length); self.download_range(request.start, request.length);
} }
Ok(Async::Ready(Some(StreamLoaderCommand::RandomAccessMode()))) => { Ok(Async::Ready(Some(StreamLoaderCommand::RandomAccessMode()))) => {
*(self.shared.download_strategy.lock().unwrap()) = DownloadStrategy::RandomAccess(); *(self.shared.download_strategy.lock().unwrap()) =
DownloadStrategy::RandomAccess();
} }
Ok(Async::Ready(Some(StreamLoaderCommand::StreamMode()))) => { Ok(Async::Ready(Some(StreamLoaderCommand::StreamMode()))) => {
*(self.shared.download_strategy.lock().unwrap()) = DownloadStrategy::Streaming(); *(self.shared.download_strategy.lock().unwrap()) =
DownloadStrategy::Streaming();
} }
Ok(Async::Ready(Some(StreamLoaderCommand::Close()))) => { Ok(Async::Ready(Some(StreamLoaderCommand::Close()))) => {
return Ok(Async::Ready(())); return Ok(Async::Ready(()));
@ -908,15 +923,20 @@ impl Future for AudioFileFetch {
} }
if let DownloadStrategy::Streaming() = self.get_download_strategy() { if let DownloadStrategy::Streaming() = self.get_download_strategy() {
let number_of_open_requests = let number_of_open_requests = self
self.shared.number_of_open_requests.load(atomic::Ordering::SeqCst); .shared
.number_of_open_requests
.load(atomic::Ordering::SeqCst);
let max_requests_to_send = let max_requests_to_send =
MAX_PREFETCH_REQUESTS - min(MAX_PREFETCH_REQUESTS, number_of_open_requests); MAX_PREFETCH_REQUESTS - min(MAX_PREFETCH_REQUESTS, number_of_open_requests);
if max_requests_to_send > 0 { if max_requests_to_send > 0 {
let bytes_pending: usize = { let bytes_pending: usize = {
let download_status = self.shared.download_status.lock().unwrap(); let download_status = self.shared.download_status.lock().unwrap();
download_status.requested.minus(&download_status.downloaded).len() download_status
.requested
.minus(&download_status.downloaded)
.len()
}; };
let ping_time_seconds = let ping_time_seconds =
@ -924,9 +944,11 @@ impl Future for AudioFileFetch {
let download_rate = self.session.channel().get_download_rate_estimate(); let download_rate = self.session.channel().get_download_rate_estimate();
let desired_pending_bytes = max( let desired_pending_bytes = max(
(PREFETCH_THRESHOLD_FACTOR * ping_time_seconds * self.shared.stream_data_rate as f64) (PREFETCH_THRESHOLD_FACTOR
* ping_time_seconds
* self.shared.stream_data_rate as f64) as usize,
(FAST_PREFETCH_THRESHOLD_FACTOR * ping_time_seconds * download_rate as f64)
as usize, as usize,
(FAST_PREFETCH_THRESHOLD_FACTOR * ping_time_seconds * download_rate as f64) as usize,
); );
if bytes_pending < desired_pending_bytes { if bytes_pending < desired_pending_bytes {
@ -1003,7 +1025,9 @@ impl Read for AudioFileStreaming {
.unwrap() .unwrap()
.0; .0;
} }
let available_length = download_status.downloaded.contained_length_from_value(offset); let available_length = download_status
.downloaded
.contained_length_from_value(offset);
assert!(available_length > 0); assert!(available_length > 0);
drop(download_status); drop(download_status);

View file

@ -113,7 +113,8 @@ impl RangeSet {
// the new range starts after anything we already passed and ends before the next range starts (they don't touch) -> insert it. // the new range starts after anything we already passed and ends before the next range starts (they don't touch) -> insert it.
self.ranges.insert(index, range.clone()); self.ranges.insert(index, range.clone());
return; return;
} else if range.start <= self.ranges[index].end() && self.ranges[index].start <= range.end() } else if range.start <= self.ranges[index].end()
&& self.ranges[index].start <= range.end()
{ {
// the new range overlaps (or touches) the first range. They are to be merged. // the new range overlaps (or touches) the first range. They are to be merged.
// In addition we might have to merge further ranges in as well. // In addition we might have to merge further ranges in as well.
@ -161,7 +162,9 @@ impl RangeSet {
if range.end() <= self.ranges[index].start { if range.end() <= self.ranges[index].start {
// the remaining ranges are past the one to subtract. -> we're done. // the remaining ranges are past the one to subtract. -> we're done.
return; return;
} else if range.start <= self.ranges[index].start && self.ranges[index].start < range.end() { } else if range.start <= self.ranges[index].start
&& self.ranges[index].start < range.end()
{
// the range to subtract started before the current range and reaches into the current range // the range to subtract started before the current range and reaches into the current range
// -> we have to remove the beginning of the range or the entire range and do the same for following ranges. // -> we have to remove the beginning of the range or the entire range and do the same for following ranges.
@ -223,8 +226,14 @@ impl RangeSet {
other_index += 1; other_index += 1;
} else { } else {
// the two intervals overlap. Add the union and advance the index of the one that ends first. // the two intervals overlap. Add the union and advance the index of the one that ends first.
let new_start = max(self.ranges[self_index].start, other.ranges[other_index].start); let new_start = max(
let new_end = min(self.ranges[self_index].end(), other.ranges[other_index].end()); self.ranges[self_index].start,
other.ranges[other_index].start,
);
let new_end = min(
self.ranges[self_index].end(),
other.ranges[other_index].end(),
);
assert!(new_start <= new_end); assert!(new_start <= new_end);
result.add_range(&Range::new(new_start, new_end - new_start)); result.add_range(&Range::new(new_start, new_end - new_start));
if self.ranges[self_index].end() <= other.ranges[other_index].end() { if self.ranges[self_index].end() <= other.ranges[other_index].end() {

View file

@ -796,12 +796,19 @@ impl SpircTask {
self.resolve_uri(&radio_uri) self.resolve_uri(&radio_uri)
} }
fn resolve_autoplay_uri(&self, uri: &str) -> Box<dyn Future<Item = String, Error = MercuryError>> { fn resolve_autoplay_uri(
&self,
uri: &str,
) -> Box<dyn Future<Item = String, Error = MercuryError>> {
let query_uri = format!("hm://autoplay-enabled/query?uri={}", uri); let query_uri = format!("hm://autoplay-enabled/query?uri={}", uri);
let request = self.session.mercury().get(query_uri); let request = self.session.mercury().get(query_uri);
Box::new(request.and_then(move |response| { Box::new(request.and_then(move |response| {
if response.status_code == 200 { if response.status_code == 200 {
let data = response.payload.first().expect("Empty autoplay uri").to_vec(); let data = response
.payload
.first()
.expect("Empty autoplay uri")
.to_vec();
let autoplay_uri = String::from_utf8(data).unwrap(); let autoplay_uri = String::from_utf8(data).unwrap();
Ok(autoplay_uri) Ok(autoplay_uri)
} else { } else {
@ -811,7 +818,10 @@ impl SpircTask {
})) }))
} }
fn resolve_uri(&self, uri: &str) -> Box<dyn Future<Item = serde_json::Value, Error = MercuryError>> { fn resolve_uri(
&self,
uri: &str,
) -> Box<dyn Future<Item = serde_json::Value, Error = MercuryError>> {
let request = self.session.mercury().get(uri); let request = self.session.mercury().get(uri);
Box::new(request.and_then(move |response| { Box::new(request.and_then(move |response| {
@ -900,7 +910,8 @@ impl SpircTask {
let track = { let track = {
let mut track_ref = self.state.get_track()[index as usize].clone(); let mut track_ref = self.state.get_track()[index as usize].clone();
let mut track_id = self.get_spotify_id_for_track(&track_ref); let mut track_id = self.get_spotify_id_for_track(&track_ref);
while track_id.is_err() || track_id.unwrap().audio_type == SpotifyAudioType::NonPlayable { while track_id.is_err() || track_id.unwrap().audio_type == SpotifyAudioType::NonPlayable
{
warn!( warn!(
"Skipping track <{:?}> at position [{}] of {}", "Skipping track <{:?}> at position [{}] of {}",
track_ref.get_uri(), track_ref.get_uri(),

View file

@ -58,7 +58,7 @@ impl<T: AsyncRead + AsyncWrite> Future for ProxyTunnel<T> {
let status = match response.parse(&buf) { let status = match response.parse(&buf) {
Ok(status) => status, Ok(status) => status,
Err(err) => { Err(err) => {
return Err(io::Error::new(io::ErrorKind::Other, err.description())) return Err(io::Error::new(io::ErrorKind::Other, err.description()));
} }
}; };

View file

@ -1,4 +1,3 @@
use env_logger; use env_logger;
use std::env; use std::env;
use tokio_core::reactor::Core; use tokio_core::reactor::Core;
@ -7,7 +6,7 @@ use librespot::core::authentication::Credentials;
use librespot::core::config::SessionConfig; use librespot::core::config::SessionConfig;
use librespot::core::session::Session; use librespot::core::session::Session;
use librespot::core::spotify_id::SpotifyId; use librespot::core::spotify_id::SpotifyId;
use librespot::metadata::{Metadata, Track, Playlist}; use librespot::metadata::{Metadata, Playlist, Track};
fn main() { fn main() {
env_logger::init(); env_logger::init();

View file

@ -301,7 +301,6 @@ impl Metadata for Playlist {
} }
fn parse(msg: &Self::Message, _: &Session) -> Self { fn parse(msg: &Self::Message, _: &Session) -> Self {
let tracks = msg let tracks = msg
.get_contents() .get_contents()
.get_items() .get_items()
@ -314,7 +313,11 @@ impl Metadata for Playlist {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if tracks.len() != msg.get_length() as usize { if tracks.len() != msg.get_length() as usize {
warn!("Got {} tracks, but the playlist should contain {} tracks.", tracks.len(), msg.get_length()); warn!(
"Got {} tracks, but the playlist should contain {} tracks.",
tracks.len(),
msg.get_length()
);
} }
Playlist { Playlist {

View file

@ -525,7 +525,10 @@ impl PlayerInternal {
if let Some(stream_loader_controller) = self.state.stream_loader_controller() { if let Some(stream_loader_controller) = self.state.stream_loader_controller() {
stream_loader_controller.set_stream_mode(); stream_loader_controller.set_stream_mode();
} }
if let PlayerState::Playing { bytes_per_second, .. } = self.state { if let PlayerState::Playing {
bytes_per_second, ..
} = self.state
{
if let Some(stream_loader_controller) = self.state.stream_loader_controller() { if let Some(stream_loader_controller) = self.state.stream_loader_controller() {
// Request our read ahead range // Request our read ahead range
let request_data_length = max( let request_data_length = max(
@ -599,7 +602,10 @@ impl PlayerInternal {
.iter() .iter()
.map(|alt_id| AudioItem::get_audio_item(&self.session, *alt_id)); .map(|alt_id| AudioItem::get_audio_item(&self.session, *alt_id));
let alternatives = future::join_all(alternatives).wait().unwrap(); let alternatives = future::join_all(alternatives).wait().unwrap();
alternatives.into_iter().find(|alt| alt.available).map(Cow::Owned) alternatives
.into_iter()
.find(|alt| alt.available)
.map(Cow::Owned)
} else { } else {
None None
} }
@ -677,8 +683,12 @@ impl PlayerInternal {
let play_from_beginning = position == 0; let play_from_beginning = position == 0;
let key = self.session.audio_key().request(spotify_id, file_id); let key = self.session.audio_key().request(spotify_id, file_id);
let encrypted_file = let encrypted_file = AudioFile::open(
AudioFile::open(&self.session, file_id, bytes_per_second, play_from_beginning); &self.session,
file_id,
bytes_per_second,
play_from_beginning,
);
let encrypted_file = encrypted_file.wait().unwrap(); let encrypted_file = encrypted_file.wait().unwrap();

View file

@ -24,8 +24,7 @@ fn main() {
let name; let name;
if line.starts_with("pub mod ") { if line.starts_with("pub mod ") {
name = &line[8..len - 1]; // Remove keywords and semi-colon name = &line[8..len - 1]; // Remove keywords and semi-colon
} } else {
else {
name = &line[4..len - 1]; // Remove keywords and semi-colon name = &line[4..len - 1]; // Remove keywords and semi-colon
} }

View file

@ -1,7 +1,7 @@
use futures::sync::mpsc::UnboundedReceiver; use futures::sync::mpsc::UnboundedReceiver;
use futures::{Async, Future, Poll, Stream}; use futures::{Async, Future, Poll, Stream};
use sha1::{Digest, Sha1};
use log::{error, info, trace, warn}; use log::{error, info, trace, warn};
use sha1::{Digest, Sha1};
use std::env; use std::env;
use std::io::{self, stderr, Write}; use std::io::{self, stderr, Write};
use std::mem; use std::mem;

View file

@ -1,5 +1,5 @@
use log::info;
use librespot::playback::player::PlayerEvent; use librespot::playback::player::PlayerEvent;
use log::info;
use std::collections::HashMap; use std::collections::HashMap;
use std::io; use std::io;
use std::process::Command; use std::process::Command;