Commit da2a0af3 authored by Fish Lin's avatar Fish Lin Committed by Commit Bot

Video Capture: update capturing dimension based on camera orientation

With device's native orientation being Portrait mode, for devices with
camera orientation of 0 or 180 degs, the capturing width and height
needs to be swapped in order to capture in respect to device's current
orientation.

Bug: 1032902
Test: Duo calling on devices with different camera orientation
Change-Id: Ib8d718cd2787011003ba9b1e2e578eaf310d50de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1961300
Commit-Queue: Fish Lin <linfish@google.com>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727024}
parent 5a0d7d03
...@@ -1472,9 +1472,29 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -1472,9 +1472,29 @@ public class VideoCaptureCamera2 extends VideoCapture {
final StreamConfigurationMap streamMap = final StreamConfigurationMap streamMap =
cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
mCameraNativeOrientation =
cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
// Update the capture width and height based on the camera orientation.
// With device's native orientation being Portrait for Android devices,
// for cameras that are mounted 0 or 180 degrees in respect to device's
// native orientation, we will need to swap the width and height in
// order to capture upright frames in respect to device's current
// orientation.
int capture_width = width;
int capture_height = height;
if (mCameraNativeOrientation == 0 || mCameraNativeOrientation == 180) {
Log.d(TAG,
"Flipping capture width and height to match device's "
+ "natural orientation");
capture_width = height;
capture_height = width;
}
// Find closest supported size. // Find closest supported size.
final Size[] supportedSizes = streamMap.getOutputSizes(ImageFormat.YUV_420_888); final Size[] supportedSizes = streamMap.getOutputSizes(ImageFormat.YUV_420_888);
final Size closestSupportedSize = findClosestSizeInArray(supportedSizes, width, height); final Size closestSupportedSize =
findClosestSizeInArray(supportedSizes, capture_width, capture_height);
if (closestSupportedSize == null) { if (closestSupportedSize == null) {
Log.e(TAG, "No supported resolutions."); Log.e(TAG, "No supported resolutions.");
return false; return false;
...@@ -1505,8 +1525,7 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -1505,8 +1525,7 @@ public class VideoCaptureCamera2 extends VideoCapture {
// |mCaptureFormat| is also used to configure the ImageReader. // |mCaptureFormat| is also used to configure the ImageReader.
mCaptureFormat = new VideoCaptureFormat(closestSupportedSize.getWidth(), mCaptureFormat = new VideoCaptureFormat(closestSupportedSize.getWidth(),
closestSupportedSize.getHeight(), frameRate, ImageFormat.YUV_420_888); closestSupportedSize.getHeight(), frameRate, ImageFormat.YUV_420_888);
mCameraNativeOrientation =
cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
// TODO(mcasas): The following line is correct for N5 with prerelease Build, // TODO(mcasas): The following line is correct for N5 with prerelease Build,
// but NOT for N7 with a dev Build. Figure out which one to support. // but NOT for N7 with a dev Build. Figure out which one to support.
mInvertDeviceOrientationReadings = mInvertDeviceOrientationReadings =
......
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