From 3511e08340165d04e18c863b656ffeb1158eefcb Mon Sep 17 00:00:00 2001 From: samrobinson Date: Tue, 21 Feb 2023 11:54:31 +0000 Subject: [PATCH] Use the supported codec name in DecodeOneFrameUtil. Tested: Before: fusion2/7d7db2d1-1c3e-3df3-8507-73b929c6eac8 (Weekly triage) After: sponge2/4c078211-e08c-43fa-91d5-346fccc04bcd (custom run) PiperOrigin-RevId: 511157461 --- .../media3/test/utils/DecodeOneFrameUtil.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/test_utils/src/main/java/androidx/media3/test/utils/DecodeOneFrameUtil.java b/libraries/test_utils/src/main/java/androidx/media3/test/utils/DecodeOneFrameUtil.java index 4bcc8c4a93..f614ee3223 100644 --- a/libraries/test_utils/src/main/java/androidx/media3/test/utils/DecodeOneFrameUtil.java +++ b/libraries/test_utils/src/main/java/androidx/media3/test/utils/DecodeOneFrameUtil.java @@ -171,14 +171,13 @@ public final class DecodeOneFrameUtil { } } - checkStateNotNull(mediaFormat); - if (!isSupportedByDecoder(mediaFormat)) { + @Nullable String decoderName = getSupportedDecoderName(checkStateNotNull(mediaFormat)); + if (decoderName == null) { throw new UnsupportedOperationException(NO_DECODER_SUPPORT_ERROR_STRING); } - // Queue the first video frame from the extractor. - String mimeType = checkNotNull(mediaFormat.getString(MediaFormat.KEY_MIME)); - mediaCodec = MediaCodec.createDecoderByType(mimeType); + mediaCodec = MediaCodec.createByCodecName(decoderName); + // Queue the first video frame from the extractor. mediaCodec.configure(mediaFormat, surface, /* crypto= */ null, /* flags= */ 0); mediaCodec.start(); int inputBufferIndex = mediaCodec.dequeueInputBuffer(DEQUEUE_TIMEOUT_US); @@ -224,12 +223,13 @@ public final class DecodeOneFrameUtil { } /** - * Returns whether a decoder supports this {@link MediaFormat}. + * Returns the name of a decoder that supports this {@link MediaFormat}. * *

Capability check is similar to * androidx.media3.transformer.EncoderUtil.java#findCodecForFormat(). */ - private static boolean isSupportedByDecoder(MediaFormat format) { + @Nullable + private static String getSupportedDecoderName(MediaFormat format) { if (Util.SDK_INT < 21) { throw new UnsupportedOperationException("Unable to detect decoder support under API 21."); } @@ -253,7 +253,7 @@ public final class DecodeOneFrameUtil { if (Util.SDK_INT == 21) { MediaFormatUtil.maybeSetInteger(format, MediaFormat.KEY_FRAME_RATE, round(frameRate)); } - return mediaCodecName != null; + return mediaCodecName; } private DecodeOneFrameUtil() {}