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 e6b0630a2e..ab428d6da8 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java @@ -240,6 +240,27 @@ public final class MediaCodecUtil { return capabilities.isFeatureSupported(CodecCapabilities.FEATURE_AdaptivePlayback); } + /** + * Tests whether the device advertises it can decode video of a given type at a specified width + * and height. + *

+ * Must not be called if the device SDK version is less than 21. + * + * @param mimeType The mime type. + * @param secure Whether the decoder is required to support secure decryption. Always pass false + * unless secure decryption really is required. + * @param width Width in pixels. + * @param height Height in pixels. + * @return Whether the decoder advertises support of the given size. + */ + @TargetApi(21) + public static boolean isSizeSupportedV21(String mimeType, boolean secure, int width, + int height) throws DecoderQueryException { + Assertions.checkState(Util.SDK_INT >= 21); + MediaCodecInfo.VideoCapabilities videoCapabilities = getVideoCapabilitiesV21(mimeType, secure); + return videoCapabilities != null && videoCapabilities.isSizeSupported(width, height); + } + /** * Tests whether the device advertises it can decode video of a given type at a specified * width, height, and frame rate. @@ -258,11 +279,7 @@ public final class MediaCodecUtil { public static boolean isSizeAndRateSupportedV21(String mimeType, boolean secure, int width, int height, double frameRate) throws DecoderQueryException { Assertions.checkState(Util.SDK_INT >= 21); - Pair info = getMediaCodecInfo(mimeType, secure); - if (info == null) { - return false; - } - MediaCodecInfo.VideoCapabilities videoCapabilities = info.second.getVideoCapabilities(); + MediaCodecInfo.VideoCapabilities videoCapabilities = getVideoCapabilitiesV21(mimeType, secure); return videoCapabilities != null && videoCapabilities.areSizeAndRateSupported(width, height, frameRate); } @@ -310,6 +327,16 @@ public final class MediaCodecUtil { return maxH264DecodableFrameSize; } + @TargetApi(21) + private static MediaCodecInfo.VideoCapabilities getVideoCapabilitiesV21(String mimeType, + boolean secure) throws DecoderQueryException { + Pair info = getMediaCodecInfo(mimeType, secure); + if (info == null) { + return null; + } + return info.second.getVideoCapabilities(); + } + /** * Conversion values taken from: https://en.wikipedia.org/wiki/H.264/MPEG-4_AVC. * diff --git a/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java b/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java index 37b2aa42a7..84717b9c79 100644 --- a/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java @@ -154,9 +154,13 @@ public final class VideoFormatSelectorUtil { if (format.width > 0 && format.height > 0) { String videoMediaMimeType = MimeTypes.getVideoMediaMimeType(format.codecs); if (Util.SDK_INT >= 21 && !MimeTypes.VIDEO_UNKNOWN.equals(videoMediaMimeType)) { - float frameRate = (format.frameRate > 0) ? format.frameRate : 30.0f; - return MediaCodecUtil.isSizeAndRateSupportedV21(videoMediaMimeType, false, - format.width, format.height, frameRate); + if (format.frameRate > 0) { + return MediaCodecUtil.isSizeAndRateSupportedV21(videoMediaMimeType, false, format.width, + format.height, format.frameRate); + } else { + return MediaCodecUtil.isSizeSupportedV21(videoMediaMimeType, false, format.width, + format.height); + } } //Assuming that the media is H.264 if (format.width * format.height > maxDecodableFrameSize) {