libcamera: control_serializer: Add support for array controls

Add support for serializing and deserializing control values that store
arrays of values. The serialized format is extended to explicitly handle
arrays.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Jacopo Mondi 2020-01-13 13:47:09 +01:00 committed by Laurent Pinchart
parent 7c6f59217e
commit fa252b710a
2 changed files with 49 additions and 37 deletions

View file

@ -14,6 +14,7 @@
#include <ipa/ipa_controls.h> #include <ipa/ipa_controls.h>
#include <libcamera/control_ids.h> #include <libcamera/control_ids.h>
#include <libcamera/controls.h> #include <libcamera/controls.h>
#include <libcamera/span.h>
#include "byte_stream_buffer.h" #include "byte_stream_buffer.h"
#include "log.h" #include "log.h"
@ -279,8 +280,9 @@ int ControlSerializer::serialize(const ControlList &list,
struct ipa_control_value_entry entry; struct ipa_control_value_entry entry;
entry.id = id; entry.id = id;
entry.count = 1;
entry.type = value.type(); entry.type = value.type();
entry.is_array = value.isArray();
entry.count = value.numElements();
entry.offset = values.offset(); entry.offset = values.offset();
entries.write(&entry); entries.write(&entry);
@ -293,40 +295,45 @@ int ControlSerializer::serialize(const ControlList &list,
return 0; return 0;
} }
template<> template<typename T>
ControlValue ControlSerializer::load<ControlValue>(ControlType type, ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer,
ByteStreamBuffer &b) bool isArray,
unsigned int count)
{
ControlValue value;
const T *data = buffer.read<T>(count);
if (!data)
return value;
if (isArray)
value.set(Span<const T>{ data, count });
else
value.set(*data);
return value;
}
ControlValue ControlSerializer::loadControlValue(ControlType type,
ByteStreamBuffer &buffer,
bool isArray,
unsigned int count)
{ {
switch (type) { switch (type) {
case ControlTypeBool: { case ControlTypeBool:
bool value; return loadControlValue<bool>(buffer, isArray, count);
b.read(&value);
return ControlValue(value);
}
case ControlTypeByte: { case ControlTypeByte:
uint8_t value; return loadControlValue<uint8_t>(buffer, isArray, count);
b.read(&value);
return ControlValue(value);
}
case ControlTypeInteger32: { case ControlTypeInteger32:
int32_t value; return loadControlValue<int32_t>(buffer, isArray, count);
b.read(&value);
return ControlValue(value);
}
case ControlTypeInteger64: { case ControlTypeInteger64:
int64_t value; return loadControlValue<int64_t>(buffer, isArray, count);
b.read(&value);
return ControlValue(value);
}
case ControlTypeFloat: { case ControlTypeFloat:
float value; return loadControlValue<float>(buffer, isArray, count);
b.read(&value);
return ControlValue(value);
}
case ControlTypeNone: case ControlTypeNone:
return ControlValue(); return ControlValue();
@ -335,12 +342,11 @@ ControlValue ControlSerializer::load<ControlValue>(ControlType type,
return ControlValue(); return ControlValue();
} }
template<> ControlRange ControlSerializer::loadControlRange(ControlType type,
ControlRange ControlSerializer::load<ControlRange>(ControlType type,
ByteStreamBuffer &b) ByteStreamBuffer &b)
{ {
ControlValue min = load<ControlValue>(type, b); ControlValue min = loadControlValue(type, b);
ControlValue max = load<ControlValue>(type, b); ControlValue max = loadControlValue(type, b);
return ControlRange(min, max); return ControlRange(min, max);
} }
@ -414,7 +420,7 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &
/* Create and store the ControlRange. */ /* Create and store the ControlRange. */
ctrls.emplace(controlIds_.back().get(), ctrls.emplace(controlIds_.back().get(),
load<ControlRange>(type, values)); loadControlRange(type, values));
} }
/* /*
@ -502,7 +508,9 @@ ControlList ControlSerializer::deserialize<ControlList>(ByteStreamBuffer &buffer
} }
ControlType type = static_cast<ControlType>(entry->type); ControlType type = static_cast<ControlType>(entry->type);
ctrls.set(entry->id, load<ControlValue>(type, values)); ctrls.set(entry->id,
loadControlValue(type, values, entry->is_array,
entry->count));
} }
return ctrls; return ctrls;

View file

@ -41,7 +41,11 @@ private:
static void store(const ControlRange &range, ByteStreamBuffer &buffer); static void store(const ControlRange &range, ByteStreamBuffer &buffer);
template<typename T> template<typename T>
T load(ControlType type, ByteStreamBuffer &b); ControlValue loadControlValue(ByteStreamBuffer &buffer, bool isArray,
unsigned int count);
ControlValue loadControlValue(ControlType type, ByteStreamBuffer &buffer,
bool isArray = false, unsigned int count = 1);
ControlRange loadControlRange(ControlType type, ByteStreamBuffer &buffer);
unsigned int serial_; unsigned int serial_;
std::vector<std::unique_ptr<ControlId>> controlIds_; std::vector<std::unique_ptr<ControlId>> controlIds_;