Skip to content

v4l2: allocator: Fix passing wrong bytesused value for single plane output buffers

mmap buffer sizes are rounded up to PAGE_SIZE. For example for I420 1280x720 buffers with stride==width the imagesize is 1382400 but buffers returned by REQBUFS(mmap) will have a length of 1384448.

When queing buffers gst_v4l2_allocator_qbuf() was passing gst_memory_get_sizes (group->mem[0]) as buffer.bytesused value. So it was passing 1384448 while only 1382400 bytes are actually used.

When outputting buffers this is sometimes causing the buffers to be rejected. Specifically when sinking to a v4l2loopback device bytesused will be passed unmodified to the application sourcing buffers from the loopback (1) and passing e.g. 1384448 instead of 1382400 will cause the buffers to be rejected by the sourcing app.

Examples of apps rejecting buffers because of this are apps using libwebrtc such as Firefox and Chrome: https://github.com/umlaeute/v4l2loopback/issues/448

Fix this by passing the actual imagesize in cases where the actual imagesize is known.

  1. This is correct behavior from v4l2loopback parts since when e.g. using encoded buffers it cannot know the correct bytesused value.

closes #2532

Merge request reports