[libcamera-devel,v1.1,3/3] cam: Drop frames once the capture limit is reached
diff mbox series

Message ID 20211012220053.5139-1-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Untitled series #2619
Related show

Commit Message

Laurent Pinchart Oct. 12, 2021, 10 p.m. UTC
The camera session keeps requeuing requests until the capture limit is
reached. This causes more request than the limit to complete, as there's
a queue of requests in flight. When capturing from multiple cameras
concurrently, this results in the captureDone signal being emitted for
every request completion after the limit is reached, instead of once per
camera session when reaching the limit.

Fix this by simply dropping any request that completes after the limit
is reached. We could instead avoid requeuing more requests than needed
to reach the limit, but that may cause request starvation in pipelines,
which are currently not handled consistently (or correctly).

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
Changes since v1:

- Add comments
---
 src/cam/camera_session.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Patch
diff mbox series

diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp
index 605018278c5a..1bf460fa3fb7 100644
--- a/src/cam/camera_session.cpp
+++ b/src/cam/camera_session.cpp
@@ -346,6 +346,16 @@  void CameraSession::requestComplete(Request *request)
 
 void CameraSession::processRequest(Request *request)
 {
+	/*
+	 * If we've reached the capture limit, we're done. This doesn't
+	 * duplicate the check below that emits the captureDone signal, as this
+	 * function will be called for each request still in flight after the
+	 * capture limit is reached and we don't want to emit the signal every
+	 * single time.
+	 */
+	if (captureLimit_ && captureCount_ >= captureLimit_)
+		return;
+
 	const Request::BufferMap &buffers = request->buffers();
 
 	/*
@@ -398,6 +408,10 @@  void CameraSession::processRequest(Request *request)
 		}
 	}
 
+	/*
+	 * Notify the user that capture is complete if the limit has just been
+	 * reached.
+	 */
 	captureCount_++;
 	if (captureLimit_ && captureCount_ >= captureLimit_) {
 		captureDone.emit();