int checkFormat(int nChannels, int nSamplesPerSec, int nBitsPerSample) { int good; good = isFormatSupported(nChannels, nSamplesPerSec, nBitsPerSample); return good; }
QVideoSurfaceFormat QAbstractVideoSurface::nearestFormat(const QVideoSurfaceFormat &format) const { return isFormatSupported(format) ? format : QVideoSurfaceFormat(); }
int VideoCaptureV4L2::openDevice(int device, int w, int h, VideoCaptureFormat capFormat) { std::vector<LinuxCaptureDevice> devices = getDeviceList(); if(device >= devices.size()) { return 0; } LinuxCaptureDevice cap = devices[device]; fd = open(cap.path.c_str(), O_RDWR | O_NONBLOCK, 0); if(fd == -1) { printf("ERROR: cannot open: %s\n", cap.path.c_str()); fd = 0; return 0; } // query capabilities struct v4l2_capability caps; memset(&caps, 0, sizeof(caps)); if (ioctl(fd, VIDIOC_QUERYCAP, &caps) == -1) { printf("ERROR: cannot detect capabilities of camera.\n"); return 0; } // test if we can use this device as capture device if(!(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { printf("ERROR: cannot use device for video capture.\n"); return 0; } // check the io type io_method = LINCAP_IO_METHOD_READ; bool can_io_readwrite = (caps.capabilities & V4L2_CAP_READWRITE) == V4L2_CAP_READWRITE; bool can_io_stream = (caps.capabilities & V4L2_CAP_STREAMING) == V4L2_CAP_STREAMING; if(!can_io_readwrite && !can_io_stream) { printf("ERROR: cannot use read() or memory streaming with this device.\n"); return 0; } if(can_io_stream) { io_method = LINCAP_IO_METHOD_MMAP; } if(!isFormatSupported(capFormat, w, h, 1)) { printf("ERROR: cannot set pixelformat and size: %dx%d\n", w,h); return 0; } width = w; height = h; // initialize IO if(io_method == LINCAP_IO_METHOD_MMAP) { initMMAP(); } else if(io_method == LINCAP_IO_METHOD_READ) { printf("ERROR: this device can use read()/write() io, but we did not yet program this.\n"); ::exit(0); } else if(io_method == LINCAP_IO_METHOD_USERPTR) { printf("ERROR: this device can use i/o with userptr, but we need to program it.\n"); ::exit(EXIT_FAILURE); } is_opened = true; return 1; }