From b48db3c489d3af5989cc9a71b0843fc69adbcc1f Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Wed, 28 Jul 2021 11:59:00 +0200 Subject: libcamera: controls: Create ControlInfoMap with ControlIdMap ControlInfoMap does not have a ControlId map associated, but rather creates one with the generateIdMap() function at creation time. As a consequence, when in the need to de-serialize a ControlInfoMap all the ControlId it contains are created by the deserializer instance, not being able to discern if the controls the ControlIdMap refers to are the global libcamera controls (and properties) or instances local to the V4L2 device that has first initialized the controls. As a consequence the ControlId stored in a de-serialized map will always be newly created entities, preventing lookup by ControlId reference on a de-serialized ControlInfoMap. In order to make it possible to use globally available ControlId instances whenever possible, create ControlInfoMap with a reference to an externally allocated ControlIdMap instead of generating one internally. As a consequence the class constructors take and additional argument, which might be not pleasant to type in, but enforces the concepts that ControlInfoMap should be created with controls part of the same id map. As the ControlIdMap the ControlInfoMap refers to needs to be allocated externally: - Use the globally available controls::controls (or properties::properties) id map when referring to libcamera controls - The V4L2 device that creates ControlInfoMap by parsing the device's controls has to allocate a ControlIdMap - The ControlSerializer that de-serializes a ControlInfoMap has to create and store the ControlIdMap the de-serialized info map refers to Signed-off-by: Jacopo Mondi Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart --- include/libcamera/controls.h | 13 ++++---- include/libcamera/internal/control_serializer.h | 1 + include/libcamera/internal/v4l2_device.h | 1 + include/libcamera/ipa/raspberrypi.h | 40 ++++++++++++------------- 4 files changed, 28 insertions(+), 27 deletions(-) (limited to 'include') diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index de733bd8..9b0d5a54 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -309,12 +309,11 @@ public: ControlInfoMap() = default; ControlInfoMap(const ControlInfoMap &other) = default; - ControlInfoMap(std::initializer_list init); - ControlInfoMap(Map &&info); + ControlInfoMap(std::initializer_list init, + const ControlIdMap &idmap); + ControlInfoMap(Map &&info, const ControlIdMap &idmap); ControlInfoMap &operator=(const ControlInfoMap &other) = default; - ControlInfoMap &operator=(std::initializer_list init); - ControlInfoMap &operator=(Map &&info); using Map::key_type; using Map::mapped_type; @@ -339,12 +338,12 @@ public: iterator find(unsigned int key); const_iterator find(unsigned int key) const; - const ControlIdMap &idmap() const { return idmap_; } + const ControlIdMap &idmap() const { return *idmap_; } private: - void generateIdmap(); + bool validate(); - ControlIdMap idmap_; + const ControlIdMap *idmap_; }; class ControlList diff --git a/include/libcamera/internal/control_serializer.h b/include/libcamera/internal/control_serializer.h index 7d4426c9..8a66be32 100644 --- a/include/libcamera/internal/control_serializer.h +++ b/include/libcamera/internal/control_serializer.h @@ -48,6 +48,7 @@ private: unsigned int serial_; std::vector> controlIds_; + std::vector> controlIdMaps_; std::map infoMaps_; std::map infoMapHandles_; }; diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index 77b835b3..423c8fb1 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -69,6 +69,7 @@ private: std::map controlInfo_; std::vector> controlIds_; + ControlIdMap controlIdMap_; ControlInfoMap controls_; std::string deviceNode_; int fd_; diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h index a8790000..521eaecd 100644 --- a/include/libcamera/ipa/raspberrypi.h +++ b/include/libcamera/ipa/raspberrypi.h @@ -27,26 +27,26 @@ namespace RPi { * and the pipeline handler may be reverted so that it aborts when an * unsupported control is encountered. */ -static const ControlInfoMap Controls = { - { &controls::AeEnable, ControlInfo(false, true) }, - { &controls::ExposureTime, ControlInfo(0, 999999) }, - { &controls::AnalogueGain, ControlInfo(1.0f, 32.0f) }, - { &controls::AeMeteringMode, ControlInfo(controls::AeMeteringModeValues) }, - { &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) }, - { &controls::AeExposureMode, ControlInfo(controls::AeExposureModeValues) }, - { &controls::ExposureValue, ControlInfo(0.0f, 16.0f) }, - { &controls::AwbEnable, ControlInfo(false, true) }, - { &controls::ColourGains, ControlInfo(0.0f, 32.0f) }, - { &controls::AwbMode, ControlInfo(controls::AwbModeValues) }, - { &controls::Brightness, ControlInfo(-1.0f, 1.0f) }, - { &controls::Contrast, ControlInfo(0.0f, 32.0f) }, - { &controls::Saturation, ControlInfo(0.0f, 32.0f) }, - { &controls::Sharpness, ControlInfo(0.0f, 16.0f, 1.0f) }, - { &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) }, - { &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) }, - { &controls::FrameDurationLimits, ControlInfo(INT64_C(1000), INT64_C(1000000000)) }, - { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }, -}; +static const ControlInfoMap Controls({ + { &controls::AeEnable, ControlInfo(false, true) }, + { &controls::ExposureTime, ControlInfo(0, 999999) }, + { &controls::AnalogueGain, ControlInfo(1.0f, 32.0f) }, + { &controls::AeMeteringMode, ControlInfo(controls::AeMeteringModeValues) }, + { &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) }, + { &controls::AeExposureMode, ControlInfo(controls::AeExposureModeValues) }, + { &controls::ExposureValue, ControlInfo(0.0f, 16.0f) }, + { &controls::AwbEnable, ControlInfo(false, true) }, + { &controls::ColourGains, ControlInfo(0.0f, 32.0f) }, + { &controls::AwbMode, ControlInfo(controls::AwbModeValues) }, + { &controls::Brightness, ControlInfo(-1.0f, 1.0f) }, + { &controls::Contrast, ControlInfo(0.0f, 32.0f) }, + { &controls::Saturation, ControlInfo(0.0f, 32.0f) }, + { &controls::Sharpness, ControlInfo(0.0f, 16.0f, 1.0f) }, + { &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) }, + { &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) }, + { &controls::FrameDurationLimits, ControlInfo(INT64_C(1000), INT64_C(1000000000)) }, + { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) } + }, controls::controls); } /* namespace RPi */ -- cgit v1.2.1