Message ID | 20220527144447.94891-23-tomi.valkeinen@ideasonboard.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Tomi, Thank you for the patch. On Fri, May 27, 2022 at 05:44:39PM +0300, Tomi Valkeinen wrote: > Add FrameMetadataPlane class and adjust the methods and uses > accordingly. > > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > 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_<Request::ReuseFlag>(pyRequest, "Reuse"); > auto pyFrameMetadata = py::class_<FrameMetadata>(m, "FrameMetadata"); > auto pyFrameMetadataStatus = py::enum_<FrameMetadata::Status>(pyFrameMetadata, "Status"); > + auto pyFrameMetadataPlane = py::class_<FrameMetadata::Plane>(pyFrameMetadata, "Plane"); > auto pyTransform = py::class_<Transform>(m, "Transform"); > auto pyColorSpace = py::class_<ColorSpace>(m, "ColorSpace"); > auto pyColorSpacePrimaries = py::enum_<ColorSpace::Primaries>(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<unsigned int> 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<FrameMetadata::Plane> 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;
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_<Request::ReuseFlag>(pyRequest, "Reuse"); auto pyFrameMetadata = py::class_<FrameMetadata>(m, "FrameMetadata"); auto pyFrameMetadataStatus = py::enum_<FrameMetadata::Status>(pyFrameMetadata, "Status"); + auto pyFrameMetadataPlane = py::class_<FrameMetadata::Plane>(pyFrameMetadata, "Plane"); auto pyTransform = py::class_<Transform>(m, "Transform"); auto pyColorSpace = py::class_<ColorSpace>(m, "ColorSpace"); auto pyColorSpacePrimaries = py::enum_<ColorSpace::Primaries>(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<unsigned int> 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<FrameMetadata::Plane> 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;
Add FrameMetadataPlane class and adjust the methods and uses accordingly. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> --- src/py/cam/cam.py | 3 ++- src/py/libcamera/py_main.cpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-)