mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Simplify AudioPacketPosition
This commit is contained in:
parent
a33014f9c5
commit
d380f1f040
4 changed files with 9 additions and 24 deletions
|
@ -56,19 +56,10 @@ impl AudioPacket {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||
pub enum AudioPositionKind {
|
||||
// the position is at the expected packet
|
||||
Current,
|
||||
// the decoder skipped some corrupted or invalid data,
|
||||
// and the position is now later than expected
|
||||
SkippedTo,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AudioPacketPosition {
|
||||
pub position_ms: u32,
|
||||
pub kind: AudioPositionKind,
|
||||
pub skipped: bool,
|
||||
}
|
||||
|
||||
impl Deref for AudioPacketPosition {
|
||||
|
|
|
@ -7,9 +7,7 @@ use std::{
|
|||
// TODO: move this to the Symphonia Ogg demuxer
|
||||
use ogg::{OggReadError, Packet, PacketReader, PacketWriteEndInfo, PacketWriter};
|
||||
|
||||
use super::{
|
||||
AudioDecoder, AudioPacket, AudioPacketPosition, AudioPositionKind, DecoderError, DecoderResult,
|
||||
};
|
||||
use super::{AudioDecoder, AudioPacket, AudioPacketPosition, DecoderError, DecoderResult};
|
||||
|
||||
use crate::{
|
||||
metadata::audio::{AudioFileFormat, AudioFiles},
|
||||
|
@ -212,7 +210,7 @@ impl<R: Read + Seek> AudioDecoder for PassthroughDecoder<R> {
|
|||
let position_ms = Self::position_pcm_to_ms(pckgp_page);
|
||||
let packet_position = AudioPacketPosition {
|
||||
position_ms,
|
||||
kind: AudioPositionKind::Current,
|
||||
skipped: false,
|
||||
};
|
||||
|
||||
let ogg_data = AudioPacket::Raw(std::mem::take(data));
|
||||
|
|
|
@ -16,9 +16,7 @@ use symphonia::{
|
|||
},
|
||||
};
|
||||
|
||||
use super::{
|
||||
AudioDecoder, AudioPacket, AudioPacketPosition, AudioPositionKind, DecoderError, DecoderResult,
|
||||
};
|
||||
use super::{AudioDecoder, AudioPacket, AudioPacketPosition, DecoderError, DecoderResult};
|
||||
|
||||
use crate::{
|
||||
metadata::audio::{AudioFileFormat, AudioFiles},
|
||||
|
@ -173,7 +171,7 @@ impl AudioDecoder for SymphoniaDecoder {
|
|||
}
|
||||
|
||||
fn next_packet(&mut self) -> DecoderResult<Option<(AudioPacketPosition, AudioPacket)>> {
|
||||
let mut position_kind = AudioPositionKind::Current;
|
||||
let mut skipped = false;
|
||||
|
||||
loop {
|
||||
let packet = match self.format.next_packet() {
|
||||
|
@ -193,7 +191,7 @@ impl AudioDecoder for SymphoniaDecoder {
|
|||
let position_ms = self.ts_to_ms(packet.pts());
|
||||
let packet_position = AudioPacketPosition {
|
||||
position_ms,
|
||||
kind: position_kind,
|
||||
skipped,
|
||||
};
|
||||
|
||||
match self.decoder.decode(&packet) {
|
||||
|
@ -215,7 +213,7 @@ impl AudioDecoder for SymphoniaDecoder {
|
|||
// The packet failed to decode due to corrupted or invalid data, get a new
|
||||
// packet and try again.
|
||||
warn!("Skipping malformed audio packet at {} ms", position_ms);
|
||||
position_kind = AudioPositionKind::SkippedTo;
|
||||
skipped = true;
|
||||
continue;
|
||||
}
|
||||
Err(err) => return Err(err.into()),
|
||||
|
|
|
@ -30,8 +30,7 @@ use crate::{
|
|||
convert::Converter,
|
||||
core::{util::SeqGenerator, Error, Session, SpotifyId},
|
||||
decoder::{
|
||||
AudioDecoder, AudioPacket, AudioPacketPosition, AudioPositionKind, PassthroughDecoder,
|
||||
SymphoniaDecoder,
|
||||
AudioDecoder, AudioPacket, AudioPacketPosition, PassthroughDecoder, SymphoniaDecoder,
|
||||
},
|
||||
metadata::audio::{AudioFileFormat, AudioFiles, AudioItem},
|
||||
mixer::AudioFilter,
|
||||
|
@ -1116,8 +1115,7 @@ impl Future for PlayerInternal {
|
|||
// Only notify if we're skipped some packets *or* we are behind.
|
||||
// If we're ahead it's probably due to a buffer of the backend
|
||||
// and we're actually in time.
|
||||
let notify_about_position = packet_position.kind
|
||||
!= AudioPositionKind::Current
|
||||
let notify_about_position = packet_position.skipped
|
||||
|| match *reported_nominal_start_time {
|
||||
None => true,
|
||||
Some(reported_nominal_start_time) => {
|
||||
|
|
Loading…
Reference in a new issue