[08/12] libcamera: delayed_controls: Add ctrls list parameter to reset() function
diff mbox series

Message ID 20240313105645.120317-9-stefan.klug@ideasonboard.com
State Superseded
Headers show
Series
  • Preparation for per-frame-controls and initial tests
Related show

Commit Message

Stefan Klug March 13, 2024, 10:56 a.m. UTC
This makes it easier for the caller. There is often this pattern

  sensor_->setControls(controls);
  delayedControls_->reset();

which can then be reduced to

  delayedControls_->reset(controls);

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

Patch
diff mbox series

diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h
index 2738e8bf..a3063400 100644
--- a/include/libcamera/internal/delayed_controls.h
+++ b/include/libcamera/internal/delayed_controls.h
@@ -27,7 +27,7 @@  public:
 	DelayedControls(V4L2Device *device,
 			const std::unordered_map<uint32_t, ControlParams> &controlParams);
 
-	void reset();
+	void reset(ControlList *controls = nullptr);
 
 	bool push(const ControlList &controls);
 	bool pushForFrame(uint32_t sequence, const ControlList &controls);
diff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp
index c46e54d1..ac38eb64 100644
--- a/src/libcamera/delayed_controls.cpp
+++ b/src/libcamera/delayed_controls.cpp
@@ -115,7 +115,7 @@  DelayedControls::DelayedControls(V4L2Device *device,
  * Resets the state machine to a starting position based on control values
  * retrieved from the device.
  */
-void DelayedControls::reset()
+void DelayedControls::reset(ControlList *ctrls)
 {
 	queueIndex_ = 0;
 	/* Frames up to maxDelay_ will be based on sensor init values. */
@@ -126,6 +126,18 @@  void DelayedControls::reset()
 	for (auto const &param : controlParams_)
 		ids.push_back(param.first->id());
 
+	if (ctrls) {
+		device_->setControls(ctrls);
+
+		LOG(DelayedControls, Debug) << "reset:";
+		auto idMap = ctrls->idMap();
+		if (idMap) {
+			for (const auto &[id, value] : *ctrls) {
+				LOG(DelayedControls, Debug) << "  " << idMap->at(id)->name() << " : " << value.toString();
+			}
+		}
+	}
+
 	ControlList controls = device_->getControls(ids);
 
 	/* Seed the control queue with the controls reported by the device. */