libcamera: v4l2_videodevice: Take stride into account to compute offsets

When creating FrameBuffer instances, the V4L2VideoDevice computes plane
offsets using minimal stride for the format. This doesn't always produce
a valid result when the device requires padding at the end of lines. Fix
it by computing offsets using the stride reported by V4L2.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2021-09-04 00:09:28 +03:00
parent 17b9db376c
commit 88589a2531

View file

@ -1354,11 +1354,21 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)
size_t offset = 0;
for (size_t i = 0; i < planes.size(); ++i) {
/*
* The stride is reported by V4L2 for the first plane
* only. Compute the stride of the other planes by
* taking the horizontal subsampling factor into
* account, which is equal to the bytesPerGroup ratio of
* the planes.
*/
unsigned int stride = format_.planes[0].bpl
* formatInfo_->planes[i].bytesPerGroup
/ formatInfo_->planes[0].bytesPerGroup;
planes[i].fd = fd;
planes[i].offset = offset;
/* \todo Take the V4L2 stride into account */
planes[i].length = formatInfo_->planeSize(format_.size, i);
planes[i].length = formatInfo_->planeSize(format_.size.height,
i, stride);
offset += planes[i].length;
}
}