[libcamera-devel] [PATCH 20/23] DNI: test compound controls

Jacopo Mondi jacopo at jmondi.org
Mon Jan 13 17:42:42 CET 2020


Define a fictional compound control and register it in  the VIMC
pipeline handler. Add a test to exercize it.

Do not include, just a proof of concept. The test could be included once
we'll have real compound controls defined.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 src/libcamera/control_ids.yaml      |  5 ++
 src/libcamera/pipeline/vimc.cpp     |  5 ++
 test/controls/compound_controls.cpp | 71 +++++++++++++++++++++++++++++
 test/controls/meson.build           |  1 +
 4 files changed, 82 insertions(+)
 create mode 100644 test/controls/compound_controls.cpp

diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml
index 4befec746a59..1bdece651638 100644
--- a/src/libcamera/control_ids.yaml
+++ b/src/libcamera/control_ids.yaml
@@ -50,4 +50,9 @@ controls:
       type: int32_t
       description: Specify a fixed gain parameter
 
+  - CompoundControl:
+      type: int32_t
+      description: A fictional compound control
+      compound: true
+
 ...
diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
index 2df5447177fa..2bcb9f2248e6 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -453,6 +453,11 @@ int VimcCameraData::init(MediaDevice *media)
 			      std::forward_as_tuple(range));
 	}
 
+	/* Register a compound control. */
+	ctrls.emplace(std::piecewise_construct,
+		      std::forward_as_tuple(&controls::CompoundControl),
+		      std::forward_as_tuple(0, 100));
+
 	controlInfo_ = std::move(ctrls);
 
 	/* Initialize the camera properties. */
diff --git a/test/controls/compound_controls.cpp b/test/controls/compound_controls.cpp
new file mode 100644
index 000000000000..96d3d9204c74
--- /dev/null
+++ b/test/controls/compound_controls.cpp
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * compound_controls.cpp - CompoundControls test
+ */
+
+#include <iostream>
+#include <vector>
+
+#include <libcamera/camera.h>
+#include <libcamera/camera_manager.h>
+#include <libcamera/control_ids.h>
+#include <libcamera/controls.h>
+#include <libcamera/span.h>
+
+#include "camera_controls.h"
+
+#include "camera_test.h"
+#include "test.h"
+
+using namespace std;
+using namespace libcamera;
+
+class CompoundControlsTest : public CameraTest, public Test
+{
+public:
+	CompoundControlsTest()
+		: CameraTest("VIMC Sensor B")
+	{
+	}
+
+protected:
+	int init() override
+	{
+		return status_;
+	}
+
+	int run() override
+	{
+		CameraControlValidator validator(camera_.get());
+		ControlList list(controls::controls, &validator);
+
+		/*
+		 * Span
+		 *
+		 * A Span can be initialized with an initializer list
+		 * and sequentially or random accessed
+		 */
+		std::array<int32_t, 3> array = { 1, 2, 3 };
+		Span<int32_t> span{ array };
+		for (uint32_t i : span)
+			cout << i << endl;
+		cout << span[0] << endl;
+
+		/*
+		 * Compound Controls: can be set with a span of values
+		 */
+		std::vector<int32_t> values = { 0, 125, 253 };
+		list.set(controls::CompoundControl, Span<int32_t>{ values });
+		Span<int32_t> iSpan = list.get(controls::CompoundControl);
+
+		cout << iSpan.size() << endl;
+		for (uint32_t i : iSpan)
+			cout << i << endl;
+
+		return TestPass;
+	}
+};
+
+TEST_REGISTER(CompoundControlsTest)
diff --git a/test/controls/meson.build b/test/controls/meson.build
index f0850df28c8a..f4752dcff33b 100644
--- a/test/controls/meson.build
+++ b/test/controls/meson.build
@@ -3,6 +3,7 @@ control_tests = [
     [ 'control_list',   'control_list.cpp' ],
     [ 'control_range',  'control_range.cpp' ],
     [ 'control_value',  'control_value.cpp' ],
+    [ 'compound_controls', 'compound_controls.cpp'],
 ]
 
 foreach t : control_tests
-- 
2.24.0



More information about the libcamera-devel mailing list