[{"id":19864,"web_url":"https://patchwork.libcamera.org/comment/19864/","msgid":"<20210927065509.GE4382@pyrite.rasen.tech>","date":"2021-09-27T06:55:09","subject":"Re: [libcamera-devel] [PATCH] simple-cam: Move camera detection\n\tcheck to where it belongs","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Laurent,\n\nOn Mon, Sep 27, 2021 at 12:05:54AM +0300, Laurent Pinchart wrote:\n> Commit 14529b6d1c4a (\"simple-cam: Early return if no cameras are found\n> on the system\") added a check to ensure that at least one camera is\n> present in the system to avoid a crash otherwise. The check was however\n> placed towards the end of the main() function, way after the camera is\n> accessed, possibly due to a rebase conflict. Move it before accessing\n> the first camera.\n> \n> While at it, replace usage of std::vector::size() with\n> std::vector::empty() which expresses the intent better.\n> \n> Fixes: 14529b6d1c4a (\"simple-cam: Early return if no cameras are found on the system\")\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  simple-cam.cpp | 17 +++++++++--------\n>  1 file changed, 9 insertions(+), 8 deletions(-)\n> \n> diff --git a/simple-cam.cpp b/simple-cam.cpp\n> index e374e45849dc..71a715a0c27d 100644\n> --- a/simple-cam.cpp\n> +++ b/simple-cam.cpp\n> @@ -163,13 +163,21 @@ int main()\n>  \t * Application lock usage of Camera by 'acquiring' them.\n>  \t * Once done with it, application shall similarly 'release' the Camera.\n>  \t *\n> -\t * As an example, use the first available camera in the system.\n> +\t * As an example, use the first available camera in the system after\n> +\t * making sure that at least one camera is available.\n>  \t *\n>  \t * Cameras can be obtained by their ID or their index, to demonstrate\n>  \t * this, the following code gets the ID of the first camera; then gets\n>  \t * the camera associated with that ID (which is of course the same as\n>  \t * cm->cameras()[0]).\n>  \t */\n> +\tif (cm->cameras().empty()) {\n> +\t\tstd::cout << \"No cameras were identified on the system.\"\n> +\t\t\t  << std::endl;\n> +\t\tcm->stop();\n> +\t\treturn EXIT_FAILURE;\n> +\t}\n> +\n>  \tstd::string cameraId = cm->cameras()[0]->id();\n>  \tcamera = cm->get(cameraId);\n>  \tcamera->acquire();\n> @@ -386,13 +394,6 @@ int main()\n>  \tfor (std::unique_ptr<Request> &request : requests)\n>  \t\tcamera->queueRequest(request.get());\n>  \n> -\tif (!cm->cameras().size()) {\n> -\t\tstd::cout << \"No cameras were identified on the system.\"\n> -\t\t\t  << std::endl;\n> -\t\tcm->stop();\n> -\t\treturn EXIT_FAILURE;\n> -\t}\n> -\n>  \t/*\n>  \t * --------------------------------------------------------------------\n>  \t * Run an EventLoop\n> \n> base-commit: 1f795410c0d99aaa15c8155d7d16ae6357487a96\n> prerequisite-patch-id: a9984c79d9b952f4004a670f8828600af70d732e\n> prerequisite-patch-id: 8dcf991243c61f7931da9f18ed5acd4920ea32c5\n> -- \n> Regards,\n> \n> Laurent Pinchart\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 CC5AABDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Sep 2021 06:55:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1DCBD6918E;\n\tMon, 27 Sep 2021 08:55:19 +0200 (CEST)","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 13C2A684C8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Sep 2021 08:55:18 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7823F49A;\n\tMon, 27 Sep 2021 08:55:16 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"j5ZMpEw2\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1632725717;\n\tbh=D9iAPqGCST4T7b3gL+0xXCnXkzf9Cdbm5hqIWdcdZ64=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=j5ZMpEw2KGCThTrR8nfy6b71iwxPF/1jO1yoI0Sdy5zOiWpGkZ4EWjRh9b0TNKpej\n\t8uCfguXRDA+XGyk61Sfl9M+ZeNhEx4TxfrSBaBT9LHiLTfRbxmOjwvg7OrUAEBpp2U\n\tR7i2GFhFGuUpCXg5jX3NZC/KUI5Xsq33C8BpytBs=","Date":"Mon, 27 Sep 2021 15:55:09 +0900","From":"paul.elder@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20210927065509.GE4382@pyrite.rasen.tech>","References":"<20210926210554.20901-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20210926210554.20901-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] simple-cam: Move camera detection\n\tcheck to where it belongs","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","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":19921,"web_url":"https://patchwork.libcamera.org/comment/19921/","msgid":"<20210928103510.pwnqxa35qy2xhlge@ideasonboard.com>","date":"2021-09-28T10:35:10","subject":"Re: [libcamera-devel] [PATCH] simple-cam: Move camera detection\n\tcheck to where it belongs","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On Mon, Sep 27, 2021 at 03:55:09PM +0900, paul.elder@ideasonboard.com wrote:\n> Hi Laurent,\n> \n> On Mon, Sep 27, 2021 at 12:05:54AM +0300, Laurent Pinchart wrote:\n> > Commit 14529b6d1c4a (\"simple-cam: Early return if no cameras are found\n> > on the system\") added a check to ensure that at least one camera is\n> > present in the system to avoid a crash otherwise. The check was however\n> > placed towards the end of the main() function, way after the camera is\n> > accessed, possibly due to a rebase conflict. Move it before accessing\n> > the first camera.\n> > \n> > While at it, replace usage of std::vector::size() with\n> > std::vector::empty() which expresses the intent better.\n> > \n> > Fixes: 14529b6d1c4a (\"simple-cam: Early return if no cameras are found on the system\")\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> > ---\n> >  simple-cam.cpp | 17 +++++++++--------\n> >  1 file changed, 9 insertions(+), 8 deletions(-)\n> > \n> > diff --git a/simple-cam.cpp b/simple-cam.cpp\n> > index e374e45849dc..71a715a0c27d 100644\n> > --- a/simple-cam.cpp\n> > +++ b/simple-cam.cpp\n> > @@ -163,13 +163,21 @@ int main()\n> >  \t * Application lock usage of Camera by 'acquiring' them.\n> >  \t * Once done with it, application shall similarly 'release' the Camera.\n> >  \t *\n> > -\t * As an example, use the first available camera in the system.\n> > +\t * As an example, use the first available camera in the system after\n> > +\t * making sure that at least one camera is available.\n> >  \t *\n> >  \t * Cameras can be obtained by their ID or their index, to demonstrate\n> >  \t * this, the following code gets the ID of the first camera; then gets\n> >  \t * the camera associated with that ID (which is of course the same as\n> >  \t * cm->cameras()[0]).\n> >  \t */\n> > +\tif (cm->cameras().empty()) {\n> > +\t\tstd::cout << \"No cameras were identified on the system.\"\n> > +\t\t\t  << std::endl;\n> > +\t\tcm->stop();\n> > +\t\treturn EXIT_FAILURE;\n> > +\t}\n> > +\n> >  \tstd::string cameraId = cm->cameras()[0]->id();\n> >  \tcamera = cm->get(cameraId);\n> >  \tcamera->acquire();\n> > @@ -386,13 +394,6 @@ int main()\n> >  \tfor (std::unique_ptr<Request> &request : requests)\n> >  \t\tcamera->queueRequest(request.get());\n> >  \n> > -\tif (!cm->cameras().size()) {\n> > -\t\tstd::cout << \"No cameras were identified on the system.\"\n> > -\t\t\t  << std::endl;\n> > -\t\tcm->stop();\n> > -\t\treturn EXIT_FAILURE;\n> > -\t}\n> > -\n> >  \t/*\n> >  \t * --------------------------------------------------------------------\n> >  \t * Run an EventLoop\n> > \n> > base-commit: 1f795410c0d99aaa15c8155d7d16ae6357487a96\n> > prerequisite-patch-id: a9984c79d9b952f4004a670f8828600af70d732e\n> > prerequisite-patch-id: 8dcf991243c61f7931da9f18ed5acd4920ea32c5\n> > -- \n> > Regards,\n> > \n> > Laurent Pinchart\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 711D9BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 28 Sep 2021 10:35:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E290B6918C;\n\tTue, 28 Sep 2021 12:35:13 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CAC2369185\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Sep 2021 12:35:12 +0200 (CEST)","from ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4D0E63F1;\n\tTue, 28 Sep 2021 12:35:12 +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=\"us6F7Fr7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1632825312;\n\tbh=LUk1i8ubD9WGWvg7gtYUKWHqcLfkkkc2q+t3e1I6PkQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=us6F7Fr7CO5XxTX1HyzRdzbQbbUoWgB5+/wQPhFj6FcCcexPk8b4D8nhAJgBUtFBr\n\tj0UosUYzf1w33HxG9VVQgX4eI4IB9C24hqTTCZ/vpOu0NB90qH4MfR899qBZacgp5R\n\tCrcOZWRkIdb8kN2R3lH8Orpb3rk05aoHJ+7YpVg0=","Date":"Tue, 28 Sep 2021 11:35:10 +0100","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"paul.elder@ideasonboard.com","Message-ID":"<20210928103510.pwnqxa35qy2xhlge@ideasonboard.com>","References":"<20210926210554.20901-1-laurent.pinchart@ideasonboard.com>\n\t<20210927065509.GE4382@pyrite.rasen.tech>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210927065509.GE4382@pyrite.rasen.tech>","Subject":"Re: [libcamera-devel] [PATCH] simple-cam: Move camera detection\n\tcheck to where it belongs","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","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]