checking capabilities

git-svn-id: svn://anubis/misc/WebcamTracker@120 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2009-08-06 01:09:55 +00:00
parent 7d1f710d57
commit ca070c2d8c
2 changed files with 65 additions and 11 deletions

View File

@ -6,19 +6,54 @@
#include <sys/ioctl.h> /* ioctl() */ #include <sys/ioctl.h> /* ioctl() */
#include <libv4lconvert.h> #include <libv4lconvert.h>
#include <iostream> #include <iostream>
#include "WebcamTracker.h"
using namespace std; using namespace std;
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
int fd = open("/dev/video0", O_RDWR); WebcamTracker("/dev/video0");
if (fd < 0) }
{
cerr << "bad fd" << endl; WebcamTracker::WebcamTracker(const char * device)
exit(1); {
} m_open = false;
m_fd = open(device, O_RDWR);
struct v4l2_capability cap; if (m_fd >= 0)
ioctl(fd, VIDIOC_QUERYCAP, &cap); {
m_open = true;
close(fd);
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);
}
} }

19
WebcamTracker.h Normal file
View File

@ -0,0 +1,19 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h> /* exit() */
#include <sys/ioctl.h> /* ioctl() */
#include <libv4lconvert.h>
#include <iostream>
class WebcamTracker
{
public:
WebcamTracker(const char * device);
~WebcamTracker();
protected:
bool m_open;
int m_fd;
};