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

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

Issue 2508803002: Rotate frames correctly for back camera (Closed)
Patch Set: calculate rotation in video_capture_device_linux Created 4 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_linux.h" 5 #include "media/capture/video/linux/video_capture_device_linux.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <list> 9 #include <list>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "media/capture/video/linux/camera_characteristics.h"
14 #include "media/capture/video/linux/v4l2_capture_delegate.h" 15 #include "media/capture/video/linux/v4l2_capture_delegate.h"
15 16
16 #if defined(OS_OPENBSD) 17 #if defined(OS_OPENBSD)
17 #include <sys/videoio.h> 18 #include <sys/videoio.h>
18 #else 19 #else
19 #include <linux/videodev2.h> 20 #include <linux/videodev2.h>
20 #endif 21 #endif
21 22
22 namespace media { 23 namespace media {
23 24
24 // Translates Video4Linux pixel formats to Chromium pixel formats. 25 // Translates Video4Linux pixel formats to Chromium pixel formats.
25 // static 26 // static
26 VideoPixelFormat VideoCaptureDeviceLinux::V4l2FourCcToChromiumPixelFormat( 27 VideoPixelFormat VideoCaptureDeviceLinux::V4l2FourCcToChromiumPixelFormat(
27 uint32_t v4l2_fourcc) { 28 uint32_t v4l2_fourcc) {
28 return V4L2CaptureDelegate::V4l2FourCcToChromiumPixelFormat(v4l2_fourcc); 29 return V4L2CaptureDelegate::V4l2FourCcToChromiumPixelFormat(v4l2_fourcc);
29 } 30 }
30 31
31 // Gets a list of usable Four CC formats prioritized. 32 // Gets a list of usable Four CC formats prioritized.
32 // static 33 // static
33 std::list<uint32_t> VideoCaptureDeviceLinux::GetListOfUsableFourCCs( 34 std::list<uint32_t> VideoCaptureDeviceLinux::GetListOfUsableFourCCs(
34 bool favour_mjpeg) { 35 bool favour_mjpeg) {
35 return V4L2CaptureDelegate::GetListOfUsableFourCcs(favour_mjpeg); 36 return V4L2CaptureDelegate::GetListOfUsableFourCcs(favour_mjpeg);
36 } 37 }
37 38
38 VideoCaptureDeviceLinux::VideoCaptureDeviceLinux( 39 VideoCaptureDeviceLinux::VideoCaptureDeviceLinux(
39 const VideoCaptureDeviceDescriptor& device_descriptor) 40 const VideoCaptureDeviceDescriptor& device_descriptor)
40 : v4l2_thread_("V4L2CaptureThread"), 41 : v4l2_thread_("V4L2CaptureThread"),
41 device_descriptor_(device_descriptor) {} 42 device_descriptor_(device_descriptor),
43 is_back_camera_(GetCameraFacing(device_descriptor)) {}
42 44
43 VideoCaptureDeviceLinux::~VideoCaptureDeviceLinux() { 45 VideoCaptureDeviceLinux::~VideoCaptureDeviceLinux() {
44 // Check if the thread is running. 46 // Check if the thread is running.
45 // This means that the device has not been StopAndDeAllocate()d properly. 47 // This means that the device has not been StopAndDeAllocate()d properly.
46 DCHECK(!v4l2_thread_.IsRunning()); 48 DCHECK(!v4l2_thread_.IsRunning());
47 v4l2_thread_.Stop(); 49 v4l2_thread_.Stop();
48 } 50 }
49 51
50 void VideoCaptureDeviceLinux::AllocateAndStart( 52 void VideoCaptureDeviceLinux::AllocateAndStart(
51 const VideoCaptureParams& params, 53 const VideoCaptureParams& params,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 if (!v4l2_thread_.IsRunning()) 108 if (!v4l2_thread_.IsRunning())
107 return; // Wrong state. 109 return; // Wrong state.
108 v4l2_thread_.task_runner()->PostTask( 110 v4l2_thread_.task_runner()->PostTask(
109 FROM_HERE, 111 FROM_HERE,
110 base::Bind(&V4L2CaptureDelegate::SetPhotoOptions, capture_impl_, 112 base::Bind(&V4L2CaptureDelegate::SetPhotoOptions, capture_impl_,
111 base::Passed(&settings), base::Passed(&callback))); 113 base::Passed(&settings), base::Passed(&callback)));
112 } 114 }
113 115
114 void VideoCaptureDeviceLinux::SetRotation(int rotation) { 116 void VideoCaptureDeviceLinux::SetRotation(int rotation) {
115 if (v4l2_thread_.IsRunning()) { 117 if (v4l2_thread_.IsRunning()) {
118 if (is_back_camera_) {
119 // For back camera, we need to rotate (360 - screen_rotation).
120 // Ex: when screen rotation is 90, we have to rotate the frame by 270
wuchengli 2016/11/17 09:26:04 This example doesn't explain anything. This exampl
121 // clockwise.
122 rotation = (360 - rotation) % 360;
123 }
116 v4l2_thread_.task_runner()->PostTask( 124 v4l2_thread_.task_runner()->PostTask(
117 FROM_HERE, 125 FROM_HERE,
118 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation)); 126 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation));
119 } 127 }
120 } 128 }
121 129
122 // static 130 // static
123 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2( 131 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2(
124 PowerLineFrequency frequency) { 132 PowerLineFrequency frequency) {
125 switch (frequency) { 133 switch (frequency) {
126 case media::PowerLineFrequency::FREQUENCY_50HZ: 134 case media::PowerLineFrequency::FREQUENCY_50HZ:
127 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ; 135 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ;
128 case media::PowerLineFrequency::FREQUENCY_60HZ: 136 case media::PowerLineFrequency::FREQUENCY_60HZ:
129 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ; 137 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ;
130 default: 138 default:
131 // If we have no idea of the frequency, at least try and set it to AUTO. 139 // If we have no idea of the frequency, at least try and set it to AUTO.
132 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO; 140 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO;
133 } 141 }
134 } 142 }
135 143
144 bool VideoCaptureDeviceLinux::GetCameraFacing(
145 const VideoCaptureDeviceDescriptor& descriptor) {
146 CameraCharacteristics characteristics;
147 return characteristics.GetCameraFacing(descriptor.model_id) ==
148 DeviceInfo::LENS_FACING_BACK;
149 }
150
136 } // namespace media 151 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698