Optimize fallback sample buffer size

This commit is contained in:
Roderick van Domburg 2022-01-04 00:50:45 +01:00
parent 01448ccbe8
commit d5a4be4aa1
No known key found for this signature in database
GPG key ID: FE2585E713F9F30A
2 changed files with 21 additions and 2 deletions

View file

@ -33,8 +33,13 @@ impl AudioFiles {
| AudioFileFormat::MP3_256
| AudioFileFormat::MP3_160
| AudioFileFormat::MP3_96
| AudioFileFormat::MP3_160_ENC
)
}
pub fn is_flac(format: AudioFileFormat) -> bool {
matches!(format, AudioFileFormat::FLAC_FLAC)
}
}
impl From<&[AudioFileMessage]> for AudioFiles {

View file

@ -43,8 +43,20 @@ impl SymphoniaDecoder {
} else if AudioFiles::is_mp3(format) {
hint.with_extension("mp3");
hint.mime_type("audio/mp3");
} else if AudioFiles::is_flac(format) {
hint.with_extension("flac");
hint.mime_type("audio/flac");
}
let max_format_size = if AudioFiles::is_ogg_vorbis(format) {
8192
} else if AudioFiles::is_mp3(format) {
2304
} else {
// like FLAC
65535
};
let format_opts = Default::default();
let metadata_opts: MetadataOptions = Default::default();
let decoder_opts: DecoderOptions = Default::default();
@ -81,8 +93,10 @@ impl SymphoniaDecoder {
)));
}
// TODO: settle on a sane default depending on the format
let max_frames = decoder.codec_params().max_frames_per_packet.unwrap_or(8192);
let max_frames = decoder
.codec_params()
.max_frames_per_packet
.unwrap_or(max_format_size);
let sample_buffer = SampleBuffer::new(max_frames, SignalSpec { rate, channels });
Ok(Self {