Skip to content

Commit

Permalink
Revert to using header bitrate for CBR MP3s
Browse files Browse the repository at this point in the history
A previous change switched to calculation of the bitrate based on the
first MPEG audio header in the stream. This had the effect of fixing
seeking to be consistent with playing from the start for streams where
every frame has the same padding value, but broke streams where the
encoder (correctly) modifies the padding value to match the declared
bitrate in the header.

Issue: #6238
PiperOrigin-RevId: 261163904
  • Loading branch information
andrewlewis authored and ojw28 committed Aug 1, 2019
1 parent 42d3ca2 commit 5eab519
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 8 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
([#6241](https://github.com/google/ExoPlayer/issues/6241)).
* Fix Flac and ALAC playback on some LG devices
([#5938](https://github.com/google/ExoPlayer/issues/5938)).
* MP3: use CBR header bitrate, not calculated bitrate. This reverts a change
from 2.9.3 ([#6238](https://github.com/google/ExoPlayer/issues/6238)).

### 2.10.4 ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ public static boolean populateHeader(int headerData, MpegAudioHeader header) {
}
}

// Calculate the bitrate in the same way Mp3Extractor calculates sample timestamps so that
// seeking to a given timestamp and playing from the start up to that timestamp give the same
// results for CBR streams. See also [internal: b/120390268].
bitrate = 8 * frameSize * sampleRate / samplesPerFrame;
String mimeType = MIME_TYPE_BY_LAYER[3 - layer];
int channels = ((headerData >> 6) & 3) == 3 ? 1 : 2;
header.setValues(version, mimeType, frameSize, sampleRate, channels, bitrate, samplesPerFrame);
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/test/assets/mp3/play-trimmed.mp3.0.dump
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
seekMap:
isSeekable = true
duration = 26122
duration = 26125
getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1
track 0:
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/test/assets/mp3/play-trimmed.mp3.1.dump
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
seekMap:
isSeekable = true
duration = 26122
duration = 26125
getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1
track 0:
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/test/assets/mp3/play-trimmed.mp3.2.dump
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
seekMap:
isSeekable = true
duration = 26122
duration = 26125
getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1
track 0:
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/test/assets/mp3/play-trimmed.mp3.3.dump
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
seekMap:
isSeekable = true
duration = 26122
duration = 26125
getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1
track 0:
Expand Down

0 comments on commit 5eab519

Please sign in to comment.