[libcamera-devel] [PATCH v2 10/10] cam: Add option to list camera properties
Jacopo Mondi
jacopo at jmondi.org
Thu Dec 5 21:43:50 CET 2019
Add the '-p'|'--props' option to the cam application to list the
properties of a camera.
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");
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";
+ }
}
}
+ if (options_.isSet(OptProps)) {
+ ret = listProperties();
+ if (ret)
+ return ret;
+ }
+
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
More information about the libcamera-devel
mailing list