[libcamera-devel] [PATCH 2/2] pipeline: rkisp1: Use utils::Cleaner to simplify error handling in start
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Tue Oct 4 04:18:42 CEST 2022
Error handling in the PipelineHandlerRkISP1::start() function is
cumbersome. Simplify it using the utils::Cleaner class.
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
src/libcamera/pipeline/rkisp1/rkisp1.cpp | 31 +++++++++---------------
1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index 455ee2a0a711..33f3b0c5ab00 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -823,69 +823,60 @@ int PipelineHandlerRkISP1::freeBuffers(Camera *camera)
int PipelineHandlerRkISP1::start(Camera *camera, [[maybe_unused]] const ControlList *controls)
{
RkISP1CameraData *data = cameraData(camera);
+ utils::Cleaner cleaner;
int ret;
/* Allocate buffers for internal pipeline usage. */
ret = allocateBuffers(camera);
if (ret)
return ret;
+ cleaner.defer([&]() { freeBuffers(camera); });
ret = data->ipa_->start();
if (ret) {
- freeBuffers(camera);
LOG(RkISP1, Error)
<< "Failed to start IPA " << camera->id();
return ret;
}
+ cleaner.defer([&]() { data->ipa_->stop(); });
data->frame_ = 0;
ret = param_->streamOn();
if (ret) {
- data->ipa_->stop();
- freeBuffers(camera);
LOG(RkISP1, Error)
<< "Failed to start parameters " << camera->id();
return ret;
}
+ cleaner.defer([&]() { param_->streamOff(); });
ret = stat_->streamOn();
if (ret) {
- param_->streamOff();
- data->ipa_->stop();
- freeBuffers(camera);
LOG(RkISP1, Error)
<< "Failed to start statistics " << camera->id();
return ret;
}
+ cleaner.defer([&]() { stat_->streamOff(); });
if (data->mainPath_->isEnabled()) {
ret = mainPath_.start();
- if (ret) {
- param_->streamOff();
- stat_->streamOff();
- data->ipa_->stop();
- freeBuffers(camera);
+ if (ret)
return ret;
- }
+ cleaner.defer([&]() { mainPath_.stop(); });
}
if (hasSelfPath_ && data->selfPath_->isEnabled()) {
ret = selfPath_.start();
- if (ret) {
- mainPath_.stop();
- param_->streamOff();
- stat_->streamOff();
- data->ipa_->stop();
- freeBuffers(camera);
+ if (ret)
return ret;
- }
}
isp_->setFrameStartEnabled(true);
activeCamera_ = camera;
- return ret;
+
+ cleaner.clear();
+ return 0;
}
void PipelineHandlerRkISP1::stopDevice(Camera *camera)
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list