Commit 357d1f8c authored by gunsch's avatar gunsch Committed by Commit bot

Use MediaFormat's crop rectangle when available instead of width/height.

Per Android media team, width/height is not always reliable. See:
https://github.com/google/ExoPlayer/blob/a7b88cd6a9bac4de5ef47b23e0d7fb50c570b3a6/library/src/main/java/com/google/android/exoplayer/MediaCodecVideoTrackRenderer.java#L319

R=qinmin@chromium.org
BUG=internal b/18224769

Review URL: https://codereview.chromium.org/698273003

Cr-Commit-Position: refs/heads/master@{#302739}
parent 62bb47df
...@@ -62,6 +62,12 @@ class MediaCodecBridge { ...@@ -62,6 +62,12 @@ class MediaCodecBridge {
// non-decreasing for the remaining frames. // non-decreasing for the remaining frames.
private static final long MAX_PRESENTATION_TIMESTAMP_SHIFT_US = 100000; private static final long MAX_PRESENTATION_TIMESTAMP_SHIFT_US = 100000;
// TODO(qinmin): Use MediaFormat constants when part of the public API.
private static final String KEY_CROP_LEFT = "crop-left";
private static final String KEY_CROP_RIGHT = "crop-right";
private static final String KEY_CROP_BOTTOM = "crop-bottom";
private static final String KEY_CROP_TOP = "crop-top";
private ByteBuffer[] mInputBuffers; private ByteBuffer[] mInputBuffers;
private ByteBuffer[] mOutputBuffers; private ByteBuffer[] mOutputBuffers;
...@@ -244,8 +250,7 @@ class MediaCodecBridge { ...@@ -244,8 +250,7 @@ class MediaCodecBridge {
if (!supportedTypes[j].equalsIgnoreCase(mime)) if (!supportedTypes[j].equalsIgnoreCase(mime))
continue; continue;
MediaCodecInfo.CodecCapabilities capabilities = MediaCodecInfo.CodecCapabilities capabilities = info.getCapabilitiesForType(mime);
info.getCapabilitiesForType(mime);
return capabilities.colorFormats; return capabilities.colorFormats;
} }
} }
...@@ -401,14 +406,25 @@ class MediaCodecBridge { ...@@ -401,14 +406,25 @@ class MediaCodecBridge {
} }
} }
private boolean outputFormatHasCropValues(MediaFormat format) {
return format.containsKey(KEY_CROP_RIGHT) && format.containsKey(KEY_CROP_LEFT)
&& format.containsKey(KEY_CROP_BOTTOM) && format.containsKey(KEY_CROP_TOP);
}
@CalledByNative @CalledByNative
private int getOutputHeight() { private int getOutputHeight() {
return mMediaCodec.getOutputFormat().getInteger(MediaFormat.KEY_HEIGHT); MediaFormat format = mMediaCodec.getOutputFormat();
return outputFormatHasCropValues(format)
? format.getInteger(KEY_CROP_BOTTOM) - format.getInteger(KEY_CROP_TOP) + 1
: format.getInteger(MediaFormat.KEY_HEIGHT);
} }
@CalledByNative @CalledByNative
private int getOutputWidth() { private int getOutputWidth() {
return mMediaCodec.getOutputFormat().getInteger(MediaFormat.KEY_WIDTH); MediaFormat format = mMediaCodec.getOutputFormat();
return outputFormatHasCropValues(format)
? format.getInteger(KEY_CROP_RIGHT) - format.getInteger(KEY_CROP_LEFT) + 1
: format.getInteger(MediaFormat.KEY_WIDTH);
} }
@CalledByNative @CalledByNative
......
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 to comment