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

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

Issue 2558483003: Reland of rotate frames correctly for back camera (Closed)
Patch Set: fix compiler error 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"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.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
21 namespace {
22
23 base::LazyInstance<CameraFacingChromeOS>::Leaky g_camera_facing_ =
24 LAZY_INSTANCE_INITIALIZER;
25
26 } // namespace
27
20 // 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
21 // thread to the media thread. 29 // thread to the media thread.
22 class VideoCaptureDeviceChromeOS::ScreenObserverDelegate 30 class VideoCaptureDeviceChromeOS::ScreenObserverDelegate
23 : public display::DisplayObserver, 31 : public display::DisplayObserver,
24 public base::RefCountedThreadSafe<ScreenObserverDelegate> { 32 public base::RefCountedThreadSafe<ScreenObserverDelegate> {
25 public: 33 public:
26 ScreenObserverDelegate( 34 ScreenObserverDelegate(
27 VideoCaptureDeviceChromeOS* capture_device, 35 VideoCaptureDeviceChromeOS* capture_device,
28 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) 36 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
29 : capture_device_(capture_device), 37 : capture_device_(capture_device),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 100 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
93 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; 101 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
94 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate); 102 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate);
95 }; 103 };
96 104
97 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS( 105 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(
98 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, 106 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
99 const VideoCaptureDeviceDescriptor& device_descriptor) 107 const VideoCaptureDeviceDescriptor& device_descriptor)
100 : VideoCaptureDeviceLinux(device_descriptor), 108 : VideoCaptureDeviceLinux(device_descriptor),
101 screen_observer_delegate_( 109 screen_observer_delegate_(
102 new ScreenObserverDelegate(this, ui_task_runner)) {} 110 new ScreenObserverDelegate(this, ui_task_runner)),
111 lens_facing_(
112 g_camera_facing_.Get().GetCameraFacing(device_descriptor.device_id,
113 device_descriptor.model_id)) {}
103 114
104 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() { 115 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() {
105 screen_observer_delegate_->RemoveObserver(); 116 screen_observer_delegate_->RemoveObserver();
106 } 117 }
107 118
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
108 void VideoCaptureDeviceChromeOS::SetDisplayRotation( 159 void VideoCaptureDeviceChromeOS::SetDisplayRotation(
109 const display::Display& display) { 160 const display::Display& display) {
110 if (display.IsInternal()) 161 if (display.IsInternal())
111 SetRotation(display.rotation() * 90); 162 SetRotation(display.rotation() * 90);
112 } 163 }
113 164
114 } // namespace media 165 } // 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