Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1241)

Unified Diff: media/base/android/java/src/org/chromium/media/MediaCodecBridge.java

Issue 1987963004: Estimate the required MediaCodec decoder max input buffer size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make MimeTypes static Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/base/android/java/src/org/chromium/media/MediaCodecUtil.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
diff --git a/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java b/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
index 04b78e43960b655e7f5719d165e467e415a7aff3..ce50ab2bdd489045db3f0c709110736f5ec4dc22 100644
--- a/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
+++ b/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
@@ -19,6 +19,7 @@ import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex;
+import org.chromium.media.MediaCodecUtil.MimeTypes;
import java.nio.ByteBuffer;
@@ -472,6 +473,7 @@ class MediaCodecBridge {
format.setInteger(
MediaFormat.KEY_MAX_HEIGHT, format.getInteger(MediaFormat.KEY_HEIGHT));
}
+ maybeSetMaxInputSize(format);
mMediaCodec.configure(format, surface, crypto, flags);
return true;
} catch (IllegalArgumentException e) {
@@ -496,6 +498,54 @@ class MediaCodecBridge {
return MediaFormat.createVideoFormat(mime, width, height);
}
+ // Use some heuristics to set KEY_MAX_INPUT_SIZE (the size of the input buffers).
+ // Taken from exoplayer:
+ // https://github.com/google/ExoPlayer/blob/8595c65678a181296cdf673eacb93d8135479340/library/src/main/java/com/google/android/exoplayer/MediaCodecVideoTrackRenderer.java
+ private void maybeSetMaxInputSize(MediaFormat format) {
+ if (format.containsKey(android.media.MediaFormat.KEY_MAX_INPUT_SIZE)) {
+ // Already set. The source of the format may know better, so do nothing.
+ return;
+ }
+ int maxHeight = format.getInteger(MediaFormat.KEY_HEIGHT);
+ if (mAdaptivePlaybackSupported && format.containsKey(MediaFormat.KEY_MAX_HEIGHT)) {
+ maxHeight = Math.max(maxHeight, format.getInteger(MediaFormat.KEY_MAX_HEIGHT));
+ }
+ int maxWidth = format.getInteger(MediaFormat.KEY_WIDTH);
+ if (mAdaptivePlaybackSupported && format.containsKey(MediaFormat.KEY_MAX_WIDTH)) {
+ maxWidth = Math.max(maxHeight, format.getInteger(MediaFormat.KEY_MAX_WIDTH));
+ }
+ int maxPixels;
+ int minCompressionRatio;
+ switch (format.getString(MediaFormat.KEY_MIME)) {
+ case MimeTypes.VIDEO_H264:
+ if ("BRAVIA 4K 2015".equals(Build.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_H265:
+ case MimeTypes.VIDEO_VP9:
+ maxPixels = maxWidth * maxHeight;
+ minCompressionRatio = 4;
+ break;
+ default:
+ // Leave the default max input size.
+ return;
+ }
+ // Estimate the maximum input size assuming three channel 4:2:0 subsampled input frames.
+ int maxInputSize = (maxPixels * 3) / (2 * minCompressionRatio);
+ format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
+ }
+
@CalledByNative
private static MediaFormat createVideoEncoderFormat(String mime, int width, int height,
int bitRate, int frameRate, int iFrameInterval, int colorFormat) {
« no previous file with comments | « no previous file | media/base/android/java/src/org/chromium/media/MediaCodecUtil.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698