From a2bcf6feee5ae6077225cc787c3d1a25d9ef95e7 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 9 Jul 2019 18:08:07 +0300 Subject: libcamera: buffer: Split memory information to BufferMemory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Niklas Söderlund --- test/camera/capture.cpp | 19 ++++++++++++++----- test/camera/statemachine.cpp | 6 ++---- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'test/camera') diff --git a/test/camera/capture.cpp b/test/camera/capture.cpp index 7ce247cc..ff1cbd6c 100644 --- a/test/camera/capture.cpp +++ b/test/camera/capture.cpp @@ -34,9 +34,13 @@ protected: completeRequestsCount_++; - /* Reuse the buffers for a new request. */ + /* Create a new request. */ + Stream *stream = buffers.begin()->first; + Buffer *buffer = buffers.begin()->second; + std::unique_ptr newBuffer = stream->createBuffer(buffer->index()); + request = camera_->createRequest(); - request->setBuffers(buffers); + request->addBuffer(std::move(newBuffer)); camera_->queueRequest(request); } @@ -78,15 +82,20 @@ protected: Stream *stream = cfg.stream(); BufferPool &pool = stream->bufferPool(); std::vector requests; - for (Buffer &buffer : pool.buffers()) { + for (unsigned int i = 0; i < pool.count(); ++i) { Request *request = camera_->createRequest(); if (!request) { cout << "Failed to create request" << endl; return TestFail; } - std::map map = { { stream, &buffer } }; - if (request->setBuffers(map)) { + std::unique_ptr buffer = stream->createBuffer(i); + if (!buffer) { + cout << "Failed to create buffer " << i << endl; + return TestFail; + } + + if (request->addBuffer(std::move(buffer))) { cout << "Failed to associating buffer with request" << endl; return TestFail; } diff --git a/test/camera/statemachine.cpp b/test/camera/statemachine.cpp index 84d2a6fa..12d5e0e1 100644 --- a/test/camera/statemachine.cpp +++ b/test/camera/statemachine.cpp @@ -211,10 +211,8 @@ protected: return TestFail; Stream *stream = *camera_->streams().begin(); - BufferPool &pool = stream->bufferPool(); - Buffer &buffer = pool.buffers().front(); - std::map map = { { stream, &buffer } }; - if (request->setBuffers(map)) + std::unique_ptr buffer = stream->createBuffer(0); + if (request->addBuffer(std::move(buffer))) return TestFail; if (camera_->queueRequest(request)) -- cgit v1.2.1