Rid of the last remaining clippy warnings

This commit is contained in:
Roderick van Domburg 2021-12-08 21:00:42 +01:00
parent 33620280f5
commit f3bb679ab1
No known key found for this signature in database
GPG key ID: A9EF5222A26F0451
3 changed files with 26 additions and 25 deletions

View file

@ -255,6 +255,12 @@ struct AudioFileShared {
read_position: AtomicUsize, read_position: AtomicUsize,
} }
pub struct InitialData {
rx: ChannelData,
length: usize,
request_sent_time: Instant,
}
impl AudioFile { impl AudioFile {
pub async fn open( pub async fn open(
session: &Session, session: &Session,
@ -270,7 +276,7 @@ impl AudioFile {
debug!("Downloading file {}", file_id); debug!("Downloading file {}", file_id);
let (complete_tx, complete_rx) = oneshot::channel(); let (complete_tx, complete_rx) = oneshot::channel();
let mut initial_data_length = if play_from_beginning { let mut length = if play_from_beginning {
INITIAL_DOWNLOAD_SIZE INITIAL_DOWNLOAD_SIZE
+ max( + max(
(READ_AHEAD_DURING_PLAYBACK.as_secs_f32() * bytes_per_second as f32) as usize, (READ_AHEAD_DURING_PLAYBACK.as_secs_f32() * bytes_per_second as f32) as usize,
@ -281,16 +287,20 @@ impl AudioFile {
} else { } else {
INITIAL_DOWNLOAD_SIZE INITIAL_DOWNLOAD_SIZE
}; };
if initial_data_length % 4 != 0 { if length % 4 != 0 {
initial_data_length += 4 - (initial_data_length % 4); length += 4 - (length % 4);
} }
let (headers, data) = request_range(session, file_id, 0, initial_data_length).split(); let (headers, rx) = request_range(session, file_id, 0, length).split();
let initial_data = InitialData {
rx,
length,
request_sent_time: Instant::now(),
};
let streaming = AudioFileStreaming::open( let streaming = AudioFileStreaming::open(
session.clone(), session.clone(),
data, initial_data,
initial_data_length,
Instant::now(),
headers, headers,
file_id, file_id,
complete_tx, complete_tx,
@ -333,9 +343,7 @@ impl AudioFile {
impl AudioFileStreaming { impl AudioFileStreaming {
pub async fn open( pub async fn open(
session: Session, session: Session,
initial_data_rx: ChannelData, initial_data: InitialData,
initial_data_length: usize,
initial_request_sent_time: Instant,
headers: ChannelHeaders, headers: ChannelHeaders,
file_id: FileId, file_id: FileId,
complete_tx: oneshot::Sender<NamedTempFile>, complete_tx: oneshot::Sender<NamedTempFile>,
@ -377,9 +385,7 @@ impl AudioFileStreaming {
session.spawn(audio_file_fetch( session.spawn(audio_file_fetch(
session.clone(), session.clone(),
shared.clone(), shared.clone(),
initial_data_rx, initial_data,
initial_request_sent_time,
initial_data_length,
write_file, write_file,
stream_loader_command_rx, stream_loader_command_rx,
complete_tx, complete_tx,

View file

@ -17,7 +17,7 @@ use librespot_core::session::Session;
use crate::range_set::{Range, RangeSet}; use crate::range_set::{Range, RangeSet};
use super::{AudioFileShared, DownloadStrategy, StreamLoaderCommand}; use super::{AudioFileShared, DownloadStrategy, InitialData, StreamLoaderCommand};
use super::{ use super::{
FAST_PREFETCH_THRESHOLD_FACTOR, MAXIMUM_ASSUMED_PING_TIME, MAX_PREFETCH_REQUESTS, FAST_PREFETCH_THRESHOLD_FACTOR, MAXIMUM_ASSUMED_PING_TIME, MAX_PREFETCH_REQUESTS,
MINIMUM_DOWNLOAD_SIZE, PREFETCH_THRESHOLD_FACTOR, MINIMUM_DOWNLOAD_SIZE, PREFETCH_THRESHOLD_FACTOR,
@ -45,7 +45,7 @@ pub fn request_range(session: &Session, file: FileId, offset: usize, length: usi
data.write_u32::<BigEndian>(0x00000000).unwrap(); data.write_u32::<BigEndian>(0x00000000).unwrap();
data.write_u32::<BigEndian>(0x00009C40).unwrap(); data.write_u32::<BigEndian>(0x00009C40).unwrap();
data.write_u32::<BigEndian>(0x00020000).unwrap(); data.write_u32::<BigEndian>(0x00020000).unwrap();
data.write(&file.0).unwrap(); data.write_all(&file.0).unwrap();
data.write_u32::<BigEndian>(start as u32).unwrap(); data.write_u32::<BigEndian>(start as u32).unwrap();
data.write_u32::<BigEndian>(end as u32).unwrap(); data.write_u32::<BigEndian>(end as u32).unwrap();
@ -356,10 +356,7 @@ impl AudioFileFetch {
pub(super) async fn audio_file_fetch( pub(super) async fn audio_file_fetch(
session: Session, session: Session,
shared: Arc<AudioFileShared>, shared: Arc<AudioFileShared>,
initial_data_rx: ChannelData, initial_data: InitialData,
initial_request_sent_time: Instant,
initial_data_length: usize,
output: NamedTempFile, output: NamedTempFile,
mut stream_loader_command_rx: mpsc::UnboundedReceiver<StreamLoaderCommand>, mut stream_loader_command_rx: mpsc::UnboundedReceiver<StreamLoaderCommand>,
complete_tx: oneshot::Sender<NamedTempFile>, complete_tx: oneshot::Sender<NamedTempFile>,
@ -367,7 +364,7 @@ pub(super) async fn audio_file_fetch(
let (file_data_tx, mut file_data_rx) = mpsc::unbounded_channel(); let (file_data_tx, mut file_data_rx) = mpsc::unbounded_channel();
{ {
let requested_range = Range::new(0, initial_data_length); let requested_range = Range::new(0, initial_data.length);
let mut download_status = shared.download_status.lock().unwrap(); let mut download_status = shared.download_status.lock().unwrap();
download_status.requested.add_range(&requested_range); download_status.requested.add_range(&requested_range);
} }
@ -375,10 +372,10 @@ pub(super) async fn audio_file_fetch(
session.spawn(receive_data( session.spawn(receive_data(
shared.clone(), shared.clone(),
file_data_tx.clone(), file_data_tx.clone(),
initial_data_rx, initial_data.rx,
0, 0,
initial_data_length, initial_data.length,
initial_request_sent_time, initial_data.request_sent_time,
)); ));
let mut fetch = AudioFileFetch { let mut fetch = AudioFileFetch {

View file

@ -1,5 +1,3 @@
#![allow(clippy::unused_io_amount, clippy::too_many_arguments)]
#[macro_use] #[macro_use]
extern crate log; extern crate log;