summaryrefslogtreecommitdiff
path: root/include/libcamera/internal/delayed_controls.h
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-10-27 01:08:23 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2021-01-29 15:35:28 +0100
commit3d4b7b0059116f5f151dec5090ec0e18bd401f24 (patch)
tree999c57f020ca4bb91439c96c1f67cb2ac200b13e /include/libcamera/internal/delayed_controls.h
parent958c80a4f1c28301ce19112e04de55a6a5102dad (diff)
libcamera: delayed_controls: Add helper for controls that apply with a delay
Some sensor controls take effect with a delay as the sensor needs time to adjust, for example exposure. Add an optional helper DelayedControls to help pipelines deal with such controls. The idea is to provide a queue of controls towards the V4L2 device and apply individual controls with the specified delay with the aim to get predictable and retrievable control values for any given frame. To do this the queue of controls needs to be at least as deep as the control with the largest delay. The DelayedControls needs to be informed of every start of exposure. This can be emulated but the helper is designed to be used with this event being provide by the kernel through V4L2 events. This helper is based on StaggeredCtrl from the Raspberry Pi pipeline handler but expands on its API. This helpers aims to replace the Raspberry Pi implementations and mimics it behavior perfectly. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Diffstat (limited to 'include/libcamera/internal/delayed_controls.h')
-rw-r--r--include/libcamera/internal/delayed_controls.h81
1 files changed, 81 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__ */