Returns the millisecond timestamp of the last frame grabbed or 0 if no frames have been grabbed
Used to successfully synchronize 2 Logitech C310 USB webcams to within 16 ms of one another
+12th patch: March 9, 2018, Taylor Lanclos <tlanclos@live.com>
+ added support for CV_CAP_PROP_BUFFERSIZE
make & enjoy!
__u32 palette;
int width, height;
+ int bufferSize;
__u32 fps;
bool convert_rgb;
bool frame_allocated;
capture->req = v4l2_requestbuffers();
- unsigned int buffer_number = DEFAULT_V4L_BUFFERS;
+ unsigned int buffer_number = capture->bufferSize;
try_again:
FirstCapture = 1;
width = DEFAULT_V4L_WIDTH;
height = DEFAULT_V4L_HEIGHT;
+ bufferSize = DEFAULT_V4L_BUFFERS;
fps = DEFAULT_V4L_FPS;
convert_rgb = true;
deviceName = _deviceName;
return CV_MAKETYPE(IPL2CV_DEPTH(capture->frame.depth), capture->frame.nChannels);
case CV_CAP_PROP_CONVERT_RGB:
return capture->convert_rgb;
+ case CV_CAP_PROP_BUFFERSIZE:
+ return capture->bufferSize;
}
if(property_id == CV_CAP_PROP_FPS) {
}
}
break;
+ case CV_CAP_PROP_BUFFERSIZE:
+ if ((int)value > MAX_V4L_BUFFERS || (int)value < 1) {
+ fprintf(stderr, "V4L: Bad buffer size %d, buffer size must be from 1 to %d\n", (int)value, MAX_V4L_BUFFERS);
+ retval = false;
+ } else {
+ capture->bufferSize = (int)value;
+ if (capture->bufferIndex > capture->bufferSize) {
+ capture->bufferIndex = 0;
+ }
+ retval = v4l2_reset(capture);
+ }
+ break;
default:
retval = icvSetControl(capture, property_id, value);
break;
perror ("Unable to stop the stream");
}
- for (unsigned int n_buffers_ = 0; n_buffers_ < capture->req.count; ++n_buffers_)
+ for (unsigned int n_buffers_ = 0; n_buffers_ < MAX_V4L_BUFFERS; ++n_buffers_)
{
- if (-1 == munmap (capture->buffers[n_buffers_].start, capture->buffers[n_buffers_].length)) {
- perror ("munmap");
+ if (capture->buffers[n_buffers_].start) {
+ if (-1 == munmap (capture->buffers[n_buffers_].start, capture->buffers[n_buffers_].length)) {
+ perror ("munmap");
+ } else {
+ capture->buffers[n_buffers_].start = 0;
+ }
}
}