[PATCH v2] py: Add bindings for ControlId array information

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sun Oct 20 23:38:09 CEST 2024


Hi Paul,

(CC'ing Tomi)

Thank you for the patch.

On Wed, Oct 16, 2024 at 08:51:30PM +0900, Paul Elder wrote:
> Add python bindings for querying whether or not a ControlId is an array
> type, and the size.
> 
> Example usage:
> >>> cid
> libcamera.ControlId(28, FrameDurationLimits[2], ControlType.Integer64)
> >>> cid.isArray
> True
> >>> cid.size
> 2
> 
> Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

Tomi, could you give this a review too ?

The patch conflicts with the master branch though, as I've pushed your
other series. Could you rebase, re-test (and re-run though CI), and push
?

I think we'll need unit tests for Python bindings soon.

> ---
> Changes in v2:
> - add size to __repr__
> ---
>  src/py/libcamera/py_main.cpp | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp
> index 983b76f6e998..cbde8be16d43 100644
> --- a/src/py/libcamera/py_main.cpp
> +++ b/src/py/libcamera/py_main.cpp
> @@ -7,6 +7,7 @@
>  
>  #include "py_main.h"
>  
> +#include <limits>
>  #include <memory>
>  #include <stdexcept>
>  #include <string>
> @@ -400,10 +401,22 @@ PYBIND11_MODULE(_libcamera, m)
>  		.def_property_readonly("id", &ControlId::id)
>  		.def_property_readonly("name", &ControlId::name)
>  		.def_property_readonly("type", &ControlId::type)
> +		.def_property_readonly("isArray", &ControlId::isArray)
> +		.def_property_readonly("size", &ControlId::size)
>  		.def("__str__", [](const ControlId &self) { return self.name(); })
>  		.def("__repr__", [](const ControlId &self) {
> -			return py::str("libcamera.ControlId({}, {}, {})")
> -				.format(self.id(), self.name(), self.type());
> +			std::string sizeStr = "";
> +			if (self.isArray()) {
> +				sizeStr = "[";
> +				size_t size = self.size();
> +				if (size == std::numeric_limits<size_t>::max())
> +					sizeStr += "n";
> +				else
> +					sizeStr += std::to_string(size);
> +				sizeStr += "]";
> +			}
> +			return py::str("libcamera.ControlId({}, {}{}, {})")
> +				.format(self.id(), self.name(), sizeStr, self.type());
>  		})
>  		.def("enumerators", &ControlId::enumerators);
>  

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list