[v3,10/16] libcamera: delayed_controls: Add fillValues() helper
diff mbox series

Message ID 20240319120517.362082-11-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • Preparation for per-frame-controls and initial tests
Related show

Commit Message

Stefan Klug March 19, 2024, 12:05 p.m. UTC
In the upcoming patches the function to initialize the value in the
ringbuffer is needed at multiple places. So it makes sense to factor it
out.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 include/libcamera/internal/delayed_controls.h |  1 +
 src/libcamera/delayed_controls.cpp            | 28 +++++++++++++++----
 2 files changed, 23 insertions(+), 6 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h
index 5a0428e0..db5c29e9 100644
--- a/include/libcamera/internal/delayed_controls.h
+++ b/include/libcamera/internal/delayed_controls.h
@@ -70,6 +70,7 @@  private:
 	};
 
 	bool controlsAreQueued(unsigned int frame, const ControlList &controls);
+	void fillValues(unsigned int fromIndex, unsigned int toIndex);
 
 	V4L2Device *device_;
 	/* \todo Evaluate if we should index on ControlId * or unsigned int */
diff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp
index 8cfa6bbb..e325b6b2 100644
--- a/src/libcamera/delayed_controls.cpp
+++ b/src/libcamera/delayed_controls.cpp
@@ -185,6 +185,27 @@  bool DelayedControls::controlsAreQueued(unsigned int sequence,
 	return true;
 }
 
+/**
+ * @brief Helper function to fill the values with the data from previous entries
+ *
+ * @param fromIndex The index to start the copy from
+ * @param toIndex The last index that gets filled
+ *
+ * The updated member of the control values is reset to false.
+ */
+void DelayedControls::fillValues(unsigned int fromIndex, unsigned int toIndex)
+{
+	/* Copy state from previous queue. */
+	for (auto &ctrl : values_) {
+		auto &ringBuffer = ctrl.second;
+		for (auto i = fromIndex; i < toIndex; i++) {
+			Info &info = ringBuffer[i + 1];
+			info = ringBuffer[i];
+			info.updated = false;
+		}
+	}
+}
+
 /**
  * \brief Push a set of controls on the queue
  * \param[in] controls List of controls to add to the device queue
@@ -196,12 +217,7 @@  bool DelayedControls::controlsAreQueued(unsigned int sequence,
  */
 bool DelayedControls::push(const ControlList &controls)
 {
-	/* Copy state from previous frame. */
-	for (auto &ctrl : values_) {
-		Info &info = ctrl.second[queueIndex_];
-		info = values_[ctrl.first][queueIndex_ - 1];
-		info.updated = false;
-	}
+	fillValues(queueIndex_ - 1, queueIndex_);
 
 	/* Update with new controls. */
 	const ControlIdMap &idmap = device_->controls().idmap();