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

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

Issue 2508803002: Rotate frames correctly for back camera (Closed)
Patch Set: remove unused header 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,
52 std::unique_ptr<VideoCaptureDevice::Client> client) { 54 std::unique_ptr<VideoCaptureDevice::Client> client) {
53 DCHECK(!capture_impl_); 55 DCHECK(!capture_impl_);
54 if (v4l2_thread_.IsRunning()) 56 if (v4l2_thread_.IsRunning())
55 return; // Wrong state. 57 return; // Wrong state.
56 v4l2_thread_.Start(); 58 v4l2_thread_.Start();
57 59
58 const int line_frequency = 60 const int line_frequency =
59 TranslatePowerLineFrequencyToV4L2(GetPowerLineFrequency(params)); 61 TranslatePowerLineFrequencyToV4L2(GetPowerLineFrequency(params));
60 capture_impl_ = new V4L2CaptureDelegate( 62 capture_impl_ = new V4L2CaptureDelegate(
61 device_descriptor_, v4l2_thread_.task_runner(), line_frequency); 63 device_descriptor_, v4l2_thread_.task_runner(), line_frequency);
62 if (!capture_impl_) { 64 if (!capture_impl_) {
63 client->OnError(FROM_HERE, "Failed to create VideoCaptureDelegate"); 65 client->OnError(FROM_HERE, "Failed to create VideoCaptureDelegate");
64 return; 66 return;
65 } 67 }
68 client->SetCameraFacing(is_back_camera_);
66 v4l2_thread_.task_runner()->PostTask( 69 v4l2_thread_.task_runner()->PostTask(
67 FROM_HERE, 70 FROM_HERE,
68 base::Bind(&V4L2CaptureDelegate::AllocateAndStart, capture_impl_, 71 base::Bind(&V4L2CaptureDelegate::AllocateAndStart, capture_impl_,
69 params.requested_format.frame_size.width(), 72 params.requested_format.frame_size.width(),
70 params.requested_format.frame_size.height(), 73 params.requested_format.frame_size.height(),
71 params.requested_format.frame_rate, base::Passed(&client))); 74 params.requested_format.frame_rate, base::Passed(&client)));
72 } 75 }
73 76
74 void VideoCaptureDeviceLinux::StopAndDeAllocate() { 77 void VideoCaptureDeviceLinux::StopAndDeAllocate() {
75 if (!v4l2_thread_.IsRunning()) 78 if (!v4l2_thread_.IsRunning())
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 case media::PowerLineFrequency::FREQUENCY_50HZ: 129 case media::PowerLineFrequency::FREQUENCY_50HZ:
127 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ; 130 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ;
128 case media::PowerLineFrequency::FREQUENCY_60HZ: 131 case media::PowerLineFrequency::FREQUENCY_60HZ:
129 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ; 132 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ;
130 default: 133 default:
131 // If we have no idea of the frequency, at least try and set it to AUTO. 134 // If we have no idea of the frequency, at least try and set it to AUTO.
132 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO; 135 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO;
133 } 136 }
134 } 137 }
135 138
139 bool VideoCaptureDeviceLinux::GetCameraFacing(
wuchengli 2016/11/16 12:15:19 This is just two lines of code. We don't need a fu
shenghao 2016/11/17 08:41:44 But I need it to be a function so that I can initi
wuchengli 2016/11/17 09:26:04 Why not initialize it in the constructor?
shenghao 2016/11/17 10:15:54 Done.
140 const VideoCaptureDeviceDescriptor& descriptor) {
141 CameraCharacteristics characteristics;
142 return characteristics.GetCameraFacing(descriptor.model_id) == 1;
wuchengli 2016/11/16 12:15:19 Need a constant for 0 and 1.
shenghao 2016/11/17 08:41:44 Done.
143 }
144
136 } // namespace media 145 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698