summaryrefslogtreecommitdiff
path: root/src/libcamera/control_serializer.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-01 17:51:42 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-20 16:47:45 +0200
commit4e3f835126b5116f5cec88634e18f3d54900892d (patch)
tree7d2c114a26a33490e8d7259dde97d6e3aeea3d16 /src/libcamera/control_serializer.cpp
parente5a9e6e9cd3e12efe9ce078171fbe67d7d41a771 (diff)
libcamera: controls: Add support for string controls
String controls are stored internally as an array of char, but the ControlValue constructor, get() and set() functions operate on an std::string for convenience. Array of strings are thus not supported. Unlike for other control types, the ControlInfo range reports the minimum and maximum allowed lengths of the string (the minimum will usually be 0), not the minimum and maximum value of each element. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/libcamera/control_serializer.cpp')
-rw-r--r--src/libcamera/control_serializer.cpp22
1 files changed, 22 insertions, 0 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);