Use scaleLargeTimestamp
in TimestampAdjuster
This helps avoid overflows in intermediate calculations. Verified the value in the test using `BigInteger`: ``` jshell> BigInteger.valueOf(1L << 52).multiply(BigInteger.valueOf(90000)).divide(BigInteger.valueOf(1000000)) $3 ==> 405323966463344 ``` Issue: androidx/media#1763 #cherrypick PiperOrigin-RevId: 684028178
This commit is contained in:
parent
2c46cea088
commit
b6d0540059
@ -74,6 +74,10 @@
|
||||
* Add workaround for codecs that get stuck after the last sample without
|
||||
returning an end-of-stream signal.
|
||||
* Text:
|
||||
* Ensure WebVTT in HLS with very large subtitle timestamps (which overflow
|
||||
a 64-bit `long` when represented as microseconds and multiplied by the
|
||||
`90,000` MPEG timebase) are displayed
|
||||
([#1763](https://github.com/androidx/media/issues/1763)).
|
||||
* Metadata:
|
||||
* Assign the `C.TRACK_TYPE_METADATA` type to tracks containing icy or
|
||||
vnd.dvb.ait content.
|
||||
|
@ -271,7 +271,7 @@ public final class TimestampAdjuster {
|
||||
* @return The corresponding value in microseconds.
|
||||
*/
|
||||
public static long ptsToUs(long pts) {
|
||||
return (pts * C.MICROS_PER_SECOND) / 90000;
|
||||
return Util.scaleLargeTimestamp(pts, C.MICROS_PER_SECOND, 90000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -295,6 +295,6 @@ public final class TimestampAdjuster {
|
||||
* @return The corresponding value as a 90 kHz clock timestamp.
|
||||
*/
|
||||
public static long usToNonWrappedPts(long us) {
|
||||
return (us * 90000) / C.MICROS_PER_SECOND;
|
||||
return Util.scaleLargeTimestamp(us, 90000, C.MICROS_PER_SECOND);
|
||||
}
|
||||
}
|
||||
|
@ -240,4 +240,10 @@ public class TimestampAdjusterTest {
|
||||
|
||||
assertThat(secondAdjustedTimestampUs - firstAdjustedTimestampUs).isGreaterThan(0x100000000L);
|
||||
}
|
||||
|
||||
// https://github.com/androidx/media/issues/1763
|
||||
@Test
|
||||
public void usToWrappedPts_usTimestampCloseToOverflow_doesntOverflow() {
|
||||
assertThat(TimestampAdjuster.usToNonWrappedPts(1L << 52)).isEqualTo(405323966463344L);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user