/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* controls.cpp - Control handling
*/
#include <libcamera/controls.h>
#include <iomanip>
#include <sstream>
#include <string>
#include <string.h>
#include "control_validator.h"
#include "log.h"
#include "utils.h"
/**
* \file controls.h
* \brief Framework to manage controls related to an object
*
* A control is a mean to govern or influence the operation of an object, and in
* particular of a camera. Every control is defined by a unique numerical ID, a
* name string and the data type of the value it stores. The libcamera API
* defines a set of standard controls in the libcamera::controls namespace, as
* a set of instances of the Control class.
*
* The main way for applications to interact with controls is through the
* ControlList stored in the Request class:
*
* \code{.cpp}
* Request *req = ...;
* ControlList &controls = req->controls();
* controls->set(controls::AwbEnable, false);
* controls->set(controls::ManualExposure, 1000);
*
* ...
*
* int32_t exposure = controls->get(controls::ManualExposure);
* \endcode
*
* The ControlList::get() and ControlList::set() methods automatically deduce
* the data type based on the control.
*/
namespace libcamera {
LOG_DEFINE_CATEGORY(Controls)
namespace {
static constexpr size_t ControlValueSize[] = {
[ControlTypeNone] = 0,
[ControlTypeBool] = sizeof(bool),
[ControlTypeByte] = sizeof(uint8_t),
[ControlTypeInteger32] = sizeof(int32_t),
[ControlTypeInteger64] = sizeof(int64_t),
[ControlTypeFloat] = sizeof(float),
[ControlTypeString] = sizeof(char),
[ControlTypeRectangle] = sizeof(Rectangle),
[ControlTypeSize] = sizeof(Size),
};
} /* namespace */
/**
* \enum ControlType
* \brief Define the data type of a Control
* \var ControlTypeNone
* Invalid type, for empty values
* \var ControlTypeBool
* The control stores a boolean value
* \var ControlTypeByte
* The control stores a byte value as an unsigned 8-bit integer
* \var ControlTypeInteger32
* The control stores a 32-bit integer value
* \var ControlTypeInteger64
* The control stores a 64-bit integer value
* \var ControlTypeFloat
* The control stores a 32-bit floating point value
* \var ControlTypeString
* The control stores a string value as an array of char
*/
/**
* \class ControlValue
* \brief Abstract type representing the value of a control
*/
/** \todo Revisit the ControlValue layout when stabilizing the ABI */
static_assert(sizeof(ControlValue) == 16, "Invalid size of ControlValue class");
/**
* \brief Construct an empty ControlValue.
*/
ControlValue::ControlValue()
|