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

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

Issue 2668813002: Remove LazyInstance usage from media/ (Closed)
Patch Set: Fix presubmit comments. Created 3 years, 10 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_config_chromeos.h" 25 #include "media/capture/video/linux/camera_config_chromeos.h"
27 #include "media/capture/video/linux/video_capture_device_chromeos.h" 26 #include "media/capture/video/linux/video_capture_device_chromeos.h"
28 #endif 27 #endif
29 #include "media/capture/video/linux/video_capture_device_linux.h" 28 #include "media/capture/video/linux/video_capture_device_linux.h"
30 29
31 namespace media { 30 namespace media {
32 31
33 namespace {
34
35 #if defined(OS_CHROMEOS)
36 base::LazyInstance<media::CameraConfigChromeOS>::Leaky g_camera_config =
37 LAZY_INSTANCE_INITIALIZER;
38 #endif
39 }
40
41 // USB VID and PID are both 4 bytes long. 32 // USB VID and PID are both 4 bytes long.
42 static const size_t kVidPidSize = 4; 33 static const size_t kVidPidSize = 4;
43 34
44 // /sys/class/video4linux/video{N}/device is a symlink to the corresponding 35 // /sys/class/video4linux/video{N}/device is a symlink to the corresponding
45 // USB device info directory. 36 // USB device info directory.
46 static const char kVidPathTemplate[] = 37 static const char kVidPathTemplate[] =
47 "/sys/class/video4linux/%s/device/../idVendor"; 38 "/sys/class/video4linux/%s/device/../idVendor";
48 static const char kPidPathTemplate[] = 39 static const char kPidPathTemplate[] =
49 "/sys/class/video4linux/%s/device/../idProduct"; 40 "/sys/class/video4linux/%s/device/../idProduct";
50 41
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // supported capture format. Devices that have capture and output 200 // supported capture format. Devices that have capture and output
210 // capabilities at the same time are memory-to-memory and are skipped, see 201 // capabilities at the same time are memory-to-memory and are skipped, see
211 // http://crbug.com/139356. 202 // http://crbug.com/139356.
212 v4l2_capability cap; 203 v4l2_capability cap;
213 if ((HANDLE_EINTR(ioctl(fd.get(), VIDIOC_QUERYCAP, &cap)) == 0) && 204 if ((HANDLE_EINTR(ioctl(fd.get(), VIDIOC_QUERYCAP, &cap)) == 0) &&
214 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE && 205 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE &&
215 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)) && 206 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)) &&
216 HasUsableFormats(fd.get(), cap.capabilities)) { 207 HasUsableFormats(fd.get(), cap.capabilities)) {
217 const std::string model_id = GetDeviceModelId(unique_id); 208 const std::string model_id = GetDeviceModelId(unique_id);
218 #if defined(OS_CHROMEOS) 209 #if defined(OS_CHROMEOS)
210 static CameraConfigChromeOS* config = new CameraConfigChromeOS();
219 device_descriptors->emplace_back( 211 device_descriptors->emplace_back(
220 reinterpret_cast<char*>(cap.card), unique_id, model_id, 212 reinterpret_cast<char*>(cap.card), unique_id, model_id,
221 VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE, 213 VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE,
222 VideoCaptureTransportType::OTHER_TRANSPORT, 214 VideoCaptureTransportType::OTHER_TRANSPORT,
223 g_camera_config.Get().GetCameraFacing(unique_id, model_id)); 215 config->GetCameraFacing(unique_id, model_id));
224 #else 216 #else
225 device_descriptors->emplace_back( 217 device_descriptors->emplace_back(
226 reinterpret_cast<char*>(cap.card), unique_id, model_id, 218 reinterpret_cast<char*>(cap.card), unique_id, model_id,
227 VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE); 219 VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE);
228 #endif 220 #endif
229 } 221 }
230 } 222 }
231 // Since JS doesn't have API to get camera facing, we sort the list to make 223 // Since JS doesn't have API to get camera facing, we sort the list to make
232 // sure apps use the front camera by default. 224 // sure apps use the front camera by default.
233 // TODO(henryhsu): remove this after JS API completed (crbug.com/543997). 225 // TODO(henryhsu): remove this after JS API completed (crbug.com/543997).
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 265 }
274 266
275 // static 267 // static
276 VideoCaptureDeviceFactory* 268 VideoCaptureDeviceFactory*
277 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( 269 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory(
278 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { 270 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
279 return new VideoCaptureDeviceFactoryLinux(ui_task_runner); 271 return new VideoCaptureDeviceFactoryLinux(ui_task_runner);
280 } 272 }
281 273
282 } // namespace media 274 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/linux/video_capture_device_chromeos.cc ('k') | media/cast/test/utility/udp_proxy_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698