summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/internal/delayed_controls.h81
-rw-r--r--include/libcamera/internal/meson.build1
2 files changed, 82 insertions, 0 deletions
diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h
new file mode 100644
index 00000000..dc447a88
--- /dev/null
+++ b/include/libcamera/internal/delayed_controls.h
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.
+ *
+ * delayed_controls.h - Helper to deal with controls that take effect with a delay
+ */
+#ifndef __LIBCAMERA_INTERNAL_DELAYED_CONTROLS_H__
+#define __LIBCAMERA_INTERNAL_DELAYED_CONTROLS_H__
+
+#include <stdint.h>
+#include <unordered_map>
+
+#include <libcamera/controls.h>
+
+namespace libcamera {
+
+class V4L2Device;
+
+class DelayedControls
+{
+public:
+ DelayedControls(V4L2Device *device,
+ const std::unordered_map<uint32_t, unsigned int> &delays);
+
+ void reset();
+
+ bool push(const ControlList &controls);
+ ControlList get(uint32_t sequence);
+
+ void applyControls(uint32_t sequence);
+
+private:
+ class Info : public ControlValue
+ {
+ public:
+ Info()
+ : updated(false)
+ {
+ }
+
+ Info(const ControlValue &v)
+ : ControlValue(v), updated(true)
+ {
+ }
+
+ bool updated;
+ };
+
+ /* \todo: Make the listSize configurable at instance creation time. */
+ static constexpr int listSize = 16;
+ class ControlRingBuffer : public std::array<Info, listSize>
+ {
+ public:
+ Info &operator[](unsigned int index)
+ {
+ return std::array<Info, listSize>::operator[](index % listSize);
+ }
+
+ const Info &operator[](unsigned int index) const
+ {
+ return std::array<Info, listSize>::operator[](index % listSize);
+ }
+ };
+
+ V4L2Device *device_;
+ /* \todo Evaluate if we should index on ControlId * or unsigned int */
+ std::unordered_map<const ControlId *, unsigned int> delays_;
+ unsigned int maxDelay_;
+
+ bool running_;
+ uint32_t firstSequence_;
+
+ uint32_t queueCount_;
+ uint32_t writeCount_;
+ /* \todo Evaluate if we should index on ControlId * or unsigned int */
+ std::unordered_map<const ControlId *, ControlRingBuffer> values_;
+};
+
+} /* namespace libcamera */
+
+#endif /* __LIBCAMERA_INTERNAL_DELAYED_CONTROLS_H__ */
diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
index 1b1bdc77..e67a359f 100644
--- a/include/libcamera/internal/meson.build
+++ b/include/libcamera/internal/meson.build
@@ -17,6 +17,7 @@ libcamera_internal_headers = files([
'camera_sensor.h',
'control_serializer.h',
'control_validator.h',
+ 'delayed_controls.h',
'device_enumerator.h',
'device_enumerator_sysfs.h',
'device_enumerator_udev.h',