Bug 1844622 - Catch and ignore runtime exception during media codec query on Android if MediaCodecInfo cannot be retrieved. r=jolin,geckoview-reviewers,owlish

Differential Revision: https://phabricator.services.mozilla.com/D184274
This commit is contained in:
az 2023-07-26 16:56:03 +00:00
parent b6a33dbfc8
commit 1ad6db6118
2 changed files with 19 additions and 8 deletions

View File

@ -468,8 +468,15 @@ import org.mozilla.gecko.gfx.GeckoSurface;
final int height =
format.containsKey(MediaFormat.KEY_HEIGHT) ? format.getInteger(MediaFormat.KEY_HEIGHT) : 0;
final int numCodecs = MediaCodecList.getCodecCount();
int numCodecs = 0;
final List<String> found = new ArrayList<>();
try {
numCodecs = MediaCodecList.getCodecCount();
} catch (final RuntimeException e) {
Log.e(LOGTAG, "Failed retrieving codec count finding matching codec names", e);
return found;
}
for (int i = 0; i < numCodecs; i++) {
final MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
if (info.isEncoder() == !isEncoder) {

View File

@ -100,11 +100,16 @@ public final class HardwareCodecCapabilityUtils {
// Return list of all codecs (decode + encode).
private static MediaCodecInfo[] getCodecList() {
final MediaCodecInfo[] codecList;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
codecList = getCodecListWithOldAPI();
} else {
final MediaCodecList list = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
codecList = list.getCodecInfos();
try {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
codecList = getCodecListWithOldAPI();
} else {
final MediaCodecList list = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
codecList = list.getCodecInfos();
}
} catch (final RuntimeException e) {
Log.e(LOGTAG, "Failed to retrieve media codec support list", e);
return new MediaCodecInfo[0];
}
return codecList;
}
@ -218,8 +223,7 @@ public final class HardwareCodecCapabilityUtils {
// Check if a given MIME Type has HW decode or encode support.
public static boolean getHWCodecCapability(final String aMimeType, final boolean aIsEncoder) {
if (Build.VERSION.SDK_INT >= 20) {
for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
final MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
for (final MediaCodecInfo info : getCodecList()) {
if (info.isEncoder() != aIsEncoder) {
continue;
}