summaryrefslogtreecommitdiff
path: root/src/libcamera/include/control_serializer.h
blob: b91d13155f5eec692466ef4c9eede752a17d138e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* 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:
	ControlSerializer();

	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>
	ControlValue loadControlValue(ByteStreamBuffer &buffer, bool isArray,
				      unsigned int count);
	ControlValue loadControlValue(ControlType type, ByteStreamBuffer &buffer,
				      bool isArray = false, unsigned int count = 1);
	ControlRange loadControlRange(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_CONTROL_SERIALIZER_H__ */