[{"id":18142,"web_url":"https://patchwork.libcamera.org/comment/18142/","msgid":"<9c526f7c-ee1e-44bc-90e8-f4a7ab27bc85@ideasonboard.com>","date":"2021-07-12T16:18:29","subject":"Re: [libcamera-devel] [PATCH 30/30] cam: Support using multiple\n\tcameras concurrently","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On 07/07/2021 03:19, Laurent Pinchart wrote:\n> To allow testing capture from multiple cameras concurrently, turn the\n> --camera option into an array option, and create one CameraSession per\n> specified camera. The code is adapted to iterate over the sessions\n> vector instead of handling a single session. Thanks to all the\n> refactoring previously performed, changes are minimal.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/cam/camera_session.cpp |  8 +++--\n>  src/cam/main.cpp           | 67 ++++++++++++++++++++++----------------\n>  2 files changed, 45 insertions(+), 30 deletions(-)\n> \n> diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp\n> index 90261a8cde2e..0d49fc1ade83 100644\n> --- a/src/cam/camera_session.cpp\n> +++ b/src/cam/camera_session.cpp\n> @@ -250,9 +250,13 @@ int CameraSession::startCapture()\n>  \t}\n>  \n>  \tif (captureLimit_)\n> -\t\tstd::cout << \"Capture \" << captureLimit_ << \" frames\" << std::endl;\n> +\t\tstd::cout << \"cam\" << cameraIndex_\n> +\t\t\t  << \": Capture \" << captureLimit_ << \" frames\"\n> +\t\t\t  << std::endl;\n>  \telse\n> -\t\tstd::cout << \"Capture until user interrupts by SIGINT\" << std::endl;\n> +\t\tstd::cout << \"cam\" << cameraIndex_\n> +\t\t\t  << \": Capture until user interrupts by SIGINT\"\n\nHrm, we've called it SIGINT here and Ctrl-C on the hotplug monitor.\n\nNot a cause of this patch though.\n\n\n> +\t\t\t  << std::endl;\n>  \n>  \treturn 0;\n>  }\n> diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n> index 96f55831ca69..f9a90672a474 100644\n> --- a/src/cam/main.cpp\n> +++ b/src/cam/main.cpp\n> @@ -112,7 +112,7 @@ int CamApp::parseOptions(int argc, char *argv[])\n>  \tOptionsParser parser;\n>  \tparser.addOption(OptCamera, OptionString,\n>  \t\t\t \"Specify which camera to operate on, by id or by index\", \"camera\",\n> -\t\t\t ArgumentRequired, \"camera\");\n>  \tparser.addOption(OptHelp, OptionNone, \"Display this help message\",\n>  \t\t\t \"help\");\n>  \tparser.addOption(OptInfo, OptionNone,\n> @@ -195,45 +195,52 @@ int CamApp::run()\n>  \t\t}\n>  \t}\n>  \n> -\t/* 2. Create the camera session. */\n> -\tstd::unique_ptr<CameraSession> session;\n> +\t/* 2. Create the camera sessions. */\n> +\tstd::vector<std::unique_ptr<CameraSession>> sessions;\n>  \n>  \tif (options_.isSet(OptCamera)) {\n> -\t\tconst OptionValue &camera = options_[OptCamera];\n> -\t\tsession = std::make_unique<CameraSession>(cm_.get(),\n> -\t\t\t\t\t\t\t  camera.toString(), 0,\n> -\t\t\t\t\t\t\t  camera.children());\n> -\t\tif (!session->isValid()) {\n> -\t\t\tstd::cout << \"Failed to create camera session\" << std::endl;\n> -\t\t\treturn -EINVAL;\n> +\t\tunsigned int index = 0;\n> +\n> +\t\tfor (const OptionValue &camera : options_[OptCamera].toArray()) {\n> +\t\t\tstd::unique_ptr<CameraSession> session =\n> +\t\t\t\tstd::make_unique<CameraSession>(cm_.get(),\n> +\t\t\t\t\t\t\t\tcamera.toString(),\n> +\t\t\t\t\t\t\t\tindex,\n> +\t\t\t\t\t\t\t\tcamera.children());\n> +\t\t\tif (!session->isValid()) {\n> +\t\t\t\tstd::cout << \"Failed to create camera session\" << std::endl;\n> +\t\t\t\treturn -EINVAL;\n> +\t\t\t}\n> +\n> +\t\t\tstd::cout << \"Using camera \" << session->camera()->id()\n> +\t\t\t\t  << \" as cam\" << index << std::endl;\n> +\n> +\t\t\tsession->captureDone.connect(this, &CamApp::captureDone);\n> +\n> +\t\t\tsessions.push_back(std::move(session));\n> +\t\t\tindex++;\n>  \t\t}\n> -\n> -\t\tstd::cout << \"Using camera \" << session->camera()->id()\n> -\t\t\t  << std::endl;\n> -\n> -\t\tsession->captureDone.connect(this, &CamApp::captureDone);\n>  \t}\n>  \n>  \t/* 3. Print camera information. */\n>  \tif (options_.isSet(OptListControls) ||\n>  \t    options_.isSet(OptListProperties) ||\n>  \t    options_.isSet(OptInfo)) {\n> -\t\tif (!session) {\n> -\t\t\tstd::cout << \"Cannot print camera information without a camera\"\n> -\t\t\t\t  << std::endl;\n> -\t\t\treturn -EINVAL;\n> +\t\tfor (const auto &session : sessions) {\n> +\t\t\tif (options_.isSet(OptListControls))\n> +\t\t\t\tsession->listControls();\n> +\t\t\tif (options_.isSet(OptListProperties))\n> +\t\t\t\tsession->listProperties();\n> +\t\t\tif (options_.isSet(OptInfo))\n> +\t\t\t\tsession->infoConfiguration();\n\n\nStill suspecting that these could now be child options of the camera...\n\nUnless they have to be done after the CameraSession is fully set up...\n\n\nAnyway, ... I haven't tested any of this yet, I think a branch would be\nnicer for that....\n\n\nBut so far so good:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n\n>  \t\t}\n> -\n> -\t\tif (options_.isSet(OptListControls))\n> -\t\t\tsession->listControls();\n> -\t\tif (options_.isSet(OptListProperties))\n> -\t\t\tsession->listProperties();\n> -\t\tif (options_.isSet(OptInfo))\n> -\t\t\tsession->infoConfiguration();\n>  \t}\n>  \n>  \t/* 4. Start capture. */\n> -\tif (session && session->options().isSet(OptCapture)) {\n> +\tfor (const auto &session : sessions) {\n> +\t\tif (!session->options().isSet(OptCapture))\n> +\t\t\tcontinue;\n> +\n>  \t\tret = session->start();\n>  \t\tif (ret) {\n>  \t\t\tstd::cout << \"Failed to start camera session\" << std::endl;\n> @@ -258,8 +265,12 @@ int CamApp::run()\n>  \t\tloop_.exec();\n>  \n>  \t/* 6. Stop capture. */\n> -\tif (session && session->options().isSet(OptCapture))\n> +\tfor (const auto &session : sessions) {\n> +\t\tif (!session->options().isSet(OptCapture))\n> +\t\t\tcontinue;\n> +\n>  \t\tsession->stop();\n> +\t}\n>  \n>  \treturn 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 87714C3225\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Jul 2021 16:18:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C3CC968526;\n\tMon, 12 Jul 2021 18:18:33 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1318C68513\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Jul 2021 18:18:33 +0200 (CEST)","from [192.168.0.20]\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 973DBCC;\n\tMon, 12 Jul 2021 18:18:32 +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=\"V/5sCG7O\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1626106712;\n\tbh=g1ny8EswUx4/FBQM5SoedrRG5TQOCIiX3eP+BcVkdiw=;\n\th=To:References:From:Subject:Date:In-Reply-To:From;\n\tb=V/5sCG7OazkG2akIU9WIXlSjVXCHuX6VOHYM++XynTd4D8WV0+gXw+V8FfVxfdYJD\n\taT7rFn1e6ca9rvb12FTnlA5MapuXeDSQbJgVeuVzCgpPji7FM+776aPpZo/aOd2uq7\n\t6lZa15ECoVCPDB0n9dPay4ABk+sK+Ycw8fB83kjA=","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20210707021941.20804-1-laurent.pinchart@ideasonboard.com>\n\t<20210707021941.20804-31-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<9c526f7c-ee1e-44bc-90e8-f4a7ab27bc85@ideasonboard.com>","Date":"Mon, 12 Jul 2021 17:18:29 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.11.0","MIME-Version":"1.0","In-Reply-To":"<20210707021941.20804-31-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 30/30] cam: Support using multiple\n\tcameras concurrently","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>"}}]