[libcamera-devel] [PATCH v10 2/5] lc-compliance: Make SimpleCapture::stop() idempotent
Nícolas F. R. A. Prado
nfraprado at collabora.com
Tue Jun 29 17:12:15 CEST 2021
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 at collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo at jmondi.org>
---
Changes in v10:
- Thanks to Jacopo:
- Updated copyright header
No changes in v9
No changes in v8
Changes in v7:
- Thanks to Jacopo:
- Moved the check for buffers allocated to the beginning of
SimpleCapture::stop()
No changes in v6
No changes in v5
No changes in v4
No changes in v3
Changes in v2:
- Suggested by Laurent:
- Fixed code style
src/lc-compliance/simple_capture.cpp | 32 ++++++++++------------------
1 file changed, 11 insertions(+), 21 deletions(-)
diff --git a/src/lc-compliance/simple_capture.cpp b/src/lc-compliance/simple_capture.cpp
index 64e862a08e3a..635c96e5e5c8 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));
}
--
2.32.0
More information about the libcamera-devel
mailing list