webrtc/talk/media/devices/v4llookup.cc
pbos@webrtc.org 371243dfa3 Remove std:: prefixes from C functions in talk/.
std::memcpy -> memcpy for instance. This change was motivated by a
compile report complaining that std::rand() was used instead of rand(),
probably with a stdlib.h include instead of cstdlib. Use of C functions
without the std:: prefix is a lot more common, so removing std:: to
address this.

BUG=
R=tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/9559004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5657 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-03-07 15:22:04 +00:00

67 lines
1.8 KiB
C++

/*
* Copyright 2009 Google Inc.
* Author: lexnikitin@google.com (Alexey Nikitin)
*
* V4LLookup provides basic functionality to work with V2L2 devices in Linux
* The functionality is implemented as a class with virtual methods for
* the purpose of unit testing.
*/
#include "talk/media/devices/v4llookup.h"
#include <errno.h>
#include <fcntl.h>
#include <linux/types.h>
#include <linux/videodev2.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "talk/base/logging.h"
namespace cricket {
V4LLookup *V4LLookup::v4l_lookup_ = NULL;
bool V4LLookup::CheckIsV4L2Device(const std::string& device_path) {
// check device major/minor numbers are in the range for video devices.
struct stat s;
if (lstat(device_path.c_str(), &s) != 0 || !S_ISCHR(s.st_mode)) return false;
int video_fd = -1;
bool is_v4l2 = false;
// check major/minur device numbers are in range for video device
if (major(s.st_rdev) == 81) {
dev_t num = minor(s.st_rdev);
if (num <= 63) {
video_fd = ::open(device_path.c_str(), O_RDONLY | O_NONBLOCK);
if ((video_fd >= 0) || (errno == EBUSY)) {
::v4l2_capability video_caps;
memset(&video_caps, 0, sizeof(video_caps));
if ((errno == EBUSY) ||
(::ioctl(video_fd, VIDIOC_QUERYCAP, &video_caps) >= 0 &&
(video_caps.capabilities & V4L2_CAP_VIDEO_CAPTURE))) {
LOG(LS_INFO) << "Found V4L2 capture device " << device_path;
is_v4l2 = true;
} else {
LOG_ERRNO(LS_ERROR) << "VIDIOC_QUERYCAP failed for " << device_path;
}
} else {
LOG_ERRNO(LS_ERROR) << "Failed to open " << device_path;
}
}
}
if (video_fd >= 0)
::close(video_fd);
return is_v4l2;
}
}; // namespace cricket