pycamera: Fix FrameBuffer::planes wrapper

In commit b8d332cdcc ("libcamera: framebuffer: Replace vector with
span in constructor") the FrameBuffer::planes() function was modified to
return a Span instead of a vector. This leads to the following runtime
exception in the python binding:

TypeError: Unregistered type : libcamera::Span<libcamera::FrameBuffer::Plane const, 18446744073709551615ul>

Fix that by manually converting the Span to a vector.

Note: The best solution would be to implement a Span type caster for
pybind11. But implementing and testing that properly is a bit more
involved than expected. As we don't need bidirectional mapping, use the
same workaround as for FrameMetadata::planes() for now.

While at it, update the lambda for pyFrameMetadata.planes() to call the
inner planes() only once.

Fixes: b8d332cdcc ("libcamera: framebuffer: Replace vector with span in constructor")
Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
This commit is contained in:
Stefan Klug
2025-09-16 15:31:53 +02:00
parent b8d332cdcc
commit 49439d6de5

View File

@@ -372,7 +372,13 @@ PYBIND11_MODULE(_libcamera, m)
.def(py::init<std::vector<FrameBuffer::Plane>, unsigned int>(),
py::arg("planes"), py::arg("cookie") = 0)
.def_property_readonly("metadata", &FrameBuffer::metadata, py::return_value_policy::reference_internal)
.def_property_readonly("planes", &FrameBuffer::planes)
.def_property_readonly("planes", [](const FrameBuffer &self) {
/* Convert from Span<> to std::vector<> */
/* Note: this creates copies */
auto planes = self.planes();
std::vector<FrameBuffer::Plane> v(planes.begin(), planes.end());
return v;
})
.def_property("cookie", &FrameBuffer::cookie, &FrameBuffer::setCookie);
pyFrameBufferPlane
@@ -495,7 +501,8 @@ PYBIND11_MODULE(_libcamera, m)
.def_property_readonly("planes", [](const FrameMetadata &self) {
/* Convert from Span<> to std::vector<> */
/* Note: this creates a copy */
std::vector<FrameMetadata::Plane> v(self.planes().begin(), self.planes().end());
auto planes = self.planes();
std::vector<FrameMetadata::Plane> v(planes.begin(), planes.end());
return v;
});