libcamera: controls: Use std::optional to handle invalid control values
Previously, ControlList::get<T>() would use default constructed objects to indicate that a ControlList does not have the requested Control. This has several disadvantages: 1) It requires types to be default constructible, 2) it does not differentiate between a default constructed object and an object that happens to have the same state as a default constructed object. std::optional<T> additionally stores the information if the object is valid or not, and therefore is more expressive than a default constructed object. Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
committed by
Laurent Pinchart
parent
ef77e26379
commit
1c4d480185
@@ -1145,7 +1145,7 @@ int PipelineHandlerIPU3::registerCameras()
|
||||
/* Convert the sensor rotation to a transformation */
|
||||
int32_t rotation = 0;
|
||||
if (data->properties_.contains(properties::Rotation))
|
||||
rotation = data->properties_.get(properties::Rotation);
|
||||
rotation = *(data->properties_.get(properties::Rotation));
|
||||
else
|
||||
LOG(IPU3, Warning) << "Rotation control not exposed by "
|
||||
<< cio2->sensor()->id()
|
||||
@@ -1331,7 +1331,7 @@ void IPU3CameraData::imguOutputBufferReady(FrameBuffer *buffer)
|
||||
request->metadata().set(controls::draft::PipelineDepth, 3);
|
||||
/* \todo Actually apply the scaler crop region to the ImgU. */
|
||||
if (request->controls().contains(controls::ScalerCrop))
|
||||
cropRegion_ = request->controls().get(controls::ScalerCrop);
|
||||
cropRegion_ = *(request->controls().get(controls::ScalerCrop));
|
||||
request->metadata().set(controls::ScalerCrop, cropRegion_);
|
||||
|
||||
if (frameInfos_.tryComplete(info))
|
||||
@@ -1424,7 +1424,7 @@ void IPU3CameraData::statBufferReady(FrameBuffer *buffer)
|
||||
return;
|
||||
}
|
||||
|
||||
ipa_->processStatsBuffer(info->id, request->metadata().get(controls::SensorTimestamp),
|
||||
ipa_->processStatsBuffer(info->id, request->metadata().get(controls::SensorTimestamp).value_or(0),
|
||||
info->statBuffer->cookie(), info->effectiveSensorControls);
|
||||
}
|
||||
|
||||
@@ -1458,8 +1458,7 @@ void IPU3CameraData::frameStart(uint32_t sequence)
|
||||
if (!request->controls().contains(controls::draft::TestPatternMode))
|
||||
return;
|
||||
|
||||
const int32_t testPatternMode = request->controls().get(
|
||||
controls::draft::TestPatternMode);
|
||||
const int32_t testPatternMode = *(request->controls().get(controls::draft::TestPatternMode));
|
||||
|
||||
int ret = cio2_.sensor()->setTestPatternMode(
|
||||
static_cast<controls::draft::TestPatternModeEnum>(testPatternMode));
|
||||
|
||||
@@ -364,7 +364,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()
|
||||
* error means the platform can never run. Let's just print a warning
|
||||
* and continue regardless; the rotation is effectively set to zero.
|
||||
*/
|
||||
int32_t rotation = data_->sensor_->properties().get(properties::Rotation);
|
||||
int32_t rotation = data_->sensor_->properties().get(properties::Rotation).value_or(0);
|
||||
bool success;
|
||||
Transform rotationTransform = transformFromRotation(rotation, &success);
|
||||
if (!success)
|
||||
@@ -1718,7 +1718,8 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &
|
||||
* V4L2_CID_NOTIFY_GAINS control (which means notifyGainsUnity_ is set).
|
||||
*/
|
||||
if (notifyGainsUnity_ && controls.contains(libcamera::controls::ColourGains)) {
|
||||
libcamera::Span<const float> colourGains = controls.get(libcamera::controls::ColourGains);
|
||||
libcamera::Span<const float> colourGains =
|
||||
*controls.get(libcamera::controls::ColourGains);
|
||||
/* The control wants linear gains in the order B, Gb, Gr, R. */
|
||||
ControlList ctrls(sensor_->controls());
|
||||
std::array<int32_t, 4> gains{
|
||||
@@ -2053,7 +2054,7 @@ Rectangle RPiCameraData::scaleIspCrop(const Rectangle &ispCrop) const
|
||||
void RPiCameraData::applyScalerCrop(const ControlList &controls)
|
||||
{
|
||||
if (controls.contains(controls::ScalerCrop)) {
|
||||
Rectangle nativeCrop = controls.get<Rectangle>(controls::ScalerCrop);
|
||||
Rectangle nativeCrop = *controls.get<Rectangle>(controls::ScalerCrop);
|
||||
|
||||
if (!nativeCrop.width || !nativeCrop.height)
|
||||
nativeCrop = { 0, 0, 1, 1 };
|
||||
@@ -2091,7 +2092,7 @@ void RPiCameraData::fillRequestMetadata(const ControlList &bufferControls,
|
||||
Request *request)
|
||||
{
|
||||
request->metadata().set(controls::SensorTimestamp,
|
||||
bufferControls.get(controls::SensorTimestamp));
|
||||
bufferControls.get(controls::SensorTimestamp).value_or(0));
|
||||
|
||||
request->metadata().set(controls::ScalerCrop, scalerCrop_);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user