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:
parent
d5baa4ce59
commit
2c46cea088
@ -1600,7 +1600,7 @@ public final class Util {
|
|||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public static long sampleCountToDurationUs(long sampleCount, int sampleRate) {
|
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
|
@UnstableApi
|
||||||
public static long durationUsToSampleCount(long durationUs, int sampleRate) {
|
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.
|
* Scales a large timestamp.
|
||||||
*
|
*
|
||||||
* <p>Equivalent to {@link #scaleLargeValue(long, long, long, RoundingMode)} with {@link
|
* <p>Equivalent to {@link #scaleLargeValue(long, long, long, RoundingMode)} with {@link
|
||||||
* RoundingMode#FLOOR}.
|
* RoundingMode#DOWN}.
|
||||||
*
|
*
|
||||||
* @param timestamp The timestamp to scale.
|
* @param timestamp The timestamp to scale.
|
||||||
* @param multiplier The multiplier.
|
* @param multiplier The multiplier.
|
||||||
@ -1911,7 +1911,7 @@ public final class Util {
|
|||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public static long scaleLargeTimestamp(long timestamp, long multiplier, long divisor) {
|
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
|
@UnstableApi
|
||||||
public static long[] scaleLargeTimestamps(List<Long> timestamps, long multiplier, long divisor) {
|
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
|
@UnstableApi
|
||||||
public static void scaleLargeTimestampsInPlace(long[] timestamps, long multiplier, long divisor) {
|
public static void scaleLargeTimestampsInPlace(long[] timestamps, long multiplier, long divisor) {
|
||||||
scaleLargeValuesInPlace(timestamps, multiplier, divisor, RoundingMode.FLOOR);
|
scaleLargeValuesInPlace(timestamps, multiplier, divisor, RoundingMode.DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,15 +33,15 @@ track 0:
|
|||||||
flags = 1
|
flags = 1
|
||||||
data = length 78829, hash 9265686F
|
data = length 78829, hash 9265686F
|
||||||
sample 1:
|
sample 1:
|
||||||
time = -321667
|
time = -321666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 32262, hash 1AD10F61
|
data = length 32262, hash 1AD10F61
|
||||||
sample 2:
|
sample 2:
|
||||||
time = -388334
|
time = -388333
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 18055, hash C6BED1E3
|
data = length 18055, hash C6BED1E3
|
||||||
sample 3:
|
sample 3:
|
||||||
time = -188334
|
time = -188333
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 65604, hash AA006B06
|
data = length 65604, hash AA006B06
|
||||||
sample 4:
|
sample 4:
|
||||||
@ -53,7 +53,7 @@ track 0:
|
|||||||
flags = 0
|
flags = 0
|
||||||
data = length 72552, hash 9535951C
|
data = length 72552, hash 9535951C
|
||||||
sample 6:
|
sample 6:
|
||||||
time = -121667
|
time = -121666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 23756, hash 4074D5AE
|
data = length 23756, hash 4074D5AE
|
||||||
sample 7:
|
sample 7:
|
||||||
@ -65,7 +65,7 @@ track 0:
|
|||||||
flags = 0
|
flags = 0
|
||||||
data = length 55804, hash D559D074
|
data = length 55804, hash D559D074
|
||||||
sample 9:
|
sample 9:
|
||||||
time = -21667
|
time = -21666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 12955, hash 35EE397F
|
data = length 12955, hash 35EE397F
|
||||||
sample 10:
|
sample 10:
|
||||||
|
@ -33,15 +33,15 @@ track 0:
|
|||||||
flags = 1
|
flags = 1
|
||||||
data = length 78829, hash 9265686F
|
data = length 78829, hash 9265686F
|
||||||
sample 1:
|
sample 1:
|
||||||
time = -321667
|
time = -321666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 32262, hash 1AD10F61
|
data = length 32262, hash 1AD10F61
|
||||||
sample 2:
|
sample 2:
|
||||||
time = -388334
|
time = -388333
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 18055, hash C6BED1E3
|
data = length 18055, hash C6BED1E3
|
||||||
sample 3:
|
sample 3:
|
||||||
time = -188334
|
time = -188333
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 65604, hash AA006B06
|
data = length 65604, hash AA006B06
|
||||||
sample 4:
|
sample 4:
|
||||||
@ -53,7 +53,7 @@ track 0:
|
|||||||
flags = 0
|
flags = 0
|
||||||
data = length 72552, hash 9535951C
|
data = length 72552, hash 9535951C
|
||||||
sample 6:
|
sample 6:
|
||||||
time = -121667
|
time = -121666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 23756, hash 4074D5AE
|
data = length 23756, hash 4074D5AE
|
||||||
sample 7:
|
sample 7:
|
||||||
@ -65,7 +65,7 @@ track 0:
|
|||||||
flags = 0
|
flags = 0
|
||||||
data = length 55804, hash D559D074
|
data = length 55804, hash D559D074
|
||||||
sample 9:
|
sample 9:
|
||||||
time = -21667
|
time = -21666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 12955, hash 35EE397F
|
data = length 12955, hash 35EE397F
|
||||||
sample 10:
|
sample 10:
|
||||||
|
@ -33,15 +33,15 @@ track 0:
|
|||||||
flags = 1
|
flags = 1
|
||||||
data = length 78829, hash 9265686F
|
data = length 78829, hash 9265686F
|
||||||
sample 1:
|
sample 1:
|
||||||
time = -321667
|
time = -321666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 32262, hash 1AD10F61
|
data = length 32262, hash 1AD10F61
|
||||||
sample 2:
|
sample 2:
|
||||||
time = -388334
|
time = -388333
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 18055, hash C6BED1E3
|
data = length 18055, hash C6BED1E3
|
||||||
sample 3:
|
sample 3:
|
||||||
time = -188334
|
time = -188333
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 65604, hash AA006B06
|
data = length 65604, hash AA006B06
|
||||||
sample 4:
|
sample 4:
|
||||||
@ -53,7 +53,7 @@ track 0:
|
|||||||
flags = 0
|
flags = 0
|
||||||
data = length 72552, hash 9535951C
|
data = length 72552, hash 9535951C
|
||||||
sample 6:
|
sample 6:
|
||||||
time = -121667
|
time = -121666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 23756, hash 4074D5AE
|
data = length 23756, hash 4074D5AE
|
||||||
sample 7:
|
sample 7:
|
||||||
@ -65,7 +65,7 @@ track 0:
|
|||||||
flags = 0
|
flags = 0
|
||||||
data = length 55804, hash D559D074
|
data = length 55804, hash D559D074
|
||||||
sample 9:
|
sample 9:
|
||||||
time = -21667
|
time = -21666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 12955, hash 35EE397F
|
data = length 12955, hash 35EE397F
|
||||||
sample 10:
|
sample 10:
|
||||||
|
@ -33,15 +33,15 @@ track 0:
|
|||||||
flags = 1
|
flags = 1
|
||||||
data = length 78829, hash 9265686F
|
data = length 78829, hash 9265686F
|
||||||
sample 1:
|
sample 1:
|
||||||
time = -321667
|
time = -321666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 32262, hash 1AD10F61
|
data = length 32262, hash 1AD10F61
|
||||||
sample 2:
|
sample 2:
|
||||||
time = -388334
|
time = -388333
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 18055, hash C6BED1E3
|
data = length 18055, hash C6BED1E3
|
||||||
sample 3:
|
sample 3:
|
||||||
time = -188334
|
time = -188333
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 65604, hash AA006B06
|
data = length 65604, hash AA006B06
|
||||||
sample 4:
|
sample 4:
|
||||||
@ -53,7 +53,7 @@ track 0:
|
|||||||
flags = 0
|
flags = 0
|
||||||
data = length 72552, hash 9535951C
|
data = length 72552, hash 9535951C
|
||||||
sample 6:
|
sample 6:
|
||||||
time = -121667
|
time = -121666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 23756, hash 4074D5AE
|
data = length 23756, hash 4074D5AE
|
||||||
sample 7:
|
sample 7:
|
||||||
@ -65,7 +65,7 @@ track 0:
|
|||||||
flags = 0
|
flags = 0
|
||||||
data = length 55804, hash D559D074
|
data = length 55804, hash D559D074
|
||||||
sample 9:
|
sample 9:
|
||||||
time = -21667
|
time = -21666
|
||||||
flags = 0
|
flags = 0
|
||||||
data = length 12955, hash 35EE397F
|
data = length 12955, hash 35EE397F
|
||||||
sample 10:
|
sample 10:
|
||||||
|
@ -798,13 +798,13 @@ MediaCodecAdapter (exotest.video.hevc):
|
|||||||
timeUs = 999999545000
|
timeUs = 999999545000
|
||||||
contents = length 78829, hash 9265686F
|
contents = length 78829, hash 9265686F
|
||||||
input buffer #1:
|
input buffer #1:
|
||||||
timeUs = 999999678333
|
timeUs = 999999678334
|
||||||
contents = length 32262, hash 1AD10F61
|
contents = length 32262, hash 1AD10F61
|
||||||
input buffer #2:
|
input buffer #2:
|
||||||
timeUs = 999999611666
|
timeUs = 999999611667
|
||||||
contents = length 18055, hash C6BED1E3
|
contents = length 18055, hash C6BED1E3
|
||||||
input buffer #3:
|
input buffer #3:
|
||||||
timeUs = 999999811666
|
timeUs = 999999811667
|
||||||
contents = length 65604, hash AA006B06
|
contents = length 65604, hash AA006B06
|
||||||
input buffer #4:
|
input buffer #4:
|
||||||
timeUs = 999999745000
|
timeUs = 999999745000
|
||||||
@ -813,7 +813,7 @@ MediaCodecAdapter (exotest.video.hevc):
|
|||||||
timeUs = 999999945000
|
timeUs = 999999945000
|
||||||
contents = length 72552, hash 9535951C
|
contents = length 72552, hash 9535951C
|
||||||
input buffer #6:
|
input buffer #6:
|
||||||
timeUs = 999999878333
|
timeUs = 999999878334
|
||||||
contents = length 23756, hash 4074D5AE
|
contents = length 23756, hash 4074D5AE
|
||||||
input buffer #7:
|
input buffer #7:
|
||||||
timeUs = 1000000078333
|
timeUs = 1000000078333
|
||||||
@ -822,7 +822,7 @@ MediaCodecAdapter (exotest.video.hevc):
|
|||||||
timeUs = 1000000011666
|
timeUs = 1000000011666
|
||||||
contents = length 55804, hash D559D074
|
contents = length 55804, hash D559D074
|
||||||
input buffer #9:
|
input buffer #9:
|
||||||
timeUs = 999999978333
|
timeUs = 999999978334
|
||||||
contents = length 12955, hash 35EE397F
|
contents = length 12955, hash 35EE397F
|
||||||
input buffer #10:
|
input buffer #10:
|
||||||
timeUs = 1000000045000
|
timeUs = 1000000045000
|
||||||
@ -1054,15 +1054,15 @@ MediaCodecAdapter (exotest.video.hevc):
|
|||||||
size = 78829
|
size = 78829
|
||||||
rendered = false
|
rendered = false
|
||||||
output buffer #1:
|
output buffer #1:
|
||||||
timeUs = 999999678333
|
timeUs = 999999678334
|
||||||
size = 32262
|
size = 32262
|
||||||
rendered = false
|
rendered = false
|
||||||
output buffer #2:
|
output buffer #2:
|
||||||
timeUs = 999999611666
|
timeUs = 999999611667
|
||||||
size = 18055
|
size = 18055
|
||||||
rendered = false
|
rendered = false
|
||||||
output buffer #3:
|
output buffer #3:
|
||||||
timeUs = 999999811666
|
timeUs = 999999811667
|
||||||
size = 65604
|
size = 65604
|
||||||
rendered = false
|
rendered = false
|
||||||
output buffer #4:
|
output buffer #4:
|
||||||
@ -1074,7 +1074,7 @@ MediaCodecAdapter (exotest.video.hevc):
|
|||||||
size = 72552
|
size = 72552
|
||||||
rendered = false
|
rendered = false
|
||||||
output buffer #6:
|
output buffer #6:
|
||||||
timeUs = 999999878333
|
timeUs = 999999878334
|
||||||
size = 23756
|
size = 23756
|
||||||
rendered = false
|
rendered = false
|
||||||
output buffer #7:
|
output buffer #7:
|
||||||
@ -1086,7 +1086,7 @@ MediaCodecAdapter (exotest.video.hevc):
|
|||||||
size = 55804
|
size = 55804
|
||||||
rendered = true
|
rendered = true
|
||||||
output buffer #9:
|
output buffer #9:
|
||||||
timeUs = 999999978333
|
timeUs = 999999978334
|
||||||
size = 12955
|
size = 12955
|
||||||
rendered = false
|
rendered = false
|
||||||
output buffer #10:
|
output buffer #10:
|
||||||
|
@ -19,7 +19,7 @@ sample:
|
|||||||
dataHashCode = -620111888
|
dataHashCode = -620111888
|
||||||
size = 423
|
size = 423
|
||||||
isKeyFrame = true
|
isKeyFrame = true
|
||||||
presentationTimeUs = -16826
|
presentationTimeUs = -16825
|
||||||
sample:
|
sample:
|
||||||
trackType = audio
|
trackType = audio
|
||||||
dataHashCode = -1530182437
|
dataHashCode = -1530182437
|
||||||
|
@ -1988,7 +1988,7 @@ public class TransformerEndToEndTest {
|
|||||||
// "gapless" audio. The generated file should have encoderDelay = 742 and first
|
// "gapless" audio. The generated file should have encoderDelay = 742 and first
|
||||||
// sample PTS of 0.
|
// sample PTS of 0.
|
||||||
assertThat(audioTrack.lastFormat.encoderDelay).isEqualTo(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))
|
assertThat(audioTrack.getSampleTimeUs(/* index= */ expectedSampleCount - 1))
|
||||||
.isEqualTo(1_538_911);
|
.isEqualTo(1_538_911);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user