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
This commit is contained in:
olly 2019-10-17 11:50:58 +01:00 committed by Oliver Woodman
parent 40dbe10b12
commit b0d0914ce5

View file

@ -377,18 +377,13 @@ public final class MediaCodecInfo {
@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 @@ public final class MediaCodecInfo {
@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 @@ 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)
private static int getMaxSupportedInstancesV23(CodecCapabilities capabilities) {
return capabilities.getMaxSupportedInstances();