mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
Set a max input size for VP8 and VP9.
Issue: #1090 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=111607802
This commit is contained in:
parent
9cdd246a55
commit
664c80da15
1 changed files with 27 additions and 11 deletions
|
|
@ -498,19 +498,10 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
|
|||
|
||||
@SuppressLint("InlinedApi")
|
||||
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)) {
|
||||
// Already set. The source of the format may know better, so do nothing.
|
||||
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);
|
||||
if (codecIsAdaptive && format.containsKey(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 {
|
|||
if (codecIsAdaptive && format.containsKey(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 maxInputSize = ((maxWidth + 15) / 16) * ((maxHeight + 15) / 16) * 192;
|
||||
int maxPixels;
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue