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

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

Issue 2609863004: Pass camera facing to WebKit (Closed)
Patch Set: change comments Created 3 years, 11 months 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_factory_linux.h" 5 #include "media/capture/video/linux/video_capture_device_factory_linux.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <sys/ioctl.h> 10 #include <sys/ioctl.h>
11 11
12 #include "base/files/file_enumerator.h" 12 #include "base/files/file_enumerator.h"
13 #include "base/files/scoped_file.h" 13 #include "base/files/scoped_file.h"
14 #include "base/posix/eintr_wrapper.h" 14 #include "base/posix/eintr_wrapper.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 17
18 #if defined(OS_OPENBSD) 18 #if defined(OS_OPENBSD)
19 #include <sys/videoio.h> 19 #include <sys/videoio.h>
20 #else 20 #else
21 #include <linux/videodev2.h> 21 #include <linux/videodev2.h>
22 #endif 22 #endif
23 23
24 #if defined(OS_CHROMEOS) 24 #if defined(OS_CHROMEOS)
25 #include "base/lazy_instance.h"
26 #include "media/capture/video/linux/camera_facing_chromeos.h"
25 #include "media/capture/video/linux/video_capture_device_chromeos.h" 27 #include "media/capture/video/linux/video_capture_device_chromeos.h"
26 #endif 28 #endif
27 #include "media/capture/video/linux/video_capture_device_linux.h" 29 #include "media/capture/video/linux/video_capture_device_linux.h"
28 30
29 namespace media { 31 namespace media {
30 32
33 namespace {
34
35 #if defined(OS_CHROMEOS)
36 base::LazyInstance<media::CameraFacingChromeOS>::Leaky g_camera_facing_helper =
37 LAZY_INSTANCE_INITIALIZER;
38 #endif
39 }
40
31 // USB VID and PID are both 4 bytes long. 41 // USB VID and PID are both 4 bytes long.
32 static const size_t kVidPidSize = 4; 42 static const size_t kVidPidSize = 4;
33 43
34 // /sys/class/video4linux/video{N}/device is a symlink to the corresponding 44 // /sys/class/video4linux/video{N}/device is a symlink to the corresponding
35 // USB device info directory. 45 // USB device info directory.
36 static const char kVidPathTemplate[] = 46 static const char kVidPathTemplate[] =
37 "/sys/class/video4linux/%s/device/../idVendor"; 47 "/sys/class/video4linux/%s/device/../idVendor";
38 static const char kPidPathTemplate[] = 48 static const char kPidPathTemplate[] =
39 "/sys/class/video4linux/%s/device/../idProduct"; 49 "/sys/class/video4linux/%s/device/../idProduct";
40 50
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // Test if this is a V4L2 capture device and if it has at least one 208 // Test if this is a V4L2 capture device and if it has at least one
199 // supported capture format. Devices that have capture and output 209 // supported capture format. Devices that have capture and output
200 // capabilities at the same time are memory-to-memory and are skipped, see 210 // capabilities at the same time are memory-to-memory and are skipped, see
201 // http://crbug.com/139356. 211 // http://crbug.com/139356.
202 v4l2_capability cap; 212 v4l2_capability cap;
203 if ((HANDLE_EINTR(ioctl(fd.get(), VIDIOC_QUERYCAP, &cap)) == 0) && 213 if ((HANDLE_EINTR(ioctl(fd.get(), VIDIOC_QUERYCAP, &cap)) == 0) &&
204 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE && 214 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE &&
205 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)) && 215 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)) &&
206 HasUsableFormats(fd.get(), cap.capabilities)) { 216 HasUsableFormats(fd.get(), cap.capabilities)) {
207 const std::string model_id = GetDeviceModelId(unique_id); 217 const std::string model_id = GetDeviceModelId(unique_id);
218 #if defined(OS_CHROMEOS)
219 device_descriptors->emplace_back(
220 reinterpret_cast<char*>(cap.card), unique_id, model_id,
221 VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE,
222 VideoCaptureTransportType::OTHER_TRANSPORT,
223 g_camera_facing_helper.Get().GetCameraFacing(unique_id, model_id));
224 #else
208 device_descriptors->emplace_back( 225 device_descriptors->emplace_back(
209 reinterpret_cast<char*>(cap.card), unique_id, model_id, 226 reinterpret_cast<char*>(cap.card), unique_id, model_id,
210 VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE); 227 VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE);
228 #endif
211 } 229 }
212 } 230 }
213 } 231 }
214 232
215 void VideoCaptureDeviceFactoryLinux::GetSupportedFormats( 233 void VideoCaptureDeviceFactoryLinux::GetSupportedFormats(
216 const VideoCaptureDeviceDescriptor& device, 234 const VideoCaptureDeviceDescriptor& device,
217 VideoCaptureFormats* supported_formats) { 235 VideoCaptureFormats* supported_formats) {
218 DCHECK(thread_checker_.CalledOnValidThread()); 236 DCHECK(thread_checker_.CalledOnValidThread());
219 if (device.device_id.empty()) 237 if (device.device_id.empty())
220 return; 238 return;
(...skipping 30 matching lines...) Expand all
251 } 269 }
252 270
253 // static 271 // static
254 VideoCaptureDeviceFactory* 272 VideoCaptureDeviceFactory*
255 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( 273 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory(
256 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { 274 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
257 return new VideoCaptureDeviceFactoryLinux(ui_task_runner); 275 return new VideoCaptureDeviceFactoryLinux(ui_task_runner);
258 } 276 }
259 277
260 } // namespace media 278 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/linux/video_capture_device_chromeos.cc ('k') | media/capture/video/video_capture_device_descriptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698