Skip to content

Commit

Permalink
Fix 96kbps playback issue (issues #1236) (#1342)
Browse files Browse the repository at this point in the history
- add missing audio formats to message AudioFile
- ensure that unknown formats gets mapped to DEFAULT_FORMAT
  • Loading branch information
fivebanger authored Sep 19, 2024
1 parent fb5c0ef commit 67d3195
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
14 changes: 11 additions & 3 deletions playback/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
AudioFileFormat::OGG_VORBIS_96 => 12,
AudioFileFormat::OGG_VORBIS_160 => 20,
Expand All @@ -913,9 +913,17 @@ impl PlayerTrackLoader {
AudioFileFormat::MP3_160_ENC => 20,
AudioFileFormat::AAC_24 => 3,
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::UNKNOWN_FORMAT => {
error!("Unknown stream data rate");
return None;
}
};
kbps * 1024
Some(kbps * 1024)
}

async fn load_track(
Expand Down Expand Up @@ -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
// while opening a cached file.
Expand Down
4 changes: 4 additions & 0 deletions protocol/proto/media_manifest.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ message AudioFile {
MP3_160_ENC = 7;
AAC_24 = 8;
AAC_48 = 9;
AAC_160 = 10;
AAC_320 = 11;
MP4_128 = 12;
OTHER5 = 13;
FLAC_FLAC = 16;
}
}
Expand Down
7 changes: 6 additions & 1 deletion protocol/proto/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ message ExternalId {
message AudioFile {
optional bytes file_id = 1;

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

Expand Down

0 comments on commit 67d3195

Please sign in to comment.