summaryrefslogtreecommitdiff
path: root/src/qcam
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/qcam
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/qcam')
-rw-r--r--src/qcam/main_window.cpp40
-rw-r--r--src/qcam/main_window.h2
2 files changed, 30 insertions, 12 deletions
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 907d2423..6ecf30e3 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -142,8 +142,7 @@ int MainWindow::startCapture()
BufferPool &pool = stream->bufferPool();
std::vector<Request *> requests;
-
- for (Buffer &buffer : pool.buffers()) {
+ for (unsigned int i = 0; i < pool.count(); ++i) {
Request *request = camera_->createRequest();
if (!request) {
std::cerr << "Can't create request" << std::endl;
@@ -151,11 +150,15 @@ int MainWindow::startCapture()
goto error;
}
- std::map<Stream *, Buffer *> map;
- map[stream] = &buffer;
- ret = request->setBuffers(map);
+ std::unique_ptr<Buffer> buffer = stream->createBuffer(i);
+ if (!buffer) {
+ std::cerr << "Can't create buffer " << i << std::endl;
+ goto error;
+ }
+
+ ret = request->addBuffer(std::move(buffer));
if (ret < 0) {
- std::cerr << "Can't set buffers for request" << std::endl;
+ std::cerr << "Can't set buffer for request" << std::endl;
goto error;
}
@@ -219,6 +222,7 @@ void MainWindow::requestComplete(Request *request,
framesCaptured_++;
+ Stream *stream = buffers.begin()->first;
Buffer *buffer = buffers.begin()->second;
double fps = buffer->timestamp() - lastBufferTime_;
@@ -232,7 +236,8 @@ void MainWindow::requestComplete(Request *request,
<< " fps: " << std::fixed << std::setprecision(2) << fps
<< std::endl;
- display(buffer);
+ BufferMemory *mem = &stream->bufferPool().buffers()[buffer->index()];
+ display(buffer, mem);
request = camera_->createRequest();
if (!request) {
@@ -240,16 +245,29 @@ void MainWindow::requestComplete(Request *request,
return;
}
- request->setBuffers(buffers);
+ for (auto it = buffers.begin(); it != buffers.end(); ++it) {
+ Stream *stream = it->first;
+ Buffer *buffer = it->second;
+ unsigned int index = buffer->index();
+
+ std::unique_ptr<Buffer> newBuffer = stream->createBuffer(index);
+ if (!newBuffer) {
+ std::cerr << "Can't create buffer " << index << std::endl;
+ return;
+ }
+
+ request->addBuffer(std::move(newBuffer));
+ }
+
camera_->queueRequest(request);
}
-int MainWindow::display(Buffer *buffer)
+int MainWindow::display(Buffer *buffer, BufferMemory *mem)
{
- if (buffer->planes().size() != 1)
+ if (mem->planes().size() != 1)
return -EINVAL;
- Plane &plane = buffer->planes().front();
+ Plane &plane = mem->planes().front();
unsigned char *raw = static_cast<unsigned char *>(plane.mem());
viewfinder_->display(raw, buffer->bytesused());
diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
index f58cb6a6..b4f6f747 100644
--- a/src/qcam/main_window.h
+++ b/src/qcam/main_window.h
@@ -48,7 +48,7 @@ private:
void requestComplete(Request *request,
const std::map<Stream *, Buffer *> &buffers);
- int display(Buffer *buffer);
+ int display(Buffer *buffer, BufferMemory *mem);
QString title_;
QTimer titleTimer_;