Commit b0d0914c by olly Committed by Oliver Woodman

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
parent 40dbe10b
...@@ -377,18 +377,13 @@ public final class MediaCodecInfo { ...@@ -377,18 +377,13 @@ public final class MediaCodecInfo {
@TargetApi(21) @TargetApi(21)
public Point alignVideoSizeV21(int width, int height) { public Point alignVideoSizeV21(int width, int height) {
if (capabilities == null) { if (capabilities == null) {
logNoSupport("align.caps");
return null; return null;
} }
VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities(); VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
if (videoCapabilities == null) { if (videoCapabilities == null) {
logNoSupport("align.vCaps");
return null; return null;
} }
int widthAlignment = videoCapabilities.getWidthAlignment(); return alignVideoSizeV21(videoCapabilities, width, height);
int heightAlignment = videoCapabilities.getHeightAlignment();
return new Point(Util.ceilDivide(width, widthAlignment) * widthAlignment,
Util.ceilDivide(height, heightAlignment) * heightAlignment);
} }
/** /**
...@@ -519,6 +514,11 @@ public final class MediaCodecInfo { ...@@ -519,6 +514,11 @@ public final class MediaCodecInfo {
@TargetApi(21) @TargetApi(21)
private static boolean areSizeAndRateSupportedV21(VideoCapabilities capabilities, int width, private static boolean areSizeAndRateSupportedV21(VideoCapabilities capabilities, int width,
int height, double frameRate) { 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) { if (frameRate == Format.NO_VALUE || frameRate <= 0) {
return capabilities.isSizeSupported(width, height); return capabilities.isSizeSupported(width, height);
} else { } else {
...@@ -530,6 +530,15 @@ public final class MediaCodecInfo { ...@@ -530,6 +530,15 @@ public final class MediaCodecInfo {
} }
} }
@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) @TargetApi(23)
private static int getMaxSupportedInstancesV23(CodecCapabilities capabilities) { private static int getMaxSupportedInstancesV23(CodecCapabilities capabilities) {
return capabilities.getMaxSupportedInstances(); return capabilities.getMaxSupportedInstances();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment