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

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

Issue 270263008: Add a ChromeOS implementation of VideoCaptureDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
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/video/capture/linux/video_capture_device_factory_linux.h" 5 #include "media/video/capture/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 #if defined(OS_OPENBSD) 9 #if defined(OS_OPENBSD)
10 #include <sys/videoio.h> 10 #include <sys/videoio.h>
11 #else 11 #else
12 #include <linux/videodev2.h> 12 #include <linux/videodev2.h>
13 #endif 13 #endif
14 #include <sys/ioctl.h> 14 #include <sys/ioctl.h>
15 15
16 #include "base/files/file_enumerator.h" 16 #include "base/files/file_enumerator.h"
17 #include "base/files/scoped_file.h" 17 #include "base/files/scoped_file.h"
18 #include "base/posix/eintr_wrapper.h" 18 #include "base/posix/eintr_wrapper.h"
19 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
20 #if defined(OS_CHROMEOS)
21 #include "media/video/capture/linux/video_capture_device_chromeos.h"
22 #endif
20 #include "media/video/capture/linux/video_capture_device_linux.h" 23 #include "media/video/capture/linux/video_capture_device_linux.h"
21 24
22 namespace media { 25 namespace media {
23 26
24 static bool HasUsableFormats(int fd) { 27 static bool HasUsableFormats(int fd) {
25 v4l2_fmtdesc fmtdesc; 28 v4l2_fmtdesc fmtdesc;
26 std::list<int> usable_fourccs; 29 std::list<int> usable_fourccs;
27 30
28 media::VideoCaptureDeviceLinux::GetListOfUsableFourCCs(false, 31 media::VideoCaptureDeviceLinux::GetListOfUsableFourCCs(false,
29 &usable_fourccs); 32 &usable_fourccs);
30 33
31 memset(&fmtdesc, 0, sizeof(v4l2_fmtdesc)); 34 memset(&fmtdesc, 0, sizeof(v4l2_fmtdesc));
32 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 35 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
33 36
34 while (HANDLE_EINTR(ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc)) == 0) { 37 while (HANDLE_EINTR(ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc)) == 0) {
35 if (std::find(usable_fourccs.begin(), usable_fourccs.end(), 38 if (std::find(usable_fourccs.begin(), usable_fourccs.end(),
36 fmtdesc.pixelformat) != usable_fourccs.end()) 39 fmtdesc.pixelformat) != usable_fourccs.end())
37 return true; 40 return true;
38 41
39 fmtdesc.index++; 42 fmtdesc.index++;
40 } 43 }
41 return false; 44 return false;
42 } 45 }
43 46
44 scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryLinux::Create( 47 scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryLinux::Create(
48 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
45 const VideoCaptureDevice::Name& device_name) { 49 const VideoCaptureDevice::Name& device_name) {
46 DCHECK(thread_checker_.CalledOnValidThread()); 50 DCHECK(thread_checker_.CalledOnValidThread());
51 #if defined(OS_CHROMEOS)
52 VideoCaptureDeviceChromeOS* self =
53 new VideoCaptureDeviceChromeOS(ui_task_runner, device_name);
54 #else
47 VideoCaptureDeviceLinux* self = new VideoCaptureDeviceLinux(device_name); 55 VideoCaptureDeviceLinux* self = new VideoCaptureDeviceLinux(device_name);
56 #endif
48 if (!self) 57 if (!self)
49 return scoped_ptr<VideoCaptureDevice>(); 58 return scoped_ptr<VideoCaptureDevice>();
50 // Test opening the device driver. This is to make sure it is available. 59 // Test opening the device driver. This is to make sure it is available.
51 // We will reopen it again in our worker thread when someone 60 // We will reopen it again in our worker thread when someone
52 // allocates the camera. 61 // allocates the camera.
53 base::ScopedFD fd(HANDLE_EINTR(open(device_name.id().c_str(), O_RDONLY))); 62 base::ScopedFD fd(HANDLE_EINTR(open(device_name.id().c_str(), O_RDONLY)));
54 if (!fd.is_valid()) { 63 if (!fd.is_valid()) {
55 DVLOG(1) << "Cannot open device"; 64 DVLOG(1) << "Cannot open device";
56 delete self; 65 delete self;
57 return scoped_ptr<VideoCaptureDevice>(); 66 return scoped_ptr<VideoCaptureDevice>();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 ++frame_interval.index; 171 ++frame_interval.index;
163 } 172 }
164 ++frame_size.index; 173 ++frame_size.index;
165 } 174 }
166 ++pixel_format.index; 175 ++pixel_format.index;
167 } 176 }
168 return; 177 return;
169 } 178 }
170 179
171 } // namespace media 180 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/linux/video_capture_device_factory_linux.h ('k') | media/video/capture/linux/video_capture_device_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698