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

Message ID 20210413075013.3069213-5-hiroh@chromium.org
State Superseded
Headers show
Series
  • Report available test pattern modes
Related show

Commit Message

Hirokazu Honda April 13, 2021, 7:50 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

Kieran Bingham April 13, 2021, 9:19 p.m. UTC | #1
Hi Hiro

On 13/04/2021 08:50, 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 c012385f..81d6af44 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, Error) << "No static test pattern map for \'"
> +					 << model() << "\'";

Is this an error? Do all sensors have to provide a test pattern?
(Maybe they do provide them, but is it a requirement?)

> +		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;
>  }
>  
>
Hirokazu Honda April 14, 2021, 1:49 a.m. UTC | #2
Hi Kieran,

On Wed, Apr 14, 2021 at 6:19 AM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> Hi Hiro
>
> On 13/04/2021 08:50, 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 c012385f..81d6af44 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, Error) << "No static test pattern map for \'"
> > +                                      << model() << "\'";
>
> Is this an error? Do all sensors have to provide a test pattern?
> (Maybe they do provide them, but is it a requirement?)
>

Right, since V4L2_CID_TEST_PATTERN is an optional call, this
should be Debug.


> > +             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;
> >  }
> >
> >
>
> --
> Regards
> --
> Kieran

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 c012385f..81d6af44 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, Error) << "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;
 }