From 8daf20485b90af2065e3db0e3fd0cd5b72fd7ac4 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 28 Feb 2020 17:01:43 +0200 Subject: libcamera: controls: Add zero-copy set API for ControlValue Extend the ControlValue class with a reserve() function to set the value without actually copying data, and a non-const data() function that allows writing data directly to the ControlValue storage. This allows allocating memory directly in ControlValue, potentially removing a data copy. Note that this change was implemented before ByteStreamBuffer gained the zero-copy read() variant, and doesn't actually save a copy in the control serializer. It however still simplifies ControlSerializer::loadControlValue(). Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/control_serializer.cpp | 61 +++--------------------------------- 1 file changed, 4 insertions(+), 57 deletions(-) (limited to 'src/libcamera/control_serializer.cpp') diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index 808419f2..fcff5e56 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -295,70 +295,17 @@ int ControlSerializer::serialize(const ControlList &list, return 0; } -template -ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer, - bool isArray, - unsigned int count) -{ - ControlValue value; - - const T *data = buffer.read(count); - if (!data) - return value; - - if (isArray) - value.set(Span{ data, count }); - else - value.set(*data); - - return value; -} - -template<> -ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer, - bool isArray, - unsigned int count) -{ - ControlValue value; - - const char *data = buffer.read(count); - if (!data) - return value; - - value.set(std::string{ data, count }); - - return value; -} - ControlValue ControlSerializer::loadControlValue(ControlType type, ByteStreamBuffer &buffer, bool isArray, unsigned int count) { - switch (type) { - case ControlTypeBool: - return loadControlValue(buffer, isArray, count); - - case ControlTypeByte: - return loadControlValue(buffer, isArray, count); - - case ControlTypeInteger32: - return loadControlValue(buffer, isArray, count); - - case ControlTypeInteger64: - return loadControlValue(buffer, isArray, count); - - case ControlTypeFloat: - return loadControlValue(buffer, isArray, count); - - case ControlTypeString: - return loadControlValue(buffer, isArray, count); + ControlValue value; - case ControlTypeNone: - return ControlValue(); - } + value.reserve(type, isArray, count); + buffer.read(value.data()); - return ControlValue(); + return value; } ControlInfo ControlSerializer::loadControlInfo(ControlType type, -- cgit v1.2.1