mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-15 16:35:06 +03:00
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:
parent
ef77e26379
commit
1c4d480185
10 changed files with 44 additions and 44 deletions
|
@ -1042,7 +1042,7 @@ int CameraCapabilities::initializeStaticMetadata()
|
|||
/* Sensor static metadata. */
|
||||
std::array<int32_t, 2> pixelArraySize;
|
||||
{
|
||||
const Size &size = properties.get(properties::PixelArraySize);
|
||||
const Size &size = properties.get(properties::PixelArraySize).value_or(Size{});
|
||||
pixelArraySize[0] = size.width;
|
||||
pixelArraySize[1] = size.height;
|
||||
staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE,
|
||||
|
@ -1050,10 +1050,10 @@ int CameraCapabilities::initializeStaticMetadata()
|
|||
}
|
||||
|
||||
if (properties.contains(properties::UnitCellSize)) {
|
||||
const Size &cellSize = properties.get<Size>(properties::UnitCellSize);
|
||||
const auto &cellSize = properties.get<Size>(properties::UnitCellSize);
|
||||
std::array<float, 2> physicalSize{
|
||||
cellSize.width * pixelArraySize[0] / 1e6f,
|
||||
cellSize.height * pixelArraySize[1] / 1e6f
|
||||
cellSize->width * pixelArraySize[0] / 1e6f,
|
||||
cellSize->height * pixelArraySize[1] / 1e6f
|
||||
};
|
||||
staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PHYSICAL_SIZE,
|
||||
physicalSize);
|
||||
|
@ -1061,7 +1061,7 @@ int CameraCapabilities::initializeStaticMetadata()
|
|||
|
||||
{
|
||||
const Span<const Rectangle> &rects =
|
||||
properties.get(properties::PixelArrayActiveAreas);
|
||||
properties.get(properties::PixelArrayActiveAreas).value_or(Span<const Rectangle>{});
|
||||
std::vector<int32_t> data{
|
||||
static_cast<int32_t>(rects[0].x),
|
||||
static_cast<int32_t>(rects[0].y),
|
||||
|
@ -1080,7 +1080,7 @@ int CameraCapabilities::initializeStaticMetadata()
|
|||
|
||||
/* Report the color filter arrangement if the camera reports it. */
|
||||
if (properties.contains(properties::draft::ColorFilterArrangement)) {
|
||||
uint8_t filterArr = properties.get(properties::draft::ColorFilterArrangement);
|
||||
uint8_t filterArr = *properties.get(properties::draft::ColorFilterArrangement);
|
||||
staticMetadata_->addEntry(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT,
|
||||
filterArr);
|
||||
}
|
||||
|
|
|
@ -306,7 +306,7 @@ int CameraDevice::initialize(const CameraConfigData *cameraConfigData)
|
|||
const ControlList &properties = camera_->properties();
|
||||
|
||||
if (properties.contains(properties::Location)) {
|
||||
int32_t location = properties.get(properties::Location);
|
||||
int32_t location = *properties.get(properties::Location);
|
||||
switch (location) {
|
||||
case properties::CameraLocationFront:
|
||||
facing_ = CAMERA_FACING_FRONT;
|
||||
|
@ -356,7 +356,7 @@ int CameraDevice::initialize(const CameraConfigData *cameraConfigData)
|
|||
* metadata.
|
||||
*/
|
||||
if (properties.contains(properties::Rotation)) {
|
||||
int rotation = properties.get(properties::Rotation);
|
||||
int rotation = *properties.get(properties::Rotation);
|
||||
orientation_ = (360 - rotation) % 360;
|
||||
if (cameraConfigData && cameraConfigData->rotation != -1 &&
|
||||
orientation_ != cameraConfigData->rotation) {
|
||||
|
@ -1181,7 +1181,8 @@ void CameraDevice::requestComplete(Request *request)
|
|||
* as soon as possible, earlier than request completion time.
|
||||
*/
|
||||
uint64_t sensorTimestamp = static_cast<uint64_t>(request->metadata()
|
||||
.get(controls::SensorTimestamp));
|
||||
.get(controls::SensorTimestamp)
|
||||
.value_or(0));
|
||||
notifyShutter(descriptor->frameNumber_, sensorTimestamp);
|
||||
|
||||
LOG(HAL, Debug) << "Request " << request->cookie() << " completed with "
|
||||
|
@ -1560,29 +1561,28 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons
|
|||
rolling_shutter_skew);
|
||||
|
||||
/* Add metadata tags reported by libcamera. */
|
||||
const int64_t timestamp = metadata.get(controls::SensorTimestamp);
|
||||
const int64_t timestamp = metadata.get(controls::SensorTimestamp).value_or(0);
|
||||
resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, timestamp);
|
||||
|
||||
if (metadata.contains(controls::draft::PipelineDepth)) {
|
||||
uint8_t pipeline_depth =
|
||||
metadata.get<int32_t>(controls::draft::PipelineDepth);
|
||||
uint8_t pipeline_depth = *metadata.get<int32_t>(controls::draft::PipelineDepth);
|
||||
resultMetadata->addEntry(ANDROID_REQUEST_PIPELINE_DEPTH,
|
||||
pipeline_depth);
|
||||
}
|
||||
|
||||
if (metadata.contains(controls::ExposureTime)) {
|
||||
int64_t exposure = metadata.get(controls::ExposureTime) * 1000ULL;
|
||||
int64_t exposure = *metadata.get(controls::ExposureTime) * 1000ULL;
|
||||
resultMetadata->addEntry(ANDROID_SENSOR_EXPOSURE_TIME, exposure);
|
||||
}
|
||||
|
||||
if (metadata.contains(controls::FrameDuration)) {
|
||||
int64_t duration = metadata.get(controls::FrameDuration) * 1000;
|
||||
int64_t duration = *metadata.get(controls::FrameDuration) * 1000;
|
||||
resultMetadata->addEntry(ANDROID_SENSOR_FRAME_DURATION,
|
||||
duration);
|
||||
}
|
||||
|
||||
if (metadata.contains(controls::ScalerCrop)) {
|
||||
Rectangle crop = metadata.get(controls::ScalerCrop);
|
||||
Rectangle crop = *metadata.get(controls::ScalerCrop);
|
||||
int32_t cropRect[] = {
|
||||
crop.x, crop.y, static_cast<int32_t>(crop.width),
|
||||
static_cast<int32_t>(crop.height),
|
||||
|
@ -1591,8 +1591,7 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons
|
|||
}
|
||||
|
||||
if (metadata.contains(controls::draft::TestPatternMode)) {
|
||||
const int32_t testPatternMode =
|
||||
metadata.get(controls::draft::TestPatternMode);
|
||||
const int32_t testPatternMode = *metadata.get(controls::draft::TestPatternMode);
|
||||
resultMetadata->addEntry(ANDROID_SENSOR_TEST_PATTERN_MODE,
|
||||
testPatternMode);
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ int32_t CameraHalManager::cameraLocation(const Camera *cam)
|
|||
if (!properties.contains(properties::Location))
|
||||
return -1;
|
||||
|
||||
return properties.get(properties::Location);
|
||||
return *properties.get(properties::Location);
|
||||
}
|
||||
|
||||
CameraDevice *CameraHalManager::cameraDeviceFromHalId(unsigned int id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue