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() {}