Skip to content

Commit

Permalink
Video Capture: Fix front camera rotation for portrait orientation
Browse files Browse the repository at this point in the history
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/+/2354539
Reviewed-by: Guido Urdaneta <guidou@chromium.org>
Commit-Queue: Rahul Singh <rahsin@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#798252}
  • Loading branch information
rahulsingh-msft authored and Commit Bot committed Aug 14, 2020
1 parent 852b79a commit c3a6583
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion media/capture/video/win/video_capture_device_utils_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit c3a6583

Please sign in to comment.