Use RoundingMode.DOWN in Util.scaleLargeTimestamp and friends

The implementation of these methods was updated from direct java integer
arithmetic in 885ddb167e.
In this change, `RoundingMode.FLOOR` was used to try and maintain
compatibility with java integer division. This was incorrect, because
java integer division uses `DOWN` (i.e. towards zero), rather than
`FLOOR` (i.e. towards negative infinity) semantics.

This change fixes the compatibility.

The dump file changes in this CL relate to tests that exercise edit
list behaviour. This involves manipulating negative timestamps, which
explains why they are impacted by this change.

PiperOrigin-RevId: 684013175
This commit is contained in:
ibaker 2024-10-09 06:21:50 -07:00 committed by Copybara-Service
parent d5baa4ce59
commit 2c46cea088
8 changed files with 38 additions and 38 deletions

View File

@ -1600,7 +1600,7 @@ public final class Util {
*/
@UnstableApi
public static long sampleCountToDurationUs(long sampleCount, int sampleRate) {
return scaleLargeValue(sampleCount, C.MICROS_PER_SECOND, sampleRate, RoundingMode.FLOOR);
return scaleLargeValue(sampleCount, C.MICROS_PER_SECOND, sampleRate, RoundingMode.DOWN);
}
/**
@ -1617,7 +1617,7 @@ public final class Util {
*/
@UnstableApi
public static long durationUsToSampleCount(long durationUs, int sampleRate) {
return scaleLargeValue(durationUs, sampleRate, C.MICROS_PER_SECOND, RoundingMode.CEILING);
return scaleLargeValue(durationUs, sampleRate, C.MICROS_PER_SECOND, RoundingMode.UP);
}
/**
@ -1902,7 +1902,7 @@ public final class Util {
* Scales a large timestamp.
*
* <p>Equivalent to {@link #scaleLargeValue(long, long, long, RoundingMode)} with {@link
* RoundingMode#FLOOR}.
* RoundingMode#DOWN}.
*
* @param timestamp The timestamp to scale.
* @param multiplier The multiplier.
@ -1911,7 +1911,7 @@ public final class Util {
*/
@UnstableApi
public static long scaleLargeTimestamp(long timestamp, long multiplier, long divisor) {
return scaleLargeValue(timestamp, multiplier, divisor, RoundingMode.FLOOR);
return scaleLargeValue(timestamp, multiplier, divisor, RoundingMode.DOWN);
}
/**
@ -1924,7 +1924,7 @@ public final class Util {
*/
@UnstableApi
public static long[] scaleLargeTimestamps(List<Long> timestamps, long multiplier, long divisor) {
return scaleLargeValues(timestamps, multiplier, divisor, RoundingMode.FLOOR);
return scaleLargeValues(timestamps, multiplier, divisor, RoundingMode.DOWN);
}
/**
@ -1936,7 +1936,7 @@ public final class Util {
*/
@UnstableApi
public static void scaleLargeTimestampsInPlace(long[] timestamps, long multiplier, long divisor) {
scaleLargeValuesInPlace(timestamps, multiplier, divisor, RoundingMode.FLOOR);
scaleLargeValuesInPlace(timestamps, multiplier, divisor, RoundingMode.DOWN);
}
/**

View File

@ -33,15 +33,15 @@ track 0:
flags = 1
data = length 78829, hash 9265686F
sample 1:
time = -321667
time = -321666
flags = 0
data = length 32262, hash 1AD10F61
sample 2:
time = -388334
time = -388333
flags = 0
data = length 18055, hash C6BED1E3
sample 3:
time = -188334
time = -188333
flags = 0
data = length 65604, hash AA006B06
sample 4:
@ -53,7 +53,7 @@ track 0:
flags = 0
data = length 72552, hash 9535951C
sample 6:
time = -121667
time = -121666
flags = 0
data = length 23756, hash 4074D5AE
sample 7:
@ -65,7 +65,7 @@ track 0:
flags = 0
data = length 55804, hash D559D074
sample 9:
time = -21667
time = -21666
flags = 0
data = length 12955, hash 35EE397F
sample 10:

View File

@ -33,15 +33,15 @@ track 0:
flags = 1
data = length 78829, hash 9265686F
sample 1:
time = -321667
time = -321666
flags = 0
data = length 32262, hash 1AD10F61
sample 2:
time = -388334
time = -388333
flags = 0
data = length 18055, hash C6BED1E3
sample 3:
time = -188334
time = -188333
flags = 0
data = length 65604, hash AA006B06
sample 4:
@ -53,7 +53,7 @@ track 0:
flags = 0
data = length 72552, hash 9535951C
sample 6:
time = -121667
time = -121666
flags = 0
data = length 23756, hash 4074D5AE
sample 7:
@ -65,7 +65,7 @@ track 0:
flags = 0
data = length 55804, hash D559D074
sample 9:
time = -21667
time = -21666
flags = 0
data = length 12955, hash 35EE397F
sample 10:

View File

@ -33,15 +33,15 @@ track 0:
flags = 1
data = length 78829, hash 9265686F
sample 1:
time = -321667
time = -321666
flags = 0
data = length 32262, hash 1AD10F61
sample 2:
time = -388334
time = -388333
flags = 0
data = length 18055, hash C6BED1E3
sample 3:
time = -188334
time = -188333
flags = 0
data = length 65604, hash AA006B06
sample 4:
@ -53,7 +53,7 @@ track 0:
flags = 0
data = length 72552, hash 9535951C
sample 6:
time = -121667
time = -121666
flags = 0
data = length 23756, hash 4074D5AE
sample 7:
@ -65,7 +65,7 @@ track 0:
flags = 0
data = length 55804, hash D559D074
sample 9:
time = -21667
time = -21666
flags = 0
data = length 12955, hash 35EE397F
sample 10:

View File

@ -33,15 +33,15 @@ track 0:
flags = 1
data = length 78829, hash 9265686F
sample 1:
time = -321667
time = -321666
flags = 0
data = length 32262, hash 1AD10F61
sample 2:
time = -388334
time = -388333
flags = 0
data = length 18055, hash C6BED1E3
sample 3:
time = -188334
time = -188333
flags = 0
data = length 65604, hash AA006B06
sample 4:
@ -53,7 +53,7 @@ track 0:
flags = 0
data = length 72552, hash 9535951C
sample 6:
time = -121667
time = -121666
flags = 0
data = length 23756, hash 4074D5AE
sample 7:
@ -65,7 +65,7 @@ track 0:
flags = 0
data = length 55804, hash D559D074
sample 9:
time = -21667
time = -21666
flags = 0
data = length 12955, hash 35EE397F
sample 10:

View File

@ -798,13 +798,13 @@ MediaCodecAdapter (exotest.video.hevc):
timeUs = 999999545000
contents = length 78829, hash 9265686F
input buffer #1:
timeUs = 999999678333
timeUs = 999999678334
contents = length 32262, hash 1AD10F61
input buffer #2:
timeUs = 999999611666
timeUs = 999999611667
contents = length 18055, hash C6BED1E3
input buffer #3:
timeUs = 999999811666
timeUs = 999999811667
contents = length 65604, hash AA006B06
input buffer #4:
timeUs = 999999745000
@ -813,7 +813,7 @@ MediaCodecAdapter (exotest.video.hevc):
timeUs = 999999945000
contents = length 72552, hash 9535951C
input buffer #6:
timeUs = 999999878333
timeUs = 999999878334
contents = length 23756, hash 4074D5AE
input buffer #7:
timeUs = 1000000078333
@ -822,7 +822,7 @@ MediaCodecAdapter (exotest.video.hevc):
timeUs = 1000000011666
contents = length 55804, hash D559D074
input buffer #9:
timeUs = 999999978333
timeUs = 999999978334
contents = length 12955, hash 35EE397F
input buffer #10:
timeUs = 1000000045000
@ -1054,15 +1054,15 @@ MediaCodecAdapter (exotest.video.hevc):
size = 78829
rendered = false
output buffer #1:
timeUs = 999999678333
timeUs = 999999678334
size = 32262
rendered = false
output buffer #2:
timeUs = 999999611666
timeUs = 999999611667
size = 18055
rendered = false
output buffer #3:
timeUs = 999999811666
timeUs = 999999811667
size = 65604
rendered = false
output buffer #4:
@ -1074,7 +1074,7 @@ MediaCodecAdapter (exotest.video.hevc):
size = 72552
rendered = false
output buffer #6:
timeUs = 999999878333
timeUs = 999999878334
size = 23756
rendered = false
output buffer #7:
@ -1086,7 +1086,7 @@ MediaCodecAdapter (exotest.video.hevc):
size = 55804
rendered = true
output buffer #9:
timeUs = 999999978333
timeUs = 999999978334
size = 12955
rendered = false
output buffer #10:

View File

@ -19,7 +19,7 @@ sample:
dataHashCode = -620111888
size = 423
isKeyFrame = true
presentationTimeUs = -16826
presentationTimeUs = -16825
sample:
trackType = audio
dataHashCode = -1530182437

View File

@ -1988,7 +1988,7 @@ public class TransformerEndToEndTest {
// "gapless" audio. The generated file should have encoderDelay = 742 and first
// sample PTS of 0.
assertThat(audioTrack.lastFormat.encoderDelay).isEqualTo(0);
assertThat(audioTrack.getSampleTimeUs(/* index= */ 0)).isEqualTo(-16_826);
assertThat(audioTrack.getSampleTimeUs(/* index= */ 0)).isEqualTo(-16_825);
assertThat(audioTrack.getSampleTimeUs(/* index= */ expectedSampleCount - 1))
.isEqualTo(1_538_911);
} else {