[{"id":36711,"web_url":"https://patchwork.libcamera.org/comment/36711/","msgid":"<176236120457.2116251.8022963522479460330@neptunite.rasen.tech>","date":"2025-11-05T16:46:44","subject":"Re: [PATCH v2 10/35] libcamera: rkisp1: Properly cancel buffers in\n\tdewarp case","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-10-23 23:48:11)\n> In case the buffer returned from the ISP was canceled, the upstream\n> buffer was not correctly marked as canceled. Move the cancel\n> functionality into an own helper function and correctly cancel the\n> upstream buffers. Add missing cancellation in case queuing to the\n> dewarper fails.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nLooks good to me.\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 48 +++++++++++++++---------\n>  1 file changed, 31 insertions(+), 17 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index dd3907e2fb5f..05409bc46ee3 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -208,6 +208,7 @@ private:\n>         int initLinks(Camera *camera, const RkISP1CameraConfiguration &config);\n>         int createCamera(MediaEntity *sensor);\n>         void tryCompleteRequest(RkISP1FrameInfo *info);\n> +       void cancelDewarpRequest(RkISP1FrameInfo *info);\n>         void imageBufferReady(FrameBuffer *buffer);\n>         void paramBufferReady(FrameBuffer *buffer);\n>         void statBufferReady(FrameBuffer *buffer);\n> @@ -1521,6 +1522,31 @@ void PipelineHandlerRkISP1::tryCompleteRequest(RkISP1FrameInfo *info)\n>         completeRequest(request);\n>  }\n>  \n> +void PipelineHandlerRkISP1::cancelDewarpRequest(RkISP1FrameInfo *info)\n> +{\n> +       RkISP1CameraData *data = cameraData(activeCamera_);\n> +       Request *request = info->request;\n> +       /*\n> +        * i.MX8MP is the only known platform with dewarper. It has\n> +        * no self path. Hence, only main path buffer completion is\n> +        * required.\n> +        *\n> +        * Also, we cannot completeBuffer(request, buffer) as buffer\n> +        * here, is an internal buffer (between ISP and dewarper) and\n> +        * is not associated to the any specific request. The request\n> +        * buffer associated with main path stream is the one that\n> +        * is required to be completed (not the internal buffer).\n> +        */\n> +       for (auto [stream, buffer] : request->buffers()) {\n> +               if (stream == &data->mainPathStream_) {\n> +                       buffer->_d()->cancel();\n> +                       completeBuffer(request, buffer);\n> +               }\n> +       }\n> +\n> +       tryCompleteRequest(info);\n> +}\n> +\n>  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)\n>  {\n>         ASSERT(activeCamera_);\n> @@ -1562,23 +1588,7 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)\n>  \n>         /* Do not queue cancelled frames to dewarper. */\n>         if (metadata.status == FrameMetadata::FrameCancelled) {\n> -               /*\n> -                * i.MX8MP is the only known platform with dewarper. It has\n> -                * no self path. Hence, only main path buffer completion is\n> -                * required.\n> -                *\n> -                * Also, we cannot completeBuffer(request, buffer) as buffer\n> -                * here, is an internal buffer (between ISP and dewarper) and\n> -                * is not associated to the any specific request. The request\n> -                * buffer associated with main path stream is the one that\n> -                * is required to be completed (not the internal buffer).\n> -                */\n> -               for (auto it : request->buffers()) {\n> -                       if (it.first == &data->mainPathStream_)\n> -                               completeBuffer(request, it.second);\n> -               }\n> -\n> -               tryCompleteRequest(info);\n> +               cancelDewarpRequest(info);\n>                 return;\n>         }\n>  \n> @@ -1636,6 +1646,8 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)\n>                 if (dewarpRequest)\n>                         dewarpRequestReady(dewarpRequest);\n>  \n> +               cancelDewarpRequest(info);\n> +\n>                 return;\n>         }\n>  \n> @@ -1646,6 +1658,8 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)\n>                                            << strerror(-ret);\n>                         /* Push it back into the queue. */\n>                         dewarpRequestReady(dewarpRequest);\n> +\n> +                       cancelDewarpRequest(info);\n>                 }\n>         }\n>  \n> -- \n> 2.48.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A1EE9BDE4C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Nov 2025 16:46:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7118F609DE;\n\tWed,  5 Nov 2025 17:46:52 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F017609DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Nov 2025 17:46:51 +0100 (CET)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:d4d0:27ea:7a74:8a9e])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 6F3A113D9; \n\tWed,  5 Nov 2025 17:44:56 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"LNtoKIRd\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762361096;\n\tbh=3ZPo2RLiM9Ff0OsZcFIiuEhkw4eYOfXg6WQkY6vVq8Y=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=LNtoKIRdUBoBK1lSiDcrAs7HBLb77KxblE5WG3tqMNewgqp43AuRPmY07qPcEN1zm\n\tUomJbPaPfOHjFCYtikTNruafQ1ocv1h0q/wMkBJyPF7hGTg1dq8cXihapIkzuwq4qU\n\tt4ze3pPn3Zi36QA4qPk2pKJvplKLtIXG5IE/v8l4=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251023144841.403689-11-stefan.klug@ideasonboard.com>","References":"<20251023144841.403689-1-stefan.klug@ideasonboard.com>\n\t<20251023144841.403689-11-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 10/35] libcamera: rkisp1: Properly cancel buffers in\n\tdewarp case","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 06 Nov 2025 01:46:44 +0900","Message-ID":"<176236120457.2116251.8022963522479460330@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36735,"web_url":"https://patchwork.libcamera.org/comment/36735/","msgid":"<176243730206.288410.9013153421096200416@isaac-ThinkPad-T16-Gen-2>","date":"2025-11-06T13:55:02","subject":"Re: [PATCH v2 10/35] libcamera: rkisp1: Properly cancel buffers in\n\tdewarp case","submitter":{"id":215,"url":"https://patchwork.libcamera.org/api/people/215/","name":"Isaac Scott","email":"isaac.scott@ideasonboard.com"},"content":"Hi Stefan,\n\nThank you for the patch!\n\nQuoting Stefan Klug (2025-10-23 15:48:11)\n> In case the buffer returned from the ISP was canceled, the upstream\n> buffer was not correctly marked as canceled. Move the cancel\n> functionality into an own helper function and correctly cancel the\n> upstream buffers. Add missing cancellation in case queuing to the\n> dewarper fails.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 48 +++++++++++++++---------\n>  1 file changed, 31 insertions(+), 17 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index dd3907e2fb5f..05409bc46ee3 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -208,6 +208,7 @@ private:\n>         int initLinks(Camera *camera, const RkISP1CameraConfiguration &config);\n>         int createCamera(MediaEntity *sensor);\n>         void tryCompleteRequest(RkISP1FrameInfo *info);\n> +       void cancelDewarpRequest(RkISP1FrameInfo *info);\n>         void imageBufferReady(FrameBuffer *buffer);\n>         void paramBufferReady(FrameBuffer *buffer);\n>         void statBufferReady(FrameBuffer *buffer);\n> @@ -1521,6 +1522,31 @@ void PipelineHandlerRkISP1::tryCompleteRequest(RkISP1FrameInfo *info)\n>         completeRequest(request);\n>  }\n>  \n> +void PipelineHandlerRkISP1::cancelDewarpRequest(RkISP1FrameInfo *info)\n> +{\n> +       RkISP1CameraData *data = cameraData(activeCamera_);\n> +       Request *request = info->request;\n> +       /*\n> +        * i.MX8MP is the only known platform with dewarper. It has\n> +        * no self path. Hence, only main path buffer completion is\n> +        * required.\n> +        *\n> +        * Also, we cannot completeBuffer(request, buffer) as buffer\n> +        * here, is an internal buffer (between ISP and dewarper) and\n> +        * is not associated to the any specific request. The request\n> +        * buffer associated with main path stream is the one that\n> +        * is required to be completed (not the internal buffer).\n> +        */\n> +       for (auto [stream, buffer] : request->buffers()) {\n> +               if (stream == &data->mainPathStream_) {\n> +                       buffer->_d()->cancel();\n> +                       completeBuffer(request, buffer);\n> +               }\n> +       }\n> +\n> +       tryCompleteRequest(info);\n> +}\n> +\n>  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)\n>  {\n>         ASSERT(activeCamera_);\n> @@ -1562,23 +1588,7 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)\n>  \n>         /* Do not queue cancelled frames to dewarper. */\n>         if (metadata.status == FrameMetadata::FrameCancelled) {\n> -               /*\n> -                * i.MX8MP is the only known platform with dewarper. It has\n> -                * no self path. Hence, only main path buffer completion is\n> -                * required.\n> -                *\n> -                * Also, we cannot completeBuffer(request, buffer) as buffer\n> -                * here, is an internal buffer (between ISP and dewarper) and\n> -                * is not associated to the any specific request. The request\n> -                * buffer associated with main path stream is the one that\n> -                * is required to be completed (not the internal buffer).\n> -                */\n> -               for (auto it : request->buffers()) {\n> -                       if (it.first == &data->mainPathStream_)\n> -                               completeBuffer(request, it.second);\n> -               }\n> -\n> -               tryCompleteRequest(info);\n> +               cancelDewarpRequest(info);\n>                 return;\n>         }\n>  \n> @@ -1636,6 +1646,8 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)\n>                 if (dewarpRequest)\n>                         dewarpRequestReady(dewarpRequest);\n>  \n> +               cancelDewarpRequest(info);\n> +\n>                 return;\n>         }\n>  \n> @@ -1646,6 +1658,8 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)\n>                                            << strerror(-ret);\n>                         /* Push it back into the queue. */\n>                         dewarpRequestReady(dewarpRequest);\n> +\n> +                       cancelDewarpRequest(info);\n>                 }\n>         }\n>  \n> -- \n> 2.48.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 1FAE3BDE4C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  6 Nov 2025 13:55:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3F37060A81;\n\tThu,  6 Nov 2025 14:55:06 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1DB6C606E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  6 Nov 2025 14:55:05 +0100 (CET)","from thinkpad.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 990E1591;\n\tThu,  6 Nov 2025 14:53:09 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Fr6En76Z\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762437189;\n\tbh=H0qOnt6aM6GfeO4BgOJ6+CoMnE71umIHztaiUd7/+qw=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Fr6En76Zcthmg4DYLZWWwxwx2ArGj1oKiH/jx4+ghQSXZzhc/GMZBXuRHOvrHZ90e\n\tqmG+tUln8sPnPJTDRI9qoQb/z+QeaT4gB2R83yXZ3ZZeTw73oBB2ZQSpfbkgr317HC\n\tLfPVaLgRPHmN+SG70LJLrUOzJa1bTdfp5eAaeomI=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251023144841.403689-11-stefan.klug@ideasonboard.com>","References":"<20251023144841.403689-1-stefan.klug@ideasonboard.com>\n\t<20251023144841.403689-11-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 10/35] libcamera: rkisp1: Properly cancel buffers in\n\tdewarp case","From":"Isaac Scott <isaac.scott@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 06 Nov 2025 13:55:02 +0000","Message-ID":"<176243730206.288410.9013153421096200416@isaac-ThinkPad-T16-Gen-2>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]