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>
This commit is contained in:
Laurent Pinchart
2019-10-26 20:25:56 +03:00
parent 56c9a978d6
commit 2c5f0ad23a
4 changed files with 564 additions and 0 deletions

View File

@@ -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__ */

View File

@@ -2,6 +2,7 @@ libcamera_headers = files([
'byte_stream_buffer.h',
'camera_controls.h',
'camera_sensor.h',
'control_serializer.h',
'control_validator.h',
'device_enumerator.h',
'device_enumerator_sysfs.h',