summaryrefslogtreecommitdiff
path: root/src/libcamera
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcamera')
-rw-r--r--src/libcamera/camera.cpp14
-rw-r--r--src/libcamera/request.cpp38
2 files changed, 43 insertions, 9 deletions
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index fb76077f..9590ab72 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -847,21 +847,22 @@ int Camera::configure(CameraConfiguration *config)
* handler, and is completely opaque to libcamera.
*
* The ownership of the returned request is passed to the caller, which is
- * responsible for either queueing the request or deleting it.
+ * responsible for deleting it. The request may be deleted in the completion
+ * handler, or reused after resetting its state with Request::reuse().
*
* \context This function is \threadsafe. It may only be called when the camera
* is in the Configured or Running state as defined in \ref camera_operation.
*
* \return A pointer to the newly created request, or nullptr on error
*/
-Request *Camera::createRequest(uint64_t cookie)
+std::unique_ptr<Request> Camera::createRequest(uint64_t cookie)
{
int ret = p_->isAccessAllowed(Private::CameraConfigured,
Private::CameraRunning);
if (ret < 0)
return nullptr;
- return new Request(this, cookie);
+ return std::make_unique<Request>(this, cookie);
}
/**
@@ -877,9 +878,6 @@ Request *Camera::createRequest(uint64_t cookie)
* Once the request has been queued, the camera will notify its completion
* through the \ref requestCompleted signal.
*
- * Ownership of the request is transferred to the camera. It will be deleted
- * automatically after it completes.
- *
* \context This function is \threadsafe. It may only be called when the camera
* is in the Running state as defined in \ref camera_operation.
*
@@ -988,13 +986,11 @@ int Camera::stop()
* \param[in] request The request that has completed
*
* This function is called by the pipeline handler to notify the camera that
- * the request has completed. It emits the requestCompleted signal and deletes
- * the request.
+ * the request has completed. It emits the requestCompleted signal.
*/
void Camera::requestComplete(Request *request)
{
requestCompleted.emit(request);
- delete request;
}
} /* namespace libcamera */
diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
index 60b30692..ae8b1660 100644
--- a/src/libcamera/request.cpp
+++ b/src/libcamera/request.cpp
@@ -38,6 +38,15 @@ LOG_DEFINE_CATEGORY(Request)
*/
/**
+ * \enum Request::ReuseFlag
+ * Flags to control the behavior of Request::reuse()
+ * \var Request::Default
+ * Don't reuse buffers
+ * \var Request::ReuseBuffers
+ * Reuse the buffers that were previously added by addBuffer()
+ */
+
+/**
* \typedef Request::BufferMap
* \brief A map of Stream to FrameBuffer pointers
*/
@@ -86,6 +95,35 @@ Request::~Request()
}
/**
+ * \brief Reset the request for reuse
+ * \param[in] flags Indicate whether or not to reuse the buffers
+ *
+ * Reset the status and controls associated with the request, to allow it to
+ * be reused and requeued without destruction. This function shall be called
+ * prior to queueing the request to the camera, in lieu of constructing a new
+ * request. The application can reuse the buffers that were previously added
+ * to the request via addBuffer() by setting \a flags to ReuseBuffers.
+ */
+void Request::reuse(ReuseFlag flags)
+{
+ pending_.clear();
+ if (flags & ReuseBuffers) {
+ for (auto pair : bufferMap_) {
+ pair.second->request_ = this;
+ pending_.insert(pair.second);
+ }
+ } else {
+ bufferMap_.clear();
+ }
+
+ status_ = RequestPending;
+ cancelled_ = false;
+
+ controls_->clear();
+ metadata_->clear();
+}
+
+/**
* \fn Request::controls()
* \brief Retrieve the request's ControlList
*