What I do is:
Open the camera by:
query the capabilities set the format set the framerate request 4 buffers query all 4 buffers use mmap (I don't know anything about what this does) turn the streaming on queue all 4 buffers
And then during every frame loop,
queue the next buffer (increase the buffer counter/reset it to the first if necessary) dequeue the next buffer
Here is the code I run to update the frame:
if (ioctl(m_file_descriptor, VIDIOC_QBUF, m_buffer_info + m_current_buffer_index) < 0) {
debug::log::message("Camera::open(): Unable to query the buffers: %s", strerror(errno));
return nullptr;
}
++m_current_buffer_index;
if (m_current_buffer_index == s_buffer_count) m_current_buffer_index = 0;
if (ioctl(m_file_descriptor, VIDIOC_DQBUF, m_buffer_info + m_current_buffer_index) < 0) {
debug::log::message("Camera::open(): Unable to dequeue the buffers: %s", strerror(errno));
return nullptr;
}
return reinterpret_cast<unsigned char *>(m_buffer_start[m_current_buffer_index]);
This code slows the application to <10 updates per second (each update takes ~106ms), where the dequeue process takes 104ms
I want to know why this is and if there is any way to make this application run in realtime since the webcam on this laptop runs at 30fps.
Edit: I found out that the camera could only run at 10hz whilst reading the raw data (in yuv422), thus the dequeue was blocking. Although I switched the format with which I was reading the camera, the dequeue process still takes much more than the amount of time necessary for blocking, according to v4l2-ctl -d /dev/video2 --list-formats-ext
. (720p at 30fps actually gives me 15fps, and lowering the res does not help) Now that I know I need to decode mjpeg frames in order to have live HD video at a high framerate, I am trying to find a way convert mjpeg to rgb (or yuv) fast