diff --git a/playback/src/decoder/mod.rs b/playback/src/decoder/mod.rs index f980b680..6d82cbc4 100644 --- a/playback/src/decoder/mod.rs +++ b/playback/src/decoder/mod.rs @@ -1,5 +1,3 @@ -use std::ops::Deref; - use thiserror::Error; #[cfg(feature = "passthrough-decoder")] @@ -58,22 +56,9 @@ impl AudioPacket { } } -#[derive(Debug, Clone)] -pub struct AudioPacketPosition { - pub position_ms: u32, - pub skipped: bool, -} - -impl Deref for AudioPacketPosition { - type Target = u32; - fn deref(&self) -> &Self::Target { - &self.position_ms - } -} - pub trait AudioDecoder { fn seek(&mut self, position_ms: u32) -> Result; - fn next_packet(&mut self) -> DecoderResult>; + fn next_packet(&mut self) -> DecoderResult>; } impl From for librespot_core::error::Error { diff --git a/playback/src/decoder/passthrough_decoder.rs b/playback/src/decoder/passthrough_decoder.rs index 59a72163..43cf7433 100644 --- a/playback/src/decoder/passthrough_decoder.rs +++ b/playback/src/decoder/passthrough_decoder.rs @@ -7,7 +7,7 @@ use std::{ // TODO: move this to the Symphonia Ogg demuxer use ogg::{OggReadError, Packet, PacketReader, PacketWriteEndInfo, PacketWriter}; -use super::{AudioDecoder, AudioPacket, AudioPacketPosition, DecoderError, DecoderResult}; +use super::{AudioDecoder, AudioPacket, DecoderError, DecoderResult}; use crate::{ metadata::audio::{AudioFileFormat, AudioFiles}, @@ -136,7 +136,7 @@ impl AudioDecoder for PassthroughDecoder { } } - fn next_packet(&mut self) -> DecoderResult> { + fn next_packet(&mut self) -> DecoderResult> { // write headers if we are (re)starting if !self.bos { self.wtr @@ -207,14 +207,10 @@ impl AudioDecoder for PassthroughDecoder { if !data.is_empty() { let position_ms = Self::position_pcm_to_ms(pckgp_page); - let packet_position = AudioPacketPosition { - position_ms, - skipped: false, - }; let ogg_data = AudioPacket::Raw(std::mem::take(data)); - return Ok(Some((packet_position, ogg_data))); + return Ok(Some((position_ms, ogg_data))); } } } diff --git a/playback/src/decoder/symphonia_decoder.rs b/playback/src/decoder/symphonia_decoder.rs index 1a4aecab..c716f7e6 100644 --- a/playback/src/decoder/symphonia_decoder.rs +++ b/playback/src/decoder/symphonia_decoder.rs @@ -16,7 +16,7 @@ use symphonia::{ }, }; -use super::{AudioDecoder, AudioPacket, AudioPacketPosition, DecoderError, DecoderResult}; +use super::{AudioDecoder, AudioPacket, DecoderError, DecoderResult}; use crate::{ metadata::audio::{AudioFileFormat, AudioFiles}, @@ -165,9 +165,7 @@ impl AudioDecoder for SymphoniaDecoder { Ok(self.ts_to_ms(seeked_to_ts.actual_ts)) } - fn next_packet(&mut self) -> DecoderResult> { - let mut skipped = false; - + fn next_packet(&mut self) -> DecoderResult> { loop { let packet = match self.format.next_packet() { Ok(packet) => packet, @@ -184,10 +182,6 @@ impl AudioDecoder for SymphoniaDecoder { }; let position_ms = self.ts_to_ms(packet.ts()); - let packet_position = AudioPacketPosition { - position_ms, - skipped, - }; match self.decoder.decode(&packet) { Ok(decoded) => { @@ -203,13 +197,12 @@ impl AudioDecoder for SymphoniaDecoder { sample_buffer.copy_interleaved_ref(decoded); let samples = AudioPacket::Samples(sample_buffer.samples().to_vec()); - return Ok(Some((packet_position, samples))); + return Ok(Some((position_ms, samples))); } Err(Error::DecodeError(_)) => { // The packet failed to decode due to corrupted or invalid data, get a new // packet and try again. warn!("Skipping malformed audio packet at {position_ms} ms"); - skipped = true; continue; } Err(err) => return Err(err.into()), diff --git a/playback/src/player.rs b/playback/src/player.rs index c993f5f6..5d166221 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -31,7 +31,7 @@ use crate::{ audio_backend::Sink, config::{Bitrate, PlayerConfig}, core::{util::SeqGenerator, Error, Session, SpotifyId}, - decoder::{AudioDecoder, AudioPacket, AudioPacketPosition, SymphoniaDecoder}, + decoder::{AudioDecoder, AudioPacket, SymphoniaDecoder}, metadata::audio::{AudioFileFormat, AudioFiles, AudioItem}, mixer::VolumeGetter, sample_pipeline::SamplePipeline, @@ -1149,9 +1149,7 @@ impl Future for PlayerInternal { { match decoder.next_packet() { Ok(result) => { - if let Some((ref packet_position, ref packet)) = result { - let decoder_position_ms = packet_position.position_ms; - + if let Some((decoder_position_ms, ref packet)) = result { *stream_position_ms = decoder_position_ms.saturating_sub(sample_pipeline_latency_ms); @@ -1416,7 +1414,7 @@ impl PlayerInternal { } } - fn handle_packet(&mut self, packet: Option<(AudioPacketPosition, AudioPacket)>) { + fn handle_packet(&mut self, packet: Option<(u32, AudioPacket)>) { match packet { Some((_, packet)) => { if !packet.is_empty() {