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

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

Issue 10824205: fix detection of video capture device on linux (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/video/capture/linux/video_capture_device_linux.h" 5 #include "media/video/capture/linux/video_capture_device_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>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 while (!enumerator.Next().empty()) { 78 while (!enumerator.Next().empty()) {
79 file_util::FileEnumerator::FindInfo info; 79 file_util::FileEnumerator::FindInfo info;
80 enumerator.GetFindInfo(&info); 80 enumerator.GetFindInfo(&info);
81 81
82 Name name; 82 Name name;
83 name.unique_id = path.value() + info.filename; 83 name.unique_id = path.value() + info.filename;
84 if ((fd = open(name.unique_id.c_str() , O_RDONLY)) < 0) { 84 if ((fd = open(name.unique_id.c_str() , O_RDONLY)) < 0) {
85 // Failed to open this device. 85 // Failed to open this device.
86 continue; 86 continue;
87 } 87 }
88 // Test if this is a V4L2 device. 88 // Test if this is a V4L2 capture device.
89 v4l2_capability cap; 89 v4l2_capability cap;
90 if ((ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) && 90 if ((ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) &&
91 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { 91 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) &&
92 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)) {
92 // This is a V4L2 video capture device 93 // This is a V4L2 video capture device
93 name.device_name = StringPrintf("%s", cap.card); 94 name.device_name = StringPrintf("%s", cap.card);
94 device_names->push_back(name); 95 device_names->push_back(name);
95 } 96 }
96 close(fd); 97 close(fd);
97 } 98 }
98 } 99 }
99 100
100 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { 101 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) {
101 VideoCaptureDeviceLinux* self = new VideoCaptureDeviceLinux(device_name); 102 VideoCaptureDeviceLinux* self = new VideoCaptureDeviceLinux(device_name);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 DCHECK_EQ(v4l2_thread_.message_loop(), MessageLoop::current()); 197 DCHECK_EQ(v4l2_thread_.message_loop(), MessageLoop::current());
197 198
198 observer_ = observer; 199 observer_ = observer;
199 200
200 // Need to open camera with O_RDWR after Linux kernel 3.3. 201 // Need to open camera with O_RDWR after Linux kernel 3.3.
201 if ((device_fd_ = open(device_name_.unique_id.c_str(), O_RDWR)) < 0) { 202 if ((device_fd_ = open(device_name_.unique_id.c_str(), O_RDWR)) < 0) {
202 SetErrorState("Failed to open V4L2 device driver."); 203 SetErrorState("Failed to open V4L2 device driver.");
203 return; 204 return;
204 } 205 }
205 206
206 // Test if this is a V4L2 device. 207 // Test if this is a V4L2 capture device.
207 v4l2_capability cap; 208 v4l2_capability cap;
208 if (!((ioctl(device_fd_, VIDIOC_QUERYCAP, &cap) == 0) && 209 if (!((ioctl(device_fd_, VIDIOC_QUERYCAP, &cap) == 0) &&
209 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))) { 210 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) &&
211 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT))) {
210 // This is not a V4L2 video capture device. 212 // This is not a V4L2 video capture device.
211 close(device_fd_); 213 close(device_fd_);
212 device_fd_ = -1; 214 device_fd_ = -1;
213 SetErrorState("This is not a V4L2 video capture device"); 215 SetErrorState("This is not a V4L2 video capture device");
214 return; 216 return;
215 } 217 }
216 218
217 v4l2_format video_fmt; 219 v4l2_format video_fmt;
218 memset(&video_fmt, 0, sizeof(video_fmt)); 220 memset(&video_fmt, 0, sizeof(video_fmt));
219 video_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 221 video_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 buffer_pool_size_ = 0; 453 buffer_pool_size_ = 0;
452 } 454 }
453 455
454 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) { 456 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) {
455 DVLOG(1) << reason; 457 DVLOG(1) << reason;
456 state_ = kError; 458 state_ = kError;
457 observer_->OnError(); 459 observer_->OnError();
458 } 460 }
459 461
460 } // namespace media 462 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698