[RFC,v1,22/23] py: Use `Request::metadata2()`
diff mbox series

Message ID 20250606164156.1442682-23-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: Add `MetadataList`
Related show

Commit Message

Barnabás Pőcze June 6, 2025, 4:41 p.m. UTC
Expose the newly introduced `MetadataList` for any given `Request`.
This done similarly to the `Request::metadata()`, using the same
`controlValueToPy()` function. However, that function is changed to
accept `ControlValueView` as its argument since `MetadataList` does
not contain `ControlValue`s directly.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/py/libcamera/py_helpers.cpp | 4 ++--
 src/py/libcamera/py_helpers.h   | 2 +-
 src/py/libcamera/py_main.cpp    | 9 ++++-----
 3 files changed, 7 insertions(+), 8 deletions(-)

Patch
diff mbox series

diff --git a/src/py/libcamera/py_helpers.cpp b/src/py/libcamera/py_helpers.cpp
index 1ad1d4c1a..32f5cdaa6 100644
--- a/src/py/libcamera/py_helpers.cpp
+++ b/src/py/libcamera/py_helpers.cpp
@@ -16,7 +16,7 @@  namespace py = pybind11;
 using namespace libcamera;
 
 template<typename T>
-static py::object valueOrTuple(const ControlValue &cv)
+static py::object valueOrTuple(const ControlValueView &cv)
 {
 	if (cv.isArray()) {
 		const T *v = reinterpret_cast<const T *>(cv.data().data());
@@ -31,7 +31,7 @@  static py::object valueOrTuple(const ControlValue &cv)
 	return py::cast(cv.get<T>());
 }
 
-py::object controlValueToPy(const ControlValue &cv)
+py::object controlValueToPy(const ControlValueView &cv)
 {
 	switch (cv.type()) {
 	case ControlTypeNone:
diff --git a/src/py/libcamera/py_helpers.h b/src/py/libcamera/py_helpers.h
index 983969dff..895006d0c 100644
--- a/src/py/libcamera/py_helpers.h
+++ b/src/py/libcamera/py_helpers.h
@@ -9,5 +9,5 @@ 
 
 #include <pybind11/pybind11.h>
 
-pybind11::object controlValueToPy(const libcamera::ControlValue &cv);
+pybind11::object controlValueToPy(const libcamera::ControlValueView &cv);
 libcamera::ControlValue pyToControlValue(const pybind11::object &ob, libcamera::ControlType type);
diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp
index 441a70ab4..126f544e7 100644
--- a/src/py/libcamera/py_main.cpp
+++ b/src/py/libcamera/py_main.cpp
@@ -460,14 +460,13 @@  PYBIND11_MODULE(_libcamera, m)
 			self.controls().set(id.id(), pyToControlValue(value, id.type()));
 		})
 		.def_property_readonly("metadata", [](Request &self) {
-			/* Convert ControlList to std container */
+			/* Convert MetadataList to std container */
 
 			std::unordered_map<const ControlId *, py::object> ret;
 
-			for (const auto &[key, cv] : self.metadata()) {
-				const ControlId *id = controls::controls.at(key);
-				py::object ob = controlValueToPy(cv);
-				ret[id] = ob;
+			for (const auto &[k, v] : self.metadata2()) {
+				const ControlId *id = controls::controls.at(k);
+				ret.try_emplace(id, controlValueToPy(v));
 			}
 
 			return ret;