From e8317de05ce62e5e7ccdef3d18a76ecd590e9ef6 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Mon, 30 May 2022 17:27:12 +0300 Subject: py: Add FrameMetadataPlane Add FrameMetadataPlane class and adjust the methods and uses accordingly. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/py/cam/cam.py | 3 ++- src/py/libcamera/py_main.cpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py index 677dd680..bf8529d9 100755 --- a/src/py/cam/cam.py +++ b/src/py/cam/cam.py @@ -285,7 +285,8 @@ class CaptureState: print('{:.6f} ({:.2f} fps) {}-{}: seq {}, bytes {}, CRCs {}' .format(ts / 1000000000, fps, ctx.id, stream_name, - meta.sequence, meta.bytesused, + meta.sequence, + '/'.join([str(p.bytes_used) for p in meta.planes]), crcs)) if ctx.opt_metadata: diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index 9e827845..52f70811 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -163,6 +163,7 @@ PYBIND11_MODULE(_libcamera, m) auto pyRequestReuse = py::enum_(pyRequest, "Reuse"); auto pyFrameMetadata = py::class_(m, "FrameMetadata"); auto pyFrameMetadataStatus = py::enum_(pyFrameMetadata, "Status"); + auto pyFrameMetadataPlane = py::class_(pyFrameMetadata, "Plane"); auto pyTransform = py::class_(m, "Transform"); auto pyColorSpace = py::class_(m, "ColorSpace"); auto pyColorSpacePrimaries = py::enum_(pyColorSpace, "Primaries"); @@ -512,11 +513,10 @@ PYBIND11_MODULE(_libcamera, m) .def_readonly("status", &FrameMetadata::status) .def_readonly("sequence", &FrameMetadata::sequence) .def_readonly("timestamp", &FrameMetadata::timestamp) - /* \todo Implement FrameMetadata::Plane properly */ - .def_property_readonly("bytesused", [](FrameMetadata &self) { - std::vector v; - v.resize(self.planes().size()); - transform(self.planes().begin(), self.planes().end(), v.begin(), [](const auto &p) { return p.bytesused; }); + .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()); return v; }); @@ -525,6 +525,9 @@ PYBIND11_MODULE(_libcamera, m) .value("Error", FrameMetadata::FrameError) .value("Cancelled", FrameMetadata::FrameCancelled); + pyFrameMetadataPlane + .def_readwrite("bytes_used", &FrameMetadata::Plane::bytesused); + pyTransform .def(py::init([](int rotation, bool hflip, bool vflip, bool transpose) { bool ok; -- cgit v1.2.1