MediaCodecTest: don't run R-specific tests on Q
Bug: 150903948
Test: run
Change-Id: If0b194294f0f5202a533d1f4594b17fc9cf1082c
diff --git a/tests/tests/media/src/android/media/cts/MediaCodecTest.java b/tests/tests/media/src/android/media/cts/MediaCodecTest.java
index a20e39f..d41716e 100644
--- a/tests/tests/media/src/android/media/cts/MediaCodecTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaCodecTest.java
@@ -41,6 +41,7 @@
import android.media.MediaFormat;
import android.media.cts.R;
import android.opengl.GLES20;
+import android.os.Build;
import android.os.ConditionVariable;
import android.os.Handler;
import android.os.HandlerThread;
@@ -55,6 +56,7 @@
import androidx.test.filters.MediumTest;
import androidx.test.filters.SmallTest;
+import com.android.compatibility.common.util.ApiLevelUtil;
import com.android.compatibility.common.util.MediaUtils;
import java.io.BufferedInputStream;
@@ -118,6 +120,7 @@
// Time out decoding, as we have no way to query whether the decoder will produce output.
private static final int DECODING_TIMEOUT_MS = 10000;
+ private static boolean mIsAtLeastR = ApiLevelUtil.isAtLeast(Build.VERSION_CODES.R);
/**
* Tests:
* <br> Exceptions for MediaCodec factory methods
@@ -315,25 +318,27 @@
fail("configure should not return MediaCodec.CodecException on wrong state");
} catch (IllegalStateException e) { // expected
}
- try {
- codec.getQueueRequest(0);
- fail("getQueueRequest should throw IllegalStateException when not configured with " +
- "CONFIGURE_FLAG_USE_BLOCK_MODEL");
- } catch (MediaCodec.CodecException e) {
- logMediaCodecException(e);
- fail("getQueueRequest should not return " +
- "MediaCodec.CodecException on wrong configuration");
- } catch (IllegalStateException e) { // expected
- }
- try {
- codec.getOutputFrame(0);
- fail("getOutputFrame should throw IllegalStateException when not configured with " +
- "CONFIGURE_FLAG_USE_BLOCK_MODEL");
- } catch (MediaCodec.CodecException e) {
- logMediaCodecException(e);
- fail("getOutputFrame should not return MediaCodec.CodecException on wrong " +
- "configuration");
- } catch (IllegalStateException e) { // expected
+ if (mIsAtLeastR) {
+ try {
+ codec.getQueueRequest(0);
+ fail("getQueueRequest should throw IllegalStateException when not configured with " +
+ "CONFIGURE_FLAG_USE_BLOCK_MODEL");
+ } catch (MediaCodec.CodecException e) {
+ logMediaCodecException(e);
+ fail("getQueueRequest should not return " +
+ "MediaCodec.CodecException on wrong configuration");
+ } catch (IllegalStateException e) { // expected
+ }
+ try {
+ codec.getOutputFrame(0);
+ fail("getOutputFrame should throw IllegalStateException when not configured with " +
+ "CONFIGURE_FLAG_USE_BLOCK_MODEL");
+ } catch (MediaCodec.CodecException e) {
+ logMediaCodecException(e);
+ fail("getOutputFrame should not return MediaCodec.CodecException on wrong " +
+ "configuration");
+ } catch (IllegalStateException e) { // expected
+ }
}
// two flushes should be fine.
@@ -368,100 +373,102 @@
} catch (IllegalStateException e) { // expected
}
- // recreate
- codec = createCodecByType(format.getString(MediaFormat.KEY_MIME), isEncoder);
+ if (mIsAtLeastR) {
+ // recreate
+ codec = createCodecByType(format.getString(MediaFormat.KEY_MIME), isEncoder);
- // configure improperly
- try {
+ // configure improperly
+ try {
+ codec.configure(format, null /* surface */, null /* crypto */,
+ MediaCodec.CONFIGURE_FLAG_USE_BLOCK_MODEL |
+ (isEncoder ? MediaCodec.CONFIGURE_FLAG_ENCODE : 0) /* flags */);
+ fail("configure with detached buffer mode should be done after setCallback");
+ } catch (MediaCodec.CodecException e) {
+ logMediaCodecException(e);
+ fail("configure should not return IllegalStateException when improperly configured");
+ } catch (IllegalStateException e) { // expected
+ }
+
+ final LinkedBlockingQueue<Integer> inputQueue = new LinkedBlockingQueue<>();
+ codec.setCallback(new MediaCodec.Callback() {
+ @Override
+ public void onInputBufferAvailable(MediaCodec codec, int index) {
+ inputQueue.offer(index);
+ }
+ @Override
+ public void onOutputBufferAvailable(
+ MediaCodec codec, int index, MediaCodec.BufferInfo info) { }
+ @Override
+ public void onOutputFormatChanged(MediaCodec codec, MediaFormat format) { }
+ @Override
+ public void onError(MediaCodec codec, CodecException e) { }
+ });
+
+ // configure with CONFIGURE_FLAG_USE_BLOCK_MODEL (enter Configured State)
codec.configure(format, null /* surface */, null /* crypto */,
MediaCodec.CONFIGURE_FLAG_USE_BLOCK_MODEL |
(isEncoder ? MediaCodec.CONFIGURE_FLAG_ENCODE : 0) /* flags */);
- fail("configure with detached buffer mode should be done after setCallback");
- } catch (MediaCodec.CodecException e) {
- logMediaCodecException(e);
- fail("configure should not return IllegalStateException when improperly configured");
- } catch (IllegalStateException e) { // expected
- }
- final LinkedBlockingQueue<Integer> inputQueue = new LinkedBlockingQueue<>();
- codec.setCallback(new MediaCodec.Callback() {
- @Override
- public void onInputBufferAvailable(MediaCodec codec, int index) {
- inputQueue.offer(index);
+ // start codec (enter Executing state)
+ codec.start();
+
+ // grab input index (this should happen immediately)
+ Integer index = null;
+ try {
+ index = inputQueue.poll(2, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
}
- @Override
- public void onOutputBufferAvailable(
- MediaCodec codec, int index, MediaCodec.BufferInfo info) { }
- @Override
- public void onOutputFormatChanged(MediaCodec codec, MediaFormat format) { }
- @Override
- public void onError(MediaCodec codec, CodecException e) { }
- });
+ assertNotNull(index);
- // configure with CONFIGURE_FLAG_USE_BLOCK_MODEL (enter Configured State)
- codec.configure(format, null /* surface */, null /* crypto */,
- MediaCodec.CONFIGURE_FLAG_USE_BLOCK_MODEL |
- (isEncoder ? MediaCodec.CONFIGURE_FLAG_ENCODE : 0) /* flags */);
+ // test a few commands
+ try {
+ codec.getInputBuffers();
+ fail("getInputBuffers called in detached buffer mode should throw exception");
+ } catch (MediaCodec.IncompatibleWithBlockModelException e) { // expected
+ }
+ try {
+ codec.getOutputBuffers();
+ fail("getOutputBuffers called in detached buffer mode should throw exception");
+ } catch (MediaCodec.IncompatibleWithBlockModelException e) { // expected
+ }
+ try {
+ codec.getInputBuffer(index);
+ fail("getInputBuffer called in detached buffer mode should throw exception");
+ } catch (MediaCodec.IncompatibleWithBlockModelException e) { // expected
+ }
+ try {
+ codec.dequeueInputBuffer(0);
+ fail("dequeueInputBuffer called in detached buffer mode should throw exception");
+ } catch (MediaCodec.IncompatibleWithBlockModelException e) { // expected
+ }
+ MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
+ try {
+ codec.dequeueOutputBuffer(info, 0);
+ fail("dequeueOutputBuffer called in detached buffer mode should throw exception");
+ } catch (MediaCodec.IncompatibleWithBlockModelException e) { // expected
+ }
- // start codec (enter Executing state)
- codec.start();
-
- // grab input index (this should happen immediately)
- Integer index = null;
- try {
- index = inputQueue.poll(2, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- }
- assertNotNull(index);
-
- // test a few commands
- try {
- codec.getInputBuffers();
- fail("getInputBuffers called in detached buffer mode should throw exception");
- } catch (MediaCodec.IncompatibleWithBlockModelException e) { // expected
- }
- try {
- codec.getOutputBuffers();
- fail("getOutputBuffers called in detached buffer mode should throw exception");
- } catch (MediaCodec.IncompatibleWithBlockModelException e) { // expected
- }
- try {
- codec.getInputBuffer(index);
- fail("getInputBuffer called in detached buffer mode should throw exception");
- } catch (MediaCodec.IncompatibleWithBlockModelException e) { // expected
- }
- try {
- codec.dequeueInputBuffer(0);
- fail("dequeueInputBuffer called in detached buffer mode should throw exception");
- } catch (MediaCodec.IncompatibleWithBlockModelException e) { // expected
- }
- MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
- try {
- codec.dequeueOutputBuffer(info, 0);
- fail("dequeueOutputBuffer called in detached buffer mode should throw exception");
- } catch (MediaCodec.IncompatibleWithBlockModelException e) { // expected
- }
-
- // test getQueueRequest
- MediaCodec.QueueRequest request = codec.getQueueRequest(index);
- try {
- request.queue();
- fail("QueueRequest should throw IllegalStateException when no buffer is set");
- } catch (IllegalStateException e) { // expected
- }
- // setting a block
- String[] names = new String[]{ codec.getName() };
- request.setLinearBlock(MediaCodec.LinearBlock.obtain(1, names), 0, 0);
- // setting additional block should fail
- try (HardwareBuffer buffer = HardwareBuffer.create(
- 16 /* width */,
- 16 /* height */,
- HardwareBuffer.YCBCR_420_888,
- 1 /* layers */,
- HardwareBuffer.USAGE_CPU_READ_OFTEN | HardwareBuffer.USAGE_CPU_WRITE_OFTEN)) {
- request.setHardwareBuffer(buffer);
- fail("QueueRequest should throw IllegalStateException multiple blocks are set.");
- } catch (IllegalStateException e) { // expected
+ // test getQueueRequest
+ MediaCodec.QueueRequest request = codec.getQueueRequest(index);
+ try {
+ request.queue();
+ fail("QueueRequest should throw IllegalStateException when no buffer is set");
+ } catch (IllegalStateException e) { // expected
+ }
+ // setting a block
+ String[] names = new String[]{ codec.getName() };
+ request.setLinearBlock(MediaCodec.LinearBlock.obtain(1, names), 0, 0);
+ // setting additional block should fail
+ try (HardwareBuffer buffer = HardwareBuffer.create(
+ 16 /* width */,
+ 16 /* height */,
+ HardwareBuffer.YCBCR_420_888,
+ 1 /* layers */,
+ HardwareBuffer.USAGE_CPU_READ_OFTEN | HardwareBuffer.USAGE_CPU_WRITE_OFTEN)) {
+ request.setHardwareBuffer(buffer);
+ fail("QueueRequest should throw IllegalStateException multiple blocks are set.");
+ } catch (IllegalStateException e) { // expected
+ }
}
// release codec
@@ -2662,8 +2669,10 @@
* through the scenario.
*/
public void testFlushAfterFirstBuffer() throws Exception {
- for (int i = 0; i < 100; ++i) {
- doFlushAfterFirstBuffer();
+ if (MediaUtils.check(mIsAtLeastR, "test needs Android 11")) {
+ for (int i = 0; i < 100; ++i) {
+ doFlushAfterFirstBuffer();
+ }
}
}