mirror of
https://github.com/librespot-org/librespot.git
synced 2025-01-07 17:24:04 +00:00
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:
parent
5e02b6643d
commit
f7c56dff44
4 changed files with 10 additions and 38 deletions
|
@ -1,5 +1,3 @@
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[cfg(feature = "passthrough-decoder")]
|
#[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 {
|
pub trait AudioDecoder {
|
||||||
fn seek(&mut self, position_ms: u32) -> Result<u32, DecoderError>;
|
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 {
|
impl From<DecoderError> for librespot_core::error::Error {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::{
|
||||||
// TODO: move this to the Symphonia Ogg demuxer
|
// TODO: move this to the Symphonia Ogg demuxer
|
||||||
use ogg::{OggReadError, Packet, PacketReader, PacketWriteEndInfo, PacketWriter};
|
use ogg::{OggReadError, Packet, PacketReader, PacketWriteEndInfo, PacketWriter};
|
||||||
|
|
||||||
use super::{AudioDecoder, AudioPacket, AudioPacketPosition, DecoderError, DecoderResult};
|
use super::{AudioDecoder, AudioPacket, DecoderError, DecoderResult};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
metadata::audio::{AudioFileFormat, AudioFiles},
|
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
|
// write headers if we are (re)starting
|
||||||
if !self.bos {
|
if !self.bos {
|
||||||
self.wtr
|
self.wtr
|
||||||
|
@ -207,14 +207,10 @@ impl<R: Read + Seek> AudioDecoder for PassthroughDecoder<R> {
|
||||||
|
|
||||||
if !data.is_empty() {
|
if !data.is_empty() {
|
||||||
let position_ms = Self::position_pcm_to_ms(pckgp_page);
|
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));
|
let ogg_data = AudioPacket::Raw(std::mem::take(data));
|
||||||
|
|
||||||
return Ok(Some((packet_position, ogg_data)));
|
return Ok(Some((position_ms, ogg_data)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ use symphonia::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{AudioDecoder, AudioPacket, AudioPacketPosition, DecoderError, DecoderResult};
|
use super::{AudioDecoder, AudioPacket, DecoderError, DecoderResult};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
metadata::audio::{AudioFileFormat, AudioFiles},
|
metadata::audio::{AudioFileFormat, AudioFiles},
|
||||||
|
@ -165,9 +165,7 @@ impl AudioDecoder for SymphoniaDecoder {
|
||||||
Ok(self.ts_to_ms(seeked_to_ts.actual_ts))
|
Ok(self.ts_to_ms(seeked_to_ts.actual_ts))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_packet(&mut self) -> DecoderResult<Option<(AudioPacketPosition, AudioPacket)>> {
|
fn next_packet(&mut self) -> DecoderResult<Option<(u32, AudioPacket)>> {
|
||||||
let mut skipped = false;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let packet = match self.format.next_packet() {
|
let packet = match self.format.next_packet() {
|
||||||
Ok(packet) => packet,
|
Ok(packet) => packet,
|
||||||
|
@ -184,10 +182,6 @@ impl AudioDecoder for SymphoniaDecoder {
|
||||||
};
|
};
|
||||||
|
|
||||||
let position_ms = self.ts_to_ms(packet.ts());
|
let position_ms = self.ts_to_ms(packet.ts());
|
||||||
let packet_position = AudioPacketPosition {
|
|
||||||
position_ms,
|
|
||||||
skipped,
|
|
||||||
};
|
|
||||||
|
|
||||||
match self.decoder.decode(&packet) {
|
match self.decoder.decode(&packet) {
|
||||||
Ok(decoded) => {
|
Ok(decoded) => {
|
||||||
|
@ -203,13 +197,12 @@ impl AudioDecoder for SymphoniaDecoder {
|
||||||
sample_buffer.copy_interleaved_ref(decoded);
|
sample_buffer.copy_interleaved_ref(decoded);
|
||||||
let samples = AudioPacket::Samples(sample_buffer.samples().to_vec());
|
let samples = AudioPacket::Samples(sample_buffer.samples().to_vec());
|
||||||
|
|
||||||
return Ok(Some((packet_position, samples)));
|
return Ok(Some((position_ms, samples)));
|
||||||
}
|
}
|
||||||
Err(Error::DecodeError(_)) => {
|
Err(Error::DecodeError(_)) => {
|
||||||
// The packet failed to decode due to corrupted or invalid data, get a new
|
// The packet failed to decode due to corrupted or invalid data, get a new
|
||||||
// packet and try again.
|
// packet and try again.
|
||||||
warn!("Skipping malformed audio packet at {position_ms} ms");
|
warn!("Skipping malformed audio packet at {position_ms} ms");
|
||||||
skipped = true;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
|
|
|
@ -31,7 +31,7 @@ use crate::{
|
||||||
audio_backend::Sink,
|
audio_backend::Sink,
|
||||||
config::{Bitrate, PlayerConfig},
|
config::{Bitrate, PlayerConfig},
|
||||||
core::{util::SeqGenerator, Error, Session, SpotifyId},
|
core::{util::SeqGenerator, Error, Session, SpotifyId},
|
||||||
decoder::{AudioDecoder, AudioPacket, AudioPacketPosition, SymphoniaDecoder},
|
decoder::{AudioDecoder, AudioPacket, SymphoniaDecoder},
|
||||||
metadata::audio::{AudioFileFormat, AudioFiles, AudioItem},
|
metadata::audio::{AudioFileFormat, AudioFiles, AudioItem},
|
||||||
mixer::VolumeGetter,
|
mixer::VolumeGetter,
|
||||||
sample_pipeline::SamplePipeline,
|
sample_pipeline::SamplePipeline,
|
||||||
|
@ -1149,9 +1149,7 @@ impl Future for PlayerInternal {
|
||||||
{
|
{
|
||||||
match decoder.next_packet() {
|
match decoder.next_packet() {
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
if let Some((ref packet_position, ref packet)) = result {
|
if let Some((decoder_position_ms, ref packet)) = result {
|
||||||
let decoder_position_ms = packet_position.position_ms;
|
|
||||||
|
|
||||||
*stream_position_ms =
|
*stream_position_ms =
|
||||||
decoder_position_ms.saturating_sub(sample_pipeline_latency_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 {
|
match packet {
|
||||||
Some((_, packet)) => {
|
Some((_, packet)) => {
|
||||||
if !packet.is_empty() {
|
if !packet.is_empty() {
|
||||||
|
|
Loading…
Reference in a new issue