Skip to content

Commit

Permalink
Round impossible H264 resolutions up to valid values for capabilities…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
ojw28 committed Oct 17, 2019
1 parent 40dbe10 commit b0d0914
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
Expand Down

0 comments on commit b0d0914

Please sign in to comment.