[libcamera-devel,v2,5/7] libcamera: CameraSensor: Attach available test pattern modes
diff mbox series

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

Commit Message

Hirokazu Honda April 21, 2021, 4:23 a.m. UTC
This add available test pattern modes to libcamera to
CameraSensorInfo.

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

Comments

Laurent Pinchart April 27, 2021, 3:56 a.m. UTC | #1
Hi Hiro,

Thank you for the patch.

On Wed, Apr 21, 2021 at 01:23:44PM +0900, Hirokazu Honda wrote:
> This add available test pattern modes to libcamera to
> CameraSensorInfo.
> 
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> ---
>  include/libcamera/internal/camera_sensor.h |  2 ++
>  src/libcamera/camera_sensor.cpp            | 38 ++++++++++++++++++++++
>  2 files changed, 40 insertions(+)
> 
> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
> index 3fa3a419..75b884db 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> availableTestPatternModes;
>  };
>  
>  class CameraSensor : protected Loggable
> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
> index 850c94b3..d20cfb4c 100644
> --- a/src/libcamera/camera_sensor.cpp
> +++ b/src/libcamera/camera_sensor.cpp
> @@ -840,6 +840,44 @@ 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>();
>  
> +	const SensorInfo *staticInfo = SensorDatabase::get(model_);
> +	if (!staticInfo) {
> +		LOG(CameraSensor, Warning)
> +			<< "No static properties available for '" << model_ << "'";
> +		LOG(CameraSensor, Warning)
> +			<< "Please consider updating the sensor database";
> +		return -EINVAL;
> +	}
> +
> +	const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN);
> +	if (v4l2TestPattern == controls().end()) {
> +		LOG(CameraSensor, Debug) << "No static test pattern map for \'"
> +					 << model() << "\'";
> +		return 0;
> +	}
> +
> +	for (const ControlValue &value : v4l2TestPattern->second.values()) {
> +		const ControlMenu &menu = value.get<ControlMenu>();
> +		ASSERT(menu.isName);
> +
> +		int32_t matchedTestPattern = -1;
> +		for (const auto &[name, testPattern] : staticInfo->testPatternModeMap) {
> +			if (strcmp(menu.name, name) == 0) {
> +				matchedTestPattern = testPattern;
> +				break;
> +			}
> +		}
> +
> +		if (matchedTestPattern != -1) {
> +			LOG(CameraSensor, Debug) << "Test pattern mode named \'"
> +						 << menu.name << "\' added";
> +			info->availableTestPatternModes.push_back(matchedTestPattern);
> +		} else {
> +			LOG(CameraSensor, Debug) << "Test pattern mode named \'"
> +						 << menu.name << "\' ignored";
> +		}
> +	}

This shouldn't be done every time sensorInfo() is called, but once at
initialization time, and cached.

> +
>  	return 0;
>  }
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index 3fa3a419..75b884db 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> availableTestPatternModes;
 };
 
 class CameraSensor : protected Loggable
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 850c94b3..d20cfb4c 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -840,6 +840,44 @@  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>();
 
+	const SensorInfo *staticInfo = SensorDatabase::get(model_);
+	if (!staticInfo) {
+		LOG(CameraSensor, Warning)
+			<< "No static properties available for '" << model_ << "'";
+		LOG(CameraSensor, Warning)
+			<< "Please consider updating the sensor database";
+		return -EINVAL;
+	}
+
+	const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN);
+	if (v4l2TestPattern == controls().end()) {
+		LOG(CameraSensor, Debug) << "No static test pattern map for \'"
+					 << model() << "\'";
+		return 0;
+	}
+
+	for (const ControlValue &value : v4l2TestPattern->second.values()) {
+		const ControlMenu &menu = value.get<ControlMenu>();
+		ASSERT(menu.isName);
+
+		int32_t matchedTestPattern = -1;
+		for (const auto &[name, testPattern] : staticInfo->testPatternModeMap) {
+			if (strcmp(menu.name, name) == 0) {
+				matchedTestPattern = testPattern;
+				break;
+			}
+		}
+
+		if (matchedTestPattern != -1) {
+			LOG(CameraSensor, Debug) << "Test pattern mode named \'"
+						 << menu.name << "\' added";
+			info->availableTestPatternModes.push_back(matchedTestPattern);
+		} else {
+			LOG(CameraSensor, Debug) << "Test pattern mode named \'"
+						 << menu.name << "\' ignored";
+		}
+	}
+
 	return 0;
 }