Commit 91b324f6 by olly Committed by Oliver Woodman

Fix weird XingSeeker indexing

There are still things broken about the seeker, but this
cleans up some of the weird bits.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177315136
parent 63dbf56b
...@@ -58,9 +58,8 @@ import com.google.android.exoplayer2.util.Util; ...@@ -58,9 +58,8 @@ import com.google.android.exoplayer2.util.Util;
} }
long sizeBytes = frame.readUnsignedIntToInt(); long sizeBytes = frame.readUnsignedIntToInt();
frame.skipBytes(1); long[] tableOfContents = new long[100];
long[] tableOfContents = new long[99]; for (int i = 0; i < 100; i++) {
for (int i = 0; i < 99; i++) {
tableOfContents[i] = frame.readUnsignedByte(); tableOfContents[i] = frame.readUnsignedByte();
} }
...@@ -105,30 +104,20 @@ import com.google.android.exoplayer2.util.Util; ...@@ -105,30 +104,20 @@ import com.google.android.exoplayer2.util.Util;
if (!isSeekable()) { if (!isSeekable()) {
return firstFramePosition; return firstFramePosition;
} }
float percent = timeUs * 100f / durationUs; double percent = (timeUs * 100d) / durationUs;
float fx; double fx;
if (percent <= 0f) { if (percent <= 0) {
fx = 0f; fx = 0;
} else if (percent >= 100f) { } else if (percent >= 100) {
fx = 256f; fx = 256;
} else { } else {
int a = (int) percent; int a = (int) percent;
float fa; float fa = tableOfContents[a];
if (a == 0) { float fb = a == 99 ? 256 : tableOfContents[a + 1];
fa = 0f;
} else {
fa = tableOfContents[a - 1];
}
float fb;
if (a < 99) {
fb = tableOfContents[a];
} else {
fb = 256f;
}
fx = fa + (fb - fa) * (percent - a); fx = fa + (fb - fa) * (percent - a);
} }
long position = Math.round((1.0 / 256) * fx * sizeBytes) + firstFramePosition; long position = Math.round((fx / 256) * sizeBytes) + firstFramePosition;
long maximumPosition = inputLength != C.LENGTH_UNSET ? inputLength - 1 long maximumPosition = inputLength != C.LENGTH_UNSET ? inputLength - 1
: firstFramePosition - headerSize + sizeBytes - 1; : firstFramePosition - headerSize + sizeBytes - 1;
return Math.min(position, maximumPosition); return Math.min(position, maximumPosition);
...@@ -139,14 +128,14 @@ import com.google.android.exoplayer2.util.Util; ...@@ -139,14 +128,14 @@ import com.google.android.exoplayer2.util.Util;
if (!isSeekable() || position < firstFramePosition) { if (!isSeekable() || position < firstFramePosition) {
return 0L; return 0L;
} }
double offsetByte = 256.0 * (position - firstFramePosition) / sizeBytes; double offsetByte = (256d * (position - firstFramePosition)) / sizeBytes;
int previousTocPosition = int previousTocPosition =
Util.binarySearchFloor(tableOfContents, (long) offsetByte, true, false) + 1; Util.binarySearchFloor(tableOfContents, (long) offsetByte, true, true);
long previousTime = getTimeUsForTocPosition(previousTocPosition); long previousTime = getTimeUsForTocPosition(previousTocPosition);
// Linearly interpolate the time taking into account the next entry. // Linearly interpolate the time taking into account the next entry.
long previousByte = previousTocPosition == 0 ? 0 : tableOfContents[previousTocPosition - 1]; long previousByte = tableOfContents[previousTocPosition];
long nextByte = previousTocPosition == 99 ? 256 : tableOfContents[previousTocPosition]; long nextByte = previousTocPosition == 99 ? 256 : tableOfContents[previousTocPosition + 1];
long nextTime = getTimeUsForTocPosition(previousTocPosition + 1); long nextTime = getTimeUsForTocPosition(previousTocPosition + 1);
long timeOffset = nextByte == previousByte ? 0 : (long) ((nextTime - previousTime) long timeOffset = nextByte == previousByte ? 0 : (long) ((nextTime - previousTime)
* (offsetByte - previousByte) / (nextByte - previousByte)); * (offsetByte - previousByte) / (nextByte - previousByte));
...@@ -163,7 +152,7 @@ import com.google.android.exoplayer2.util.Util; ...@@ -163,7 +152,7 @@ import com.google.android.exoplayer2.util.Util;
* interpreted as a percentage of the stream's duration between 0 and 100. * interpreted as a percentage of the stream's duration between 0 and 100.
*/ */
private long getTimeUsForTocPosition(int tocPosition) { private long getTimeUsForTocPosition(int tocPosition) {
return durationUs * tocPosition / 100; return (durationUs * tocPosition) / 100;
} }
} }
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