Commit 4e8ea009 by christosts Committed by Oliver Woodman

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
parent 85cf5768
...@@ -45,13 +45,14 @@ import org.robolectric.shadows.ShadowLooper; ...@@ -45,13 +45,14 @@ import org.robolectric.shadows.ShadowLooper;
public class AsynchronousMediaCodecBufferEnqueuerTest { public class AsynchronousMediaCodecBufferEnqueuerTest {
@Rule public final MockitoRule mockito = MockitoJUnit.rule(); @Rule public final MockitoRule mockito = MockitoJUnit.rule();
private MediaCodec codec;
private AsynchronousMediaCodecBufferEnqueuer enqueuer; private AsynchronousMediaCodecBufferEnqueuer enqueuer;
private TestHandlerThread handlerThread; private TestHandlerThread handlerThread;
@Mock private ConditionVariable mockConditionVariable; @Mock private ConditionVariable mockConditionVariable;
@Before @Before
public void setUp() throws IOException { public void setUp() throws IOException {
MediaCodec codec = MediaCodec.createByCodecName("h264"); codec = MediaCodec.createByCodecName("h264");
handlerThread = new TestHandlerThread("TestHandlerThread"); handlerThread = new TestHandlerThread("TestHandlerThread");
enqueuer = enqueuer =
new AsynchronousMediaCodecBufferEnqueuer(codec, handlerThread, mockConditionVariable); new AsynchronousMediaCodecBufferEnqueuer(codec, handlerThread, mockConditionVariable);
...@@ -103,16 +104,18 @@ public class AsynchronousMediaCodecBufferEnqueuerTest { ...@@ -103,16 +104,18 @@ public class AsynchronousMediaCodecBufferEnqueuerTest {
ShadowLooper shadowLooper = Shadows.shadowOf(looper); ShadowLooper shadowLooper = Shadows.shadowOf(looper);
for (int cycle = 0; cycle < 100; cycle++) { 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++) { for (int i = 0; i < 10; i++) {
int inputBufferIndex = codec.dequeueInputBuffer(0);
enqueuer.queueInputBuffer( enqueuer.queueInputBuffer(
/* index= */ i, /* index= */ inputBufferIndex,
/* offset= */ 0, /* offset= */ 0,
/* size= */ 0, /* size= */ 0,
/* presentationTimeUs= */ i, /* presentationTimeUs= */ i,
/* flags= */ 0); /* flags= */ 0);
} }
// Execute all messages. // Execute all messages, queues input buffers back to MediaCodec.
shadowLooper.idle(); shadowLooper.idle();
} }
...@@ -162,16 +165,18 @@ public class AsynchronousMediaCodecBufferEnqueuerTest { ...@@ -162,16 +165,18 @@ public class AsynchronousMediaCodecBufferEnqueuerTest {
ShadowLooper shadowLooper = Shadows.shadowOf(looper); ShadowLooper shadowLooper = Shadows.shadowOf(looper);
for (int cycle = 0; cycle < 100; cycle++) { 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++) { for (int i = 0; i < 10; i++) {
enqueuer.queueSecureInputBuffer( enqueuer.queueSecureInputBuffer(
/* index= */ i, /* index= */ inputBufferIndex,
/* offset= */ 0, /* offset= */ 0,
/* info= */ info, /* info= */ info,
/* presentationTimeUs= */ i, /* presentationTimeUs= */ i,
/* flags= */ 0); /* flags= */ 0);
} }
// Execute all messages. // Execute all messages, queues input buffers back to MediaCodec.
shadowLooper.idle(); shadowLooper.idle();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment