Commit d3d5ffce by christosts Committed by Marc Baechinger

Increase max sample size for HEVC.

Increase the estimated max sample size for HEVC by 2x, and set a minimum
size of 2MB. The 2MB will be applied for resolutions up to 1080p, after
which the new calculation takes effect. This is in par with the
platform's HEVC software decoder.

PiperOrigin-RevId: 467641494
parent 80b635e7
...@@ -111,6 +111,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -111,6 +111,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
/** Magic frame render timestamp that indicates the EOS in tunneling mode. */ /** Magic frame render timestamp that indicates the EOS in tunneling mode. */
private static final long TUNNELING_EOS_PRESENTATION_TIME_US = Long.MAX_VALUE; private static final long TUNNELING_EOS_PRESENTATION_TIME_US = Long.MAX_VALUE;
/** The minimum input buffer size for HEVC. */
private static final int HEVC_MAX_INPUT_SIZE_THRESHOLD = 2 * 1024 * 1024;
private static boolean evaluatedDeviceNeedsSetOutputSurfaceWorkaround; private static boolean evaluatedDeviceNeedsSetOutputSurfaceWorkaround;
private static boolean deviceNeedsSetOutputSurfaceWorkaround; private static boolean deviceNeedsSetOutputSurfaceWorkaround;
...@@ -787,14 +790,20 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -787,14 +790,20 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
// Attempt to infer a maximum input size from the format. // Attempt to infer a maximum input size from the format.
int maxPixels;
int minCompressionRatio;
switch (sampleMimeType) { switch (sampleMimeType) {
case MimeTypes.VIDEO_H263: case MimeTypes.VIDEO_H263:
case MimeTypes.VIDEO_MP4V: case MimeTypes.VIDEO_MP4V:
maxPixels = width * height; case MimeTypes.VIDEO_AV1:
minCompressionRatio = 2; // Assume a min compression of 2 similar to the platform's C2SoftAomDec.cpp.
break; case MimeTypes.VIDEO_VP8:
// Assume a min compression of 2 similar to the platform's SoftVPX.cpp.
return getMaxSampleSize(/* pixelCount= */ width * height, /* minCompressionRatio= */ 2);
case MimeTypes.VIDEO_H265:
// Assume a min compression of 2 similar to the platform's C2SoftHevcDec.cpp, but restrict
// the minimum size.
return max(
HEVC_MAX_INPUT_SIZE_THRESHOLD,
getMaxSampleSize(/* pixelCount= */ width * height, /* minCompressionRatio= */ 2));
case MimeTypes.VIDEO_H264: case MimeTypes.VIDEO_H264:
if ("BRAVIA 4K 2015".equals(Util.MODEL) // Sony Bravia 4K if ("BRAVIA 4K 2015".equals(Util.MODEL) // Sony Bravia 4K
|| ("Amazon".equals(Util.MANUFACTURER) || ("Amazon".equals(Util.MANUFACTURER)
...@@ -805,27 +814,14 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -805,27 +814,14 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
return Format.NO_VALUE; return Format.NO_VALUE;
} }
// Round up width/height to an integer number of macroblocks. // Round up width/height to an integer number of macroblocks.
maxPixels = Util.ceilDivide(width, 16) * Util.ceilDivide(height, 16) * 16 * 16; int maxPixels = Util.ceilDivide(width, 16) * Util.ceilDivide(height, 16) * 16 * 16;
minCompressionRatio = 2; return getMaxSampleSize(maxPixels, /* minCompressionRatio= */ 2);
break;
case MimeTypes.VIDEO_AV1:
// AV1 does not specify a ratio so use the values from the platform's C2SoftAomDec.cpp.
case MimeTypes.VIDEO_VP8:
// VPX does not specify a ratio so use the values from the platform's SoftVPX.cpp.
maxPixels = width * height;
minCompressionRatio = 2;
break;
case MimeTypes.VIDEO_H265:
case MimeTypes.VIDEO_VP9: case MimeTypes.VIDEO_VP9:
maxPixels = width * height; return getMaxSampleSize(/* pixelCount= */ width * height, /* minCompressionRatio= */ 4);
minCompressionRatio = 4;
break;
default: default:
// Leave the default max input size. // Leave the default max input size.
return Format.NO_VALUE; return Format.NO_VALUE;
} }
// Estimate the maximum input size assuming three channel 4:2:0 subsampled input frames.
return (maxPixels * 3) / (2 * minCompressionRatio);
} }
@Override @Override
...@@ -1733,6 +1729,17 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -1733,6 +1729,17 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
} }
/**
* Returns the maximum sample size assuming three channel 4:2:0 subsampled input frames with the
* specified {@code minCompressionRatio}
*
* @param pixelCount The number of pixels
* @param minCompressionRatio The minimum compression ratio
*/
private static int getMaxSampleSize(int pixelCount, int minCompressionRatio) {
return (pixelCount * 3) / (2 * minCompressionRatio);
}
private static boolean evaluateDeviceNeedsSetOutputSurfaceWorkaround() { private static boolean evaluateDeviceNeedsSetOutputSurfaceWorkaround() {
if (Util.SDK_INT <= 28) { if (Util.SDK_INT <= 28) {
// Workaround for MiTV and MiBox devices which have been observed broken up to API 28. // Workaround for MiTV and MiBox devices which have been observed broken up to API 28.
......
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