#include "quickcam.h" //linux specific #include #include #include #include #include #define WIDTH 640 #define HEIGHT 480 Quickcam::Quickcam( char *device ) : Camera(WIDTH, HEIGHT), bytes(WIDTH*HEIGHT*4) { fd = open(device, O_RDWR); if (fd == -1) { fprintf(stderr, "failed to open video device %s: %s\n", device, strerror(errno)); exit(1); } /* struct video_capability cap; if (ioctl(fd, VIDIOCGCAP, &cap) == -1) { fprintf(stderr, "(querycap) %s\n", strerror(errno)); return EXIT_FAILURE; } */ struct video_picture pict; doOrDie(ioctl(fd, VIDIOCGPICT, &pict), "getpict"); pict.palette = VIDEO_PALETTE_RGB32; doOrDie(ioctl(fd, VIDIOCSPICT, &pict), "setpict"); struct video_window win; //get window info doOrDie(ioctl(fd, VIDIOCGWIN, &win), "getwin"); win.width = WIDTH; win.height = HEIGHT; //set window info doOrDie(ioctl(fd, VIDIOCSWIN, &win), "error setting window size"); } Quickcam::~Quickcam( void ) { close(fd); } void Quickcam::doOrDie(int retval, char *message) { if (retval == -1) { fprintf(stderr, "%s: %s\n", message, strerror(errno)); exit(1); } } void Quickcam::update( void ) { int read_sz = read(fd, pixels->pixels, bytes); doOrDie(read_sz, "read failure"); }