From a8c40942b99e7e50d43a40c4b0a601c7428b30fd Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 27 Sep 2019 23:59:43 +0300 Subject: libcamera: controls: Improve the API towards applications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rework the control-related classes to improve the API towards applications. The goal is to enable writing code similar to Request *req = ...; ControlList &controls = req->controls(); controls->set(controls::AwbEnable, false); controls->set(controls::ManualExposure, 1000); ... int32_t exposure = controls->get(controls::ManualExposure); with the get and set operations ensuring type safety for the control values. This is achieved by creating the following classes: - Control defines controls and is the main way to reference a control. It is a template class to allow methods using it to refer to the control type. - ControlId is the base class of Control. It stores the control ID, name and type, and can be used in contexts where a control needs to be referenced regardless of its type (for instance in lists of controls). This class replaces ControlIdentifier. - ControlValue is kept as-is. The ControlList class now exposes two template get() and set() methods that replace the operator[]. They ensure type safety by infering the value type from the Control reference that they receive. The main way to refer to a control is now through the Control class, and optionally through its base ControlId class. The ControlId enumeration is removed, replaced by a list of global Control instances. Numerical control IDs are turned into macros, and are still exposed as they are required to communicate with IPAs (especially to deserialise control lists). They should however not be used by applications. Auto-generation of header and source files is removed for now to keep the change simple. It will be added back in the future in a more elaborate form. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- test/controls/control_info.cpp | 25 ++++++++-------- test/controls/control_list.cpp | 66 +++++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 49 deletions(-) (limited to 'test/controls') diff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp index 2aba568a..dbc43df8 100644 --- a/test/controls/control_info.cpp +++ b/test/controls/control_info.cpp @@ -7,6 +7,7 @@ #include +#include #include #include "test.h" @@ -23,17 +24,17 @@ protected: * Test information retrieval from a control with no minimum * and maximum. */ - ControlInfo info(Brightness); + ControlInfo brightness(controls::Brightness); - if (info.id() != Brightness || - info.type() != ControlTypeInteger32 || - info.name() != std::string("Brightness")) { + if (brightness.id() != controls::Brightness || + brightness.id().type() != ControlTypeInteger32 || + brightness.id().name() != std::string("Brightness")) { cout << "Invalid control identification for Brightness" << endl; return TestFail; } - if (info.min().get() != 0 || - info.max().get() != 0) { + if (brightness.min().get() != 0 || + brightness.max().get() != 0) { cout << "Invalid control range for Brightness" << endl; return TestFail; } @@ -42,17 +43,17 @@ protected: * Test information retrieval from a control with a minimum and * a maximum value. */ - info = ControlInfo(Contrast, 10, 200); + ControlInfo contrast(controls::Contrast, 10, 200); - if (info.id() != Contrast || - info.type() != ControlTypeInteger32 || - info.name() != std::string("Contrast")) { + if (contrast.id() != controls::Contrast || + contrast.id().type() != ControlTypeInteger32 || + contrast.id().name() != std::string("Contrast")) { cout << "Invalid control identification for Contrast" << endl; return TestFail; } - if (info.min().get() != 10 || - info.max().get() != 200) { + if (contrast.min().get() != 10 || + contrast.max().get() != 200) { cout << "Invalid control range for Contrast" << endl; return TestFail; } diff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp index 5215840b..05369681 100644 --- a/test/controls/control_list.cpp +++ b/test/controls/control_list.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include "test.h" @@ -52,7 +53,7 @@ protected: return TestFail; } - if (list.contains(Brightness)) { + if (list.contains(controls::Brightness)) { cout << "List should not contain Brightness control" << endl; return TestFail; } @@ -70,7 +71,7 @@ protected: * Set a control, and verify that the list now contains it, and * nothing else. */ - list[Brightness] = 255; + list.set(controls::Brightness, 255); if (list.empty()) { cout << "List should not be empty" << endl; @@ -82,7 +83,7 @@ protected: return TestFail; } - if (!list.contains(Brightness)) { + if (!list.contains(controls::Brightness)) { cout << "List should contain Brightness control" << endl; return TestFail; } @@ -96,54 +97,45 @@ protected: return TestFail; } - if (list[Brightness].get() != 255) { + if (list.get(controls::Brightness) != 255) { cout << "Incorrest Brightness control value" << endl; return TestFail; } - if (list.contains(Contrast)) { + if (list.contains(controls::Contrast)) { cout << "List should not contain Contract control" << endl; return TestFail; } - /* - * Set a second control through ControlInfo and retrieve it - * through both controlId and ControlInfo. - */ - const ControlInfoMap &controls = camera_->controls(); - const ControlInfo *brightness = &controls.find(Brightness)->second; - const ControlInfo *contrast = &controls.find(Contrast)->second; - - list[brightness] = 64; - list[contrast] = 128; + /* Update the first control and set a second one. */ + list.set(controls::Brightness, 64); + list.set(controls::Contrast, 128); - if (!list.contains(Contrast) || !list.contains(contrast)) { + if (!list.contains(controls::Contrast) || + !list.contains(controls::Contrast)) { cout << "List should contain Contrast control" << endl; return TestFail; } - /* - * Test control value retrieval and update through ControlInfo. - */ - if (list[brightness].get() != 64 || - list[contrast].get() != 128) { + if (list.get(controls::Brightness) != 64 || + list.get(controls::Contrast) != 128) { cout << "Failed to retrieve control value" << endl; return TestFail; } - list[brightness] = 10; - list[contrast] = 20; + /* + * Update both controls and verify that the container doesn't + * grow. + */ + list.set(controls::Brightness, 10); + list.set(controls::Contrast, 20); - if (list[brightness].get() != 10 || - list[contrast].get() != 20) { + if (list.get(controls::Brightness) != 10 || + list.get(controls::Contrast) != 20) { cout << "Failed to update control value" << endl; return TestFail; } - /* - * Assert that the container has not grown with the control - * updated. - */ if (list.size() != 2) { cout << "List should contain two elements" << endl; return TestFail; @@ -157,8 +149,8 @@ protected: */ ControlList newList(camera_.get()); - newList[Brightness] = 128; - newList[Saturation] = 255; + newList.set(controls::Brightness, 128); + newList.set(controls::Saturation, 255); newList.update(list); list.clear(); @@ -178,16 +170,16 @@ protected: return TestFail; } - if (!newList.contains(Brightness) || - !newList.contains(Contrast) || - !newList.contains(Saturation)) { + if (!newList.contains(controls::Brightness) || + !newList.contains(controls::Contrast) || + !newList.contains(controls::Saturation)) { cout << "New list contains incorrect items" << endl; return TestFail; } - if (newList[Brightness].get() != 10 || - newList[Contrast].get() != 20 || - newList[Saturation].get() != 255) { + if (newList.get(controls::Brightness) != 10 || + newList.get(controls::Contrast) != 20 || + newList.get(controls::Saturation) != 255) { cout << "New list contains incorrect values" << endl; return TestFail; } -- cgit v1.2.1