summaryrefslogtreecommitdiff
path: root/src/lc-compliance/simple_capture.cpp
diff options
context:
space:
mode:
authorNĂ­colas F. R. A. Prado <nfraprado@collabora.com>2021-07-02 09:21:11 -0300
committerJacopo Mondi <jacopo@jmondi.org>2021-07-06 12:40:47 +0200
commit034e0e81a2884c456eb191753ffb023fb8107062 (patch)
treee08e643f3b55de580d6e3c8d65d539e8eec1e102 /src/lc-compliance/simple_capture.cpp
parentb0bf6b0aa90e2ce94ec77e389eea0e5849f2eaec (diff)
lc-compliance: Make SimpleCapture::stop() idempotent
Make SimpleCapture::stop() be able to be called multiple times and at any point so that it can be called from the destructor and an assert failure can return immediately. Signed-off-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/lc-compliance/simple_capture.cpp')
-rw-r--r--src/lc-compliance/simple_capture.cpp32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/lc-compliance/simple_capture.cpp b/src/lc-compliance/simple_capture.cpp
index 64e862a0..635c96e5 100644
--- a/src/lc-compliance/simple_capture.cpp
+++ b/src/lc-compliance/simple_capture.cpp
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
- * Copyright (C) 2020, Google Inc.
+ * Copyright (C) 2020-2021, Google Inc.
*
* simple_capture.cpp - Simple capture helper
*/
@@ -17,6 +17,7 @@ SimpleCapture::SimpleCapture(std::shared_ptr<Camera> camera)
SimpleCapture::~SimpleCapture()
{
+ stop();
}
Results::Result SimpleCapture::configure(StreamRole role)
@@ -55,12 +56,14 @@ Results::Result SimpleCapture::start()
void SimpleCapture::stop()
{
- Stream *stream = config_->at(0).stream();
+ if (!config_ || !allocator_->allocated())
+ return;
camera_->stop();
camera_->requestCompleted.disconnect(this, &SimpleCapture::requestComplete);
+ Stream *stream = config_->at(0).stream();
allocator_->free(stream);
}
@@ -84,7 +87,6 @@ Results::Result SimpleCaptureBalanced::capture(unsigned int numRequests)
if (buffers.size() > numRequests) {
/* Cache buffers.size() before we destroy it in stop() */
int buffers_size = buffers.size();
- stop();
return { Results::Skip, "Camera needs " + std::to_string(buffers_size)
+ " requests, can't test only " + std::to_string(numRequests) };
@@ -98,20 +100,14 @@ Results::Result SimpleCaptureBalanced::capture(unsigned int numRequests)
std::vector<std::unique_ptr<libcamera::Request>> requests;
for (const std::unique_ptr<FrameBuffer> &buffer : buffers) {
std::unique_ptr<Request> request = camera_->createRequest();
- if (!request) {
- stop();
+ if (!request)
return { Results::Fail, "Can't create request" };
- }
- if (request->addBuffer(stream, buffer.get())) {
- stop();
+ if (request->addBuffer(stream, buffer.get()))
return { Results::Fail, "Can't set buffer for request" };
- }
- if (queueRequest(request.get()) < 0) {
- stop();
+ if (queueRequest(request.get()) < 0)
return { Results::Fail, "Failed to queue request" };
- }
requests.push_back(std::move(request));
}
@@ -175,20 +171,14 @@ Results::Result SimpleCaptureUnbalanced::capture(unsigned int numRequests)
std::vector<std::unique_ptr<libcamera::Request>> requests;
for (const std::unique_ptr<FrameBuffer> &buffer : buffers) {
std::unique_ptr<Request> request = camera_->createRequest();
- if (!request) {
- stop();
+ if (!request)
return { Results::Fail, "Can't create request" };
- }
- if (request->addBuffer(stream, buffer.get())) {
- stop();
+ if (request->addBuffer(stream, buffer.get()))
return { Results::Fail, "Can't set buffer for request" };
- }
- if (camera_->queueRequest(request.get()) < 0) {
- stop();
+ if (camera_->queueRequest(request.get()) < 0)
return { Results::Fail, "Failed to queue request" };
- }
requests.push_back(std::move(request));
}