Commit 91b0d55f by ibaker Committed by Ian Baker

Fix calculations that may lose precision compared to their target type

PiperOrigin-RevId: 444861268
parent 5d1af646
......@@ -1243,7 +1243,7 @@ public final class Util {
long time = dateTime.getTimeInMillis();
if (timezoneShift != 0) {
time -= timezoneShift * 60000;
time -= timezoneShift * 60000L;
}
return time;
......
......@@ -412,6 +412,7 @@ public final class AmrExtractor implements Extractor {
* @return The stream bitrate.
*/
private static int getBitrateFromFrameSize(int frameSize, long durationUsPerFrame) {
return (int) ((frameSize * C.BITS_PER_BYTE * C.MICROS_PER_SECOND) / durationUsPerFrame);
return (int)
((frameSize * ((long) C.BITS_PER_BYTE) * C.MICROS_PER_SECOND) / durationUsPerFrame);
}
}
......@@ -1740,9 +1740,9 @@ public class MatroskaExtractor implements Extractor {
checkArgument(timeUs != C.TIME_UNSET);
byte[] timeCodeData;
int hours = (int) (timeUs / (3600 * C.MICROS_PER_SECOND));
timeUs -= (hours * 3600 * C.MICROS_PER_SECOND);
timeUs -= (hours * 3600L * C.MICROS_PER_SECOND);
int minutes = (int) (timeUs / (60 * C.MICROS_PER_SECOND));
timeUs -= (minutes * 60 * C.MICROS_PER_SECOND);
timeUs -= (minutes * 60L * C.MICROS_PER_SECOND);
int seconds = (int) (timeUs / C.MICROS_PER_SECOND);
timeUs -= (seconds * C.MICROS_PER_SECOND);
int lastValue = (int) (timeUs / lastTimecodeValueScalingFactor);
......
......@@ -89,7 +89,7 @@ import com.google.android.exoplayer2.util.Util;
default:
return null;
}
position += segmentSize * scale;
position += segmentSize * ((long) scale);
}
if (inputLength != C.LENGTH_UNSET && inputLength != position) {
Log.w(TAG, "VBRI data size mismatch: " + inputLength + ", " + position);
......
......@@ -363,6 +363,7 @@ public final class AdtsExtractor implements Extractor {
* @return The stream bitrate.
*/
private static int getBitrateFromFrameSize(int frameSize, long durationUsPerFrame) {
return (int) ((frameSize * C.BITS_PER_BYTE * C.MICROS_PER_SECOND) / durationUsPerFrame);
return (int)
((frameSize * ((long) C.BITS_PER_BYTE) * C.MICROS_PER_SECOND) / durationUsPerFrame);
}
}
......@@ -142,7 +142,8 @@ public final class FakeAdaptiveDataSet extends FakeDataSet {
for (int i = 0; i < trackGroup.length; i++) {
String uri = getUri(i);
Format format = trackGroup.getFormat(i);
double avgChunkLength = format.bitrate * chunkDurationUs / (8 * C.MICROS_PER_SECOND);
double avgChunkLength =
format.bitrate * chunkDurationUs / ((double) (8 * C.MICROS_PER_SECOND));
FakeData newData = this.newData(uri);
for (int j = 0; j < fullChunks; j++) {
newData.appendReadData((int) (avgChunkLength * bitrateFactors[j]));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment