[PATCH v2 2/7] libcamera: camera: Turn queuedRequests_ to a map

Daniel Scally dan.scally at ideasonboard.com
Tue Feb 20 17:43:12 CET 2024


To facilitate fetching Requests queued to a camera using their
sequence number, transform the queuedRequests_ list to a map with
the sequence as the key.

Signed-off-by: Daniel Scally <dan.scally at ideasonboard.com>
---
Changes in v2:

	- New patch

 include/libcamera/internal/camera.h |  4 ++--
 src/libcamera/camera.cpp            |  4 ++--
 src/libcamera/pipeline_handler.cpp  | 12 ++++++++----
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h
index 38dd94ff..fff70ff6 100644
--- a/include/libcamera/internal/camera.h
+++ b/include/libcamera/internal/camera.h
@@ -8,7 +8,7 @@
 #pragma once
 
 #include <atomic>
-#include <list>
+#include <map>
 #include <memory>
 #include <set>
 #include <string>
@@ -33,7 +33,7 @@ public:
 
 	PipelineHandler *pipe() { return pipe_.get(); }
 
-	std::list<Request *> queuedRequests_;
+	std::map<uint32_t, Request *> queuedRequests_;
 	ControlInfoMap controlInfo_;
 	ControlList properties_;
 
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index a71dc933..3aa051f9 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -601,9 +601,9 @@ Camera::Private::~Private()
 
 /**
  * \var Camera::Private::queuedRequests_
- * \brief The list of queued and not yet completed requests
+ * \brief The map of queued and not yet completed requests
  *
- * This list tracks requests queued in order to ensure completion of all
+ * This map tracks requests queued in order to ensure completion of all
  * requests when the pipeline handler is stopped.
  *
  * \sa PipelineHandler::queueRequest(), PipelineHandler::stop(),
diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index 343804e9..a8a67a7d 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -428,9 +428,9 @@ void PipelineHandler::doQueueRequest(Request *request)
 
 	Camera *camera = request->_d()->camera();
 	Camera::Private *data = camera->_d();
-	data->queuedRequests_.push_back(request);
 
 	request->_d()->sequence_ = data->requestSequence_++;
+	data->queuedRequests_[request->sequence()] = request;
 
 	if (request->_d()->cancelled_) {
 		completeRequest(request);
@@ -532,13 +532,17 @@ void PipelineHandler::completeRequest(Request *request)
 
 	Camera::Private *data = camera->_d();
 
-	while (!data->queuedRequests_.empty()) {
-		Request *req = data->queuedRequests_.front();
+	for (auto it = data->queuedRequests_.begin(), it_next = it;
+	     it != data->queuedRequests_.end(); it = it_next) {
+		uint32_t seq = it->first;
+		Request *req = it->second;
+		++it_next;
+
 		if (req->status() == Request::RequestPending)
 			break;
 
 		ASSERT(!req->hasPendingBuffers());
-		data->queuedRequests_.pop_front();
+		data->queuedRequests_.erase(seq);
 		camera->requestComplete(req);
 	}
 }
-- 
2.34.1



More information about the libcamera-devel mailing list