[libcamera-devel] [PATCH 15/31] libcamera: controls: Expose raw data in ControlValue
Kieran Bingham
kieran.bingham at ideasonboard.com
Tue Mar 3 00:44:28 CET 2020
Hi Laurent,
On 29/02/2020 16:42, Laurent Pinchart wrote:
> Add a data() function to the ControlValue class to expose the raw data
> stored by the class as a Span<const uint8_t>. This will be useful to
> simplify the serialization of ControlValue instances.
>
> The size computation for the raw data is moved from the
> ControlSerializer, which is updated accordingly to use the data()
> function in order to access the size. Simplification of the
> ControlSerializer will happen in a subsequent change.
>
Nice, I think I see where this is going...
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> ---
> include/libcamera/controls.h | 3 +++
> src/libcamera/control_serializer.cpp | 13 +------------
> src/libcamera/controls.cpp | 23 +++++++++++++++++++++++
> 3 files changed, 27 insertions(+), 12 deletions(-)
>
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 6f0ebf4f3ca5..4538be06af93 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -12,6 +12,8 @@
> #include <string>
> #include <unordered_map>
>
> +#include <libcamera/span.h>
> +
> namespace libcamera {
>
> class ControlValidator;
> @@ -65,6 +67,7 @@ public:
>
> ControlType type() const { return type_; }
> bool isNone() const { return type_ == ControlTypeNone; }
> + Span<const uint8_t> data() const;
>
> std::string toString() const;
>
> diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
> index 803ac16c2456..2b66ab978f81 100644
> --- a/src/libcamera/control_serializer.cpp
> +++ b/src/libcamera/control_serializer.cpp
> @@ -27,17 +27,6 @@ namespace libcamera {
>
> LOG_DEFINE_CATEGORY(Serializer)
>
> -namespace {
> -
> -static constexpr size_t ControlValueSize[] = {
> - [ControlTypeNone] = 1,
> - [ControlTypeBool] = sizeof(bool),
> - [ControlTypeInteger32] = sizeof(int32_t),
> - [ControlTypeInteger64] = sizeof(int64_t),
> -};
> -
> -} /* namespace */
> -
> /**
> * \class ControlSerializer
> * \brief Serializer and deserializer for control-related classes
> @@ -106,7 +95,7 @@ void ControlSerializer::reset()
>
> size_t ControlSerializer::binarySize(const ControlValue &value)
> {
> - return ControlValueSize[value.type()];
> + return value.data().size_bytes();
> }
>
> size_t ControlSerializer::binarySize(const ControlRange &range)
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 76230a052de1..b2331ab7540d 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -47,6 +47,17 @@ namespace libcamera {
>
> LOG_DEFINE_CATEGORY(Controls)
>
> +namespace {
> +
> +static constexpr size_t ControlValueSize[] = {
> + [ControlTypeNone] = 1,
> + [ControlTypeBool] = sizeof(bool),
> + [ControlTypeInteger32] = sizeof(int32_t),
> + [ControlTypeInteger64] = sizeof(int64_t),
> +};
> +
> +} /* namespace */
> +
> /**
> * \enum ControlType
> * \brief Define the data type of a Control
> @@ -91,6 +102,18 @@ ControlValue::ControlValue()
> * \return True if the value type is ControlTypeNone, false otherwise
> */
>
> +/**
> + * \brief Retrieve the raw of a control value
Retrieve the raw '{data, bytes}' of a control value?
> + * \return The raw data of the control value as a span of uint8_t
> + */
> +Span<const uint8_t> ControlValue::data() const
> +{
> + return {
> + reinterpret_cast<const uint8_t *>(&bool_),
> + ControlValueSize[type_]
> + };
Eeep, that starts looking like some sort of lambda/function/scope syntax
due to the { }; positions ...
> +}
> +
> /**
> * \brief Assemble and return a string describing the value
> * \return A string describing the ControlValue
>
--
Regards
--
Kieran
More information about the libcamera-devel
mailing list