v4l2: fix setting buffer size

Closed Marek Marczykowski-Górecki requested to merge marmarek/gstreamer:v4l2-bytesused into main

v4l2src (at least) may allocate larger buffer than the actual data in there. The buffer size is stored in group->planes[i].length, while the actual data amount is in group->planes[i].bytesused (retrieved using VIDIOC_QUERYBUF ioctl in gst_v4l2_memory_group_new()). Larger buffer isn't an issue for sinks that calculate data size on their own (based on frame format and dimensions) - in this case, excess data is simply ignored. But it is an issue for dumb sinks that just passthrough data without parsing it - like filesink or fdsink. In this case, the output stream will contain the extra padding, messing the data.

The simplest problematic pipeline is:

v4l2src ! fdsink

GstMemory struct do support this case, by having maxsize and size members. The size member (amount of valid data) was set to the size of the whole buffer. Fix this by setting it in gst_v4l2_allocator_reset_size() to bytesused value.

Signed-off-by: Marek Marczykowski-Górecki marmarek@invisiblethingslab.com

Merge request reports