mirror of
https://github.com/samsonjs/media.git
synced 2026-04-14 12:45:47 +00:00
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
(cherry picked from commit b9a4e614f7)
This commit is contained in:
parent
cebdb17134
commit
fbd0bae265
2 changed files with 9 additions and 1 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue