From 99edc6a4b447399d62f578d0aeed0eabbeddd98c Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Thu, 28 May 2015 17:07:12 +0100 Subject: [PATCH] Avoid using OMX.qcom.audio.decoder.mp3 on HTC Butterfly. This OMX component is listed but can't be instantiated on this device. According to the GitHub issue, some other devices are also affected, so these will have to be added too. Issue: #377 --- .../android/exoplayer/MediaCodecUtil.java | 25 +++++++++++++++++-- .../google/android/exoplayer/util/Util.java | 6 +++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java index c3f3fc85f2..22e2dde9ce 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java @@ -134,8 +134,7 @@ public class MediaCodecUtil { for (int i = 0; i < numberOfCodecs; i++) { MediaCodecInfo info = mediaCodecList.getCodecInfoAt(i); String codecName = info.getName(); - if (!info.isEncoder() && codecName.startsWith("OMX.") - && (secureDecodersExplicit || !codecName.endsWith(".secure"))) { + if (isCodecUsableDecoder(info, codecName, secureDecodersExplicit)) { String[] supportedTypes = info.getSupportedTypes(); for (int j = 0; j < supportedTypes.length; j++) { String supportedType = supportedTypes[j]; @@ -166,6 +165,28 @@ public class MediaCodecUtil { return null; } + /** + * Returns whether the specified codec is usable for decoding on the current device. + */ + private static boolean isCodecUsableDecoder(MediaCodecInfo info, String name, + boolean secureDecodersExplicit) { + if (info.isEncoder() || !name.startsWith("OMX.") + || (!secureDecodersExplicit && name.endsWith(".secure"))) { + return false; + } + + // Workaround an issue where creating a particular MP3 decoder on some HTC devices on platform + // API version 16 crashes mediaserver. + if (Util.SDK_INT == 16 + && ("dlxu".equals(Util.PRODUCT) // HTC Butterfly + || "protou".equals(Util.PRODUCT)) // HTC Desire X + && name.equals("OMX.qcom.audio.decoder.mp3")) { + return false; + } + + return true; + } + private static boolean isAdaptive(CodecCapabilities capabilities) { if (Util.SDK_INT >= 19) { return isAdaptiveV19(capabilities); diff --git a/library/src/main/java/com/google/android/exoplayer/util/Util.java b/library/src/main/java/com/google/android/exoplayer/util/Util.java index 03fc20564d..5dc2993ef6 100644 --- a/library/src/main/java/com/google/android/exoplayer/util/Util.java +++ b/library/src/main/java/com/google/android/exoplayer/util/Util.java @@ -59,6 +59,12 @@ public final class Util { */ public static final int SDK_INT = android.os.Build.VERSION.SDK_INT; + /** + * Like {@link android.os.Build#PRODUCT}, but in a place where it can be conveniently overridden + * for local testing. + */ + public static final String PRODUCT = android.os.Build.PRODUCT; + private static final Pattern XS_DATE_TIME_PATTERN = Pattern.compile( "(\\d\\d\\d\\d)\\-(\\d\\d)\\-(\\d\\d)[Tt]" + "(\\d\\d):(\\d\\d):(\\d\\d)(\\.(\\d+))?"