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

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

Issue 2508803002: Rotate frames correctly for back camera (Closed)
Patch Set: add some comments 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"), device_descriptor_(device_descriptor) {
41 device_descriptor_(device_descriptor) {} 42 CameraCharacteristics characteristics;
43 is_back_camera_ =
44 characteristics.GetCameraFacing(device_descriptor.model_id) ==
45 DeviceInfo::LENS_FACING_BACK;
46 }
42 47
43 VideoCaptureDeviceLinux::~VideoCaptureDeviceLinux() { 48 VideoCaptureDeviceLinux::~VideoCaptureDeviceLinux() {
44 // Check if the thread is running. 49 // Check if the thread is running.
45 // This means that the device has not been StopAndDeAllocate()d properly. 50 // This means that the device has not been StopAndDeAllocate()d properly.
46 DCHECK(!v4l2_thread_.IsRunning()); 51 DCHECK(!v4l2_thread_.IsRunning());
47 v4l2_thread_.Stop(); 52 v4l2_thread_.Stop();
48 } 53 }
49 54
50 void VideoCaptureDeviceLinux::AllocateAndStart( 55 void VideoCaptureDeviceLinux::AllocateAndStart(
51 const VideoCaptureParams& params, 56 const VideoCaptureParams& params,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 if (!v4l2_thread_.IsRunning()) 111 if (!v4l2_thread_.IsRunning())
107 return; // Wrong state. 112 return; // Wrong state.
108 v4l2_thread_.task_runner()->PostTask( 113 v4l2_thread_.task_runner()->PostTask(
109 FROM_HERE, 114 FROM_HERE,
110 base::Bind(&V4L2CaptureDelegate::SetPhotoOptions, capture_impl_, 115 base::Bind(&V4L2CaptureDelegate::SetPhotoOptions, capture_impl_,
111 base::Passed(&settings), base::Passed(&callback))); 116 base::Passed(&settings), base::Passed(&callback)));
112 } 117 }
113 118
114 void VideoCaptureDeviceLinux::SetRotation(int rotation) { 119 void VideoCaptureDeviceLinux::SetRotation(int rotation) {
115 if (v4l2_thread_.IsRunning()) { 120 if (v4l2_thread_.IsRunning()) {
121 if (is_back_camera_) {
wuchengli 2016/11/18 05:08:50 Add a comment to explain we assume an external cam
shenghao 2016/11/21 06:24:53 Done.
122 // For back camera, we need to rotate (360 - screen_rotation).
123 // Ex: when screen rotation is 90, we have to rotate the frame by 270
124 // clockwise.
wuchengli 2016/11/18 05:08:50 Use ascii art to explain the image of front facing
shenghao 2016/11/21 06:24:53 Done.
125 rotation = (360 - rotation) % 360;
126 }
116 v4l2_thread_.task_runner()->PostTask( 127 v4l2_thread_.task_runner()->PostTask(
117 FROM_HERE, 128 FROM_HERE,
118 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation)); 129 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation));
119 } 130 }
120 } 131 }
121 132
122 // static 133 // static
123 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2( 134 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2(
124 PowerLineFrequency frequency) { 135 PowerLineFrequency frequency) {
125 switch (frequency) { 136 switch (frequency) {
126 case media::PowerLineFrequency::FREQUENCY_50HZ: 137 case media::PowerLineFrequency::FREQUENCY_50HZ:
127 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ; 138 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ;
128 case media::PowerLineFrequency::FREQUENCY_60HZ: 139 case media::PowerLineFrequency::FREQUENCY_60HZ:
129 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ; 140 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ;
130 default: 141 default:
131 // If we have no idea of the frequency, at least try and set it to AUTO. 142 // If we have no idea of the frequency, at least try and set it to AUTO.
132 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO; 143 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO;
133 } 144 }
134 } 145 }
135 146
136 } // namespace media 147 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698