From 4e8ea009b8d6de7f9ae3ff369656632beb3ac450 Mon Sep 17 00:00:00 2001 From: christosts Date: Thu, 7 May 2020 11:13:23 +0100 Subject: [PATCH] Fix AsynchronousMediaCodecBufferEnqueuerTest Fixes AsynchronousMediaCodecBufferEnqueuerTest broken tests by enqueueing input buffers that have previously been dequeued from the MediaCodec. The test assumes that the shadow MediaCodec implementation can dequeue at least 10 input buffers before queueing them back. Although fragile, it seems to work with the current robolectric shadow MediaCodec. This is at the moment preferred compared to making the test more complicated. PiperOrigin-RevId: 310325096 --- ...nchronousMediaCodecBufferEnqueuerTest.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecBufferEnqueuerTest.java b/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecBufferEnqueuerTest.java index c7020b4169..38fa04adbc 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecBufferEnqueuerTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecBufferEnqueuerTest.java @@ -45,13 +45,14 @@ import org.robolectric.shadows.ShadowLooper; public class AsynchronousMediaCodecBufferEnqueuerTest { @Rule public final MockitoRule mockito = MockitoJUnit.rule(); + private MediaCodec codec; private AsynchronousMediaCodecBufferEnqueuer enqueuer; private TestHandlerThread handlerThread; @Mock private ConditionVariable mockConditionVariable; @Before public void setUp() throws IOException { - MediaCodec codec = MediaCodec.createByCodecName("h264"); + codec = MediaCodec.createByCodecName("h264"); handlerThread = new TestHandlerThread("TestHandlerThread"); enqueuer = new AsynchronousMediaCodecBufferEnqueuer(codec, handlerThread, mockConditionVariable); @@ -103,16 +104,18 @@ public class AsynchronousMediaCodecBufferEnqueuerTest { ShadowLooper shadowLooper = Shadows.shadowOf(looper); for (int cycle = 0; cycle < 100; cycle++) { - // Enqueue 10 messages to looper. + // This test assumes that the shadow MediaCodec implementation can dequeue at least + // 10 input buffers before queueing them back. for (int i = 0; i < 10; i++) { + int inputBufferIndex = codec.dequeueInputBuffer(0); enqueuer.queueInputBuffer( - /* index= */ i, + /* index= */ inputBufferIndex, /* offset= */ 0, /* size= */ 0, /* presentationTimeUs= */ i, /* flags= */ 0); } - // Execute all messages. + // Execute all messages, queues input buffers back to MediaCodec. shadowLooper.idle(); } @@ -162,16 +165,18 @@ public class AsynchronousMediaCodecBufferEnqueuerTest { ShadowLooper shadowLooper = Shadows.shadowOf(looper); for (int cycle = 0; cycle < 100; cycle++) { - // Enqueue 10 messages to looper. + // This test assumes that the shadow MediaCodec implementation can dequeue at least + // 10 input buffers before queueing them back. + int inputBufferIndex = codec.dequeueInputBuffer(0); for (int i = 0; i < 10; i++) { enqueuer.queueSecureInputBuffer( - /* index= */ i, + /* index= */ inputBufferIndex, /* offset= */ 0, /* info= */ info, /* presentationTimeUs= */ i, /* flags= */ 0); } - // Execute all messages. + // Execute all messages, queues input buffers back to MediaCodec. shadowLooper.idle(); }