[{"id":33456,"web_url":"https://patchwork.libcamera.org/comment/33456/","msgid":"<20250224194920.GH6778@pendragon.ideasonboard.com>","date":"2025-02-24T19:49:20","subject":"Re: [PATCH v2 2/5] 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 Mon, Feb 24, 2025 at 07:52:32PM +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> ---\n>  .../internal/software_isp/software_isp.h      |  1 +\n>  src/libcamera/software_isp/software_isp.cpp   | 22 ++++++++++++++++---\n>  2 files changed, 20 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..f2344355 100644\n> --- a/include/libcamera/internal/software_isp/software_isp.h\n> +++ b/include/libcamera/internal/software_isp/software_isp.h\n> @@ -101,6 +101,7 @@ private:\n>  \n>  \tstd::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\n>  \tbool running_;\n> +\tstd::deque<FrameBuffer *> queuedOutputBuffers_;\n\n#include <deque>\n\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..4339e547 100644\n> --- a/src/libcamera/software_isp/software_isp.cpp\n> +++ b/src/libcamera/software_isp/software_isp.cpp\n> @@ -17,6 +17,7 @@\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 +301,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 +335,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 +380,12 @@ void SoftwareIsp::inputReady(FrameBuffer *input)\n>  \n>  void SoftwareIsp::outputReady(FrameBuffer *output)\n>  {\n> -\toutputBufferReady.emit(output);\n> +\tif (running_) {\n> +\t\tqueuedOutputBuffers_.erase(find(queuedOutputBuffers_.begin(),\n\ns/find/std::find/\n\nand #include <algorithm>.\n\nThis being said, the software ISP always processes buffers in order. Do\nwe need to call find(), can't we just call pop_front() with an assertion\nto ensure the element matches ?\n\n> +\t\t\t\t\t\tqueuedOutputBuffers_.end(),\n> +\t\t\t\t\t\toutput));\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 3E3E6C324E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Feb 2025 19:49:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8439B68702;\n\tMon, 24 Feb 2025 20:49:40 +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 5EDAD686FE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Feb 2025 20:49:39 +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 7F716220;\n\tMon, 24 Feb 2025 20:48:12 +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=\"ELLdf0pj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740426492;\n\tbh=opNyvP9VrAcvj6awcsh4PC+/dvD545hcvFZH2VmMQCY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ELLdf0pj0yOwvUlVh9DQ3WMmyYsfYJi40lw+DOF+t6zSc7QsxeX6a9eUkgUMXZg7B\n\tFP2izOp3LJG9uykL7PM3I57FmrQGKsLPznjoWDEKW+bY9U7PN3P2ggakH7g4Hk+VDT\n\tUISwXsjyGsBrIOeq83/VC0MDdEZen1C0eTBMNXQ8=","Date":"Mon, 24 Feb 2025 21:49:20 +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 v2 2/5] libcamera: software_isp: Handle queued output\n\tbuffers on stop","Message-ID":"<20250224194920.GH6778@pendragon.ideasonboard.com>","References":"<20250224185235.43381-1-mzamazal@redhat.com>\n\t<20250224185235.43381-3-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250224185235.43381-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":33462,"web_url":"https://patchwork.libcamera.org/comment/33462/","msgid":"<855xkzm5j9.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-02-24T20:50:02","subject":"Re: [PATCH v2 2/5] libcamera: software_isp: Handle queued output\n\tbuffers on stop","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hi Laurent,\n\nthank you for review.\n\nLaurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> Hi Milan,\n>\n> Thank you for the patch.\n>\n> On Mon, Feb 24, 2025 at 07:52:32PM +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>> ---\n>>  .../internal/software_isp/software_isp.h      |  1 +\n>>  src/libcamera/software_isp/software_isp.cpp   | 22 ++++++++++++++++---\n>>  2 files changed, 20 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..f2344355 100644\n>> --- a/include/libcamera/internal/software_isp/software_isp.h\n>> +++ b/include/libcamera/internal/software_isp/software_isp.h\n>> @@ -101,6 +101,7 @@ private:\n>>  \n>>  \tstd::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\n>>  \tbool running_;\n>> +\tstd::deque<FrameBuffer *> queuedOutputBuffers_;\n>\n> #include <deque>\n>\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..4339e547 100644\n>> --- a/src/libcamera/software_isp/software_isp.cpp\n>> +++ b/src/libcamera/software_isp/software_isp.cpp\n>> @@ -17,6 +17,7 @@\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 +301,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 +335,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 +380,12 @@ void SoftwareIsp::inputReady(FrameBuffer *input)\n>>  \n>>  void SoftwareIsp::outputReady(FrameBuffer *output)\n>>  {\n>> -\toutputBufferReady.emit(output);\n>> +\tif (running_) {\n>> +\t\tqueuedOutputBuffers_.erase(find(queuedOutputBuffers_.begin(),\n>\n> s/find/std::find/\n>\n> and #include <algorithm>.\n>\n> This being said, the software ISP always processes buffers in order. Do\n> we need to call find(), can't we just call pop_front() with an assertion\n> to ensure the element matches ?\n\nI can't see any contradiction to this and it works for me so I'll do it\nthis way in v3.\n\n>> +\t\t\t\t\t\tqueuedOutputBuffers_.end(),\n>> +\t\t\t\t\t\toutput));\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 17803C32A9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Feb 2025 20:50:10 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C763768708;\n\tMon, 24 Feb 2025 21:50:09 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 44A04686FF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Feb 2025 21:50:08 +0100 (CET)","from mail-wr1-f70.google.com (mail-wr1-f70.google.com\n\t[209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-618-wgIINBLNMceW_MoAX2oT7Q-1; Mon, 24 Feb 2025 15:50:05 -0500","by mail-wr1-f70.google.com with SMTP id\n\tffacd0b85a97d-38f36f03312so1874092f8f.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Feb 2025 12:50:05 -0800 (PST)","from mzamazal-thinkpadp1gen7.tpbc.csb\n\t(ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-390cd86c9ccsm94225f8f.21.2025.02.24.12.50.02\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 24 Feb 2025 12:50:03 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"SM+NTwx8\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1740430207;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=/rGpRTV1CYtMgeTIm+qQlUBnTHGfue8cge7pNB8wgpY=;\n\tb=SM+NTwx8b+PR0MwzaxRSbML4q6bILXgj2s+HgvKZsnnuXpMuU/lrtPg3jFdPq3aagKJVDg\n\tYC4fjDLR6pGt8ji662BV1mR2yiivR9ikQigobLnKH9iYH2G2ktdaaCKroBwdxxBnJB7OkB\n\tz/9qx/hOgpwfoh705r8jSlkrb2MPdN8=","X-MC-Unique":"wgIINBLNMceW_MoAX2oT7Q-1","X-Mimecast-MFC-AGG-ID":"wgIINBLNMceW_MoAX2oT7Q_1740430204","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1740430204; x=1741035004;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=/rGpRTV1CYtMgeTIm+qQlUBnTHGfue8cge7pNB8wgpY=;\n\tb=iEA0B6EelAmvHtOFaEoXQCvdXTFH6aGyNra4py8+uS3zdbVX0zHDrV2qUirFe/ixcV\n\tnubKj7aLtpHcunBNeFyA7AmJbsGVrihcF/7ENrC208SJ/mEJODlxh4y8MzwLImKMuSw/\n\tIeEjvUexLlu/qE/MIV7VfFvvfKx91ExwrjCoNB4989X/8H+3lKzlO4Qozc4AvBnFNWom\n\tA9vSjzXcIuLRIqGzEuk9xdsqXeAhvu3f+5KB11/blnuIcg/zVX1sqgj2CwCCRgFgImZL\n\tWMnrLXPd2rsA1+By3LDxQrZvE8/LZ7ddduK77oOh145FKdBbDrb7N1+ZLFFF/IMv2mjg\n\tCDpw==","X-Gm-Message-State":"AOJu0Ywuk50jP5UpjXb9VygNnp4eNn4JxY0s57Buv2u1zWQSnWuXI1fk\n\tgyzig1MSKBVdAdI+lR1X5eSS7nRs3oXFzmbxjqGRNCil5VUX2IYVhTqUbjPpuJj0xFoWEinEmoE\n\t0yPethXyrDdvuykmQ+psRVwef73qcSl3m24Y30/blExuc+y65ctTtNQyaoaDsqhM4ieUV3FiHko\n\tOqIlQ=","X-Gm-Gg":"ASbGnctsUudPxidEcld7uJikV1r/bPyEl4i8iQ7Q3eYVrk0f2Je/GnpFUonPrdP1csx\n\tS/VQFvTtjakK6WJAY/dPbOyNCkrrm2e+XnI6uXzukwdSSS/EVUfW+O+iysBMS9xnBOUBqnFwVbD\n\tQ/odurcLEDkoqUUtOBf87ix9xp4zc3zqQ/YOBoodNSgwVbdDJQMwvfFDu65J7zWpFNzUpflyDVj\n\tMj37QkT61sWw/tOD3SGjSfsff4fwjBroHW1GO9rB79cZjSh/htiK2nwDu8FHm+CbDrS00H6SdVB\n\t8Z9j9BNlQJt8ZsxNpenFo7h18+sO9r6+ZPxgLX7vCyghaDbqA/UJDpv3uZW4qy4R7y+c","X-Received":["by 2002:a05:6000:1541:b0:38f:38eb:fcff with SMTP id\n\tffacd0b85a97d-390cc60a682mr398164f8f.29.1740430204140; \n\tMon, 24 Feb 2025 12:50:04 -0800 (PST)","by 2002:a05:6000:1541:b0:38f:38eb:fcff with SMTP id\n\tffacd0b85a97d-390cc60a682mr398149f8f.29.1740430203789; \n\tMon, 24 Feb 2025 12:50:03 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IERXURFpLVbTZC9jW4BLHJ4n66eEkF90xC6c/8nTMkV8JtHvOf/Y48jviOSLBE8oDOZMPmilg==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,  Stanislaw Gruszka\n\t<stanislaw.gruszka@linux.intel.com>,  Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v2 2/5] libcamera: software_isp: Handle queued output\n\tbuffers on stop","In-Reply-To":"<20250224194920.GH6778@pendragon.ideasonboard.com> (Laurent\n\tPinchart's message of \"Mon, 24 Feb 2025 21:49:20 +0200\")","References":"<20250224185235.43381-1-mzamazal@redhat.com>\n\t<20250224185235.43381-3-mzamazal@redhat.com>\n\t<20250224194920.GH6778@pendragon.ideasonboard.com>","Date":"Mon, 24 Feb 2025 21:50:02 +0100","Message-ID":"<855xkzm5j9.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"0grwal1kkIjMFOzZnSXDqa0prNdeMrb6V3kCOJaUUTg_1740430204","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>"}}]