summaryrefslogtreecommitdiff
path: root/src/libcamera/request.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-07-09 18:08:07 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-07-14 16:00:54 +0300
commita2bcf6feee5ae6077225cc787c3d1a25d9ef95e7 (patch)
treeb654f7e4a25852edba8ba1ecaff86779ccddb25e /src/libcamera/request.cpp
parent9bb36ec274da530e509fe2f4010b262c43e812f3 (diff)
libcamera: buffer: Split memory information to BufferMemory
The Buffer class is a large beast the stores information about the buffer memory, dynamic metadata related to the frame stored in the buffer, and buffer reference data (in the index). In order to implement buffer import we will need to extend this with dmabuf file descriptors, making usage of the class even more complex. Refactor the Buffer class by splitting the buffer memory information to a BufferMemory class, and repurposing the Buffer class to reference a buffer and to store dynamic metadata. The BufferMemory class becomes a long term storage, valid and stable from the time buffer memory is allocated to the time it is freed. The Buffer class, on the other hand, becomes transient, is created on demand when an application requires a buffer, is given to a request, and is deleted when the request completes. Buffer and BufferMemory don't need to be copied, so their copy constructor and assignment operators are deleted. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/request.cpp')
-rw-r--r--src/libcamera/request.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
index 8cf41a43..45e7133f 100644
--- a/src/libcamera/request.cpp
+++ b/src/libcamera/request.cpp
@@ -60,6 +60,14 @@ Request::Request(Camera *camera, uint64_t cookie)
{
}
+Request::~Request()
+{
+ for (auto it : bufferMap_) {
+ Buffer *buffer = it.second;
+ delete buffer;
+ }
+}
+
/**
* \fn Request::controls()
* \brief Retrieve the request's ControlList
@@ -87,19 +95,30 @@ Request::Request(Camera *camera, uint64_t cookie)
*/
/**
- * \brief Set the streams to capture with associated buffers
- * \param[in] streamMap The map of streams to buffers
+ * \brief Store a Buffer with its associated Stream in the Request
+ * \param[in] buffer The Buffer to store in the request
+ *
+ * Ownership of the buffer is passed to the request. It will be deleted when
+ * the request is destroyed after completing.
+ *
+ * A request can only contain one buffer per stream. If a buffer has already
+ * been added to the request for the same stream, this method returns -EEXIST.
+ *
* \return 0 on success or a negative error code otherwise
- * \retval -EBUSY Buffers have already been set
+ * \retval -EEXIST The request already contains a buffer for the stream
*/
-int Request::setBuffers(const std::map<Stream *, Buffer *> &streamMap)
+int Request::addBuffer(std::unique_ptr<Buffer> buffer)
{
- if (!bufferMap_.empty()) {
- LOG(Request, Error) << "Buffers already set";
- return -EBUSY;
+ Stream *stream = buffer->stream();
+
+ auto it = bufferMap_.find(stream);
+ if (it != bufferMap_.end()) {
+ LOG(Request, Error) << "Buffer already set for stream";
+ return -EEXIST;
}
- bufferMap_ = streamMap;
+ bufferMap_[stream] = buffer.release();
+
return 0;
}