<div dir="ltr"><div dir="ltr">Hi Kieran,<div><br></div><div>Thank you for your feedback.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 21 Jun 2022 at 13:15, Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com">kieran.bingham@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Quoting Naushir Patuck via libcamera-devel (2022-06-10 13:25:32)<br>
> The ipa currently advertises a static ControlInfoMap to specify the available<br>
> controls and their limits. Fix this limitation by having the IPA populate a new<br>
> ControlInfoMap with updated limits for ExposureTime, AnalogueGain, and<br>
> FrameDurationLimits controls based on the current sensor mode. This new<br>
> ControlInfoMap is then returned back to the pipeline handler and available to<br>
> the application after a successful Camera::Configure() call.<br>
> <br>
> Signed-off-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank">naush@raspberrypi.com</a>><br>
> ---<br>
> include/libcamera/ipa/raspberrypi.mojom | 1 +<br>
> src/ipa/raspberrypi/raspberrypi.cpp | 24 ++++++++++++++++---<br>
> .../pipeline/raspberrypi/raspberrypi.cpp | 3 +++<br>
> 3 files changed, 25 insertions(+), 3 deletions(-)<br>
> <br>
> diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom<br>
> index 77f52c282b0f..c0de435b7b33 100644<br>
> --- a/include/libcamera/ipa/raspberrypi.mojom<br>
> +++ b/include/libcamera/ipa/raspberrypi.mojom<br>
> @@ -45,6 +45,7 @@ struct IPAConfig {<br>
> <br>
> struct IPAConfigResult {<br>
<br>
Aha, I see the precedent for "Result" now. so perhaps it's more suitable<br>
in the previous patch than I realised.<br>
<br>
<br>
> float modeSensitivity;<br>
> + libcamera.ControlInfoMap controlInfo;<br>
> };<br>
> <br>
> struct StartConfig {<br>
> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp<br>
> index 089528f5e126..295f6b735dc0 100644<br>
> --- a/src/ipa/raspberrypi/raspberrypi.cpp<br>
> +++ b/src/ipa/raspberrypi/raspberrypi.cpp<br>
> @@ -74,8 +74,6 @@ constexpr Duration controllerMinFrameDuration = 1.0s / 30.0;<br>
> /* List of controls handled by the Raspberry Pi IPA */<br>
> static const ControlInfoMap::Map ipaControls{<br>
> { &controls::AeEnable, ControlInfo(false, true) },<br>
> - { &controls::ExposureTime, ControlInfo(0, 999999) },<br>
> - { &controls::AnalogueGain, ControlInfo(1.0f, 32.0f) },<br>
> { &controls::AeMeteringMode, ControlInfo(controls::AeMeteringModeValues) },<br>
> { &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) },<br>
> { &controls::AeExposureMode, ControlInfo(controls::AeExposureModeValues) },<br>
> @@ -89,7 +87,6 @@ static const ControlInfoMap::Map ipaControls{<br>
> { &controls::Sharpness, ControlInfo(0.0f, 16.0f, 1.0f) },<br>
> { &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) },<br>
> { &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) },<br>
> - { &controls::FrameDurationLimits, ControlInfo(INT64_C(1000), INT64_C(1000000000)) },<br>
> { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }<br>
> };<br>
> <br>
> @@ -446,6 +443,27 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,<br>
> ASSERT(controls);<br>
> *controls = std::move(ctrls);<br>
> <br>
> + /*<br>
> + * Apply the correct limits to the exposure, gain and frame duration controls<br>
> + * based on the current sensor mode.<br>
> + */<br>
> + ControlInfoMap::Map ctrlMap = ipaControls;<br>
> + const Duration minSensorFrameDuration = mode_.min_frame_length * mode_.line_length;<br>
> + const Duration maxSensorFrameDuration = mode_.max_frame_length * mode_.line_length;<br>
> + ctrlMap.emplace(&controls::FrameDurationLimits,<br>
> + ControlInfo(static_cast<int64_t>(minSensorFrameDuration.get<std::micro>()),<br>
> + static_cast<int64_t>(maxSensorFrameDuration.get<std::micro>())));<br>
> +<br>
> + ctrlMap.emplace(&controls::AnalogueGain,<br>
> + ControlInfo(1.0f, static_cast<float>(helper_->Gain(maxSensorGainCode_))));<br>
> +<br>
> + const uint32_t exposureMin = sensorCtrls_.at(V4L2_CID_EXPOSURE).min().get<int32_t>();<br>
> + const uint32_t exposureMax = sensorCtrls_.at(V4L2_CID_EXPOSURE).max().get<int32_t>();<br>
> + ctrlMap.emplace(&controls::ExposureTime,<br>
> + ControlInfo(static_cast<int32_t>(helper_->Exposure(exposureMin).get<std::micro>()),<br>
> + static_cast<int32_t>(helper_->Exposure(exposureMax).get<std::micro>())));<br>
> +<br>
> + result->controlInfo = ControlInfoMap(std::move(ctrlMap), controls::controls);<br>
<br>
<br>
aha, this means applications can't read the exposure time / gain<br>
controls before the camera is configured.<br>
<br>
I think that sounds 'correct' - but I wonder if we need to make that<br>
clear in some documentation somewhere, or somehow in an extension of<br>
'simple-cam' showing how to manage camera controls. (Not to block this<br>
patch of course).<br></blockquote><div><br></div><div>I did stop to think what to do here. We could add ControlInfo for<br></div><div>ExposureTime and AnalogueGain for the "default" sensor mode, but</div><div>getting to the sensor mode is a bit more difficult in ipa::init() as things</div><div>stand. Additionally, these values would likely have to be ignored by</div><div>the application. It has to do a camera::Configure() call before starting,</div><div>so the values might have changed, rendering the previous values as</div><div>invalid.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
We should make sure applications realise they have to recheck controls<br>
after a configuration operation. (Maybe that's obvious .. I'm not sure).<br></blockquote><div><br></div><div>Documenting this is probably a good thing so as to avoid application writers</div><div>from tripping up!</div><div><br></div><div>Regards,</div><div>Naush</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
I was dwelling on if we should only send the updates to the<br>
ControlInfoMap over the IPC mechanism, but I don't think this is<br>
critical path, and it's simpler to send the whole updated map - so:<br>
<br>
<br>
Reviewed-by: Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com" target="_blank">kieran.bingham@ideasonboard.com</a>><br>
<br>
> return 0;<br>
> }<br>
> <br>
> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
> index d980c1a71dd8..4596f2babcea 100644<br>
> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
> @@ -940,6 +940,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)<br>
> /* Store the mode sensitivity for the application. */<br>
> data->properties_.set(properties::SensorSensitivity, result.modeSensitivity);<br>
> <br>
> + /* Update the controls that the Raspberry Pi IPA can handle. */<br>
> + data->controlInfo_ = result.controlInfo;<br>
> +<br>
> /* Setup the Video Mux/Bridge entities. */<br>
> for (auto &[device, link] : data->bridgeDevices_) {<br>
> /*<br>
> -- <br>
> 2.25.1<br>
><br>
</blockquote></div></div>