From a0cd112659109eec93199b9fb929e9495904621e Mon Sep 17 00:00:00 2001 From: dvdsk Date: Tue, 10 Oct 2023 14:26:12 +0200 Subject: [PATCH] revert to upstream non-seekable minimp3, comment out minimp3-seek support --- Cargo.toml | 5 ++--- src/decoder/mp3.rs | 36 ++++++++++++++++++++++++------------ src/decoder/symphonia.rs | 2 +- src/source/mod.rs | 2 +- tests/seek.rs | 2 +- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 66629584..0b069adf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,7 @@ cpal = "0.15" claxon = { version = "0.4.2", optional = true } hound = { version = "3.3.1", optional = true } lewton = { version = "0.10", optional = true } -# minimp3_fixed = { version = "0.5.4", optional = true} -minimp3 = { git = "https://github.com/dvdsk/minimp3-rs.git", optional = true } +minimp3_fixed = { version = "0.5.4", optional = true} symphonia = { version = "0.5.2", optional = true, default-features = false } crossbeam-channel = { version = "0.5.8", optional = true } thiserror = "1.0.49" @@ -27,7 +26,7 @@ flac = ["claxon"] vorbis = ["lewton"] wav = ["hound"] mp3 = ["symphonia-mp3"] -minimp3 = ["dep:minimp3"] +minimp3 = ["dep:minimp3_fixed"] wasm-bindgen = ["cpal/wasm-bindgen"] symphonia-aac = ["symphonia/aac"] symphonia-all = ["symphonia-aac", "symphonia-flac", "symphonia-isomp4", "symphonia-mp3", "symphonia-vorbis", "symphonia-wav"] diff --git a/src/decoder/mp3.rs b/src/decoder/mp3.rs index 1ee4c06a..102b9bd4 100644 --- a/src/decoder/mp3.rs +++ b/src/decoder/mp3.rs @@ -1,17 +1,20 @@ use std::io::{Read, Seek, SeekFrom}; use std::time::Duration; -use crate::Source; use crate::source::SeekError; +use crate::Source; +use minimp3_fixed as minimp3; use minimp3::Frame; -use minimp3::{Decoder, SeekDecoder}; +use minimp3::Decoder; +// use minimp3::{Decoder, SeekDecoder}; pub struct Mp3Decoder where R: Read + Seek, { - decoder: SeekDecoder, + // decoder: SeekDecoder, + decoder: Decoder, current_frame: Frame, current_frame_offset: usize, } @@ -24,11 +27,13 @@ where if !is_mp3(data.by_ref()) { return Err(data); } - let mut decoder = SeekDecoder::new(data) + // let mut decoder = SeekDecoder::new(data) + let mut decoder = Decoder::new(data); // paramaters are correct and minimp3 is used correctly // thus if we crash here one of these invariants is broken: - .expect("should be able to allocate memory, perform IO"); - let current_frame = decoder.decode_frame() + // .expect("should be able to allocate memory, perform IO"); + // let current_frame = decoder.decode_frame() + let current_frame = decoder.next_frame() // the reader makes enough data availible therefore // if we crash here the invariant broken is: .expect("data should not corrupt"); @@ -69,11 +74,17 @@ where } fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> { - let pos = (pos.as_secs_f32() * self.sample_rate() as f32) as u64; - // do not trigger a sample_rate, channels and frame len update - // as the seek only takes effect after the current frame is done - self.decoder.seek_samples(pos)?; - Ok(()) + // TODO waiting for PR in minimp3_fixed or minimp3 + + // let pos = (pos.as_secs_f32() * self.sample_rate() as f32) as u64; + // // do not trigger a sample_rate, channels and frame len update + // // as the seek only takes effect after the current frame is done + // self.decoder.seek_samples(pos)?; + // Ok(()) + + Err(SeekError::NotSupported { + underlying_source: std::any::type_name::(), + }) } } @@ -85,7 +96,8 @@ where fn next(&mut self) -> Option { if self.current_frame_offset == self.current_frame_len().unwrap() { - if let Ok(frame) = self.decoder.decode_frame() { + if let Ok(frame) = self.decoder.next_frame() { + // if let Ok(frame) = self.decoder.decode_frame() { self.current_frame = frame; self.current_frame_offset = 0; } else { diff --git a/src/decoder/symphonia.rs b/src/decoder/symphonia.rs index 459c88e7..d8d9924c 100644 --- a/src/decoder/symphonia.rs +++ b/src/decoder/symphonia.rs @@ -1,4 +1,4 @@ -use std::{io::ErrorKind, time::Duration}; +use std::time::Duration; use symphonia::{ core::{ audio::{AudioBufferRef, SampleBuffer, SignalSpec}, diff --git a/src/source/mod.rs b/src/source/mod.rs index b57ace89..e7831af1 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -398,7 +398,7 @@ pub enum SeekError { LewtonDecoder(#[from] lewton::VorbisError), #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] #[error("Error seeking in mp3 source: {0}")] - Minimp3Decorder(#[from] minimp3::Error), + Minimp3Decorder(#[from] minimp3_fixed::Error), #[error("An error occured")] Other(Box), } diff --git a/tests/seek.rs b/tests/seek.rs index 8f91c02b..04d0bf09 100644 --- a/tests/seek.rs +++ b/tests/seek.rs @@ -37,7 +37,7 @@ fn sink_and_decoder(format: &str) -> (Sink, Decoder) { fn format_decoder_info() -> &'static [(&'static str, bool, &'static str)] { &[ #[cfg(feature = "minimp3")] - ("mp3", true, "minimp3"), + ("mp3", false, "minimp3"), #[cfg(feature = "symphonia-mp3")] ("mp3", true, "symphonia"), #[cfg(feature = "hound")]