mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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.
This commit is contained in:
parent
15da18d900
commit
d8934e2751
1 changed files with 5 additions and 5 deletions
|
|
@ -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;
|
||||||
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;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue