diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/control_serializer.cpp | 22 | ||||
-rw-r--r-- | src/libcamera/controls.cpp | 33 | ||||
-rwxr-xr-x | src/libcamera/gen-controls.py | 18 |
3 files changed, 63 insertions, 10 deletions
diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index eef875f4..808419f2 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -314,6 +314,22 @@ ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer, return value; } +template<> +ControlValue ControlSerializer::loadControlValue<std::string>(ByteStreamBuffer &buffer, + bool isArray, + unsigned int count) +{ + ControlValue value; + + const char *data = buffer.read<char>(count); + if (!data) + return value; + + value.set(std::string{ data, count }); + + return value; +} + ControlValue ControlSerializer::loadControlValue(ControlType type, ByteStreamBuffer &buffer, bool isArray, @@ -335,6 +351,9 @@ ControlValue ControlSerializer::loadControlValue(ControlType type, case ControlTypeFloat: return loadControlValue<float>(buffer, isArray, count); + case ControlTypeString: + return loadControlValue<std::string>(buffer, isArray, count); + case ControlTypeNone: return ControlValue(); } @@ -345,6 +364,9 @@ ControlValue ControlSerializer::loadControlValue(ControlType type, ControlInfo ControlSerializer::loadControlInfo(ControlType type, ByteStreamBuffer &b) { + if (type == ControlTypeString) + type = ControlTypeInteger32; + ControlValue min = loadControlValue(type, b); ControlValue max = loadControlValue(type, b); diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 53649fe8..11cec519 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -57,6 +57,7 @@ static constexpr size_t ControlValueSize[] = { [ControlTypeInteger32] = sizeof(int32_t), [ControlTypeInteger64] = sizeof(int64_t), [ControlTypeFloat] = sizeof(float), + [ControlTypeString] = sizeof(char), }; } /* namespace */ @@ -76,6 +77,8 @@ static constexpr size_t ControlValueSize[] = { * 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 */ /** @@ -164,7 +167,8 @@ ControlValue &ControlValue::operator=(const ControlValue &other) * \brief Retrieve the number of elements stored in the ControlValue * * For instances storing an array, this function returns the number of elements - * in the array. Otherwise, it returns 1. + * in the array. For instances storing a string, it returns the length of the + * string, not counting the terminating '\0'. Otherwise, it returns 1. * * \return The number of elements stored in the ControlValue */ @@ -192,6 +196,11 @@ std::string ControlValue::toString() const return "<ValueType Error>"; const uint8_t *data = ControlValue::data().data(); + + if (type_ == ControlTypeString) + return std::string(reinterpret_cast<const char *>(data), + numElements_); + std::string str(isArray_ ? "[ " : ""); for (unsigned int i = 0; i < numElements_; ++i) { @@ -222,6 +231,7 @@ std::string ControlValue::toString() const break; } case ControlTypeNone: + case ControlTypeString: break; } @@ -439,12 +449,22 @@ ControlInfo::ControlInfo(const ControlValue &min, /** * \fn ControlInfo::min() * \brief Retrieve the minimum value of the control + * + * For string controls, this is the minimum length of the string, not counting + * the terminating '\0'. For all other control types, this is the minimum value + * of each element. + * * \return A ControlValue with the minimum value for the control */ /** * \fn ControlInfo::max() * \brief Retrieve the maximum value of the control + * + * For string controls, this is the maximum length of the string, not counting + * the terminating '\0'. For all other control types, this is the maximum value + * of each element. + * * \return A ControlValue with the maximum value for the control */ @@ -653,7 +673,16 @@ void ControlInfoMap::generateIdmap() idmap_.clear(); for (const auto &ctrl : *this) { - if (ctrl.first->type() != ctrl.second.min().type()) { + /* + * For string controls, min and max define the valid + * range for the string size, not for the individual + * values. + */ + ControlType rangeType = ctrl.first->type() == ControlTypeString + ? ControlTypeInteger32 : ctrl.first->type(); + const ControlInfo &info = ctrl.second; + + if (info.min().type() != rangeType) { LOG(Controls, Error) << "Control " << utils::hex(ctrl.first->id()) << " type and info type mismatch"; diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py index ff8bda6b..87c3d52a 100755 --- a/src/libcamera/gen-controls.py +++ b/src/libcamera/gen-controls.py @@ -42,10 +42,11 @@ ${description} name, ctrl = ctrl.popitem() id_name = snake_case(name).upper() - if ctrl.get('size'): - ctrl_type = 'Span<const %s>' % ctrl['type'] - else: - ctrl_type = ctrl['type'] + ctrl_type = ctrl['type'] + if ctrl_type == 'string': + ctrl_type = 'std::string' + elif ctrl.get('size'): + ctrl_type = 'Span<const %s>' % ctrl_type info = { 'name': name, @@ -97,10 +98,11 @@ def generate_h(controls): ids.append('\t' + id_name + ' = ' + str(id_value) + ',') - if ctrl.get('size'): - ctrl_type = 'Span<const %s>' % ctrl['type'] - else: - ctrl_type = ctrl['type'] + ctrl_type = ctrl['type'] + if ctrl_type == 'string': + ctrl_type = 'std::string' + elif ctrl.get('size'): + ctrl_type = 'Span<const %s>' % ctrl_type info = { 'name': name, |