[{"id":33139,"web_url":"https://patchwork.libcamera.org/comment/33139/","msgid":"<fevtogq2mwscax7ktcldq7qpaomh2cnrmkqojmoquaikfyqnpd@pocxe6cflwnv>","date":"2025-01-22T12:54:41","subject":"Re: [RFC PATCH v2 16/16] apps: lc-compliance: Run request completion\n\thandler in \"main\" thread","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Barnabás\n\nOn Tue, Jan 14, 2025 at 06:23:05PM +0000, Barnabás Pőcze wrote:\n> Currently, `Capture::requestCompleted()` runs in the `CameraManager`'s\n> thread. This makes it a bit more complicated to use googletest and\n> report errors in those callbacks since lc-compliance sets up\n> googletest to throw exceptions on fatal errors / test skip, but\n> those exceptions are only caught on the \"main\" thread, the one\n> running the test suite.\n>\n> To minimize the burden of dealing with synchronization in tests,\n> execute `Capture::requestCompleted()` in the event loop's thread\n> by utilizing `EventLoop::callLater()`.\n>\n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> ---\n>  src/apps/lc-compliance/helpers/capture.cpp | 21 ++++++++++++---------\n>  src/apps/lc-compliance/helpers/capture.h   |  2 +-\n>  2 files changed, 13 insertions(+), 10 deletions(-)\n>\n> diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp\n> index dbaff4138..528a3a13a 100644\n> --- a/src/apps/lc-compliance/helpers/capture.cpp\n> +++ b/src/apps/lc-compliance/helpers/capture.cpp\n> @@ -129,16 +129,13 @@ void Capture::prepareRequests(std::optional<unsigned int> queueLimit)\n>  \t}\n>  }\n>\n> -int Capture::queueRequest(libcamera::Request *request)\n> +void Capture::queueRequest(libcamera::Request *request)\n>  {\n>  \tif (queueLimit_ && queueCount_ >= *queueLimit_)\n> -\t\treturn 0;\n> -\n> -\tif (int ret = camera_->queueRequest(request); ret < 0)\n> -\t\treturn ret;\n> +\t\treturn;\n>\n> +\tASSERT_EQ(camera_->queueRequest(request), 0);\n>  \tqueueCount_ += 1;\n> -\treturn 0;\n>  }\n>\n>  void Capture::requestComplete(Request *request)\n> @@ -153,8 +150,7 @@ void Capture::requestComplete(Request *request)\n>  \t\t<< \"Request didn't complete successfully\";\n>\n>  \trequest->reuse(Request::ReuseBuffers);\n> -\tif (queueRequest(request))\n> -\t\tloop_->exit(-EINVAL);\n\nPer my understanding, this interrupts the loop_->exec() call\nand goes through the cleanup procedure in Capture::run().\n\nIf we ASSERT_EQ here, will the loop_ be interrupted and stop() be\ncalled ?\n\nThanks\n  j\n\n> +\tqueueRequest(request);\n>  }\n>\n>  void Capture::start()\n> @@ -173,7 +169,14 @@ void Capture::start()\n>\n>  \tASSERT_TRUE(allocator_.allocated());\n>\n> -\tcamera_->requestCompleted.connect(this, &Capture::requestComplete);\n> +\tcamera_->requestCompleted.connect(this, [this](libcamera::Request *request) {\n> +\t\t/* Runs in the CameraManager thread. */\n> +\n> +\t\tloop_->callLater([this, request] {\n> +\t\t\t/* Run handler in the context of the event loop. */\n> +\t\t\trequestComplete(request);\n> +\t\t});\n> +\t});\n>\n>  \tASSERT_EQ(camera_->start(), 0) << \"Failed to start camera\";\n>  }\n> diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h\n> index 391184ad6..9003a0934 100644\n> --- a/src/apps/lc-compliance/helpers/capture.h\n> +++ b/src/apps/lc-compliance/helpers/capture.h\n> @@ -30,7 +30,7 @@ private:\n>  \tvoid stop();\n>\n>  \tvoid prepareRequests(std::optional<unsigned int> queueLimit = {});\n> -\tint queueRequest(libcamera::Request *request);\n> +\tvoid queueRequest(libcamera::Request *request);\n>  \tvoid requestComplete(libcamera::Request *request);\n>\n>  \tstd::shared_ptr<libcamera::Camera> camera_;\n> --\n> 2.48.0\n>\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 60C30C3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Jan 2025 12:54:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 80EA368558;\n\tWed, 22 Jan 2025 13:54:46 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A155268549\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jan 2025 13:54:44 +0100 (CET)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AAC93C16;\n\tWed, 22 Jan 2025 13:53:41 +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=\"MXQplef1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1737550421;\n\tbh=22wanWMCix4wvdOip5aee6rGfGdC5ElfpOlHqAv2Eak=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=MXQplef1AZ6CMbY04To31s/oGGaciouTr6AY14MKkpJ+3Ss87y14lTJWHitY+3Jgl\n\t/D7zlaKVoArD/GZzFMMV/+cRreU1As1u7yHJ94e5T7h3i/5RJe2ZRfWRYpnlpzhcFu\n\tHbsL5MZAdZJXYf1i9nUFERAfevUCzxk2lUXxtKVs=","Date":"Wed, 22 Jan 2025 13:54:41 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v2 16/16] apps: lc-compliance: Run request completion\n\thandler in \"main\" thread","Message-ID":"<fevtogq2mwscax7ktcldq7qpaomh2cnrmkqojmoquaikfyqnpd@pocxe6cflwnv>","References":"<20250114182143.1773762-1-pobrn@protonmail.com>\n\t<20250114182143.1773762-17-pobrn@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20250114182143.1773762-17-pobrn@protonmail.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":33239,"web_url":"https://patchwork.libcamera.org/comment/33239/","msgid":"<5xuq2v_PPjJzB96J_ePowt77IisjURhFlc8mekiKBiNjPWH_EZUiukp6kThifVl41WbY2cq2NJK6ZetNQS_OrdFXqM6l92WGMZ2DTcPojL8=@protonmail.com>","date":"2025-01-30T14:46:50","subject":"Re: [RFC PATCH v2 16/16] apps: lc-compliance: Run request completion\n\thandler in \"main\" thread","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/people/133/","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"content":"2025. január 22., szerda 13:54 keltezéssel, Jacopo Mondi <jacopo.mondi@ideasonboard.com> írta:\n\n> Hi Barnabás\n> \n> On Tue, Jan 14, 2025 at 06:23:05PM +0000, Barnabás Pőcze wrote:\n> > Currently, `Capture::requestCompleted()` runs in the `CameraManager`'s\n> > thread. This makes it a bit more complicated to use googletest and\n> > report errors in those callbacks since lc-compliance sets up\n> > googletest to throw exceptions on fatal errors / test skip, but\n> > those exceptions are only caught on the \"main\" thread, the one\n> > running the test suite.\n> >\n> > To minimize the burden of dealing with synchronization in tests,\n> > execute `Capture::requestCompleted()` in the event loop's thread\n> > by utilizing `EventLoop::callLater()`.\n> >\n> > Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> > ---\n> >  src/apps/lc-compliance/helpers/capture.cpp | 21 ++++++++++++---------\n> >  src/apps/lc-compliance/helpers/capture.h   |  2 +-\n> >  2 files changed, 13 insertions(+), 10 deletions(-)\n> >\n> > diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp\n> > index dbaff4138..528a3a13a 100644\n> > --- a/src/apps/lc-compliance/helpers/capture.cpp\n> > +++ b/src/apps/lc-compliance/helpers/capture.cpp\n> > @@ -129,16 +129,13 @@ void Capture::prepareRequests(std::optional<unsigned int> queueLimit)\n> >  \t}\n> >  }\n> >\n> > -int Capture::queueRequest(libcamera::Request *request)\n> > +void Capture::queueRequest(libcamera::Request *request)\n> >  {\n> >  \tif (queueLimit_ && queueCount_ >= *queueLimit_)\n> > -\t\treturn 0;\n> > -\n> > -\tif (int ret = camera_->queueRequest(request); ret < 0)\n> > -\t\treturn ret;\n> > +\t\treturn;\n> >\n> > +\tASSERT_EQ(camera_->queueRequest(request), 0);\n> >  \tqueueCount_ += 1;\n> > -\treturn 0;\n> >  }\n> >\n> >  void Capture::requestComplete(Request *request)\n> > @@ -153,8 +150,7 @@ void Capture::requestComplete(Request *request)\n> >  \t\t<< \"Request didn't complete successfully\";\n> >\n> >  \trequest->reuse(Request::ReuseBuffers);\n> > -\tif (queueRequest(request))\n> > -\t\tloop_->exit(-EINVAL);\n> \n> Per my understanding, this interrupts the loop_->exec() call\n> and goes through the cleanup procedure in Capture::run().\n> \n> If we ASSERT_EQ here, will the loop_ be interrupted and stop() be\n> called ?\n\nYes, that will happen, although there was an issue in the interaction\nwith libevent, but that is now fixed in the third version.\n\n\n> \n> Thanks\n>   j\n> \n> > +\tqueueRequest(request);\n> >  }\n> >\n> >  void Capture::start()\n> > @@ -173,7 +169,14 @@ void Capture::start()\n> >\n> >  \tASSERT_TRUE(allocator_.allocated());\n> >\n> > -\tcamera_->requestCompleted.connect(this, &Capture::requestComplete);\n> > +\tcamera_->requestCompleted.connect(this, [this](libcamera::Request *request) {\n> > +\t\t/* Runs in the CameraManager thread. */\n> > +\n> > +\t\tloop_->callLater([this, request] {\n> > +\t\t\t/* Run handler in the context of the event loop. */\n> > +\t\t\trequestComplete(request);\n> > +\t\t});\n> > +\t});\n> >\n> >  \tASSERT_EQ(camera_->start(), 0) << \"Failed to start camera\";\n> >  }\n> > diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h\n> > index 391184ad6..9003a0934 100644\n> > --- a/src/apps/lc-compliance/helpers/capture.h\n> > +++ b/src/apps/lc-compliance/helpers/capture.h\n> > @@ -30,7 +30,7 @@ private:\n> >  \tvoid stop();\n> >\n> >  \tvoid prepareRequests(std::optional<unsigned int> queueLimit = {});\n> > -\tint queueRequest(libcamera::Request *request);\n> > +\tvoid queueRequest(libcamera::Request *request);\n> >  \tvoid requestComplete(libcamera::Request *request);\n> >\n> >  \tstd::shared_ptr<libcamera::Camera> camera_;\n> > --\n> > 2.48.0\n> >\n> >\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 6BE67C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Jan 2025 14:46:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 93BAE68563;\n\tThu, 30 Jan 2025 15:46:56 +0100 (CET)","from mail-10631.protonmail.ch (mail-10631.protonmail.ch\n\t[79.135.106.31])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F7F66034C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Jan 2025 15:46:54 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"EJUSl6eN\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1738248413; x=1738507613;\n\tbh=mIJIQtfMMUWEPorASuwfsPLDoXsb7lBVusvtZLvmsG8=;\n\th=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post;\n\tb=EJUSl6eNC+4ZH50fU/FH3vMMC47eWATCNM92hDmVOO927qtznERQfn5ow/I49FtgD\n\tXmynBwLr+tjtXnbqEuL7ibURd6ybFUfb8NReNd1bHn8ISwF+Wosh9WtxKlEN8PIAK7\n\tDrBg2TI5wT+DSdbp6uUGaw3LjudMoX4gAInXv4VNcdd+r3Ve6Ic3ZSQg+zf62uBEBs\n\tN5EIXh79Wt6UJQ7CxKrs0gzynmBAKanKzKb9RJJOuOQ/zhDSkgqtazdpnoPWV5EKaY\n\tuzwu8VcdiHKFDF3NksSctSBzKHg2T3JtJDy2dCMjbzity9bh98iMorZr60zjaMfRiG\n\tbCrPHMbpMsUIA==","Date":"Thu, 30 Jan 2025 14:46:50 +0000","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v2 16/16] apps: lc-compliance: Run request completion\n\thandler in \"main\" thread","Message-ID":"<5xuq2v_PPjJzB96J_ePowt77IisjURhFlc8mekiKBiNjPWH_EZUiukp6kThifVl41WbY2cq2NJK6ZetNQS_OrdFXqM6l92WGMZ2DTcPojL8=@protonmail.com>","In-Reply-To":"<fevtogq2mwscax7ktcldq7qpaomh2cnrmkqojmoquaikfyqnpd@pocxe6cflwnv>","References":"<20250114182143.1773762-1-pobrn@protonmail.com>\n\t<20250114182143.1773762-17-pobrn@protonmail.com>\n\t<fevtogq2mwscax7ktcldq7qpaomh2cnrmkqojmoquaikfyqnpd@pocxe6cflwnv>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"a71438dbf676b4ff588047395739fd302c5c0829","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","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>"}}]