mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Make conversions to durationsUs consistent in SpeedProviders
PiperOrigin-RevId: 687334787
This commit is contained in:
parent
b64bf88272
commit
0108fb938e
3 changed files with 6 additions and 4 deletions
|
|
@ -15,8 +15,8 @@
|
|||
*/
|
||||
package androidx.media3.common.util;
|
||||
|
||||
import static java.lang.Math.floor;
|
||||
import static java.lang.Math.min;
|
||||
import static java.lang.Math.round;
|
||||
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.audio.SpeedProvider;
|
||||
|
|
@ -45,6 +45,7 @@ public class SpeedProviderUtil {
|
|||
/ (double) speedProvider.getSpeed(speedChangeTimeUs);
|
||||
speedChangeTimeUs = nextSpeedChangeTimeUs;
|
||||
}
|
||||
return round(outputDurationUs);
|
||||
// Use floor to be consistent with Util#scaleLargeTimestamp().
|
||||
return (long) floor(outputDurationUs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,6 @@ public class SpeedProviderUtilTest {
|
|||
/* startTimesUs= */ new long[] {0, 113}, /* speeds= */ new float[] {2, 1});
|
||||
|
||||
assertThat(getDurationAfterSpeedProviderApplied(speedProvider, /* durationUs= */ 113))
|
||||
.isEqualTo(57);
|
||||
.isEqualTo(56);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
package androidx.media3.test.utils;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static androidx.media3.common.util.Util.sampleCountToDurationUs;
|
||||
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.audio.AudioProcessor.AudioFormat;
|
||||
|
|
@ -56,7 +57,7 @@ public final class TestSpeedProvider implements SpeedProvider {
|
|||
long[] startTimesUs = new long[frameCounts.length];
|
||||
int totalFrameCount = 0;
|
||||
for (int i = 0; i < frameCounts.length; i++) {
|
||||
startTimesUs[i] = totalFrameCount * C.MICROS_PER_SECOND / audioFormat.sampleRate;
|
||||
startTimesUs[i] = sampleCountToDurationUs(totalFrameCount, audioFormat.sampleRate);
|
||||
totalFrameCount += frameCounts[i];
|
||||
}
|
||||
return new TestSpeedProvider(startTimesUs, speeds);
|
||||
|
|
|
|||
Loading…
Reference in a new issue