[libcamera-devel] [RFC PATCH 4/5] WIP: libcamera: V4L2VideoDevice: Fix a bug in CreateBuffer()
Hirokazu Honda
hiroh at chromium.org
Wed Aug 11 14:40:14 CEST 2021
FrameBuffer created in V4L2VideoDevice::CreateBuffer() has the same
number of planes as v4l2 buffer planes. However, if the format is
a single planar format, the number of planes is one. FrameBuffer
should have the same number of planes as color format planes.
Signed-off-by: Hirokazu Honda <hiroh at chromium.org>
---
src/libcamera/v4l2_videodevice.cpp | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index ce60dff6..e70076f3 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1269,7 +1269,6 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)
const bool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);
const unsigned int numPlanes = multiPlanar ? buf.length : 1;
-
if (numPlanes == 0 || numPlanes > VIDEO_MAX_PLANES) {
LOG(V4L2, Error) << "Invalid number of planes";
return nullptr;
@@ -1289,6 +1288,20 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)
planes.push_back(std::move(plane));
}
+
+ V4L2DeviceFormat format{};
+ ret = getFormat(&format);
+ if (ret < 0) {
+ LOG(V4L2, Error) << "Failed to get buffer format";
+ return nullptr;
+ }
+ if (format.fourcc == V4L2_PIX_FMT_NV12) {
+ planes.resize(2);
+ planes[0].length = format.size.width * format.size.height;
+ planes[1].fd = planes[0].fd;
+ planes[1].length = format.size.width * ((format.size.height + 1) / 2);
+ }
+
return std::make_unique<FrameBuffer>(std::move(planes));
}
--
2.32.0.605.g8dce9f2422-goog
More information about the libcamera-devel
mailing list