Remove AudioPacketPosition

We don't need it since we now tell if we've skipped packets by calculating a max delta.
This commit is contained in:
JasonLG1979 2023-06-24 18:59:01 -05:00
parent 5e02b6643d
commit f7c56dff44
4 changed files with 10 additions and 38 deletions

View file

@ -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<u32, DecoderError>;
fn next_packet(&mut self) -> DecoderResult<Option<(AudioPacketPosition, AudioPacket)>>;
fn next_packet(&mut self) -> DecoderResult<Option<(u32, AudioPacket)>>;
}
impl From<DecoderError> for librespot_core::error::Error {

View file

@ -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<R: Read + Seek> AudioDecoder for PassthroughDecoder<R> {
}
}
fn next_packet(&mut self) -> DecoderResult<Option<(AudioPacketPosition, AudioPacket)>> {
fn next_packet(&mut self) -> DecoderResult<Option<(u32, AudioPacket)>> {
// write headers if we are (re)starting
if !self.bos {
self.wtr
@ -207,14 +207,10 @@ impl<R: Read + Seek> AudioDecoder for PassthroughDecoder<R> {
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)));
}
}
}

View file

@ -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<Option<(AudioPacketPosition, AudioPacket)>> {
let mut skipped = false;
fn next_packet(&mut self) -> DecoderResult<Option<(u32, AudioPacket)>> {
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()),

View file

@ -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() {