From 0b0f32e7366b2de94983d8cb02d4c32a10b0f561 Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Tue, 25 Nov 2025 17:28:19 +0100 Subject: [PATCH] libcamera: rkisp1: Properly cancel buffers in dewarp case In case the buffer returned from the ISP was canceled, the upstream buffer was not correctly marked as canceled. Move the cancel functionality into an own helper function and correctly cancel the upstream buffers. Add missing cancellation in case queuing to the dewarper fails. Signed-off-by: Stefan Klug Reviewed-by: Paul Elder Reviewed-by: Isaac Scott --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 51 +++++++++++++++--------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index dbd6bf96..b56b306f 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -207,6 +207,7 @@ private: int initLinks(Camera *camera, const RkISP1CameraConfiguration &config); int createCamera(MediaEntity *sensor); void tryCompleteRequest(RkISP1FrameInfo *info); + void cancelDewarpRequest(RkISP1FrameInfo *info); void imageBufferReady(FrameBuffer *buffer); void paramBufferReady(FrameBuffer *buffer); void statBufferReady(FrameBuffer *buffer); @@ -1499,6 +1500,31 @@ void PipelineHandlerRkISP1::tryCompleteRequest(RkISP1FrameInfo *info) completeRequest(request); } +void PipelineHandlerRkISP1::cancelDewarpRequest(RkISP1FrameInfo *info) +{ + RkISP1CameraData *data = cameraData(activeCamera_); + Request *request = info->request; + /* + * i.MX8MP is the only known platform with dewarper. It has + * no self path. Hence, only main path buffer completion is + * required. + * + * Also, we cannot completeBuffer(request, buffer) as buffer + * here, is an internal buffer (between ISP and dewarper) and + * is not associated to the any specific request. The request + * buffer associated with main path stream is the one that + * is required to be completed (not the internal buffer). + */ + for (auto [stream, buffer] : request->buffers()) { + if (stream == &data->mainPathStream_) { + buffer->_d()->cancel(); + completeBuffer(request, buffer); + } + } + + tryCompleteRequest(info); +} + void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer) { ASSERT(activeCamera_); @@ -1540,23 +1566,7 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer) /* Do not queue cancelled frames to dewarper. */ if (metadata.status == FrameMetadata::FrameCancelled) { - /* - * i.MX8MP is the only known platform with dewarper. It has - * no self path. Hence, only main path buffer completion is - * required. - * - * Also, we cannot completeBuffer(request, buffer) as buffer - * here, is an internal buffer (between ISP and dewarper) and - * is not associated to the any specific request. The request - * buffer associated with main path stream is the one that - * is required to be completed (not the internal buffer). - */ - for (auto it : request->buffers()) { - if (it.first == &data->mainPathStream_) - completeBuffer(request, it.second); - } - - tryCompleteRequest(info); + cancelDewarpRequest(info); return; } @@ -1598,10 +1608,15 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer) * by the application. */ int ret = dewarper_->queueBuffers(buffer, request->buffers()); - if (ret < 0) + if (ret < 0) { LOG(RkISP1, Error) << "Cannot queue buffers to dewarper: " << strerror(-ret); + cancelDewarpRequest(info); + + return; + } + request->metadata().set(controls::ScalerCrop, activeCrop_.value()); }