504 gLog << warn <<
"WARNING - Device " <<
fPath <<
" already open." << endl;
508 gLog << all <<
"Opening " <<
fPath <<
"... " << flush;
518 gLog << err <<
"ERROR: " << strerror(errno) << endl;
525 if (fcntl(
fFileDesc, F_SETFD, FD_CLOEXEC)<0)
527 gLog << err <<
"ERROR - Call to fnctl (F_SETFD, FD_CLOEXEC) failed." << endl;
550 if (
Ioctl(VIDIOC_S_INPUT, &index)==-1)
552 gLog << err <<
"ERROR - Could not set input." << endl;
557 if (
Ioctl(VIDIOC_G_INPUT, &index))
559 gLog << err <<
"ERROR - Could not get input." << endl;
564 memset(&input, 0,
sizeof (input));
566 if (
Ioctl(VIDIOC_ENUMINPUT, &input))
568 gLog << err <<
"ERROR - Could enum input." << endl;
571 gLog <<
"*** Input: " << input.name <<
" (" << input.index <<
")" << endl;
574 if (
Ioctl (VIDIOC_S_STD, &st))
576 gLog << err <<
"ERROR - Could not set standard." << endl;
581 if (
Ioctl(VIDIOC_QUERYCAP, &cap))
583 gLog << err <<
"ERROR - Could not get capabilities." << endl;
587 if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
589 gLog << err <<
"ERROR - No capture capabaility." << endl;
593 v4l2_cropcap cropcap;
594 cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
596 if (
Ioctl(VIDIOC_CROPCAP, &cropcap)==-1)
601 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
602 crop.c = cropcap.defrect;
604 if (
Ioctl(VIDIOC_S_CROP, &crop))
606 gLog << err <<
"Could not reset cropping." << endl;
611 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
612 fmt.fmt.pix.width = 768;
613 fmt.fmt.pix.height = 576;
614 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
616 if (
Ioctl(VIDIOC_S_FMT, &fmt)==-1)
618 gLog << err <<
"ERROR - Could not set format." << endl;
625 v4l2_requestbuffers reqbuf;
626 memset (&reqbuf, 0,
sizeof (reqbuf));
628 reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
629 reqbuf.memory = V4L2_MEMORY_MMAP;
632 if (
Ioctl(VIDIOC_REQBUFS, &reqbuf)==-1)
634 gLog << err <<
"ERROR - Couldn't setup frame buffers." << endl;
638 gLog << all <<
"Allocated " << reqbuf.count <<
" frame buffers." << endl;
640 for (
unsigned int i=0;
i<reqbuf.count;
i++)
643 memset (&buffer, 0,
sizeof (buffer));
645 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
646 buffer.memory = V4L2_MEMORY_MMAP;
649 if (
Ioctl(VIDIOC_QUERYBUF, &buffer))
651 gLog << err <<
"ERROR - Request of frame buffer " <<
i <<
" failed." << endl;
655 void *ptr = mmap(NULL, buffer.length,
656 PROT_READ | PROT_WRITE,
660 if (MAP_FAILED == ptr)
663 gLog << err <<
"ERROR - Could not allocate shared memory." << endl;
671 fBuffers.push_back(make_pair(buffer, ptr));
int Ioctl(int req, void *opt, bool allowirq=true, bool force=false) const
std::vector< std::pair< v4l2_buffer, void * > > fBuffers