summaryrefslogtreecommitdiff
path: root/src/libcamera/pipeline_handler.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-02-28 17:59:10 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-03-01 20:46:40 +0200
commitb2c06cf40975398eb56be74fa3cd5d1b7b13cb50 (patch)
treeef4b85d6dc15b6f3eae21d3807986d4d790251e1 /src/libcamera/pipeline_handler.cpp
parent1accc258cc8efb077f8437be702646583ee61ca6 (diff)
libcamera: Handle request completion explicitly in pipeline handlers
Request complete by themselves when all the buffers they contain have completed, connecting the buffer's completed signal to be notified of buffer completion. While this works for now, it prevents pipelines from delaying request completion until all metadata is available, and makes it impossible to ensure that requests complete in the order they are queued. To fix this, make request completion handling explicit in pipeline handlers. The base PipelineHandler class is extended with implementations of the queueRequest() and stop() methods and gets new completeBuffer() and completeRequest() methods to help pipeline handlers tracking requests and buffers. The three existing pipeline handlers connect the bufferReady signal of their capture video node to a slot of their respective camera data instance, where they use the PipelineHandler helpers to notify buffer and request completion. Request completion is handled synchronously with buffer completion as the pipeline handlers don't need to support more advanced use cases, but this paves the road for future work. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/pipeline_handler.cpp')
-rw-r--r--src/libcamera/pipeline_handler.cpp93
1 files changed, 92 insertions, 1 deletions
diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index 54f23794..1a858f26 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -5,6 +5,7 @@
* pipeline_handler.cpp - Pipeline handler infrastructure
*/
+#include <libcamera/buffer.h>
#include <libcamera/camera.h>
#include <libcamera/camera_manager.h>
@@ -75,6 +76,17 @@ LOG_DEFINE_CATEGORY(Pipeline)
*/
/**
+ * \var CameraData::queuedRequests_
+ * \brief The list of queued and not yet completed request
+ *
+ * The list of queued request is used to track requests queued in order to
+ * ensure completion of all requests when the pipeline handler is stopped.
+ *
+ * \sa PipelineHandler::queueRequest(), PipelineHandler::stop(),
+ * PipelineHandler::completeRequest()
+ */
+
+/**
* \class PipelineHandler
* \brief Create and manage cameras based on a set of media devices
*
@@ -226,8 +238,30 @@ PipelineHandler::~PipelineHandler()
* This method stops capturing and processing requests immediately. All pending
* requests are cancelled and complete immediately in an error state.
*
- * \todo Complete the pending requests immediately
+ * Pipeline handlers shall override this method to stop the pipeline, ensure
+ * that all pending request completion signaled through completeRequest() have
+ * returned, and call the base implementation of the stop() method as the last
+ * step of their implementation. The base implementation cancels all requests
+ * queued but not yet complete.
*/
+void PipelineHandler::stop(Camera *camera)
+{
+ CameraData *data = cameraData(camera);
+
+ while (!data->queuedRequests_.empty()) {
+ Request *request = data->queuedRequests_.front();
+ data->queuedRequests_.pop_front();
+
+ while (!request->pending_.empty()) {
+ Buffer *buffer = *request->pending_.begin();
+ buffer->cancel();
+ completeBuffer(camera, request, buffer);
+ }
+
+ request->complete(Request::RequestCancelled);
+ camera->requestComplete(request);
+ }
+}
/**
* \fn PipelineHandler::queueRequest()
@@ -241,8 +275,65 @@ PipelineHandler::~PipelineHandler()
* parameters will be applied to the frames captured in the buffers provided in
* the request.
*
+ * Pipeline handlers shall override this method. The base implementation in the
+ * PipelineHandler class keeps track of queued requests in order to ensure
+ * completion of all requests when the pipeline handler is stopped with stop().
+ * Requests completion shall be signaled by the pipeline handler using the
+ * completeRequest() method.
+ *
* \return 0 on success or a negative error code otherwise
*/
+int PipelineHandler::queueRequest(Camera *camera, Request *request)
+{
+ CameraData *data = cameraData(camera);
+ data->queuedRequests_.push_back(request);
+
+ return 0;
+}
+
+/**
+ * \brief Complete a buffer for a request
+ * \param[in] camera The camera the request belongs to
+ * \param[in] request The request the buffer belongs to
+ * \param[in] buffer The buffer that has completed
+ *
+ * This method shall be called by pipeline handlers to signal completion of the
+ * \a buffer part of the \a request. It notifies applications of buffer
+ * completion and updates the request's internal buffer tracking. The request
+ * is not completed automatically when the last buffer completes, pipeline
+ * handlers shall complete requests explicitly with completeRequest().
+ *
+ * \return True if all buffers contained in the request have completed, false
+ * otherwise
+ */
+bool PipelineHandler::completeBuffer(Camera *camera, Request *request,
+ Buffer *buffer)
+{
+ camera->bufferCompleted.emit(request, buffer);
+ return request->completeBuffer(buffer);
+}
+
+/**
+ * \brief Signal request completion
+ * \param[in] camera The camera that the request belongs to
+ * \param[in] request The request that has completed
+ *
+ * The pipeline handler shall call this method to notify the \a camera that the
+ * request request has complete. The request is deleted and shall not be
+ * accessed once this method returns.
+ *
+ * The pipeline handler shall ensure that requests complete in the same order
+ * they are submitted.
+ */
+void PipelineHandler::completeRequest(Camera *camera, Request *request)
+{
+ CameraData *data = cameraData(camera);
+ ASSERT(request == data->queuedRequests_.front());
+ data->queuedRequests_.pop_front();
+
+ request->complete(Request::RequestComplete);
+ camera->requestComplete(request);
+}
/**
* \brief Register a camera to the camera manager and pipeline handler