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

Side by Side Diff: media/capture/video/linux/video_capture_device_chromeos.cc

Issue 2648743002: Rotate frames according to camera orientation (Closed)
Patch Set: Created 3 years, 11 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/capture/video/linux/video_capture_device_chromeos.h" 5 #include "media/capture/video/linux/video_capture_device_chromeos.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "ui/display/display.h" 15 #include "ui/display/display.h"
16 #include "ui/display/display_observer.h" 16 #include "ui/display/display_observer.h"
17 #include "ui/display/screen.h" 17 #include "ui/display/screen.h"
18 18
19 namespace media { 19 namespace media {
20 20
21 namespace { 21 namespace {
22 22
23 base::LazyInstance<CameraFacingChromeOS>::Leaky g_camera_facing_ = 23 base::LazyInstance<CameraConfigChromeOS>::Leaky g_camera_config_ =
24 LAZY_INSTANCE_INITIALIZER; 24 LAZY_INSTANCE_INITIALIZER;
25 25
26 } // namespace 26 } // namespace
27 27
28 // This is a delegate class used to transfer Display change events from the UI 28 // This is a delegate class used to transfer Display change events from the UI
29 // thread to the media thread. 29 // thread to the media thread.
30 class VideoCaptureDeviceChromeOS::ScreenObserverDelegate 30 class VideoCaptureDeviceChromeOS::ScreenObserverDelegate
31 : public display::DisplayObserver, 31 : public display::DisplayObserver,
32 public base::RefCountedThreadSafe<ScreenObserverDelegate> { 32 public base::RefCountedThreadSafe<ScreenObserverDelegate> {
33 public: 33 public:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate); 102 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate);
103 }; 103 };
104 104
105 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS( 105 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(
106 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, 106 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
107 const VideoCaptureDeviceDescriptor& device_descriptor) 107 const VideoCaptureDeviceDescriptor& device_descriptor)
108 : VideoCaptureDeviceLinux(device_descriptor), 108 : VideoCaptureDeviceLinux(device_descriptor),
109 screen_observer_delegate_( 109 screen_observer_delegate_(
110 new ScreenObserverDelegate(this, ui_task_runner)), 110 new ScreenObserverDelegate(this, ui_task_runner)),
111 lens_facing_( 111 lens_facing_(
112 g_camera_facing_.Get().GetCameraFacing(device_descriptor.device_id, 112 g_camera_config_.Get().GetCameraFacing(device_descriptor.device_id,
113 device_descriptor.model_id)) {} 113 device_descriptor.model_id)),
114 orientation_(g_camera_config_.Get().GetOrientation(device_descriptor.devic e_id, device_descriptor.model_id)) {}
114 115
115 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() { 116 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() {
116 screen_observer_delegate_->RemoveObserver(); 117 screen_observer_delegate_->RemoveObserver();
117 } 118 }
118 119
119 void VideoCaptureDeviceChromeOS::SetRotation(int rotation) { 120 void VideoCaptureDeviceChromeOS::SetRotation(int rotation) {
120 // We assume external camera is facing the users. If not, the users can 121 // We assume external camera is facing the users. If not, the users can
121 // rotate the camera manually by themselves. 122 // rotate the camera manually by themselves.
122 if (lens_facing_ == VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT) { 123 if (lens_facing_ == VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT) {
123 // Original frame when |rotation| = 0 124 // Original frame when |rotation| = 0
(...skipping 22 matching lines...) Expand all
146 // | **** * | 147 // | **** * |
147 // | *** * | 148 // | *** * |
148 // | *** * | 149 // | *** * |
149 // | **** * | 150 // | **** * |
150 // | ******** | 151 // | ******** |
151 // ----------------------- 152 // -----------------------
152 // 153 //
153 // Therefore, for back camera, we need to rotate (360 - |rotation|). 154 // Therefore, for back camera, we need to rotate (360 - |rotation|).
154 rotation = (360 - rotation) % 360; 155 rotation = (360 - rotation) % 360;
155 } 156 }
157 // Take into account camera orientation w.r.t. the display.
158 rotation = (rotation + orientation_) % 360;
156 VideoCaptureDeviceLinux::SetRotation(rotation); 159 VideoCaptureDeviceLinux::SetRotation(rotation);
157 } 160 }
158 161
159 void VideoCaptureDeviceChromeOS::SetDisplayRotation( 162 void VideoCaptureDeviceChromeOS::SetDisplayRotation(
160 const display::Display& display) { 163 const display::Display& display) {
161 if (display.IsInternal()) 164 if (display.IsInternal())
162 SetRotation(display.rotation() * 90); 165 SetRotation(display.rotation() * 90);
163 } 166 }
164 167
165 } // namespace media 168 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698