From 0344206814deb5782d0aa24fca2b6bf1b2eac8ef 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 --- .../exoplayer2/testutil/DecodeOneFrameUtil.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/DecodeOneFrameUtil.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/DecodeOneFrameUtil.java index da681541c7..641f0c45f9 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/DecodeOneFrameUtil.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/DecodeOneFrameUtil.java @@ -169,14 +169,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); @@ -222,12 +221,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 * com.google.android.exoplayer2.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."); } @@ -251,7 +251,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() {}