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

Unified Diff: media/capture/video/linux/video_capture_device_chromeos.cc

Issue 2508803002: Rotate frames correctly for back camera (Closed)
Patch Set: misc review comments Created 4 years, 1 month 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
Index: media/capture/video/linux/video_capture_device_chromeos.cc
diff --git a/media/capture/video/linux/video_capture_device_chromeos.cc b/media/capture/video/linux/video_capture_device_chromeos.cc
index 1e6006c734ab71b66f6353794a6f244571b424ae..aba144d0f7615c8de7d403812d6000ba5e2f0bd1 100644
--- a/media/capture/video/linux/video_capture_device_chromeos.cc
+++ b/media/capture/video/linux/video_capture_device_chromeos.cc
@@ -7,6 +7,7 @@
#include <stdint.h>
#include "base/bind.h"
+#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
@@ -17,6 +18,13 @@
namespace media {
+namespace {
+
+base::LazyInstance<CameraCharacteristics> g_camera_characteristics_ =
mcasas 2016/11/29 19:12:56 Use base::LazyInstane<>::Leaky to avoid slowing do
shenghao 2016/12/01 07:34:21 Done.
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
// This is a delegate class used to transfer Display change events from the UI
// thread to the media thread.
class VideoCaptureDeviceChromeOS::ScreenObserverDelegate
@@ -99,12 +107,55 @@ VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(
const VideoCaptureDeviceDescriptor& device_descriptor)
: VideoCaptureDeviceLinux(device_descriptor),
screen_observer_delegate_(
- new ScreenObserverDelegate(this, ui_task_runner)) {}
+ new ScreenObserverDelegate(this, ui_task_runner)),
+ lens_facing_(g_camera_characteristics_.Get().GetCameraFacing(
+ device_descriptor.device_id,
+ device_descriptor.model_id)) {}
mcasas 2016/11/29 19:12:56 Make |lens_facing_| const and initialize it inste
shenghao 2016/12/01 07:34:21 I don't understand. Ain't I initializing it instea
mcasas 2016/12/03 03:37:11 You're assigning right now. As it is, the compiler
VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() {
screen_observer_delegate_->RemoveObserver();
}
+void VideoCaptureDeviceChromeOS::SetRotation(int rotation) {
+ // We assume external camera is facing the users. If not, the users can
+ // rotate the camera manually by themselves.
+ if (lens_facing_ == CameraDeviceInfo::LensFacing::kBack) {
+ // Original frame when screen_rotation = 0
mcasas 2016/11/29 19:12:56 Here and elsewhere in these comments s/screen_rota
shenghao 2016/12/01 07:34:21 Done.
+ // -----------------------
+ // | * |
+ // | * * |
+ // | * * |
+ // | ******* |
+ // | * * |
+ // | * * |
+ // -----------------------
+ //
+ // screen_rotation = 90, this is what back camera sees
+ // -----------------------
+ // | ******** |
+ // | * **** |
+ // | * *** |
+ // | * *** |
+ // | * **** |
+ // | ******** |
+ // -----------------------
+ //
+ // screen_rotation = 90, this is what front camera sees
+ // -----------------------
+ // | ******** |
+ // | **** * |
+ // | *** * |
+ // | *** * |
+ // | **** * |
+ // | ******** |
+ // -----------------------
+ //
+ // Therefore, for back camera, we need to rotate (360 - screen_rotation).
+ rotation = (360 - rotation) % 360;
+ }
+ VideoCaptureDeviceLinux::SetRotation(rotation);
+}
+
void VideoCaptureDeviceChromeOS::SetDisplayRotation(
const display::Display& display) {
if (display.IsInternal())

Powered by Google App Engine
This is Rietveld 408576698