@@ -27,35 +27,30 @@ void Capture::configure(libcamera::Span<const libcamera::StreamRole> roles)
{
assert(!roles.empty());
- config_ = camera_->generateConfiguration(roles);
- if (!config_)
+ auto config = camera_->generateConfiguration(roles);
+ if (!config)
GTEST_SKIP() << "Roles not supported by camera";
- ASSERT_EQ(config_->size(), roles.size()) << "Unexpected number of streams in configuration";
+ ASSERT_EQ(config->size(), roles.size()) << "Unexpected number of streams in configuration";
/*
* Set the buffers count to the largest value across all streams.
* \todo: Should all streams from a Camera have the same buffer count ?
*/
auto largest =
- std::max_element(config_->begin(), config_->end(),
+ std::max_element(config->begin(), config->end(),
[](const StreamConfiguration &l, const StreamConfiguration &r)
{ return l.bufferCount < r.bufferCount; });
- assert(largest != config_->end());
+ assert(largest != config->end());
- for (auto &cfg : *config_)
+ for (auto &cfg : *config)
cfg.bufferCount = largest->bufferCount;
- if (config_->validate() != CameraConfiguration::Valid) {
- config_.reset();
- FAIL() << "Configuration not valid";
- }
+ ASSERT_EQ(config->validate(), CameraConfiguration::Valid);
+ ASSERT_EQ(camera_->configure(config.get()), 0);
- if (camera_->configure(config_.get())) {
- config_.reset();
- FAIL() << "Failed to configure camera";
- }
+ config_ = std::move(config);
}
void Capture::run(unsigned int captureLimit, std::optional<unsigned int> queueLimit)
Save the result of `Camera::generateConfiguration()` in a local variable, and only commit it to the member variable `config_` if it passes all checks. This removes the need for explicit `config_.reset()` calls in error paths, hence making things simpler. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> --- src/apps/lc-compliance/helpers/capture.cpp | 23 +++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-)