From d380f1f04049719e6d973baed0fb57dbacad790c Mon Sep 17 00:00:00 2001 From: Roderick van Domburg Date: Fri, 7 Jan 2022 11:13:23 +0100 Subject: [PATCH] Simplify `AudioPacketPosition` --- playback/src/decoder/mod.rs | 11 +---------- playback/src/decoder/passthrough_decoder.rs | 6 ++---- playback/src/decoder/symphonia_decoder.rs | 10 ++++------ playback/src/player.rs | 6 ++---- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/playback/src/decoder/mod.rs b/playback/src/decoder/mod.rs index 05279c1b..2526da34 100644 --- a/playback/src/decoder/mod.rs +++ b/playback/src/decoder/mod.rs @@ -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 { diff --git a/playback/src/decoder/passthrough_decoder.rs b/playback/src/decoder/passthrough_decoder.rs index ec3a7753..b04b8e0d 100644 --- a/playback/src/decoder/passthrough_decoder.rs +++ b/playback/src/decoder/passthrough_decoder.rs @@ -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 AudioDecoder for PassthroughDecoder { 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)); diff --git a/playback/src/decoder/symphonia_decoder.rs b/playback/src/decoder/symphonia_decoder.rs index 049e4998..27cb9e83 100644 --- a/playback/src/decoder/symphonia_decoder.rs +++ b/playback/src/decoder/symphonia_decoder.rs @@ -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> { - 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()), diff --git a/playback/src/player.rs b/playback/src/player.rs index f8319798..cfa4414e 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -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) => {