diff options
author | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2019-11-22 16:22:56 +0100 |
---|---|---|
committer | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2020-01-12 16:10:38 +0100 |
commit | 9217f274f64f690b768d332663e1731a3ee5ef15 (patch) | |
tree | ee152928be1eaea656c929e56e27e97b175de435 /test | |
parent | eb4030f6c07174a520be1ebd73628e9ae4789569 (diff) |
libcamera: Switch to FrameBuffer interface
Switch to the FrameBuffer interface where all buffers are treated as
external buffers and are allocated outside the camera. Applications
allocating buffers using libcamera are switched to use the
FrameBufferAllocator helper.
Follow-up changes to this one will finalize the transition to the new
FrameBuffer interface by removing code that is left unused after this
change.
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/camera/buffer_import.cpp | 19 | ||||
-rw-r--r-- | test/camera/capture.cpp | 38 | ||||
-rw-r--r-- | test/camera/statemachine.cpp | 12 |
3 files changed, 39 insertions, 30 deletions
diff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp index 327db791..f506d1b2 100644 --- a/test/camera/buffer_import.cpp +++ b/test/camera/buffer_import.cpp @@ -120,7 +120,7 @@ public: } protected: - void bufferComplete(Request *request, Buffer *buffer) + void bufferComplete(Request *request, FrameBuffer *buffer) { if (buffer->metadata().status != FrameMetadata::FrameSuccess) return; @@ -133,17 +133,16 @@ protected: if (request->status() != Request::RequestComplete) return; - const std::map<Stream *, Buffer *> &buffers = request->buffers(); + const std::map<Stream *, FrameBuffer *> &buffers = request->buffers(); completeRequestsCount_++; /* Create a new request. */ Stream *stream = buffers.begin()->first; - int dmabuf = buffers.begin()->second->dmabufs()[0]; - std::unique_ptr<Buffer> buffer = stream->createBuffer({ dmabuf, -1, -1 }); + FrameBuffer *buffer = buffers.begin()->second; request = camera_->createRequest(); - request->addBuffer(stream, std::move(buffer)); + request->addBuffer(stream, buffer); camera_->queueRequest(request); } @@ -158,9 +157,6 @@ protected: return TestFail; } - StreamConfiguration &cfg = config_->at(0); - cfg.memoryType = ExternalMemory; - return TestPass; } @@ -191,17 +187,14 @@ protected: return TestFail; std::vector<Request *> requests; - for (const std::unique_ptr<FrameBuffer> &framebuffer : source.buffers()) { - int dmabuf = framebuffer->planes()[0].fd.fd(); - + for (const std::unique_ptr<FrameBuffer> &buffer : source.buffers()) { Request *request = camera_->createRequest(); if (!request) { std::cout << "Failed to create request" << std::endl; return TestFail; } - std::unique_ptr<Buffer> buffer = stream->createBuffer({ dmabuf, -1, -1 }); - if (request->addBuffer(stream, std::move(buffer))) { + if (request->addBuffer(stream, buffer.get())) { std::cout << "Failed to associating buffer with request" << std::endl; return TestFail; } diff --git a/test/camera/capture.cpp b/test/camera/capture.cpp index 0d9ffc47..de879ee4 100644 --- a/test/camera/capture.cpp +++ b/test/camera/capture.cpp @@ -26,7 +26,7 @@ protected: unsigned int completeBuffersCount_; unsigned int completeRequestsCount_; - void bufferComplete(Request *request, Buffer *buffer) + void bufferComplete(Request *request, FrameBuffer *buffer) { if (buffer->metadata().status != FrameMetadata::FrameSuccess) return; @@ -39,17 +39,16 @@ protected: if (request->status() != Request::RequestComplete) return; - const std::map<Stream *, Buffer *> &buffers = request->buffers(); + const std::map<Stream *, FrameBuffer *> &buffers = request->buffers(); completeRequestsCount_++; /* Create a new request. */ Stream *stream = buffers.begin()->first; - Buffer *buffer = buffers.begin()->second; - std::unique_ptr<Buffer> newBuffer = stream->createBuffer(buffer->index()); + FrameBuffer *buffer = buffers.begin()->second; request = camera_->createRequest(); - request->addBuffer(stream, std::move(newBuffer)); + request->addBuffer(stream, buffer); camera_->queueRequest(request); } @@ -64,9 +63,16 @@ protected: return TestFail; } + allocator_ = FrameBufferAllocator::create(camera_); + return TestPass; } + void cleanup() override + { + delete allocator_; + } + int run() override { StreamConfiguration &cfg = config_->at(0); @@ -87,21 +93,20 @@ protected: } Stream *stream = cfg.stream(); + + int ret = allocator_->allocate(stream); + if (ret < 0) + return TestFail; + std::vector<Request *> requests; - for (unsigned int i = 0; i < cfg.bufferCount; ++i) { + for (const std::unique_ptr<FrameBuffer> &buffer : allocator_->buffers(stream)) { Request *request = camera_->createRequest(); if (!request) { cout << "Failed to create request" << endl; return TestFail; } - std::unique_ptr<Buffer> buffer = stream->createBuffer(i); - if (!buffer) { - cout << "Failed to create buffer " << i << endl; - return TestFail; - } - - if (request->addBuffer(stream, std::move(buffer))) { + if (request->addBuffer(stream, buffer.get())) { cout << "Failed to associating buffer with request" << endl; return TestFail; } @@ -134,10 +139,12 @@ protected: while (timer.isRunning()) dispatcher->processEvents(); - if (completeRequestsCount_ <= cfg.bufferCount * 2) { + unsigned int nbuffers = allocator_->buffers(stream).size(); + + if (completeRequestsCount_ <= nbuffers * 2) { cout << "Failed to capture enough frames (got " << completeRequestsCount_ << " expected at least " - << cfg.bufferCount * 2 << ")" << endl; + << nbuffers * 2 << ")" << endl; return TestFail; } @@ -160,6 +167,7 @@ protected: } std::unique_ptr<CameraConfiguration> config_; + FrameBufferAllocator *allocator_; }; } /* namespace */ diff --git a/test/camera/statemachine.cpp b/test/camera/statemachine.cpp index f627b8f3..f3a7ca7c 100644 --- a/test/camera/statemachine.cpp +++ b/test/camera/statemachine.cpp @@ -185,6 +185,12 @@ protected: if (camera_->allocateBuffers()) return TestFail; + /* Use internally allocated buffers. */ + allocator_ = FrameBufferAllocator::create(camera_); + Stream *stream = *camera_->streams().begin(); + if (allocator_->allocate(stream) < 0) + return TestFail; + if (camera_->start()) return TestFail; @@ -218,8 +224,7 @@ protected: return TestFail; Stream *stream = *camera_->streams().begin(); - std::unique_ptr<Buffer> buffer = stream->createBuffer(0); - if (request->addBuffer(stream, std::move(buffer))) + if (request->addBuffer(stream, allocator_->buffers(stream)[0].get())) return TestFail; if (camera_->queueRequest(request)) @@ -229,6 +234,8 @@ protected: if (camera_->stop()) return TestFail; + delete allocator_; + if (camera_->freeBuffers()) return TestFail; @@ -283,6 +290,7 @@ protected: } std::unique_ptr<CameraConfiguration> defconf_; + FrameBufferAllocator *allocator_; }; } /* namespace */ |