From d8934e27512f2a7ed7090a87285dad55a9842057 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Tue, 29 Sep 2015 11:37:40 +0100 Subject: [PATCH] Make mapping from position to time more accurate in XING MP3 streams. This change keeps the proportion offset * 256 as a floating point value rather than rounding it before linear interpolation, which will increase precision slightly when seeking in streams with XING headers. In practice, this won't make much of a difference because precise seeking in VBR MP3s with XING headers seems not to be possible without reading the entire file, due to the fact that the (uneven) distribution of bits is represented by a fixed number of table of contents entries. --- .../android/exoplayer/extractor/mp3/XingSeeker.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/mp3/XingSeeker.java b/library/src/main/java/com/google/android/exoplayer/extractor/mp3/XingSeeker.java index b8d86bcedc..7de38898c5 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/mp3/XingSeeker.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/mp3/XingSeeker.java @@ -123,7 +123,7 @@ import com.google.android.exoplayer.util.Util; fx = fa + (fb - fa) * (percent - a); } - long position = (long) ((1f / 256) * fx * sizeBytes) + firstFramePosition; + long position = (long) ((1.0 / 256) * fx * sizeBytes) + firstFramePosition; return inputLength != C.LENGTH_UNBOUNDED ? Math.min(position, inputLength - 1) : position; } @@ -132,8 +132,8 @@ import com.google.android.exoplayer.util.Util; if (!isSeekable()) { return 0L; } - long offsetByte = 256 * (position - firstFramePosition) / sizeBytes; - int previousIndex = Util.binarySearchFloor(tableOfContents, offsetByte, true, false); + double offsetByte = 256.0 * (position - firstFramePosition) / sizeBytes; + int previousIndex = Util.binarySearchFloor(tableOfContents, (long) offsetByte, true, false); long previousTime = getTimeUsForTocIndex(previousIndex); if (previousIndex == 98) { return previousTime; @@ -143,8 +143,8 @@ import com.google.android.exoplayer.util.Util; long previousByte = previousIndex == -1 ? 0 : tableOfContents[previousIndex]; long nextByte = tableOfContents[previousIndex + 1]; long nextTime = getTimeUsForTocIndex(previousIndex + 1); - long timeOffset = - (nextTime - previousTime) * (offsetByte - previousByte) / (nextByte - previousByte); + long timeOffset = nextByte == previousByte ? 0 : (long) ((nextTime - previousTime) + * (offsetByte - previousByte) / (nextByte - previousByte)); return previousTime + timeOffset; }