From 12ce9f7c0ff31e45e677e549f636b0c66de1b1d5 Mon Sep 17 00:00:00 2001 From: claincly Date: Thu, 10 Feb 2022 13:59:54 +0000 Subject: [PATCH] Fix the logic to get the max supported encoding level. On some Android devices, the return value of ``` MediaCodecInfo.getCapabilitiesForType(mimeType).profileLevels ``` contains one entry for each encoding profile, like but on some other devices, there are multiple entries for the same profile, like , , , where we need to iterate through all the entries and find the max. PiperOrigin-RevId: 427727030 --- .../main/java/androidx/media3/transformer/EncoderUtil.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java b/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java index 3a6c9bc63d..970644433a 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java @@ -16,6 +16,7 @@ package androidx.media3.transformer; +import static java.lang.Math.max; import static java.lang.Math.round; import android.media.MediaCodec; @@ -127,12 +128,13 @@ public final class EncoderUtil { MediaCodecInfo.CodecProfileLevel[] profileLevels = encoderInfo.getCapabilitiesForType(mimeType).profileLevels; + int maxSupportedLevel = LEVEL_UNSET; for (MediaCodecInfo.CodecProfileLevel profileLevel : profileLevels) { if (profileLevel.profile == profile) { - return profileLevel.level; + maxSupportedLevel = max(maxSupportedLevel, profileLevel.level); } } - return LEVEL_UNSET; + return maxSupportedLevel; } /**