Simplify AudioPacketPosition

This commit is contained in:
Roderick van Domburg 2022-01-07 11:13:23 +01:00
parent a33014f9c5
commit d380f1f040
No known key found for this signature in database
GPG key ID: FE2585E713F9F30A
4 changed files with 9 additions and 24 deletions

View file

@ -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)] #[derive(Debug, Clone)]
pub struct AudioPacketPosition { pub struct AudioPacketPosition {
pub position_ms: u32, pub position_ms: u32,
pub kind: AudioPositionKind, pub skipped: bool,
} }
impl Deref for AudioPacketPosition { impl Deref for AudioPacketPosition {

View file

@ -7,9 +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::{ use super::{AudioDecoder, AudioPacket, AudioPacketPosition, DecoderError, DecoderResult};
AudioDecoder, AudioPacket, AudioPacketPosition, AudioPositionKind, DecoderError, DecoderResult,
};
use crate::{ use crate::{
metadata::audio::{AudioFileFormat, AudioFiles}, 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 position_ms = Self::position_pcm_to_ms(pckgp_page);
let packet_position = AudioPacketPosition { let packet_position = AudioPacketPosition {
position_ms, position_ms,
kind: AudioPositionKind::Current, skipped: false,
}; };
let ogg_data = AudioPacket::Raw(std::mem::take(data)); let ogg_data = AudioPacket::Raw(std::mem::take(data));

View file

@ -16,9 +16,7 @@ use symphonia::{
}, },
}; };
use super::{ use super::{AudioDecoder, AudioPacket, AudioPacketPosition, DecoderError, DecoderResult};
AudioDecoder, AudioPacket, AudioPacketPosition, AudioPositionKind, DecoderError, DecoderResult,
};
use crate::{ use crate::{
metadata::audio::{AudioFileFormat, AudioFiles}, metadata::audio::{AudioFileFormat, AudioFiles},
@ -173,7 +171,7 @@ impl AudioDecoder for SymphoniaDecoder {
} }
fn next_packet(&mut self) -> DecoderResult<Option<(AudioPacketPosition, AudioPacket)>> { fn next_packet(&mut self) -> DecoderResult<Option<(AudioPacketPosition, AudioPacket)>> {
let mut position_kind = AudioPositionKind::Current; let mut skipped = false;
loop { loop {
let packet = match self.format.next_packet() { 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 position_ms = self.ts_to_ms(packet.pts());
let packet_position = AudioPacketPosition { let packet_position = AudioPacketPosition {
position_ms, position_ms,
kind: position_kind, skipped,
}; };
match self.decoder.decode(&packet) { 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 // 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 {} ms", position_ms); warn!("Skipping malformed audio packet at {} ms", position_ms);
position_kind = AudioPositionKind::SkippedTo; skipped = true;
continue; continue;
} }
Err(err) => return Err(err.into()), Err(err) => return Err(err.into()),

View file

@ -30,8 +30,7 @@ use crate::{
convert::Converter, convert::Converter,
core::{util::SeqGenerator, Error, Session, SpotifyId}, core::{util::SeqGenerator, Error, Session, SpotifyId},
decoder::{ decoder::{
AudioDecoder, AudioPacket, AudioPacketPosition, AudioPositionKind, PassthroughDecoder, AudioDecoder, AudioPacket, AudioPacketPosition, PassthroughDecoder, SymphoniaDecoder,
SymphoniaDecoder,
}, },
metadata::audio::{AudioFileFormat, AudioFiles, AudioItem}, metadata::audio::{AudioFileFormat, AudioFiles, AudioItem},
mixer::AudioFilter, mixer::AudioFilter,
@ -1116,8 +1115,7 @@ impl Future for PlayerInternal {
// Only notify if we're skipped some packets *or* we are behind. // 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 // If we're ahead it's probably due to a buffer of the backend
// and we're actually in time. // and we're actually in time.
let notify_about_position = packet_position.kind let notify_about_position = packet_position.skipped
!= AudioPositionKind::Current
|| match *reported_nominal_start_time { || match *reported_nominal_start_time {
None => true, None => true,
Some(reported_nominal_start_time) => { Some(reported_nominal_start_time) => {