summaryrefslogtreecommitdiff
path: root/test/camera/capture.cpp
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-11-22 16:22:56 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-01-12 16:10:38 +0100
commit9217f274f64f690b768d332663e1731a3ee5ef15 (patch)
treeee152928be1eaea656c929e56e27e97b175de435 /test/camera/capture.cpp
parenteb4030f6c07174a520be1ebd73628e9ae4789569 (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/camera/capture.cpp')
-rw-r--r--test/camera/capture.cpp38
1 files changed, 23 insertions, 15 deletions
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 */