OLD | NEW |
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 Loading... |
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 camera_orientation_( |
| 115 g_camera_config_.Get().GetOrientation(device_descriptor.device_id, |
| 116 device_descriptor.model_id)) {} |
114 | 117 |
115 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() { | 118 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() { |
116 screen_observer_delegate_->RemoveObserver(); | 119 screen_observer_delegate_->RemoveObserver(); |
117 } | 120 } |
118 | 121 |
119 void VideoCaptureDeviceChromeOS::SetRotation(int rotation) { | 122 void VideoCaptureDeviceChromeOS::SetRotation(int rotation) { |
120 // We assume external camera is facing the users. If not, the users can | 123 // We assume external camera is facing the users. If not, the users can |
121 // rotate the camera manually by themselves. | 124 // rotate the camera manually by themselves. |
122 if (lens_facing_ == VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT) { | 125 if (lens_facing_ == VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT) { |
123 // Original frame when |rotation| = 0 | 126 // Original frame when |rotation| = 0 |
(...skipping 22 matching lines...) Expand all Loading... |
146 // | **** * | | 149 // | **** * | |
147 // | *** * | | 150 // | *** * | |
148 // | *** * | | 151 // | *** * | |
149 // | **** * | | 152 // | **** * | |
150 // | ******** | | 153 // | ******** | |
151 // ----------------------- | 154 // ----------------------- |
152 // | 155 // |
153 // Therefore, for back camera, we need to rotate (360 - |rotation|). | 156 // Therefore, for back camera, we need to rotate (360 - |rotation|). |
154 rotation = (360 - rotation) % 360; | 157 rotation = (360 - rotation) % 360; |
155 } | 158 } |
| 159 // Take into account camera orientation w.r.t. the display. |
| 160 rotation = (rotation + camera_orientation_) % 360; |
156 VideoCaptureDeviceLinux::SetRotation(rotation); | 161 VideoCaptureDeviceLinux::SetRotation(rotation); |
157 } | 162 } |
158 | 163 |
159 void VideoCaptureDeviceChromeOS::SetDisplayRotation( | 164 void VideoCaptureDeviceChromeOS::SetDisplayRotation( |
160 const display::Display& display) { | 165 const display::Display& display) { |
161 if (display.IsInternal()) | 166 if (display.IsInternal()) |
162 SetRotation(display.rotation() * 90); | 167 SetRotation(display.rotation() * 90); |
163 } | 168 } |
164 | 169 |
165 } // namespace media | 170 } // namespace media |
OLD | NEW |