[{"id":33483,"web_url":"https://patchwork.libcamera.org/comment/33483/","msgid":"<20250225235958.GA21362@pendragon.ideasonboard.com>","date":"2025-02-25T23:59:58","subject":"Re: [PATCH v3 2/6] libcamera: software_isp: Handle queued output\n\tbuffers on stop","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Milan,\n\nThank you for the patch.\n\nOn Tue, Feb 25, 2025 at 04:06:08PM +0100, Milan Zamazal wrote:\n> When SoftwareIsp stops, input and output buffers queued to it may not\n> yet be fully processed.  They will be eventually returned but stop means\n> stop, there should be no processing related actions invoked afterwards.\n> \n> Let's stop forwarding processed output buffers from the SoftwareIsp\n> slots once SoftwareIsp is stopped.  Let's track the queued output\n> buffers and mark those still pending as canceled in SoftwareIsp::stop\n> and return them to the pipeline handler.\n> \n> Dealing with input buffers is addressed in a separate patch.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  .../internal/software_isp/software_isp.h      |  2 ++\n>  src/libcamera/software_isp/software_isp.cpp   | 23 ++++++++++++++++---\n>  2 files changed, 22 insertions(+), 3 deletions(-)\n> \n> diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\n> index af0dcc24..5073ce7a 100644\n> --- a/include/libcamera/internal/software_isp/software_isp.h\n> +++ b/include/libcamera/internal/software_isp/software_isp.h\n> @@ -7,6 +7,7 @@\n>  \n>  #pragma once\n>  \n> +#include <deque>\n>  #include <functional>\n>  #include <initializer_list>\n>  #include <map>\n> @@ -101,6 +102,7 @@ private:\n>  \n>  \tstd::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\n>  \tbool running_;\n> +\tstd::deque<FrameBuffer *> queuedOutputBuffers_;\n>  };\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> index 1a39f4d8..140cddf3 100644\n> --- a/src/libcamera/software_isp/software_isp.cpp\n> +++ b/src/libcamera/software_isp/software_isp.cpp\n> @@ -13,10 +13,13 @@\n>  #include <sys/types.h>\n>  #include <unistd.h>\n>  \n> +#include <libcamera/base/log.h>\n> +\n>  #include <libcamera/controls.h>\n>  #include <libcamera/formats.h>\n>  #include <libcamera/stream.h>\n>  \n> +#include \"libcamera/internal/framebuffer.h\"\n>  #include \"libcamera/internal/ipa_manager.h\"\n>  #include \"libcamera/internal/software_isp/debayer_params.h\"\n>  \n> @@ -300,8 +303,11 @@ int SoftwareIsp::queueBuffers(uint32_t frame, FrameBuffer *input,\n>  \t\t\treturn -EINVAL;\n>  \t}\n>  \n> -\tfor (auto iter = outputs.begin(); iter != outputs.end(); iter++)\n> -\t\tprocess(frame, input, iter->second);\n> +\tfor (auto iter = outputs.begin(); iter != outputs.end(); iter++) {\n> +\t\tFrameBuffer *const buffer = iter->second;\n> +\t\tqueuedOutputBuffers_.push_back(buffer);\n> +\t\tprocess(frame, input, buffer);\n> +\t}\n>  \n>  \treturn 0;\n>  }\n> @@ -331,6 +337,13 @@ void SoftwareIsp::stop()\n>  \n>  \trunning_ = false;\n>  \tipa_->stop();\n> +\n> +\tfor (auto buffer : queuedOutputBuffers_) {\n> +\t\tFrameMetadata &metadata = buffer->_d()->metadata();\n> +\t\tmetadata.status = FrameMetadata::FrameCancelled;\n> +\t\toutputBufferReady.emit(buffer);\n> +\t}\n> +\tqueuedOutputBuffers_.clear();\n>  }\n>  \n>  /**\n> @@ -369,7 +382,11 @@ void SoftwareIsp::inputReady(FrameBuffer *input)\n>  \n>  void SoftwareIsp::outputReady(FrameBuffer *output)\n>  {\n> -\toutputBufferReady.emit(output);\n> +\tif (running_) {\n> +\t\tASSERT(queuedOutputBuffers_.front() == output);\n> +\t\tqueuedOutputBuffers_.pop_front();\n> +\t\toutputBufferReady.emit(output);\n> +\t}\n>  }\n>  \n>  } /* namespace libcamera */","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 E5CFEBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Feb 2025 00:00:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D300E68735;\n\tWed, 26 Feb 2025 01:00:19 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E8A261852\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Feb 2025 01:00:18 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 26CD0502;\n\tWed, 26 Feb 2025 00:58:50 +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=\"OJT/3ivy\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740527930;\n\tbh=oVkcxq7Dw+YNxlNhzdgNK2TWUMvxAdiVONYOX+7Uu9g=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=OJT/3ivy1pJYoms0bZt0ysJe+Cnr8lk7IVFfSoE70/hUAzi3gX5Sr7MMvLAfwDAoD\n\tkT+bfW9a6pnG60UFremlunzoKAEKCLrUX2ny2msZXYdkkwr0cfKH5tC6v4gj/QeZLL\n\tG6U5nWSRWv28O8I8LhlXWppaT7MqQVLKOyUehYfw=","Date":"Wed, 26 Feb 2025 01:59:58 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v3 2/6] libcamera: software_isp: Handle queued output\n\tbuffers on stop","Message-ID":"<20250225235958.GA21362@pendragon.ideasonboard.com>","References":"<20250225150614.20195-1-mzamazal@redhat.com>\n\t<20250225150614.20195-3-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250225150614.20195-3-mzamazal@redhat.com>","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":33519,"web_url":"https://patchwork.libcamera.org/comment/33519/","msgid":"<174087019901.3864332.3714154404849883842@ping.linuxembedded.co.uk>","date":"2025-03-01T23:03:19","subject":"Re: [PATCH v3 2/6] libcamera: software_isp: Handle queued output\n\tbuffers on stop","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Milan Zamazal (2025-02-25 15:06:08)\n> When SoftwareIsp stops, input and output buffers queued to it may not\n> yet be fully processed.  They will be eventually returned but stop means\n> stop, there should be no processing related actions invoked afterwards.\n> \n> Let's stop forwarding processed output buffers from the SoftwareIsp\n> slots once SoftwareIsp is stopped.  Let's track the queued output\n> buffers and mark those still pending as canceled in SoftwareIsp::stop\n\ns/canceled/cancelled/ (to be fixed while applying)\n\n> and return them to the pipeline handler.\n> \n> Dealing with input buffers is addressed in a separate patch.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  .../internal/software_isp/software_isp.h      |  2 ++\n>  src/libcamera/software_isp/software_isp.cpp   | 23 ++++++++++++++++---\n>  2 files changed, 22 insertions(+), 3 deletions(-)\n> \n> diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\n> index af0dcc24..5073ce7a 100644\n> --- a/include/libcamera/internal/software_isp/software_isp.h\n> +++ b/include/libcamera/internal/software_isp/software_isp.h\n> @@ -7,6 +7,7 @@\n>  \n>  #pragma once\n>  \n> +#include <deque>\n>  #include <functional>\n>  #include <initializer_list>\n>  #include <map>\n> @@ -101,6 +102,7 @@ private:\n>  \n>         std::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\n>         bool running_;\n> +       std::deque<FrameBuffer *> queuedOutputBuffers_;\n>  };\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> index 1a39f4d8..140cddf3 100644\n> --- a/src/libcamera/software_isp/software_isp.cpp\n> +++ b/src/libcamera/software_isp/software_isp.cpp\n> @@ -13,10 +13,13 @@\n>  #include <sys/types.h>\n>  #include <unistd.h>\n>  \n> +#include <libcamera/base/log.h>\n> +\n>  #include <libcamera/controls.h>\n>  #include <libcamera/formats.h>\n>  #include <libcamera/stream.h>\n>  \n> +#include \"libcamera/internal/framebuffer.h\"\n>  #include \"libcamera/internal/ipa_manager.h\"\n>  #include \"libcamera/internal/software_isp/debayer_params.h\"\n>  \n> @@ -300,8 +303,11 @@ int SoftwareIsp::queueBuffers(uint32_t frame, FrameBuffer *input,\n>                         return -EINVAL;\n>         }\n>  \n> -       for (auto iter = outputs.begin(); iter != outputs.end(); iter++)\n> -               process(frame, input, iter->second);\n> +       for (auto iter = outputs.begin(); iter != outputs.end(); iter++) {\n> +               FrameBuffer *const buffer = iter->second;\n> +               queuedOutputBuffers_.push_back(buffer);\n> +               process(frame, input, buffer);\n> +       }\n>  \n>         return 0;\n>  }\n> @@ -331,6 +337,13 @@ void SoftwareIsp::stop()\n>  \n>         running_ = false;\n>         ipa_->stop();\n> +\n> +       for (auto buffer : queuedOutputBuffers_) {\n> +               FrameMetadata &metadata = buffer->_d()->metadata();\n> +               metadata.status = FrameMetadata::FrameCancelled;\n> +               outputBufferReady.emit(buffer);\n> +       }\n> +       queuedOutputBuffers_.clear();\n>  }\n>  \n>  /**\n> @@ -369,7 +382,11 @@ void SoftwareIsp::inputReady(FrameBuffer *input)\n>  \n>  void SoftwareIsp::outputReady(FrameBuffer *output)\n>  {\n> -       outputBufferReady.emit(output);\n> +       if (running_) {\n> +               ASSERT(queuedOutputBuffers_.front() == output);\n> +               queuedOutputBuffers_.pop_front();\n> +               outputBufferReady.emit(output);\n> +       }\n>  }\n>  \n>  } /* namespace libcamera */\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 42736C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  1 Mar 2025 23:03:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7099168823;\n\tSun,  2 Mar 2025 00:03:24 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7641D61853\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  2 Mar 2025 00:03:22 +0100 (CET)","from pendragon.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 1652F7FA;\n\tSun,  2 Mar 2025 00:01:52 +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=\"Co2JrTdU\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740870112;\n\tbh=GD2T2+CvZu9tdNpmSOolztA8TqEUX0ythggSoPnGAfc=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Co2JrTdUjFgwGM1NwwO8aRWC4gn3zByFbMWGNWTBRmn3EPuJt8qzdntB3zIqV1a+2\n\t804vlqjgH8pa3xuU0XGBJbNtPcUNRmkWaLNNGGKMO3eOrHoH3dv/vGFB3qeTi/JlGR\n\tUYY+Il++TrmLAVqlOk4UwEGrMeH0ABSJ3P82w3L4=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250225150614.20195-3-mzamazal@redhat.com>","References":"<20250225150614.20195-1-mzamazal@redhat.com>\n\t<20250225150614.20195-3-mzamazal@redhat.com>","Subject":"Re: [PATCH v3 2/6] libcamera: software_isp: Handle queued output\n\tbuffers on stop","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>,\n\tStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Sat, 01 Mar 2025 23:03:19 +0000","Message-ID":"<174087019901.3864332.3714154404849883842@ping.linuxembedded.co.uk>","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>"}}]