diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 43952f29f45..98f8e85857c 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -56,6 +56,8 @@ * IMA extension: Upgrade IMA dependency to 3.10.6. * Cronet extension: Upgrade Cronet dependency to 71.3578.98. * OkHttp extension: Upgrade OkHttp dependency to 3.12.1. +* MP3: Wider fix for issue where streams would play twice on some Samsung + devices ([#4519](https://github.com/google/ExoPlayer/issues/4519)). ### 2.9.4 ### diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecUtil.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecUtil.java index ae3a9f123f6..55459692c91 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecUtil.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecUtil.java @@ -58,8 +58,6 @@ private DecoderQueryException(Throwable cause) { private static final String TAG = "MediaCodecUtil"; private static final Pattern PROFILE_PATTERN = Pattern.compile("^\\D?(\\d+)$"); - private static final RawAudioCodecComparator RAW_AUDIO_CODEC_COMPARATOR = - new RawAudioCodecComparator(); private static final HashMap> decoderInfosCache = new HashMap<>(); @@ -311,32 +309,6 @@ private static boolean isCodecUsableDecoder(android.media.MediaCodecInfo info, S return false; } - // Work around https://github.com/google/ExoPlayer/issues/398. - if (Util.SDK_INT < 18 && "OMX.SEC.MP3.Decoder".equals(name)) { - return false; - } - - // Work around https://github.com/google/ExoPlayer/issues/4519. - if ("OMX.SEC.mp3.dec".equals(name) - && (Util.MODEL.startsWith("GT-I9152") - || Util.MODEL.startsWith("GT-I9515") - || Util.MODEL.startsWith("GT-P5220") - || Util.MODEL.startsWith("GT-S7580") - || Util.MODEL.startsWith("SM-G350") - || Util.MODEL.startsWith("SM-G386") - || Util.MODEL.startsWith("SM-T231") - || Util.MODEL.startsWith("SM-T530") - || Util.MODEL.startsWith("SCH-I535") - || Util.MODEL.startsWith("SPH-L710"))) { - return false; - } - if ("OMX.brcm.audio.mp3.decoder".equals(name) - && (Util.MODEL.startsWith("GT-I9152") - || Util.MODEL.startsWith("GT-S7580") - || Util.MODEL.startsWith("SM-G350"))) { - return false; - } - // Work around https://github.com/google/ExoPlayer/issues/1528 and // https://github.com/google/ExoPlayer/issues/3171. if (Util.SDK_INT < 18 && "OMX.MTK.AUDIO.DECODER.AAC".equals(name) @@ -423,7 +395,18 @@ private static boolean isCodecUsableDecoder(android.media.MediaCodecInfo info, S */ private static void applyWorkarounds(String mimeType, List decoderInfos) { if (MimeTypes.AUDIO_RAW.equals(mimeType)) { - Collections.sort(decoderInfos, RAW_AUDIO_CODEC_COMPARATOR); + Collections.sort(decoderInfos, new RawAudioCodecComparator()); + } else if (Util.SDK_INT < 21 && decoderInfos.size() > 1) { + String firstCodecName = decoderInfos.get(0).name; + if ("OMX.SEC.mp3.dec".equals(firstCodecName) + || "OMX.SEC.MP3.Decoder".equals(firstCodecName) + || "OMX.brcm.audio.mp3.decoder".equals(firstCodecName)) { + // Prefer OMX.google codecs over OMX.SEC.mp3.dec, OMX.SEC.MP3.Decoder and + // OMX.brcm.audio.mp3.decoder on older devices. See: + // https://github.com/google/ExoPlayer/issues/398 and + // https://github.com/google/ExoPlayer/issues/4519. + Collections.sort(decoderInfos, new PreferOmxGoogleCodecComparator()); + } } } @@ -729,6 +712,18 @@ private static int scoreMediaCodecInfo(MediaCodecInfo mediaCodecInfo) { } } + /** Comparator for preferring OMX.google media codecs. */ + private static final class PreferOmxGoogleCodecComparator implements Comparator { + @Override + public int compare(MediaCodecInfo a, MediaCodecInfo b) { + return scoreMediaCodecInfo(a) - scoreMediaCodecInfo(b); + } + + private static int scoreMediaCodecInfo(MediaCodecInfo mediaCodecInfo) { + return mediaCodecInfo.name.startsWith("OMX.google") ? -1 : 0; + } + } + static { AVC_PROFILE_NUMBER_TO_CONST = new SparseIntArray(); AVC_PROFILE_NUMBER_TO_CONST.put(66, CodecProfileLevel.AVCProfileBaseline);