mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00: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
(cherry picked from commit ada4dc982f)
This commit is contained in:
parent
b433bf928b
commit
3a5e367b93
1 changed files with 12 additions and 7 deletions
|
|
@ -261,6 +261,11 @@ public class MediaCodecVideoRendererTest {
|
|||
/* startPositionUs= */ 0,
|
||||
/* offsetUs= */ 0,
|
||||
/* 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.render(0, SystemClock.elapsedRealtime() * 1000);
|
||||
|
|
@ -276,18 +281,18 @@ public class MediaCodecVideoRendererTest {
|
|||
END_OF_STREAM_ITEM));
|
||||
fakeSampleStream.writeData(/* startPositionUs= */ 0);
|
||||
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()) {
|
||||
mediaCodecVideoRenderer.render(posUs, SystemClock.elapsedRealtime() * 1000);
|
||||
posUs += 10_000;
|
||||
}
|
||||
shadowOf(testMainLooper).idle();
|
||||
|
||||
ArgumentCaptor<DecoderCounters> argumentDecoderCounters =
|
||||
ArgumentCaptor.forClass(DecoderCounters.class);
|
||||
verify(eventListener).onVideoEnabled(argumentDecoderCounters.capture());
|
||||
assertThat(argumentDecoderCounters.getValue().renderedOutputBufferCount).isEqualTo(3);
|
||||
assertThat(argumentDecoderCounters.getValue().droppedInputBufferCount).isEqualTo(1);
|
||||
assertThat(argumentDecoderCounters.getValue().droppedToKeyframeCount).isEqualTo(1);
|
||||
assertThat(decoderCounters.renderedOutputBufferCount).isEqualTo(3);
|
||||
assertThat(decoderCounters.droppedInputBufferCount).isEqualTo(1);
|
||||
assertThat(decoderCounters.droppedToKeyframeCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in a new issue