Fix seeking bug in opus

Fix a bug when seeking in an opus container. The calculations inside
DefaultOggSeeker may overflow a long primitive.

Issue: androidx/media#391

#minor-release

PiperOrigin-RevId: 534128513
This commit is contained in:
christosts 2023-05-22 19:24:30 +01:00 committed by tonihei
parent a9e3f5def4
commit b9a4e614f7
2 changed files with 9 additions and 1 deletions

View File

@ -9,6 +9,8 @@
* ExoPlayer:
* Add `FilteringMediaSource` that allows to filter available track types
from a `MediaSource`.
* Fix bug seeking in files with long opus audio
([#391](https://github.com/androidx/media/issues/391)).
* Transformer:
* Track Selection:
* Extractors:

View File

@ -28,6 +28,7 @@ import androidx.media3.extractor.SeekMap;
import androidx.media3.extractor.SeekPoint;
import java.io.EOFException;
import java.io.IOException;
import java.math.BigInteger;
/** Seeks in an Ogg stream. */
/* package */ final class DefaultOggSeeker implements OggSeeker {
@ -260,7 +261,12 @@ import java.io.IOException;
long targetGranule = streamReader.convertTimeToGranule(timeUs);
long estimatedPosition =
payloadStartPosition
+ (targetGranule * (payloadEndPosition - payloadStartPosition) / totalGranules)
// Use BigInteger arithmetic to avoid long overflow
// https://github.com/androidx/media/issues/391
+ BigInteger.valueOf(targetGranule)
.multiply(BigInteger.valueOf(payloadEndPosition - payloadStartPosition))
.divide(BigInteger.valueOf(totalGranules))
.longValue()
- DEFAULT_OFFSET;
estimatedPosition =
Util.constrainValue(estimatedPosition, payloadStartPosition, payloadEndPosition - 1);