2 * Copyright 2009 Google Inc.
3 * Author: lexnikitin@google.com (Alexey Nikitin)
5 * V4LLookup provides basic functionality to work with V2L2 devices in Linux
6 * The functionality is implemented as a class with virtual methods for
7 * the purpose of unit testing.
9 #include "talk/media/devices/v4llookup.h"
13 #include <linux/types.h>
14 #include <linux/videodev2.h>
15 #include <sys/ioctl.h>
16 #include <sys/types.h>
22 #include "talk/base/logging.h"
26 V4LLookup *V4LLookup::v4l_lookup_ = NULL;
28 bool V4LLookup::CheckIsV4L2Device(const std::string& device_path) {
29 // check device major/minor numbers are in the range for video devices.
32 if (lstat(device_path.c_str(), &s) != 0 || !S_ISCHR(s.st_mode)) return false;
37 // check major/minur device numbers are in range for video device
38 if (major(s.st_rdev) == 81) {
39 dev_t num = minor(s.st_rdev);
41 video_fd = ::open(device_path.c_str(), O_RDONLY | O_NONBLOCK);
42 if ((video_fd >= 0) || (errno == EBUSY)) {
43 ::v4l2_capability video_caps;
44 memset(&video_caps, 0, sizeof(video_caps));
46 if ((errno == EBUSY) ||
47 (::ioctl(video_fd, VIDIOC_QUERYCAP, &video_caps) >= 0 &&
48 (video_caps.capabilities & V4L2_CAP_VIDEO_CAPTURE))) {
49 LOG(LS_INFO) << "Found V4L2 capture device " << device_path;
53 LOG_ERRNO(LS_ERROR) << "VIDIOC_QUERYCAP failed for " << device_path;
56 LOG_ERRNO(LS_ERROR) << "Failed to open " << device_path;
67 }; // namespace cricket