From 689e8916caf11942286a1f1264e55dcb709d3939 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 12 Jul 2019 22:32:01 +0300 Subject: libcamera: buffer: Add an accessor to the BufferMemory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Buffer instances reference memory, which is modelled internally by a BufferMemory instance. Store a pointer to the BufferMemory in the Buffer class, and populate it when the buffer is queued to the camera through a request. This is useful for applications to access the buffer memory in the buffer or request completion handler. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/buffer.cpp | 11 +++++++++++ src/libcamera/camera.cpp | 4 ++++ 2 files changed, 15 insertions(+) (limited to 'src/libcamera') diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp index 99358633..fe29c2f6 100644 --- a/src/libcamera/buffer.cpp +++ b/src/libcamera/buffer.cpp @@ -300,6 +300,17 @@ Buffer::Buffer(unsigned int index, const Buffer *metadata) * \return The dmabuf file descriptors */ +/** + * \fn Buffer::mem() + * \brief Retrieve the BufferMemory this buffer is associated with + * + * The association between the buffer and a BufferMemory instance is valid from + * the time the request containing this buffer is queued to a camera to the end + * of that request's completion handler. + * + * \return The BufferMemory this buffer is associated with + */ + /** * \fn Buffer::bytesused() * \brief Retrieve the number of bytes occupied by the data in the buffer diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index af69607b..db15fd46 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -811,10 +811,14 @@ int Camera::queueRequest(Request *request) for (auto const &it : request->buffers()) { Stream *stream = it.first; + Buffer *buffer = it.second; + if (activeStreams_.find(stream) == activeStreams_.end()) { LOG(Camera, Error) << "Invalid request"; return -EINVAL; } + + buffer->mem_ = &stream->buffers()[buffer->index_]; } int ret = request->prepare(); -- cgit v1.2.1