From 9c5ea4f1ba724704bb9c8f261b210fc1cf432b40 Mon Sep 17 00:00:00 2001 From: samrobinson Date: Wed, 28 Aug 2024 05:15:23 -0700 Subject: [PATCH] Assert silent bytes are 0 in AudioGraphInputTest PiperOrigin-RevId: 668403467 --- .../transformer/AudioGraphInputTest.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/libraries/transformer/src/test/java/androidx/media3/transformer/AudioGraphInputTest.java b/libraries/transformer/src/test/java/androidx/media3/transformer/AudioGraphInputTest.java index 3742f90ab5..7004d56db8 100644 --- a/libraries/transformer/src/test/java/androidx/media3/transformer/AudioGraphInputTest.java +++ b/libraries/transformer/src/test/java/androidx/media3/transformer/AudioGraphInputTest.java @@ -410,8 +410,7 @@ public class AudioGraphInputTest { List outputBytes = drainAudioGraphInputUntilEnded(audioGraphInput); long expectedSampleCount = Util.durationUsToSampleCount(1_000_000, STEREO_44100.sampleRate); // Silent audio generator rounds up duration. - assertThat(outputBytes.size()) - .isEqualTo((expectedSampleCount + 1) * STEREO_44100.bytesPerFrame); + assertThat(outputBytes).hasSize((int) ((expectedSampleCount + 1) * STEREO_44100.bytesPerFrame)); assertThat(outputBytes.subList(0, inputData.length)) .containsExactlyElementsIn(Bytes.asList(inputData)) .inOrder(); @@ -452,8 +451,7 @@ public class AudioGraphInputTest { List outputBytes = drainAudioGraphInputUntilEnded(audioGraphInput); long expectedSampleCount = Util.durationUsToSampleCount(500_000, STEREO_44100.sampleRate); // Silent audio generator rounds up duration. - assertThat(outputBytes.size()) - .isEqualTo((expectedSampleCount + 1) * STEREO_44100.bytesPerFrame); + assertThat(outputBytes).hasSize((int) ((expectedSampleCount + 1) * STEREO_44100.bytesPerFrame)); // Sonic takes a while to zero-out the input. assertThat(min(outputBytes.subList(inputData.length * 6 / 10, outputBytes.size()))) .isEqualTo(0); @@ -462,8 +460,7 @@ public class AudioGraphInputTest { } @Test - public void getOutput_withSilentMediaItemChange_outputsCorrectAmountOfSilentBytes() - throws Exception { + public void getOutput_withSilentMediaItemChange_outputsCorrectSilentBytes() throws Exception { AudioGraphInput audioGraphInput = new AudioGraphInput( /* requestedOutputAudioFormat= */ AudioFormat.NOT_SET, @@ -476,13 +473,15 @@ public class AudioGraphInputTest { /* decodedFormat= */ null, /* isLast= */ true); - int bytesOutput = drainAudioGraphInputUntilEnded(audioGraphInput).size(); + List bytesOutput = drainAudioGraphInputUntilEnded(audioGraphInput); long expectedSampleCount = Util.durationUsToSampleCount(1_000_000, STEREO_44100.sampleRate); - assertThat(bytesOutput).isEqualTo(expectedSampleCount * STEREO_44100.bytesPerFrame); + assertThat(bytesOutput).hasSize((int) (expectedSampleCount * STEREO_44100.bytesPerFrame)); + assertThat(min(bytesOutput)).isEqualTo(0); + assertThat(max(bytesOutput)).isEqualTo(0); } @Test - public void getOutput_withThreeSilentMediaItemChanges_outputsCorrectAmountOfSilentBytes() + public void getOutput_withThreeSilentMediaItemChanges_outputsCorrectSilentBytes() throws Exception { AudioGraphInput audioGraphInput = new AudioGraphInput( @@ -506,13 +505,15 @@ public class AudioGraphInputTest { /* decodedFormat= */ null, /* isLast= */ true); - int bytesOutput = drainAudioGraphInputUntilEnded(audioGraphInput).size(); + List bytesOutput = drainAudioGraphInputUntilEnded(audioGraphInput); long expectedSampleCount = Util.durationUsToSampleCount(1_000_000, STEREO_44100.sampleRate); - assertThat(bytesOutput).isEqualTo(expectedSampleCount * STEREO_44100.bytesPerFrame); + assertThat(bytesOutput).hasSize((int) (expectedSampleCount * STEREO_44100.bytesPerFrame)); + assertThat(min(bytesOutput)).isEqualTo(0); + assertThat(max(bytesOutput)).isEqualTo(0); } @Test - public void getOutput_withSilentMediaItemAndEffectsChange_outputsCorrectAmountOfSilentBytes() + public void getOutput_withSilentMediaItemAndEffectsChange_outputsCorrectSilentBytes() throws Exception { AudioGraphInput audioGraphInput = new AudioGraphInput( @@ -526,9 +527,11 @@ public class AudioGraphInputTest { /* decodedFormat= */ null, /* isLast= */ true); - int bytesOutput = drainAudioGraphInputUntilEnded(audioGraphInput).size(); + List bytesOutput = drainAudioGraphInputUntilEnded(audioGraphInput); long expectedSampleCount = Util.durationUsToSampleCount(500_000, STEREO_44100.sampleRate); - assertThat(bytesOutput).isEqualTo(expectedSampleCount * STEREO_44100.bytesPerFrame); + assertThat(bytesOutput).hasSize((int) (expectedSampleCount * STEREO_44100.bytesPerFrame)); + assertThat(min(bytesOutput)).isEqualTo(0); + assertThat(max(bytesOutput)).isEqualTo(0); } @Test