0

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

  • 1
    I can see a laptop webcam dropping down to 10Hz in normal/dark conditions if automatic exposure time control is left on. – genpfault Nov 28 '19 at 23:40
  • @genpfault, Is there a way you know of to disable 'automatic exposure time control'. If it weren't obvious, I'm using Linux. (Ubuntu 19.10) – Gabe Rundlett Nov 28 '19 at 23:55
  • That's about 60 megabytes/sec for an uncompressed 1920x1080 frame size. Magic number, that's how fast a 7200 rpm spindle disk drive moves. Don't flush the mmap view, perhaps. – Hans Passant Nov 29 '19 at 00:38
  • It's 41.47MB if you consider the colors are stored in yuv422 (which they are). Also, I am running the camera at 1280x720p (reducing it to 18.43MB). I don't know what you mean by flushing the mmap, as I stated in the original question, I don't know what mmap does, could you give me some more information on what you mean? Thank you in advance. – Gabe Rundlett Nov 29 '19 at 01:10

0 Answers0