mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Make conversions to durationsUs consistent in SpeedProviders
PiperOrigin-RevId: 687334787
This commit is contained in:
parent
b64bf88272
commit
0108fb938e
@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package androidx.media3.common.util;
|
package androidx.media3.common.util;
|
||||||
|
|
||||||
|
import static java.lang.Math.floor;
|
||||||
import static java.lang.Math.min;
|
import static java.lang.Math.min;
|
||||||
import static java.lang.Math.round;
|
|
||||||
|
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.audio.SpeedProvider;
|
import androidx.media3.common.audio.SpeedProvider;
|
||||||
@ -45,6 +45,7 @@ public class SpeedProviderUtil {
|
|||||||
/ (double) speedProvider.getSpeed(speedChangeTimeUs);
|
/ (double) speedProvider.getSpeed(speedChangeTimeUs);
|
||||||
speedChangeTimeUs = nextSpeedChangeTimeUs;
|
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});
|
/* startTimesUs= */ new long[] {0, 113}, /* speeds= */ new float[] {2, 1});
|
||||||
|
|
||||||
assertThat(getDurationAfterSpeedProviderApplied(speedProvider, /* durationUs= */ 113))
|
assertThat(getDurationAfterSpeedProviderApplied(speedProvider, /* durationUs= */ 113))
|
||||||
.isEqualTo(57);
|
.isEqualTo(56);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package androidx.media3.test.utils;
|
package androidx.media3.test.utils;
|
||||||
|
|
||||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
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.C;
|
||||||
import androidx.media3.common.audio.AudioProcessor.AudioFormat;
|
import androidx.media3.common.audio.AudioProcessor.AudioFormat;
|
||||||
@ -56,7 +57,7 @@ public final class TestSpeedProvider implements SpeedProvider {
|
|||||||
long[] startTimesUs = new long[frameCounts.length];
|
long[] startTimesUs = new long[frameCounts.length];
|
||||||
int totalFrameCount = 0;
|
int totalFrameCount = 0;
|
||||||
for (int i = 0; i < frameCounts.length; i++) {
|
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];
|
totalFrameCount += frameCounts[i];
|
||||||
}
|
}
|
||||||
return new TestSpeedProvider(startTimesUs, speeds);
|
return new TestSpeedProvider(startTimesUs, speeds);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user