mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Optimize fallback sample buffer size
This commit is contained in:
parent
01448ccbe8
commit
d5a4be4aa1
2 changed files with 21 additions and 2 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue