[{"id":16518,"web_url":"https://patchwork.libcamera.org/comment/16518/","msgid":"<YIH5jWXsYhD/5fmV@pendragon.ideasonboard.com>","date":"2021-04-22T22:32:45","subject":"Re: [libcamera-devel] [RFC PATCH 1/2] lc-compliance: Make\n\tSimpleCapture::stop() idempotent","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Nícolas,\n\nThank you for the patch.\n\nOn Thu, Apr 22, 2021 at 06:06:08PM -0300, Nícolas F. R. A. Prado wrote:\n> Make SimpleCapture::stop() be able to be called multiple times and at\n> any point so that it can be called from the destructor and an assert\n> failure can return immeadiately.\n\ns/immeadiately/immediately/\n\n> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n> ---\n>  src/lc-compliance/simple_capture.cpp | 12 +++++-------\n>  1 file changed, 5 insertions(+), 7 deletions(-)\n> \n> diff --git a/src/lc-compliance/simple_capture.cpp b/src/lc-compliance/simple_capture.cpp\n> index 811a62200096..e6715ac07f12 100644\n> --- a/src/lc-compliance/simple_capture.cpp\n> +++ b/src/lc-compliance/simple_capture.cpp\n> @@ -17,6 +17,7 @@ SimpleCapture::SimpleCapture(std::shared_ptr<Camera> camera)\n>  \n>  SimpleCapture::~SimpleCapture()\n>  {\n> +\tstop();\n>  }\n>  \n>  Results::Result SimpleCapture::configure(StreamRole role)\n> @@ -52,12 +53,16 @@ Results::Result SimpleCapture::start()\n>  \n>  void SimpleCapture::stop()\n>  {\n> +\tif (!config_)\n> +\t\treturn;\n\nMissing blank line.\n\n>  \tStream *stream = config_->at(0).stream();\n\nYou could move this line right before allocator_->free(), as that's\nwhere it's used.\n\n>  \n>  \tcamera_->stop();\n\nWe'll get an error message if Camera::start() hasn't been called (or has\nfailed). It may not be a very big issue, but I think it would make sense\nto either add a member data field in SimpleCapture to track the camera\nstate, or make Camera::start() idempotent too. This can be done on top I\nthink.\n\n>  \tcamera_->requestCompleted.disconnect(this, &SimpleCapture::requestComplete);\n>  \n> +\tif (!allocator_->allocated())\n> +\t\treturn;\n\nMissing blank line here too.\n\n>  \tallocator_->free(stream);\n>  }\n>  \n> @@ -81,7 +86,6 @@ Results::Result SimpleCaptureBalanced::capture(unsigned int numRequests)\n>  \tif (buffers.size() > numRequests) {\n>  \t\t/* Cache buffers.size() before we destroy it in stop() */\n>  \t\tint buffers_size = buffers.size();\n> -\t\tstop();\n>  \n>  \t\treturn { Results::Skip, \"Camera needs \" + std::to_string(buffers_size)\n>  \t\t\t+ \" requests, can't test only \" + std::to_string(numRequests) };\n> @@ -96,17 +100,14 @@ Results::Result SimpleCaptureBalanced::capture(unsigned int numRequests)\n>  \tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n>  \t\tstd::unique_ptr<Request> request = camera_->createRequest();\n>  \t\tif (!request) {\n> -\t\t\tstop();\n>  \t\t\treturn { Results::Fail, \"Can't create request\" };\n>  \t\t}\n\nYou can drop the curly braces here and below.\n\n>  \n>  \t\tif (request->addBuffer(stream, buffer.get())) {\n> -\t\t\tstop();\n>  \t\t\treturn { Results::Fail, \"Can't set buffer for request\" };\n>  \t\t}\n>  \n>  \t\tif (queueRequest(request.get()) < 0) {\n> -\t\t\tstop();\n>  \t\t\treturn { Results::Fail, \"Failed to queue request\" };\n>  \t\t}\n>  \n> @@ -173,17 +174,14 @@ Results::Result SimpleCaptureUnbalanced::capture(unsigned int numRequests)\n>  \tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n>  \t\tstd::unique_ptr<Request> request = camera_->createRequest();\n>  \t\tif (!request) {\n> -\t\t\tstop();\n>  \t\t\treturn { Results::Fail, \"Can't create request\" };\n>  \t\t}\n>  \n>  \t\tif (request->addBuffer(stream, buffer.get())) {\n> -\t\t\tstop();\n>  \t\t\treturn { Results::Fail, \"Can't set buffer for request\" };\n>  \t\t}\n>  \n>  \t\tif (camera_->queueRequest(request.get()) < 0) {\n> -\t\t\tstop();\n>  \t\t\treturn { Results::Fail, \"Failed to queue request\" };\n>  \t\t}\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 77FB8BDB15\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 22 Apr 2021 22:32:53 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A034568858;\n\tFri, 23 Apr 2021 00:32:52 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DC7CA6883C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Apr 2021 00:32:50 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 593CD564;\n\tFri, 23 Apr 2021 00:32:50 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"VsVsX4B9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1619130770;\n\tbh=USmMIsC0QYvLf2AeUjdhGdIAdMhcm1a5LnmQmK59Uc0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=VsVsX4B9Z3O7QYrXQ/5JnMnN9hAf9kCG8Kxwf/Rh86+FzoOtyBmgnbW95igxYzYQV\n\tt83BRslCdgSDeJUSwpLGrniwMjw76uJ2yC8KCyMUUOw+5Uiss6e6CYDBZUiAj/0a+z\n\tw4h8n2jYrhRx3QdTA7g7qI6Zv1M4sQU5jdS+DOOE=","Date":"Fri, 23 Apr 2021 01:32:45 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4=?= Prado <nfraprado@collabora.com>","Message-ID":"<YIH5jWXsYhD/5fmV@pendragon.ideasonboard.com>","References":"<20210422210609.425987-1-nfraprado@collabora.com>\n\t<20210422210609.425987-2-nfraprado@collabora.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210422210609.425987-2-nfraprado@collabora.com>","Subject":"Re: [libcamera-devel] [RFC PATCH 1/2] lc-compliance: Make\n\tSimpleCapture::stop() idempotent","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>","Cc":"libcamera-devel@lists.libcamera.org, kernel@collabora.com, =?utf-8?q?A?=\n\t=?utf-8?b?bmRyw6k=?= Almeida <andrealmeid@collabora.com>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]