[libcamera-devel] [PATCH v2 10/10] cam: Add option to list camera properties

Niklas Söderlund niklas.soderlund at ragnatech.se
Sat Dec 7 00:06:05 CET 2019


Hi Jacopo,

Thanks for your work.

On 2019-12-05 21:43:50 +0100, Jacopo Mondi wrote:
> Add the '-p'|'--props' option to the cam application to list the
> properties of a camera.

I would make the long option --properties or maybe even 
--list-properties.

> 
> Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
> ---
>  src/cam/main.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
>  src/cam/main.h   |  1 +
>  2 files changed, 61 insertions(+)
> 
> diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> index a38cca959aca..7e1eb20d6df7 100644
> --- a/src/cam/main.cpp
> +++ b/src/cam/main.cpp
> @@ -11,6 +11,7 @@
>  #include <string.h>
>  
>  #include <libcamera/libcamera.h>
> +#include <libcamera/property_ids.h>
>  
>  #include "capture.h"
>  #include "event_loop.h"
> @@ -36,6 +37,7 @@ public:
>  private:
>  	int parseOptions(int argc, char *argv[]);
>  	int prepareConfig();
> +	int listProperties();
>  	int infoConfiguration();
>  	int run();
>  
> @@ -180,6 +182,7 @@ int CamApp::parseOptions(int argc, char *argv[])
>  	parser.addOption(OptInfo, OptionNone,
>  			 "Display information about stream(s)", "info");
>  	parser.addOption(OptList, OptionNone, "List all cameras", "list");
> +	parser.addOption(OptProps, OptionNone, "List the cameras properties", "props");

List camera properties ?

>  
>  	options_ = parser.parse(argc, argv);
>  	if (!options_.valid())
> @@ -268,6 +271,47 @@ int CamApp::prepareConfig()
>  	return 0;
>  }
>  
> +int CamApp::listProperties()
> +{
> +	if (!camera_) {
> +		std::cout << "Cannot list properties without a camera"
> +			  << std::endl;
> +		return -EINVAL;
> +	}
> +
> +	const ControlList &properties = camera_->properties();
> +	for (const auto &prop : properties) {
> +		unsigned int id = prop.first;
> +		const auto &ctrlId = properties::properties.find(id);
> +		const ControlId *ctrl = ctrlId->second;
> +		const ControlValue &value = prop.second;
> +
> +		std::cout << "Property: " << ctrl->name() << " = ";
> +
> +		switch (ctrl->type()) {
> +		case ControlTypeBool: {
> +			bool val = value.get<bool>();
> +			std::cout << (val ? "True" : "False") << std::endl;
> +			break;
> +		}
> +		case ControlTypeInteger32: {
> +			int32_t val = value.get<int32_t>();
> +			std::cout << val << std::endl;
> +			break;
> +		}
> +		case ControlTypeInteger64: {
> +			int64_t val = value.get<int64_t>();
> +			std::cout << val << std::endl;
> +			break;
> +		}
> +		default:
> +			break;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
>  int CamApp::infoConfiguration()
>  {
>  	if (!config_) {
> @@ -309,9 +353,25 @@ int CamApp::run()
>  		for (const std::shared_ptr<Camera> &cam : cm_->cameras()) {
>  			std::cout << index << ": " << cam->name() << std::endl;
>  			index++;
> +
> +			const ControlList &properties = cam->properties();
> +			for (const auto &prop : properties) {
> +				auto it = properties::properties.find(prop.first);
> +				if (it == properties::properties.end())
> +					continue;
> +
> +				std::cout << it->second->name() << ": " <<
> +					prop.second.get<int32_t>() << "\n";
> +			}

I don't think we wish to list properties when listing the camera.

>  		}
>  	}
>  
> +	if (options_.isSet(OptProps)) {
> +		ret = listProperties();
> +		if (ret)
> +			return ret;
> +	}

Maybe this shall be merged with the OptInfo option (and it's help 
updated that it list information about a camera and all its streams)?

> +
>  	if (options_.isSet(OptInfo)) {
>  		ret = infoConfiguration();
>  		if (ret)
> diff --git a/src/cam/main.h b/src/cam/main.h
> index 0997476bb335..afcad4353b7d 100644
> --- a/src/cam/main.h
> +++ b/src/cam/main.h
> @@ -14,6 +14,7 @@ enum {
>  	OptHelp = 'h',
>  	OptInfo = 'I',
>  	OptList = 'l',
> +	OptProps = 'p',
>  	OptStream = 's',
>  };
>  
> -- 
> 2.23.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list