diff --git a/WebcamTracker.cc b/WebcamTracker.cc index 1916b17..3ba7ada 100644 --- a/WebcamTracker.cc +++ b/WebcamTracker.cc @@ -6,19 +6,54 @@ #include /* ioctl() */ #include #include +#include "WebcamTracker.h" using namespace std; int main(int argc, char * argv[]) { - int fd = open("/dev/video0", O_RDWR); - if (fd < 0) - { - cerr << "bad fd" << endl; - exit(1); - } - - struct v4l2_capability cap; - ioctl(fd, VIDIOC_QUERYCAP, &cap); - - close(fd); + WebcamTracker("/dev/video0"); +} + +WebcamTracker::WebcamTracker(const char * device) +{ + m_open = false; + m_fd = open(device, O_RDWR); + if (m_fd >= 0) + { + m_open = true; + + struct v4l2_capability cap; + ioctl(m_fd, VIDIOC_QUERYCAP, &cap); +#define check_cap(x) do { \ + if (cap.capabilities & (x)) \ + cout << " cap: " << #x << endl; \ + } while (0) + check_cap(V4L2_CAP_VIDEO_CAPTURE); + check_cap(V4L2_CAP_VIDEO_OUTPUT); + check_cap(V4L2_CAP_VIDEO_OVERLAY); + check_cap(V4L2_CAP_VBI_CAPTURE); + check_cap(V4L2_CAP_VBI_OUTPUT); + check_cap(V4L2_CAP_SLICED_VBI_CAPTURE); + check_cap(V4L2_CAP_SLICED_VBI_OUTPUT); + check_cap(V4L2_CAP_RDS_CAPTURE); + check_cap(V4L2_CAP_VIDEO_OUTPUT_OVERLAY); + check_cap(V4L2_CAP_TUNER); + check_cap(V4L2_CAP_AUDIO); + check_cap(V4L2_CAP_RADIO); + check_cap(V4L2_CAP_READWRITE); + check_cap(V4L2_CAP_ASYNCIO); + check_cap(V4L2_CAP_STREAMING); + } + else + { + cerr << "Could not open device '" << device << "'" << endl; + } +} + +WebcamTracker::~WebcamTracker() +{ + if (m_open) + { + close(m_fd); + } } diff --git a/WebcamTracker.h b/WebcamTracker.h new file mode 100644 index 0000000..3f04398 --- /dev/null +++ b/WebcamTracker.h @@ -0,0 +1,19 @@ + +#include +#include +#include +#include /* exit() */ +#include /* ioctl() */ +#include +#include + +class WebcamTracker +{ + public: + WebcamTracker(const char * device); + ~WebcamTracker(); + + protected: + bool m_open; + int m_fd; +};