libcamera/include/libcamera/internal/control_serializer.h
Christian Rauch cbc2be34ed libcamera: control_serializer: store/load all ControlValue types
The min/max/def ControlValue of a ControlInfo can take arbitrary types that
are different from each other and different from the ControlId type.
The serialiser serialises these ControlValue separately by their type but
does not store the type. The deserialiser assumes that ControlValue types
match the ControlId type. If this is not the case, deserialisation will try
to deserialise values of the wrong type.

Fix this by serialising each of the min/max/def ControlValue's ControlType
and storing it just before the serialised ControlValue.

Fixes: https://bugs.libcamera.org/show_bug.cgi?id=137

Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
Tested-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
2022-09-12 18:28:59 +09:00

62 lines
1.5 KiB
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* control_serializer.h - Control (de)serializer
*/
#pragma once
#include <map>
#include <memory>
#include <vector>
#include <libcamera/controls.h>
namespace libcamera {
class ByteStreamBuffer;
class ControlSerializer
{
public:
enum class Role {
Proxy,
Worker
};
ControlSerializer(Role role);
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(ByteStreamBuffer &buffer,
bool isArray = false, unsigned int count = 1);
ControlInfo loadControlInfo(ByteStreamBuffer &buffer);
unsigned int serial_;
unsigned int serialSeed_;
std::vector<std::unique_ptr<ControlId>> controlIds_;
std::vector<std::unique_ptr<ControlIdMap>> controlIdMaps_;
std::map<unsigned int, ControlInfoMap> infoMaps_;
std::map<const ControlInfoMap *, unsigned int> infoMapHandles_;
};
} /* namespace libcamera */