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

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

Issue 2554903002: Revert of Rotate frames correctly for back camera (Closed)
Patch Set: Created 4 years 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"
11 #include "base/macros.h" 10 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
15 #include "ui/display/display.h" 14 #include "ui/display/display.h"
16 #include "ui/display/display_observer.h" 15 #include "ui/display/display_observer.h"
17 #include "ui/display/screen.h" 16 #include "ui/display/screen.h"
18 17
19 namespace media { 18 namespace media {
20 19
21 namespace {
22
23 base::LazyInstance<CameraFacingChromeOS>::Leaky g_camera_facing_ =
24 LAZY_INSTANCE_INITIALIZER;
25
26 } // namespace
27
28 // This is a delegate class used to transfer Display change events from the UI 20 // This is a delegate class used to transfer Display change events from the UI
29 // thread to the media thread. 21 // thread to the media thread.
30 class VideoCaptureDeviceChromeOS::ScreenObserverDelegate 22 class VideoCaptureDeviceChromeOS::ScreenObserverDelegate
31 : public display::DisplayObserver, 23 : public display::DisplayObserver,
32 public base::RefCountedThreadSafe<ScreenObserverDelegate> { 24 public base::RefCountedThreadSafe<ScreenObserverDelegate> {
33 public: 25 public:
34 ScreenObserverDelegate( 26 ScreenObserverDelegate(
35 VideoCaptureDeviceChromeOS* capture_device, 27 VideoCaptureDeviceChromeOS* capture_device,
36 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) 28 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
37 : capture_device_(capture_device), 29 : capture_device_(capture_device),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 92 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
101 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; 93 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
102 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate); 94 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate);
103 }; 95 };
104 96
105 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS( 97 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(
106 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, 98 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
107 const VideoCaptureDeviceDescriptor& device_descriptor) 99 const VideoCaptureDeviceDescriptor& device_descriptor)
108 : VideoCaptureDeviceLinux(device_descriptor), 100 : VideoCaptureDeviceLinux(device_descriptor),
109 screen_observer_delegate_( 101 screen_observer_delegate_(
110 new ScreenObserverDelegate(this, ui_task_runner)), 102 new ScreenObserverDelegate(this, ui_task_runner)) {}
111 lens_facing_(
112 g_camera_facing_.Get().GetCameraFacing(device_descriptor.device_id,
113 device_descriptor.model_id)) {}
114 103
115 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() { 104 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() {
116 screen_observer_delegate_->RemoveObserver(); 105 screen_observer_delegate_->RemoveObserver();
117 } 106 }
118 107
119 void VideoCaptureDeviceChromeOS::SetRotation(int rotation) {
120 // We assume external camera is facing the users. If not, the users can
121 // rotate the camera manually by themselves.
122 if (lens_facing_ == CameraFacingChromeOS::LensFacing::BACK) {
123 // Original frame when |rotation| = 0
124 // -----------------------
125 // | * |
126 // | * * |
127 // | * * |
128 // | ******* |
129 // | * * |
130 // | * * |
131 // -----------------------
132 //
133 // |rotation| = 90, this is what back camera sees
134 // -----------------------
135 // | ******** |
136 // | * **** |
137 // | * *** |
138 // | * *** |
139 // | * **** |
140 // | ******** |
141 // -----------------------
142 //
143 // |rotation| = 90, this is what front camera sees
144 // -----------------------
145 // | ******** |
146 // | **** * |
147 // | *** * |
148 // | *** * |
149 // | **** * |
150 // | ******** |
151 // -----------------------
152 //
153 // Therefore, for back camera, we need to rotate (360 - |rotation|).
154 rotation = (360 - rotation) % 360;
155 }
156 VideoCaptureDeviceLinux::SetRotation(rotation);
157 }
158
159 void VideoCaptureDeviceChromeOS::SetDisplayRotation( 108 void VideoCaptureDeviceChromeOS::SetDisplayRotation(
160 const display::Display& display) { 109 const display::Display& display) {
161 if (display.IsInternal()) 110 if (display.IsInternal())
162 SetRotation(display.rotation() * 90); 111 SetRotation(display.rotation() * 90);
163 } 112 }
164 113
165 } // namespace media 114 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/linux/video_capture_device_chromeos.h ('k') | media/capture/video/linux/video_capture_device_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698