mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 13:42:34 +00:00
style clippy fixes
This commit is contained in:
parent
6f1f44f04a
commit
34366fe656
5 changed files with 23 additions and 25 deletions
|
@ -104,7 +104,7 @@ where
|
||||||
let new_pos = new_pos.next_multiple_of(self.channels() as usize);
|
let new_pos = new_pos.next_multiple_of(self.channels() as usize);
|
||||||
let new_pos = new_pos - curr_channel;
|
let new_pos = new_pos - curr_channel;
|
||||||
|
|
||||||
self.pos = new_pos as usize;
|
self.pos = new_pos;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,8 +172,8 @@ mod tests {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod try_seek {
|
mod try_seek {
|
||||||
use std::time::Duration;
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn channel_order_stays_correct() {
|
fn channel_order_stays_correct() {
|
||||||
|
|
|
@ -32,7 +32,10 @@ pub(crate) struct SymphoniaDecoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SymphoniaDecoder {
|
impl SymphoniaDecoder {
|
||||||
pub(crate) fn new(mss: MediaSourceStream, extension: Option<&str>) -> Result<Self, DecoderError> {
|
pub(crate) fn new(
|
||||||
|
mss: MediaSourceStream,
|
||||||
|
extension: Option<&str>,
|
||||||
|
) -> Result<Self, DecoderError> {
|
||||||
match SymphoniaDecoder::init(mss, extension) {
|
match SymphoniaDecoder::init(mss, extension) {
|
||||||
Err(e) => match e {
|
Err(e) => match e {
|
||||||
Error::IoError(e) => Err(DecoderError::IoError(e.to_string())),
|
Error::IoError(e) => Err(DecoderError::IoError(e.to_string())),
|
||||||
|
@ -73,13 +76,8 @@ impl SymphoniaDecoder {
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut decoder = symphonia::default::get_codecs().make(
|
let mut decoder = symphonia::default::get_codecs()
|
||||||
&stream.codec_params,
|
.make(&stream.codec_params, &DecoderOptions { verify: true })?;
|
||||||
&DecoderOptions {
|
|
||||||
verify: true,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)?;
|
|
||||||
let total_duration = stream
|
let total_duration = stream
|
||||||
.codec_params
|
.codec_params
|
||||||
.time_base
|
.time_base
|
||||||
|
@ -164,13 +162,16 @@ impl Source for SymphoniaDecoder {
|
||||||
// make sure the next sample is for the right channel
|
// make sure the next sample is for the right channel
|
||||||
let to_skip = self.current_frame_offset % self.channels() as usize;
|
let to_skip = self.current_frame_offset % self.channels() as usize;
|
||||||
|
|
||||||
let seek_res = self.format.seek(
|
let seek_res = self
|
||||||
SeekMode::Accurate,
|
.format
|
||||||
SeekTo::Time {
|
.seek(
|
||||||
time,
|
SeekMode::Accurate,
|
||||||
track_id: None,
|
SeekTo::Time {
|
||||||
},
|
time,
|
||||||
).map_err(SeekError::BaseSeek)?;
|
track_id: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.map_err(SeekError::BaseSeek)?;
|
||||||
|
|
||||||
self.refine_position(seek_res)?;
|
self.refine_position(seek_res)?;
|
||||||
self.current_frame_offset += to_skip;
|
self.current_frame_offset += to_skip;
|
||||||
|
@ -196,10 +197,7 @@ impl SymphoniaDecoder {
|
||||||
fn refine_position(&mut self, seek_res: SeekedTo) -> Result<(), source::SeekError> {
|
fn refine_position(&mut self, seek_res: SeekedTo) -> Result<(), source::SeekError> {
|
||||||
let mut samples_to_pass = seek_res.required_ts - seek_res.actual_ts;
|
let mut samples_to_pass = seek_res.required_ts - seek_res.actual_ts;
|
||||||
let packet = loop {
|
let packet = loop {
|
||||||
let candidate = self
|
let candidate = self.format.next_packet().map_err(SeekError::Refining)?;
|
||||||
.format
|
|
||||||
.next_packet()
|
|
||||||
.map_err(SeekError::Refining)?;
|
|
||||||
if candidate.dur() > samples_to_pass {
|
if candidate.dur() > samples_to_pass {
|
||||||
break candidate;
|
break candidate;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -76,7 +76,7 @@ where
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// seek is broken, https://github.com/RustAudio/lewton/issues/73.
|
/// seek is broken, https://github.com/RustAudio/lewton/issues/73.
|
||||||
// We could work around it by:
|
// We could work around it by:
|
||||||
// - using unsafe to create an instance of Self
|
// - using unsafe to create an instance of Self
|
||||||
// - use mem::swap to turn the &mut self into a mut self
|
// - use mem::swap to turn the &mut self into a mut self
|
||||||
|
@ -103,7 +103,7 @@ where
|
||||||
fn next(&mut self) -> Option<i16> {
|
fn next(&mut self) -> Option<i16> {
|
||||||
if let Some(sample) = self.current_data.get(self.next).copied() {
|
if let Some(sample) = self.current_data.get(self.next).copied() {
|
||||||
self.next += 1;
|
self.next += 1;
|
||||||
if self.current_data.len() == 0 {
|
if self.current_data.is_empty() {
|
||||||
if let Ok(Some(data)) = self.stream_reader.read_dec_packet_itl() {
|
if let Ok(Some(data)) = self.stream_reader.read_dec_packet_itl() {
|
||||||
self.current_data = data;
|
self.current_data = data;
|
||||||
self.next = 0;
|
self.next = 0;
|
||||||
|
|
|
@ -143,7 +143,7 @@ where
|
||||||
|
|
||||||
self.reader
|
self.reader
|
||||||
.reader
|
.reader
|
||||||
.seek(new_pos as u32)
|
.seek(new_pos)
|
||||||
.map_err(SeekError::HoundDecoder)?;
|
.map_err(SeekError::HoundDecoder)?;
|
||||||
self.reader.samples_read = new_pos * self.channels() as u32;
|
self.reader.samples_read = new_pos * self.channels() as u32;
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ where
|
||||||
// We would then however need to enable seeking backwards across sources too.
|
// We would then however need to enable seeking backwards across sources too.
|
||||||
// That no longer seems in line with the queue behaviour.
|
// That no longer seems in line with the queue behaviour.
|
||||||
//
|
//
|
||||||
// A final pain point is that we would need the total duration for the
|
// A final pain point is that we would need the total duration for the
|
||||||
// next few songs.
|
// next few songs.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> {
|
fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> {
|
||||||
|
|
Loading…
Reference in a new issue