Fix 96kbps playback issue (issues #1236) (#1342)

- add missing audio formats to message AudioFile
- ensure that unknown formats gets mapped to DEFAULT_FORMAT
This commit is contained in:
fivebanger 2024-09-19 21:59:20 +02:00 committed by GitHub
parent fb5c0efdd6
commit 67d31959f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 4 deletions

View file

@ -901,7 +901,7 @@ impl PlayerTrackLoader {
} }
} }
fn stream_data_rate(&self, format: AudioFileFormat) -> usize { fn stream_data_rate(&self, format: AudioFileFormat) -> Option<usize> {
let kbps = match format { let kbps = match format {
AudioFileFormat::OGG_VORBIS_96 => 12, AudioFileFormat::OGG_VORBIS_96 => 12,
AudioFileFormat::OGG_VORBIS_160 => 20, AudioFileFormat::OGG_VORBIS_160 => 20,
@ -913,9 +913,17 @@ impl PlayerTrackLoader {
AudioFileFormat::MP3_160_ENC => 20, AudioFileFormat::MP3_160_ENC => 20,
AudioFileFormat::AAC_24 => 3, AudioFileFormat::AAC_24 => 3,
AudioFileFormat::AAC_48 => 6, AudioFileFormat::AAC_48 => 6,
AudioFileFormat::AAC_160 => 20,
AudioFileFormat::AAC_320 => 40,
AudioFileFormat::MP4_128 => 16,
AudioFileFormat::OTHER5 => 40,
AudioFileFormat::FLAC_FLAC => 112, // assume 900 kbit/s on average AudioFileFormat::FLAC_FLAC => 112, // assume 900 kbit/s on average
AudioFileFormat::UNKNOWN_FORMAT => {
error!("Unknown stream data rate");
return None;
}
}; };
kbps * 1024 Some(kbps * 1024)
} }
async fn load_track( async fn load_track(
@ -993,7 +1001,7 @@ impl PlayerTrackLoader {
} }
}; };
let bytes_per_second = self.stream_data_rate(format); let bytes_per_second = self.stream_data_rate(format)?;
// This is only a loop to be able to reload the file if an error occurred // This is only a loop to be able to reload the file if an error occurred
// while opening a cached file. // while opening a cached file.

View file

@ -18,6 +18,10 @@ message AudioFile {
MP3_160_ENC = 7; MP3_160_ENC = 7;
AAC_24 = 8; AAC_24 = 8;
AAC_48 = 9; AAC_48 = 9;
AAC_160 = 10;
AAC_320 = 11;
MP4_128 = 12;
OTHER5 = 13;
FLAC_FLAC = 16; FLAC_FLAC = 16;
} }
} }

View file

@ -288,7 +288,7 @@ message ExternalId {
message AudioFile { message AudioFile {
optional bytes file_id = 1; optional bytes file_id = 1;
optional Format format = 2; optional Format format = 2 [default = UNKNOWN_FORMAT];
enum Format { enum Format {
OGG_VORBIS_96 = 0; OGG_VORBIS_96 = 0;
OGG_VORBIS_160 = 1; OGG_VORBIS_160 = 1;
@ -300,7 +300,12 @@ message AudioFile {
MP3_160_ENC = 7; MP3_160_ENC = 7;
AAC_24 = 8; AAC_24 = 8;
AAC_48 = 9; AAC_48 = 9;
AAC_160 = 10;
AAC_320 = 11;
MP4_128 = 12;
OTHER5 = 13;
FLAC_FLAC = 16; FLAC_FLAC = 16;
UNKNOWN_FORMAT = 255;
} }
} }