[libcamera-devel,v3,5/7] libcamera: CameraSensor: Enable retrieving supported test pattern modes
diff mbox series

Message ID 20210428073617.373422-6-hiroh@chromium.org
State Superseded
Headers show
Series
  • Report Android HAL client test pattern modes
Related show

Commit Message

Hirokazu Honda April 28, 2021, 7:36 a.m. UTC
This enables retrieving supported test pattern modes through
CameraSensorInfo.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 include/libcamera/internal/camera_sensor.h |  5 +++
 src/libcamera/camera_sensor.cpp            | 40 ++++++++++++++++++++++
 2 files changed, 45 insertions(+)

Patch
diff mbox series

diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index 3fa3a419..eec37a54 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -38,6 +38,8 @@  struct CameraSensorInfo {
 
 	uint32_t minFrameLength;
 	uint32_t maxFrameLength;
+
+	std::vector<int32_t> testPatternModes;
 };
 
 class CameraSensor : protected Loggable
@@ -79,6 +81,8 @@  private:
 	void initVimcDefaultProperties();
 	void initStaticProperties();
 	int initProperties();
+	void initTestPatternModes(
+		const std::map<std::string, int32_t> &testPatternModeMap);
 
 	const MediaEntity *entity_;
 	std::unique_ptr<V4L2Subdevice> subdev_;
@@ -90,6 +94,7 @@  private:
 	V4L2Subdevice::Formats formats_;
 	std::vector<unsigned int> mbusCodes_;
 	std::vector<Size> sizes_;
+	std::vector<int32_t> testPatternModes_;
 
 	Size pixelArraySize_;
 	Rectangle activeArea_;
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 850c94b3..a5c0fff7 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -411,6 +411,42 @@  void CameraSensor::initVimcDefaultProperties()
 	activeArea_ = Rectangle(pixelArraySize_);
 }
 
+void CameraSensor::initTestPatternModes(
+	const std::map<std::string, int32_t> &testPatternModeMap)
+{
+	const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN);
+	if (v4l2TestPattern == controls().end()) {
+		LOG(CameraSensor, Debug) << "No static test pattern map for \'"
+					 << model() << "\'";
+		return;
+	}
+
+	const std::vector<ControlValue> &indices = v4l2TestPattern->second.values();
+	const std::vector<ControlValue> &names = v4l2TestPattern->second.extraValues();
+	if (indices.size() != names.size()) {
+		LOG(CameraSensor, Error)
+			<< "The number of indices and names are different"
+			<< ", indices.size()=" << indices.size()
+			<< ", names.size()=" << names.size();
+		return;
+	}
+
+	for (const ControlValue &value : names) {
+		const std::string &name = value.get<std::string>();
+
+		const auto it = testPatternModeMap.find(name);
+		if (it != testPatternModeMap.end()) {
+			LOG(CameraSensor, Debug) << "Test pattern mode named \'"
+						 << name << "\' ignored";
+			continue;
+		}
+
+		LOG(CameraSensor, Debug) << "Test pattern mode named \'"
+					 << name << "\' added";
+		testPatternModes_.push_back(it->second);
+	}
+}
+
 void CameraSensor::initStaticProperties()
 {
 	const SensorInfo *info = SensorDatabase::get(model_);
@@ -424,6 +460,8 @@  void CameraSensor::initStaticProperties()
 
 	/* Register the properties retrieved from the sensor database. */
 	properties_.set(properties::UnitCellSize, info->unitCellSize);
+
+	initTestPatternModes(info->testPatternModeMap);
 }
 
 int CameraSensor::initProperties()
@@ -840,6 +878,8 @@  int CameraSensor::sensorInfo(CameraSensorInfo *info) const
 	info->minFrameLength = info->outputSize.height + vblank.min().get<int32_t>();
 	info->maxFrameLength = info->outputSize.height + vblank.max().get<int32_t>();
 
+	info->testPatternModes = testPatternModes_;
+
 	return 0;
 }