diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-10-26 20:25:56 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-11-20 21:47:50 +0200 |
commit | 2c5f0ad23aa40d7410b28e01405c730e75c6cf83 (patch) | |
tree | 4aa9d63d6553fe4a20abddc28065b7ec9cfdc8fe /src/libcamera/include/control_serializer.h | |
parent | 56c9a978d676eb840b60b2e2c193755c64b996ab (diff) |
libcamera: Add controls serializer
Add a new ControlSerializer helper to serialize and deserialize
ControlInfoMap and ControlList instances. This will be used to implement
the C IPA protocol and the communication with IPA through IPC.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/include/control_serializer.h')
-rw-r--r-- | src/libcamera/include/control_serializer.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/libcamera/include/control_serializer.h b/src/libcamera/include/control_serializer.h new file mode 100644 index 00000000..bb3cb8e7 --- /dev/null +++ b/src/libcamera/include/control_serializer.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * control_serializer.h - Control (de)serializer + */ +#ifndef __LIBCAMERA_CONTROL_SERIALIZER_H__ +#define __LIBCAMERA_CONTROL_SERIALIZER_H__ + +#include <map> +#include <memory> +#include <vector> + +#include <libcamera/controls.h> + +namespace libcamera { + +class ByteStreamBuffer; + +class ControlSerializer +{ +public: + void reset(); + + static size_t binarySize(const ControlInfoMap &info); + static size_t binarySize(const ControlList &list); + + int serialize(const ControlInfoMap &info, ByteStreamBuffer &buffer); + int serialize(const ControlList &list, ByteStreamBuffer &buffer); + + template<typename T> + T deserialize(ByteStreamBuffer &buffer); + +private: + static size_t binarySize(const ControlValue &value); + static size_t binarySize(const ControlRange &range); + + static void store(const ControlValue &value, ByteStreamBuffer &buffer); + static void store(const ControlRange &range, ByteStreamBuffer &buffer); + + template<typename T> + T load(ControlType type, ByteStreamBuffer &b); + + unsigned int serial_; + std::vector<std::unique_ptr<ControlId>> controlIds_; + std::map<unsigned int, ControlInfoMap> infoMaps_; + std::map<const ControlInfoMap *, unsigned int> infoMapHandles_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_CONTROL_SERIALIZER_H__ */ |