Files
external_libcamera/include/libcamera/internal/control_serializer.h
Paul Elder 892c0f4c19 libcamera: control_serializer: Save serialized ControlInfoMap in a cache
The ControlSerializer saves all ControlInfoMaps that it has already
(de)serialized, in order to (de)serialize ControlLists that contain the
ControlInfoMaps. Leverage this to cache ControlInfoMaps, such that the
ControlSerializer will not re-(de)serialize a ControlInfoMap that it has
previously (de)serialized.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-02-16 19:20:57 +09:00

58 lines
1.5 KiB
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* control_serializer.h - Control (de)serializer
*/
#ifndef __LIBCAMERA_INTERNAL_CONTROL_SERIALIZER_H__
#define __LIBCAMERA_INTERNAL_CONTROL_SERIALIZER_H__
#include <map>
#include <memory>
#include <vector>
#include <libcamera/controls.h>
namespace libcamera {
class ByteStreamBuffer;
class ControlSerializer
{
public:
ControlSerializer();
void reset();
static size_t binarySize(const ControlInfoMap &infoMap);
static size_t binarySize(const ControlList &list);
int serialize(const ControlInfoMap &infoMap, ByteStreamBuffer &buffer);
int serialize(const ControlList &list, ByteStreamBuffer &buffer);
template<typename T>
T deserialize(ByteStreamBuffer &buffer);
bool isCached(const ControlInfoMap &infoMap);
private:
static size_t binarySize(const ControlValue &value);
static size_t binarySize(const ControlInfo &info);
static void store(const ControlValue &value, ByteStreamBuffer &buffer);
static void store(const ControlInfo &info, ByteStreamBuffer &buffer);
ControlValue loadControlValue(ControlType type, ByteStreamBuffer &buffer,
bool isArray = false, unsigned int count = 1);
ControlInfo loadControlInfo(ControlType type, ByteStreamBuffer &buffer);
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_INTERNAL_CONTROL_SERIALIZER_H__ */