From 49439d6de55a6f61cfabf5fc3fd69442fd232e7b Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Tue, 16 Sep 2025 15:31:53 +0200 Subject: [PATCH] pycamera: Fix FrameBuffer::planes wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In commit b8d332cdcc13 ("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 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: b8d332cdcc13 ("libcamera: framebuffer: Replace vector with span in constructor") Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Barnabás Pőcze --- src/py/libcamera/py_main.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index 441a70ab..a983ea75 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -372,7 +372,13 @@ PYBIND11_MODULE(_libcamera, m) .def(py::init, 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 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 v(self.planes().begin(), self.planes().end()); + auto planes = self.planes(); + std::vector v(planes.begin(), planes.end()); return v; });