Two independent instances of the ControlSerializer class are in use at the IPC boundaries, one in the Proxy class that serializes data from the pipeline handler to the IPA, and one in the ProxyWorker which serializes data in the opposite direction. Each instance operates autonomously, without any centralized point of control, and each one assigns a numerical handle to each ControlInfoMap it serializes. This creates a risk of potential collision on the handle values, as both instances will use the same numerical space and are not aware of what handles has been already used by the instance "on the other side". To fix that, partition the handles numerical space by initializing the control serializer with a seed according to the role of the component that creates the serializer and increment the handle number by 2, to avoid any collision risk. While this is temporary and rather hacky solution, it solves an issue with isolated IPA modules without too much complexity added. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
65 lines
1.7 KiB
C++
65 lines
1.7 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:
|
|
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(ControlType type, ByteStreamBuffer &buffer,
|
|
bool isArray = false, unsigned int count = 1);
|
|
ControlInfo loadControlInfo(ControlType type, 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 */
|
|
|
|
#endif /* __LIBCAMERA_INTERNAL_CONTROL_SERIALIZER_H__ */
|