Commit d8934e27 by Oliver Woodman

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.
parent 15da18d9
...@@ -123,7 +123,7 @@ import com.google.android.exoplayer.util.Util; ...@@ -123,7 +123,7 @@ import com.google.android.exoplayer.util.Util;
fx = fa + (fb - fa) * (percent - a); 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; return inputLength != C.LENGTH_UNBOUNDED ? Math.min(position, inputLength - 1) : position;
} }
...@@ -132,8 +132,8 @@ import com.google.android.exoplayer.util.Util; ...@@ -132,8 +132,8 @@ import com.google.android.exoplayer.util.Util;
if (!isSeekable()) { if (!isSeekable()) {
return 0L; return 0L;
} }
long offsetByte = 256 * (position - firstFramePosition) / sizeBytes; double offsetByte = 256.0 * (position - firstFramePosition) / sizeBytes;
int previousIndex = Util.binarySearchFloor(tableOfContents, offsetByte, true, false); int previousIndex = Util.binarySearchFloor(tableOfContents, (long) offsetByte, true, false);
long previousTime = getTimeUsForTocIndex(previousIndex); long previousTime = getTimeUsForTocIndex(previousIndex);
if (previousIndex == 98) { if (previousIndex == 98) {
return previousTime; return previousTime;
...@@ -143,8 +143,8 @@ import com.google.android.exoplayer.util.Util; ...@@ -143,8 +143,8 @@ import com.google.android.exoplayer.util.Util;
long previousByte = previousIndex == -1 ? 0 : tableOfContents[previousIndex]; long previousByte = previousIndex == -1 ? 0 : tableOfContents[previousIndex];
long nextByte = tableOfContents[previousIndex + 1]; long nextByte = tableOfContents[previousIndex + 1];
long nextTime = getTimeUsForTocIndex(previousIndex + 1); long nextTime = getTimeUsForTocIndex(previousIndex + 1);
long timeOffset = long timeOffset = nextByte == previousByte ? 0 : (long) ((nextTime - previousTime)
(nextTime - previousTime) * (offsetByte - previousByte) / (nextByte - previousByte); * (offsetByte - previousByte) / (nextByte - previousByte));
return previousTime + timeOffset; return previousTime + timeOffset;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment