mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08: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
This commit is contained in:
parent
a9e3f5def4
commit
b9a4e614f7
@ -9,6 +9,8 @@
|
|||||||
* ExoPlayer:
|
* ExoPlayer:
|
||||||
* Add `FilteringMediaSource` that allows to filter available track types
|
* Add `FilteringMediaSource` that allows to filter available track types
|
||||||
from a `MediaSource`.
|
from a `MediaSource`.
|
||||||
|
* Fix bug seeking in files with long opus audio
|
||||||
|
([#391](https://github.com/androidx/media/issues/391)).
|
||||||
* Transformer:
|
* Transformer:
|
||||||
* Track Selection:
|
* Track Selection:
|
||||||
* Extractors:
|
* Extractors:
|
||||||
|
@ -28,6 +28,7 @@ import androidx.media3.extractor.SeekMap;
|
|||||||
import androidx.media3.extractor.SeekPoint;
|
import androidx.media3.extractor.SeekPoint;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
/** Seeks in an Ogg stream. */
|
/** Seeks in an Ogg stream. */
|
||||||
/* package */ final class DefaultOggSeeker implements OggSeeker {
|
/* package */ final class DefaultOggSeeker implements OggSeeker {
|
||||||
@ -260,7 +261,12 @@ import java.io.IOException;
|
|||||||
long targetGranule = streamReader.convertTimeToGranule(timeUs);
|
long targetGranule = streamReader.convertTimeToGranule(timeUs);
|
||||||
long estimatedPosition =
|
long estimatedPosition =
|
||||||
payloadStartPosition
|
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;
|
- DEFAULT_OFFSET;
|
||||||
estimatedPosition =
|
estimatedPosition =
|
||||||
Util.constrainValue(estimatedPosition, payloadStartPosition, payloadEndPosition - 1);
|
Util.constrainValue(estimatedPosition, payloadStartPosition, payloadEndPosition - 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user