Commit c3a6583c authored by Rahul Singh's avatar Rahul Singh Committed by Commit Bot

Video Capture: Fix front camera rotation for portrait orientation

Windows devices

Currently, GetCameraRotation() in video_capture_device_utils_win.cc
assumes a landscape device. On upcoming Windows devices with naturally
portrait displays this leads to the video capture feed being off by 90
degrees counterclockwise. This is because the camera continues to be
mounted in a landscape orientation while the display is naturally
portrait.

This CL adds IsPortraitDevice() in video_capture_device_utils_win.cc
which deduces whether we are running on a portrait orientation Windows
device. This method is called as part of GetCameraRotation() and helps
us correct the video rotation by 90 degrees counterclockwise for
portrait orientation devices.

Testing:
Verified that with this change:
1. Front camera on portrait orientation devices rotates correctly.
2. We preserve existing rotation behavior on landscape
orientation devices and when external cameras are attached.

Bug: 1061541
Change-Id: I4a7e9552471242c544ee181ab0d0f4685c09f1d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354539Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Rahul Singh <rahsin@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#798252}
parent 852b79ac
......@@ -13,8 +13,20 @@
namespace media {
namespace {
const int kDegreesToArcSeconds = 3600;
const int kSecondsTo100MicroSeconds = 10000;
// Determines if camera is mounted on a device with naturally portrait display.
bool IsPortraitDevice(DWORD display_height,
DWORD display_width,
int device_angle) {
if (device_angle == 0 || device_angle == 180)
return display_height >= display_width;
else
return display_height < display_width;
}
} // namespace
// Windows platform stores pan and tilt (min, max, step and current) in
......@@ -97,6 +109,7 @@ int GetCameraRotation(VideoFacingMode facing) {
if (::EnumDisplaySettings(internal_display_device.DeviceName,
ENUM_CURRENT_SETTINGS, &mode)) {
int device_orientation = 0;
int portrait_correction = 0;
switch (mode.dmDisplayOrientation) {
case DMDO_DEFAULT:
device_orientation = 0;
......@@ -111,7 +124,13 @@ int GetCameraRotation(VideoFacingMode facing) {
device_orientation = 270;
break;
}
rotation = (360 - device_orientation) % 360;
// Correct the 90 degree offset between the camera mounted in landscape and
// the default orientation on a naturally portrait device.
if (IsPortraitDevice(mode.dmPelsHeight, mode.dmPelsWidth,
device_orientation)) {
portrait_correction = 90;
}
rotation = (360 - device_orientation - portrait_correction) % 360;
}
return rotation;
......
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