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 <profile, maxSupportedLevel>

but on some other devices, there are multiple entries for the same profile,

like <HIGH_PROFILE, LEVEL1>, <HIGH_PROFILE, LEVEL2>, <HIGH_PROFILE, LEVEL3>,
where we need to iterate through all the entries and find the max.

PiperOrigin-RevId: 427727030
This commit is contained in:
claincly 2022-02-10 13:59:54 +00:00 committed by Ian Baker
parent ad5f2387e0
commit 12ce9f7c0f

View File

@ -16,6 +16,7 @@
package androidx.media3.transformer; package androidx.media3.transformer;
import static java.lang.Math.max;
import static java.lang.Math.round; import static java.lang.Math.round;
import android.media.MediaCodec; import android.media.MediaCodec;
@ -127,12 +128,13 @@ public final class EncoderUtil {
MediaCodecInfo.CodecProfileLevel[] profileLevels = MediaCodecInfo.CodecProfileLevel[] profileLevels =
encoderInfo.getCapabilitiesForType(mimeType).profileLevels; encoderInfo.getCapabilitiesForType(mimeType).profileLevels;
int maxSupportedLevel = LEVEL_UNSET;
for (MediaCodecInfo.CodecProfileLevel profileLevel : profileLevels) { for (MediaCodecInfo.CodecProfileLevel profileLevel : profileLevels) {
if (profileLevel.profile == profile) { if (profileLevel.profile == profile) {
return profileLevel.level; maxSupportedLevel = max(maxSupportedLevel, profileLevel.level);
} }
} }
return LEVEL_UNSET; return maxSupportedLevel;
} }
/** /**