From b0d0914ce5b71c771de901e2baf70e677e97b3e6 Mon Sep 17 00:00:00 2001 From: olly <olly@google.com> Date: Thu, 17 Oct 2019 11:50:58 +0100 Subject: [PATCH] Round impossible H264 resolutions up to valid values for capabilities check If an odd resolution is impossible in the specification itself, then we know that the caller is passing invalid data. Round up on the assumption it's a rounding error so that playback can proceed. Issue: #6551 PiperOrigin-RevId: 275226813 --- .../exoplayer2/mediacodec/MediaCodecInfo.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java index 7fc748485b9..8581f279d0e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java @@ -377,18 +377,13 @@ public boolean isVideoSizeAndRateSupportedV21(int width, int height, double fram @TargetApi(21) public Point alignVideoSizeV21(int width, int height) { if (capabilities == null) { - logNoSupport("align.caps"); return null; } VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities(); if (videoCapabilities == null) { - logNoSupport("align.vCaps"); return null; } - int widthAlignment = videoCapabilities.getWidthAlignment(); - int heightAlignment = videoCapabilities.getHeightAlignment(); - return new Point(Util.ceilDivide(width, widthAlignment) * widthAlignment, - Util.ceilDivide(height, heightAlignment) * heightAlignment); + return alignVideoSizeV21(videoCapabilities, width, height); } /** @@ -519,6 +514,11 @@ private static boolean isSecureV21(CodecCapabilities capabilities) { @TargetApi(21) private static boolean areSizeAndRateSupportedV21(VideoCapabilities capabilities, int width, int height, double frameRate) { + // Don't ever fail due to alignment. See: https://github.com/google/ExoPlayer/issues/6551. + Point alignedSize = alignVideoSizeV21(capabilities, width, height); + width = alignedSize.x; + height = alignedSize.y; + if (frameRate == Format.NO_VALUE || frameRate <= 0) { return capabilities.isSizeSupported(width, height); } else { @@ -530,6 +530,15 @@ private static boolean areSizeAndRateSupportedV21(VideoCapabilities capabilities } } + @TargetApi(21) + private static Point alignVideoSizeV21(VideoCapabilities capabilities, int width, int height) { + int widthAlignment = capabilities.getWidthAlignment(); + int heightAlignment = capabilities.getHeightAlignment(); + return new Point( + Util.ceilDivide(width, widthAlignment) * widthAlignment, + Util.ceilDivide(height, heightAlignment) * heightAlignment); + } + @TargetApi(23) private static int getMaxSupportedInstancesV23(CodecCapabilities capabilities) { return capabilities.getMaxSupportedInstances();