[{"id":33484,"web_url":"https://patchwork.libcamera.org/comment/33484/","msgid":"<20250226000347.GB21362@pendragon.ideasonboard.com>","date":"2025-02-26T00:03:47","subject":"Re: [PATCH v3 3/6] libcamera: software_isp: Handle queued input\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:09PM +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 input buffers from SoftwareIsp slots\n> when SoftwareIsp is stopped.  Let's track the queued input buffers and\n> return them back for capture in SoftwareIsp::stop().\n> \n> The returned input buffers are marked as canceled.  This is not\n> necessary at the moment but it gives the pipeline handlers chance to\n> deal with this if they need to.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  .../internal/software_isp/software_isp.h       |  1 +\n>  src/libcamera/software_isp/software_isp.cpp    | 18 +++++++++++++++++-\n>  2 files changed, 18 insertions(+), 1 deletion(-)\n> \n> diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\n> index 5073ce7a..400a4dc5 100644\n> --- a/include/libcamera/internal/software_isp/software_isp.h\n> +++ b/include/libcamera/internal/software_isp/software_isp.h\n> @@ -102,6 +102,7 @@ private:\n>  \n>  \tstd::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\n>  \tbool running_;\n> +\tstd::deque<FrameBuffer *> queuedInputBuffers_;\n>  \tstd::deque<FrameBuffer *> queuedOutputBuffers_;\n>  };\n>  \n> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> index 140cddf3..beac66fc 100644\n> --- a/src/libcamera/software_isp/software_isp.cpp\n> +++ b/src/libcamera/software_isp/software_isp.cpp\n> @@ -303,6 +303,8 @@ int SoftwareIsp::queueBuffers(uint32_t frame, FrameBuffer *input,\n>  \t\t\treturn -EINVAL;\n>  \t}\n>  \n> +\tqueuedInputBuffers_.push_back(input);\n> +\n>  \tfor (auto iter = outputs.begin(); iter != outputs.end(); iter++) {\n>  \t\tFrameBuffer *const buffer = iter->second;\n>  \t\tqueuedOutputBuffers_.push_back(buffer);\n> @@ -329,6 +331,9 @@ int SoftwareIsp::start()\n>  \n>  /**\n>   * \\brief Stops the Software ISP streaming operation\n> + *\n> + * All pending buffers are returned back as canceled before this method\n> + * finishes.\n\ns/emthod finishes/function returns/\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>   */\n>  void SoftwareIsp::stop()\n>  {\n> @@ -344,6 +349,13 @@ void SoftwareIsp::stop()\n>  \t\toutputBufferReady.emit(buffer);\n>  \t}\n>  \tqueuedOutputBuffers_.clear();\n> +\n> +\tfor (auto buffer : queuedInputBuffers_) {\n> +\t\tFrameMetadata &metadata = buffer->_d()->metadata();\n> +\t\tmetadata.status = FrameMetadata::FrameCancelled;\n> +\t\tinputBufferReady.emit(buffer);\n> +\t}\n> +\tqueuedInputBuffers_.clear();\n>  }\n>  \n>  /**\n> @@ -377,7 +389,11 @@ void SoftwareIsp::statsReady(uint32_t frame, uint32_t bufferId)\n>  \n>  void SoftwareIsp::inputReady(FrameBuffer *input)\n>  {\n> -\tinputBufferReady.emit(input);\n> +\tif (running_) {\n> +\t\tASSERT(queuedInputBuffers_.front() == input);\n> +\t\tqueuedInputBuffers_.pop_front();\n> +\t\tinputBufferReady.emit(input);\n> +\t}\n>  }\n>  \n>  void SoftwareIsp::outputReady(FrameBuffer *output)","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 BD66BBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Feb 2025 00:04:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E6F4E68735;\n\tWed, 26 Feb 2025 01:04:07 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7C21861852\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Feb 2025 01:04:06 +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 AAF37502;\n\tWed, 26 Feb 2025 01:02:38 +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=\"s1Sgkox7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740528158;\n\tbh=FoFuTgQIMPRZThoOoUucycH+a7b3gDdskrJWppdSymA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=s1Sgkox7Qjy6hH3ayPxs5zSRHYH58bx74d3plKISwhfYWpOfCQcWI93Bf0LCXHerv\n\tLeToOGapxaHJFAurAOzJaEFXgDcjxFu+QdZiplAu4FPXzMEtXtAI+MkIOkEIOpjHwg\n\t32l+UYRii765X9Nxz4wZ/UnD+OjRFBYnRlGA7BlU=","Date":"Wed, 26 Feb 2025 02:03:47 +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 3/6] libcamera: software_isp: Handle queued input\n\tbuffers on stop","Message-ID":"<20250226000347.GB21362@pendragon.ideasonboard.com>","References":"<20250225150614.20195-1-mzamazal@redhat.com>\n\t<20250225150614.20195-4-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250225150614.20195-4-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":33520,"web_url":"https://patchwork.libcamera.org/comment/33520/","msgid":"<174087027045.3864332.2864561704000748295@ping.linuxembedded.co.uk>","date":"2025-03-01T23:04:30","subject":"Re: [PATCH v3 3/6] libcamera: software_isp: Handle queued input\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 Laurent Pinchart (2025-02-26 00:03:47)\n> Hi Milan,\n> \n> Thank you for the patch.\n> \n> On Tue, Feb 25, 2025 at 04:06:09PM +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 input buffers from SoftwareIsp slots\n> > when SoftwareIsp is stopped.  Let's track the queued input buffers and\n> > return them back for capture in SoftwareIsp::stop().\n> > \n> > The returned input buffers are marked as canceled.  This is not\n\ns/canceled/cancelled/\n\n> > necessary at the moment but it gives the pipeline handlers chance to\n> > deal with this if they need to.\n> > \n> > Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> > ---\n> >  .../internal/software_isp/software_isp.h       |  1 +\n> >  src/libcamera/software_isp/software_isp.cpp    | 18 +++++++++++++++++-\n> >  2 files changed, 18 insertions(+), 1 deletion(-)\n> > \n> > diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\n> > index 5073ce7a..400a4dc5 100644\n> > --- a/include/libcamera/internal/software_isp/software_isp.h\n> > +++ b/include/libcamera/internal/software_isp/software_isp.h\n> > @@ -102,6 +102,7 @@ private:\n> >  \n> >       std::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\n> >       bool running_;\n> > +     std::deque<FrameBuffer *> queuedInputBuffers_;\n> >       std::deque<FrameBuffer *> queuedOutputBuffers_;\n> >  };\n> >  \n> > diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> > index 140cddf3..beac66fc 100644\n> > --- a/src/libcamera/software_isp/software_isp.cpp\n> > +++ b/src/libcamera/software_isp/software_isp.cpp\n> > @@ -303,6 +303,8 @@ int SoftwareIsp::queueBuffers(uint32_t frame, FrameBuffer *input,\n> >                       return -EINVAL;\n> >       }\n> >  \n> > +     queuedInputBuffers_.push_back(input);\n> > +\n> >       for (auto iter = outputs.begin(); iter != outputs.end(); iter++) {\n> >               FrameBuffer *const buffer = iter->second;\n> >               queuedOutputBuffers_.push_back(buffer);\n> > @@ -329,6 +331,9 @@ int SoftwareIsp::start()\n> >  \n> >  /**\n> >   * \\brief Stops the Software ISP streaming operation\n> > + *\n> > + * All pending buffers are returned back as canceled before this method\n> > + * finishes.\n> \n> s/emthod finishes/function returns/\n> \n\nWill fix.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> >   */\n> >  void SoftwareIsp::stop()\n> >  {\n> > @@ -344,6 +349,13 @@ void SoftwareIsp::stop()\n> >               outputBufferReady.emit(buffer);\n> >       }\n> >       queuedOutputBuffers_.clear();\n> > +\n> > +     for (auto buffer : queuedInputBuffers_) {\n> > +             FrameMetadata &metadata = buffer->_d()->metadata();\n> > +             metadata.status = FrameMetadata::FrameCancelled;\n> > +             inputBufferReady.emit(buffer);\n> > +     }\n> > +     queuedInputBuffers_.clear();\n> >  }\n> >  \n> >  /**\n> > @@ -377,7 +389,11 @@ void SoftwareIsp::statsReady(uint32_t frame, uint32_t bufferId)\n> >  \n> >  void SoftwareIsp::inputReady(FrameBuffer *input)\n> >  {\n> > -     inputBufferReady.emit(input);\n> > +     if (running_) {\n> > +             ASSERT(queuedInputBuffers_.front() == input);\n> > +             queuedInputBuffers_.pop_front();\n> > +             inputBufferReady.emit(input);\n> > +     }\n> >  }\n> >  \n> >  void SoftwareIsp::outputReady(FrameBuffer *output)\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","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 83E72C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  1 Mar 2025 23:04:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4753668822;\n\tSun,  2 Mar 2025 00:04:35 +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 2469E687FA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  2 Mar 2025 00:04:33 +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 E2F8B670;\n\tSun,  2 Mar 2025 00:03:02 +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=\"HrWPcwp7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740870183;\n\tbh=z38ocqYXGcdw3E0C1GTHsHYvjZT/066vARzoQ1sirR8=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=HrWPcwp7xfPx9fBq+Nw76gd/Wva1gdUw5gLLbqPtSCmCJJDIITuzzi084Aj6OMAn4\n\ttfLAhOKSV3mBoA2riJZO5n7N0xFmrqMZqBa0F+ReKbYIlxauMAJXWr32s5WmXCgs0e\n\txUvqmgcft1/V/K4xxp/amCDmecOD1/9eTMc1Q/oE=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250226000347.GB21362@pendragon.ideasonboard.com>","References":"<20250225150614.20195-1-mzamazal@redhat.com>\n\t<20250225150614.20195-4-mzamazal@redhat.com>\n\t<20250226000347.GB21362@pendragon.ideasonboard.com>","Subject":"Re: [PATCH v3 3/6] libcamera: software_isp: Handle queued input\n\tbuffers on stop","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tMilan Zamazal <mzamazal@redhat.com>","Date":"Sat, 01 Mar 2025 23:04:30 +0000","Message-ID":"<174087027045.3864332.2864561704000748295@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>"}}]