libcamera: stream: Map external buffers to indexes
Add and use an operation to assign to Buffer representing external memory locations an index at queueRequest() time. The index is used to identify the memory buffer to be queued to the video device once the buffer will be queued in a Request. In order to minimize relocations in the V4L2 backend, this method provides a best-effort caching mechanisms that attempts to reuse BufferMemory previously mapped to the buffer's dmabuf file descriptors, if any. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
committed by
Laurent Pinchart
parent
689e8916ca
commit
9ed9d9b3c1
@@ -800,6 +800,7 @@ Request *Camera::createRequest(uint64_t cookie)
|
||||
* \retval -ENODEV The camera has been disconnected from the system
|
||||
* \retval -EACCES The camera is not running so requests can't be queued
|
||||
* \retval -EINVAL The request is invalid
|
||||
* \retval -ENOMEM No buffer memory was available to handle the request
|
||||
*/
|
||||
int Camera::queueRequest(Request *request)
|
||||
{
|
||||
@@ -818,6 +819,16 @@ int Camera::queueRequest(Request *request)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (stream->memoryType() == ExternalMemory) {
|
||||
int index = stream->mapBuffer(buffer);
|
||||
if (index < 0) {
|
||||
LOG(Camera, Error) << "No buffer memory available";
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
buffer->index_ = index;
|
||||
}
|
||||
|
||||
buffer->mem_ = &stream->buffers()[buffer->index_];
|
||||
}
|
||||
|
||||
@@ -901,7 +912,14 @@ int Camera::stop()
|
||||
*/
|
||||
void Camera::requestComplete(Request *request)
|
||||
{
|
||||
requestCompleted.emit(request, request->bufferMap_);
|
||||
for (auto it : request->buffers()) {
|
||||
Stream *stream = it.first;
|
||||
Buffer *buffer = it.second;
|
||||
if (stream->memoryType() == ExternalMemory)
|
||||
stream->unmapBuffer(buffer);
|
||||
}
|
||||
|
||||
requestCompleted.emit(request, request->buffers());
|
||||
delete request;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user