Chromium Code Reviews| 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/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "media/capture/video/linux/v4l2_capture_delegate.h" | |
| 14 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 15 #include "ui/display/display_observer.h" | 16 #include "ui/display/display_observer.h" |
| 16 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
| 17 | 18 |
| 18 namespace media { | 19 namespace media { |
| 19 | 20 |
| 20 // This is a delegate class used to transfer Display change events from the UI | 21 // This is a delegate class used to transfer Display change events from the UI |
| 21 // thread to the media thread. | 22 // thread to the media thread. |
| 22 class VideoCaptureDeviceChromeOS::ScreenObserverDelegate | 23 class VideoCaptureDeviceChromeOS::ScreenObserverDelegate |
| 23 : public display::DisplayObserver, | 24 : public display::DisplayObserver, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 93 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 93 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; | 94 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; |
| 94 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate); | 95 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate); |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS( | 98 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS( |
| 98 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 99 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 99 const VideoCaptureDeviceDescriptor& device_descriptor) | 100 const VideoCaptureDeviceDescriptor& device_descriptor) |
| 100 : VideoCaptureDeviceLinux(device_descriptor), | 101 : VideoCaptureDeviceLinux(device_descriptor), |
| 101 screen_observer_delegate_( | 102 screen_observer_delegate_( |
| 102 new ScreenObserverDelegate(this, ui_task_runner)) {} | 103 new ScreenObserverDelegate(this, ui_task_runner)), |
| 104 lens_facing_(CameraDeviceInfo::UNINITIALIZED), | |
| 105 camera_characteristics_(LAZY_INSTANCE_INITIALIZER) {} | |
| 103 | 106 |
| 104 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() { | 107 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() { |
| 105 screen_observer_delegate_->RemoveObserver(); | 108 screen_observer_delegate_->RemoveObserver(); |
| 106 } | 109 } |
| 107 | 110 |
| 111 void VideoCaptureDeviceChromeOS::SetRotation(int rotation) { | |
| 112 if (v4l2_thread_.IsRunning()) { | |
| 113 if (lens_facing_ == CameraDeviceInfo::UNINITIALIZED) { | |
| 114 camera_characteristics_.Get().InitializeDeviceInfo(); | |
|
kcwu
2016/11/24 15:48:52
Will VideoCaptureDeviceChromeOS be created more th
shenghao
2016/11/28 08:52:04
Done.
| |
| 115 lens_facing_ = camera_characteristics_.Get().GetCameraFacing( | |
|
kcwu
2016/11/24 15:48:52
If there are two cameras starting capture at the s
kcwu
2016/11/28 05:48:43
FYI, http://stackoverflow.com/questions/5912539/st
shenghao
2016/11/28 08:52:04
Methods like find() can be called safely according
| |
| 116 device_descriptor_.device_id, device_descriptor_.model_id); | |
| 117 } | |
| 118 // We assume external camera is facing the users. If not, the users can | |
| 119 // rotate the camera manually by themselves. | |
| 120 if (lens_facing_ == CameraDeviceInfo::LENS_FACING_BACK) { | |
| 121 // Original frame when screen_rotation = 0 | |
| 122 // ----------------------- | |
| 123 // | * | | |
| 124 // | * * | | |
| 125 // | * * | | |
| 126 // | ******* | | |
| 127 // | * * | | |
| 128 // | * * | | |
| 129 // ----------------------- | |
| 130 // | |
| 131 // screen_rotation = 90, this is what back camera sees | |
| 132 // ----------------------- | |
| 133 // | ******** | | |
| 134 // | * **** | | |
| 135 // | * *** | | |
| 136 // | * *** | | |
| 137 // | * **** | | |
| 138 // | ******** | | |
| 139 // ----------------------- | |
| 140 // | |
| 141 // screen_rotation = 90, this is what front camera sees | |
|
kcwu
2016/11/24 15:48:52
270 ?
shenghao
2016/11/28 08:52:04
This is 90. We want to demonstrate the difference
| |
| 142 // ----------------------- | |
| 143 // | ******** | | |
| 144 // | **** * | | |
| 145 // | *** * | | |
| 146 // | *** * | | |
| 147 // | **** * | | |
| 148 // | ******** | | |
| 149 // ----------------------- | |
| 150 // | |
| 151 // Therefore, for back camera, we need to rotate (360 - screen_rotation). | |
| 152 rotation = (360 - rotation) % 360; | |
| 153 } | |
| 154 v4l2_thread_.task_runner()->PostTask( | |
|
kcwu
2016/11/24 15:48:52
How about call
VideoCaptureDeviceLinux::SetRotatio
shenghao
2016/11/28 08:52:04
Done.
| |
| 155 FROM_HERE, | |
| 156 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation)); | |
| 157 } | |
| 158 } | |
| 159 | |
| 108 void VideoCaptureDeviceChromeOS::SetDisplayRotation( | 160 void VideoCaptureDeviceChromeOS::SetDisplayRotation( |
| 109 const display::Display& display) { | 161 const display::Display& display) { |
| 110 if (display.IsInternal()) | 162 if (display.IsInternal()) |
| 111 SetRotation(display.rotation() * 90); | 163 SetRotation(display.rotation() * 90); |
| 112 } | 164 } |
| 113 | 165 |
| 114 } // namespace media | 166 } // namespace media |
| OLD | NEW |