Commit 664c80da by andrewlewis Committed by Oliver Woodman

Set a max input size for VP8 and VP9.

Issue: #1090
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=111607802
parent 9cdd246a
...@@ -498,19 +498,10 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer { ...@@ -498,19 +498,10 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
private void maybeSetMaxInputSize(android.media.MediaFormat format, boolean codecIsAdaptive) { private void maybeSetMaxInputSize(android.media.MediaFormat format, boolean codecIsAdaptive) {
if (!MimeTypes.VIDEO_H264.equals(format.getString(android.media.MediaFormat.KEY_MIME))) {
// Only set a max input size for H264 for now.
return;
}
if (format.containsKey(android.media.MediaFormat.KEY_MAX_INPUT_SIZE)) { if (format.containsKey(android.media.MediaFormat.KEY_MAX_INPUT_SIZE)) {
// Already set. The source of the format may know better, so do nothing. // Already set. The source of the format may know better, so do nothing.
return; return;
} }
if ("BRAVIA 4K 2015".equals(Util.MODEL)) {
// The Sony BRAVIA 4k TV has input buffers that are too small for the calculated 4k video
// maximum input size, so use the default value.
return;
}
int maxHeight = format.getInteger(android.media.MediaFormat.KEY_HEIGHT); int maxHeight = format.getInteger(android.media.MediaFormat.KEY_HEIGHT);
if (codecIsAdaptive && format.containsKey(android.media.MediaFormat.KEY_MAX_HEIGHT)) { if (codecIsAdaptive && format.containsKey(android.media.MediaFormat.KEY_MAX_HEIGHT)) {
maxHeight = Math.max(maxHeight, format.getInteger(android.media.MediaFormat.KEY_MAX_HEIGHT)); maxHeight = Math.max(maxHeight, format.getInteger(android.media.MediaFormat.KEY_MAX_HEIGHT));
...@@ -519,8 +510,33 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer { ...@@ -519,8 +510,33 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
if (codecIsAdaptive && format.containsKey(android.media.MediaFormat.KEY_MAX_WIDTH)) { if (codecIsAdaptive && format.containsKey(android.media.MediaFormat.KEY_MAX_WIDTH)) {
maxWidth = Math.max(maxHeight, format.getInteger(android.media.MediaFormat.KEY_MAX_WIDTH)); maxWidth = Math.max(maxHeight, format.getInteger(android.media.MediaFormat.KEY_MAX_WIDTH));
} }
// H264 requires compression ratio of at least 2, and uses macroblocks. int maxPixels;
int maxInputSize = ((maxWidth + 15) / 16) * ((maxHeight + 15) / 16) * 192; int minCompressionRatio;
switch (format.getString(android.media.MediaFormat.KEY_MIME)) {
case MimeTypes.VIDEO_H264:
if ("BRAVIA 4K 2015".equals(Util.MODEL)) {
// The Sony BRAVIA 4k TV has input buffers that are too small for the calculated 4k video
// maximum input size, so use the default value.
return;
}
// Round up width/height to an integer number of macroblocks.
maxPixels = ((maxWidth + 15) / 16) * ((maxHeight + 15) / 16) * 16 * 16;
minCompressionRatio = 2;
break;
case MimeTypes.VIDEO_VP8:
// VPX does not specify a ratio so use the values from the platform's SoftVPX.cpp.
maxPixels = maxWidth * maxHeight;
minCompressionRatio = 2;
break;
case MimeTypes.VIDEO_VP9:
maxPixels = maxWidth * maxHeight;
minCompressionRatio = 4;
break;
default:
// Leave the default max input size.
return;
}
int maxInputSize = (maxPixels * 3) / (2 * minCompressionRatio);
format.setInteger(android.media.MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize); format.setInteger(android.media.MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
} }
......
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