From 92142b1a0cb2cca118fbb7ad26d8caa7bfcefece Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Sat, 12 Nov 2022 05:08:36 +0100 Subject: [PATCH] Default to pure-Rust Symphonia for MP3 decoding (#453) * Default to symphonia-mp3 over minimp3 * Update documentation to state that MP3 is decoded by Symphonia --- Cargo.toml | 3 ++- README.md | 15 ++++++++------- src/decoder/mod.rs | 32 ++++++++++++++++---------------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 491c14e..ad21bcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,8 @@ default = ["flac", "vorbis", "wav", "mp3"] flac = ["claxon"] vorbis = ["lewton"] wav = ["hound"] -mp3 = ["minimp3"] +mp3 = ["symphonia-mp3"] +minimp3 = ["dep:minimp3"] 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/README.md b/README.md index f13a5d1..614ab1f 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,15 @@ Rust playback library. - - Playback is handled by [cpal](https://github.com/RustAudio/cpal). - - MP3 decoding is handled by [minimp3](https://github.com/lieff/minimp3). - - WAV decoding is handled by [hound](https://github.com/ruud-v-a/hound). - - Vorbis decoding is handled by [lewton](https://github.com/est31/lewton). - - Flac decoding is handled by [claxon](https://github.com/ruuda/claxon). - - MP4 and AAC (both disabled by default) are handled by [Symphonia](https://github.com/pdeljanov/Symphonia). +Playback is handled by [cpal](https://github.com/RustAudio/cpal). Format decoding can be handled either by [Symphonia](https://github.com/pdeljanov/Symphonia), or by format-specific decoders: - Alternatively, Symphonia can be used to decode any of the other codecs above. See the docs for more details on backends. + - MP3 by [minimp3](https://github.com/lieff/minimp3) (but defaults to [Symphonia](https://github.com/pdeljanov/Symphonia)). + - WAV by [hound](https://github.com/ruud-v-a/hound). + - Vorbis by [lewton](https://github.com/est31/lewton). + - FLAC by [claxon](https://github.com/ruuda/claxon). + - MP4 and AAC (both disabled by default) are handled only by [Symphonia](https://github.com/pdeljanov/Symphonia). + +See [the docs](https://docs.rs/rodio/latest/rodio/#alternative-decoder-backends) for more details on backends. # [Documentation](http://docs.rs/rodio) diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index 2abb18f..ae5f431 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -18,7 +18,7 @@ use ::symphonia::core::io::{MediaSource, MediaSourceStream}; #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] mod flac; -#[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] +#[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] mod mp3; #[cfg(feature = "symphonia")] mod read_seek_source; @@ -50,7 +50,7 @@ where Vorbis(vorbis::VorbisDecoder), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] Flac(flac::FlacDecoder), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] Mp3(mp3::Mp3Decoder), #[cfg(feature = "symphonia")] Symphonia(symphonia::SymphoniaDecoder), @@ -90,7 +90,7 @@ where } }; - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] let data = match mp3::Mp3Decoder::new(data) { Err(data) => data, Ok(decoder) => { @@ -159,7 +159,7 @@ where } /// Builds a new decoder from mp3 data. - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] pub fn new_mp3(data: R) -> Result, DecoderError> { match mp3::Mp3Decoder::new(data) { Err(_) => Err(DecoderError::UnrecognizedFormat), @@ -268,7 +268,7 @@ where DecoderImpl::Vorbis(source) => source.next(), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => source.next(), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => source.next(), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => source.next(), @@ -285,7 +285,7 @@ where DecoderImpl::Vorbis(source) => source.size_hint(), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => source.size_hint(), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => source.size_hint(), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => source.size_hint(), @@ -307,7 +307,7 @@ where DecoderImpl::Vorbis(source) => source.current_frame_len(), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => source.current_frame_len(), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => source.current_frame_len(), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => source.current_frame_len(), @@ -324,7 +324,7 @@ where DecoderImpl::Vorbis(source) => source.channels(), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => source.channels(), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => source.channels(), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => source.channels(), @@ -341,7 +341,7 @@ where DecoderImpl::Vorbis(source) => source.sample_rate(), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => source.sample_rate(), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => source.sample_rate(), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => source.sample_rate(), @@ -358,7 +358,7 @@ where DecoderImpl::Vorbis(source) => source.total_duration(), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => source.total_duration(), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => source.total_duration(), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => source.total_duration(), @@ -382,7 +382,7 @@ where DecoderImpl::Vorbis(source) => source.next(), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => source.next(), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => source.next(), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => source.next(), @@ -419,7 +419,7 @@ where let sample = source.next(); (DecoderImpl::Flac(source), sample) } - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => { let mut reader = source.into_inner(); reader.seek(SeekFrom::Start(0)).ok()?; @@ -451,7 +451,7 @@ where DecoderImpl::Vorbis(source) => (source.size_hint().0, None), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => (source.size_hint().0, None), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => (source.size_hint().0, None), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => (source.size_hint().0, None), @@ -473,7 +473,7 @@ where DecoderImpl::Vorbis(source) => source.current_frame_len(), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => source.current_frame_len(), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => source.current_frame_len(), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => source.current_frame_len(), @@ -490,7 +490,7 @@ where DecoderImpl::Vorbis(source) => source.channels(), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => source.channels(), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => source.channels(), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => source.channels(), @@ -507,7 +507,7 @@ where DecoderImpl::Vorbis(source) => source.sample_rate(), #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] DecoderImpl::Flac(source) => source.sample_rate(), - #[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] + #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))] DecoderImpl::Mp3(source) => source.sample_rate(), #[cfg(feature = "symphonia")] DecoderImpl::Symphonia(source) => source.sample_rate(),