Commit 3540b9d7 by claincly Committed by Ian Baker

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
parent be19f038
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.transformer; package com.google.android.exoplayer2.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;
...@@ -125,12 +126,13 @@ public final class EncoderUtil { ...@@ -125,12 +126,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;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment