Commit fd6b5746 by ibaker Committed by Ian Baker

Fix calculations that may lose precision compared to their target type

PiperOrigin-RevId: 444861268
parent 7af91fc9
......@@ -1245,7 +1245,7 @@ public final class Util {
long time = dateTime.getTimeInMillis();
if (timezoneShift != 0) {
time -= timezoneShift * 60000;
time -= timezoneShift * 60000L;
}
return time;
......
......@@ -414,6 +414,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);
}
}
......@@ -1742,9 +1742,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 androidx.media3.extractor.SeekPoint;
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);
......
......@@ -365,6 +365,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);
}
}
......@@ -144,7 +144,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