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
This commit is contained in:
Sergey "Shnatsel" Davidoff 2022-11-12 05:08:36 +01:00 committed by GitHub
parent 70c80462e6
commit 92142b1a0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 24 deletions

View file

@ -24,7 +24,8 @@ default = ["flac", "vorbis", "wav", "mp3"]
flac = ["claxon"] flac = ["claxon"]
vorbis = ["lewton"] vorbis = ["lewton"]
wav = ["hound"] wav = ["hound"]
mp3 = ["minimp3"] mp3 = ["symphonia-mp3"]
minimp3 = ["dep:minimp3"]
wasm-bindgen = ["cpal/wasm-bindgen"] wasm-bindgen = ["cpal/wasm-bindgen"]
symphonia-aac = ["symphonia/aac"] symphonia-aac = ["symphonia/aac"]
symphonia-all = ["symphonia-aac", "symphonia-flac", "symphonia-isomp4", "symphonia-mp3", "symphonia-vorbis", "symphonia-wav"] symphonia-all = ["symphonia-aac", "symphonia-flac", "symphonia-isomp4", "symphonia-mp3", "symphonia-vorbis", "symphonia-wav"]

View file

@ -6,14 +6,15 @@
Rust playback library. Rust playback library.
- Playback is handled by [cpal](https://github.com/RustAudio/cpal). 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:
- 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).
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) # [Documentation](http://docs.rs/rodio)

View file

@ -18,7 +18,7 @@ use ::symphonia::core::io::{MediaSource, MediaSourceStream};
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
mod flac; mod flac;
#[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))]
mod mp3; mod mp3;
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
mod read_seek_source; mod read_seek_source;
@ -50,7 +50,7 @@ where
Vorbis(vorbis::VorbisDecoder<R>), Vorbis(vorbis::VorbisDecoder<R>),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
Flac(flac::FlacDecoder<R>), Flac(flac::FlacDecoder<R>),
#[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))]
Mp3(mp3::Mp3Decoder<R>), Mp3(mp3::Mp3Decoder<R>),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
Symphonia(symphonia::SymphoniaDecoder), 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) { let data = match mp3::Mp3Decoder::new(data) {
Err(data) => data, Err(data) => data,
Ok(decoder) => { Ok(decoder) => {
@ -159,7 +159,7 @@ where
} }
/// Builds a new decoder from mp3 data. /// 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<Decoder<R>, DecoderError> { pub fn new_mp3(data: R) -> Result<Decoder<R>, DecoderError> {
match mp3::Mp3Decoder::new(data) { match mp3::Mp3Decoder::new(data) {
Err(_) => Err(DecoderError::UnrecognizedFormat), Err(_) => Err(DecoderError::UnrecognizedFormat),
@ -268,7 +268,7 @@ where
DecoderImpl::Vorbis(source) => source.next(), DecoderImpl::Vorbis(source) => source.next(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.next(), 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(), DecoderImpl::Mp3(source) => source.next(),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.next(), DecoderImpl::Symphonia(source) => source.next(),
@ -285,7 +285,7 @@ where
DecoderImpl::Vorbis(source) => source.size_hint(), DecoderImpl::Vorbis(source) => source.size_hint(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.size_hint(), 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(), DecoderImpl::Mp3(source) => source.size_hint(),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.size_hint(), DecoderImpl::Symphonia(source) => source.size_hint(),
@ -307,7 +307,7 @@ where
DecoderImpl::Vorbis(source) => source.current_frame_len(), DecoderImpl::Vorbis(source) => source.current_frame_len(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.current_frame_len(), 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(), DecoderImpl::Mp3(source) => source.current_frame_len(),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.current_frame_len(), DecoderImpl::Symphonia(source) => source.current_frame_len(),
@ -324,7 +324,7 @@ where
DecoderImpl::Vorbis(source) => source.channels(), DecoderImpl::Vorbis(source) => source.channels(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.channels(), 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(), DecoderImpl::Mp3(source) => source.channels(),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.channels(), DecoderImpl::Symphonia(source) => source.channels(),
@ -341,7 +341,7 @@ where
DecoderImpl::Vorbis(source) => source.sample_rate(), DecoderImpl::Vorbis(source) => source.sample_rate(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.sample_rate(), 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(), DecoderImpl::Mp3(source) => source.sample_rate(),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.sample_rate(), DecoderImpl::Symphonia(source) => source.sample_rate(),
@ -358,7 +358,7 @@ where
DecoderImpl::Vorbis(source) => source.total_duration(), DecoderImpl::Vorbis(source) => source.total_duration(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.total_duration(), 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(), DecoderImpl::Mp3(source) => source.total_duration(),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.total_duration(), DecoderImpl::Symphonia(source) => source.total_duration(),
@ -382,7 +382,7 @@ where
DecoderImpl::Vorbis(source) => source.next(), DecoderImpl::Vorbis(source) => source.next(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.next(), 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(), DecoderImpl::Mp3(source) => source.next(),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.next(), DecoderImpl::Symphonia(source) => source.next(),
@ -419,7 +419,7 @@ where
let sample = source.next(); let sample = source.next();
(DecoderImpl::Flac(source), sample) (DecoderImpl::Flac(source), sample)
} }
#[cfg(all(feature = "mp3", not(feature = "symphonia-mp3")))] #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))]
DecoderImpl::Mp3(source) => { DecoderImpl::Mp3(source) => {
let mut reader = source.into_inner(); let mut reader = source.into_inner();
reader.seek(SeekFrom::Start(0)).ok()?; reader.seek(SeekFrom::Start(0)).ok()?;
@ -451,7 +451,7 @@ where
DecoderImpl::Vorbis(source) => (source.size_hint().0, None), DecoderImpl::Vorbis(source) => (source.size_hint().0, None),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => (source.size_hint().0, None), 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), DecoderImpl::Mp3(source) => (source.size_hint().0, None),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => (source.size_hint().0, None), DecoderImpl::Symphonia(source) => (source.size_hint().0, None),
@ -473,7 +473,7 @@ where
DecoderImpl::Vorbis(source) => source.current_frame_len(), DecoderImpl::Vorbis(source) => source.current_frame_len(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.current_frame_len(), 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(), DecoderImpl::Mp3(source) => source.current_frame_len(),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.current_frame_len(), DecoderImpl::Symphonia(source) => source.current_frame_len(),
@ -490,7 +490,7 @@ where
DecoderImpl::Vorbis(source) => source.channels(), DecoderImpl::Vorbis(source) => source.channels(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.channels(), 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(), DecoderImpl::Mp3(source) => source.channels(),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.channels(), DecoderImpl::Symphonia(source) => source.channels(),
@ -507,7 +507,7 @@ where
DecoderImpl::Vorbis(source) => source.sample_rate(), DecoderImpl::Vorbis(source) => source.sample_rate(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.sample_rate(), 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(), DecoderImpl::Mp3(source) => source.sample_rate(),
#[cfg(feature = "symphonia")] #[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.sample_rate(), DecoderImpl::Symphonia(source) => source.sample_rate(),