mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Fix flakiness in MediaCodecVideoRendererTest
The test is flaky because the decoding process in the renderer depends on some timing from MediaCodec beyond our control and the new keyframe added in the test is sometimes 'dropped' when it arrives too late. We can fix this by controlling the test progress a bit more tightly: first rendering with the same current time until the key frame is processed and then start increasing the time until we've reached the end. #cherrypick PiperOrigin-RevId: 646064352
This commit is contained in:
parent
e591c37b1e
commit
ada4dc982f
@ -261,6 +261,11 @@ public class MediaCodecVideoRendererTest {
|
|||||||
/* startPositionUs= */ 0,
|
/* startPositionUs= */ 0,
|
||||||
/* offsetUs= */ 0,
|
/* offsetUs= */ 0,
|
||||||
/* mediaPeriodId= */ new MediaSource.MediaPeriodId(new Object()));
|
/* mediaPeriodId= */ new MediaSource.MediaPeriodId(new Object()));
|
||||||
|
shadowOf(testMainLooper).idle();
|
||||||
|
ArgumentCaptor<DecoderCounters> argumentDecoderCounters =
|
||||||
|
ArgumentCaptor.forClass(DecoderCounters.class);
|
||||||
|
verify(eventListener).onVideoEnabled(argumentDecoderCounters.capture());
|
||||||
|
DecoderCounters decoderCounters = argumentDecoderCounters.getValue();
|
||||||
|
|
||||||
mediaCodecVideoRenderer.start();
|
mediaCodecVideoRenderer.start();
|
||||||
mediaCodecVideoRenderer.render(0, SystemClock.elapsedRealtime() * 1000);
|
mediaCodecVideoRenderer.render(0, SystemClock.elapsedRealtime() * 1000);
|
||||||
@ -276,18 +281,18 @@ public class MediaCodecVideoRendererTest {
|
|||||||
END_OF_STREAM_ITEM));
|
END_OF_STREAM_ITEM));
|
||||||
fakeSampleStream.writeData(/* startPositionUs= */ 0);
|
fakeSampleStream.writeData(/* startPositionUs= */ 0);
|
||||||
mediaCodecVideoRenderer.setCurrentStreamFinal();
|
mediaCodecVideoRenderer.setCurrentStreamFinal();
|
||||||
|
// Render until the new keyframe has been processed and then increase time to reach the end.
|
||||||
|
while (decoderCounters.renderedOutputBufferCount < 2) {
|
||||||
|
mediaCodecVideoRenderer.render(posUs, SystemClock.elapsedRealtime() * 1000);
|
||||||
|
}
|
||||||
while (!mediaCodecVideoRenderer.isEnded()) {
|
while (!mediaCodecVideoRenderer.isEnded()) {
|
||||||
mediaCodecVideoRenderer.render(posUs, SystemClock.elapsedRealtime() * 1000);
|
mediaCodecVideoRenderer.render(posUs, SystemClock.elapsedRealtime() * 1000);
|
||||||
posUs += 10_000;
|
posUs += 10_000;
|
||||||
}
|
}
|
||||||
shadowOf(testMainLooper).idle();
|
|
||||||
|
|
||||||
ArgumentCaptor<DecoderCounters> argumentDecoderCounters =
|
assertThat(decoderCounters.renderedOutputBufferCount).isEqualTo(3);
|
||||||
ArgumentCaptor.forClass(DecoderCounters.class);
|
assertThat(decoderCounters.droppedInputBufferCount).isEqualTo(1);
|
||||||
verify(eventListener).onVideoEnabled(argumentDecoderCounters.capture());
|
assertThat(decoderCounters.droppedToKeyframeCount).isEqualTo(1);
|
||||||
assertThat(argumentDecoderCounters.getValue().renderedOutputBufferCount).isEqualTo(3);
|
|
||||||
assertThat(argumentDecoderCounters.getValue().droppedInputBufferCount).isEqualTo(1);
|
|
||||||
assertThat(argumentDecoderCounters.getValue().droppedToKeyframeCount).isEqualTo(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user