{"id":12941,"url":"https://patchwork.libcamera.org/api/1.1/patches/12941/?format=json","web_url":"https://patchwork.libcamera.org/patch/12941/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210712215645.30478-29-laurent.pinchart@ideasonboard.com>","date":"2021-07-12T21:56:43","name":"[libcamera-devel,v2,28/30] cam: Make camera-related options sub-options of OptCamera","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"35c140b2c92135d715fb8d7cc9d48bab98d071bd","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12941/mbox/","series":[{"id":2229,"url":"https://patchwork.libcamera.org/api/1.1/series/2229/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2229","date":"2021-07-12T21:56:15","name":"Multi-camera support in the cam application","version":2,"mbox":"https://patchwork.libcamera.org/series/2229/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12941/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12941/checks/","tags":{},"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 18FA0C3229\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Jul 2021 21:58:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B94216854B;\n\tMon, 12 Jul 2021 23:57:59 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 283F168553\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Jul 2021 23:57:45 +0200 (CEST)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CEEC556B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Jul 2021 23:57:44 +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=\"tmqx2qoc\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1626127065;\n\tbh=koaXduLa/fdL0ZUVM/Z6iHnevdczY2iiyqE8I2ADNmY=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=tmqx2qocMEQZksRHGvTOKGIsCCeRQ3XT84328xVsnQ4nAdjG05/R4U7gRFwYJ6zZO\n\tWthlE4mtH4EEP/SiJLyWFvW3Lh6aknQsvOKw2O+NMejivM0AzdLb3NPhd0ji+LC+7H\n\tvbzHPqoSvfmX06QBCCgFFgaKsRiJXLs2Dj4s8g8g=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 13 Jul 2021 00:56:43 +0300","Message-Id":"<20210712215645.30478-29-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.31.1","In-Reply-To":"<20210712215645.30478-1-laurent.pinchart@ideasonboard.com>","References":"<20210712215645.30478-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 28/30] cam: Make camera-related options\n\tsub-options of OptCamera","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>"},"content":"Use the new hierarchical options feature of the option parser to turn\ncamera-related option (--capture, --file, --stream, --strict-formats and\n--metadata) into children of the --camera option. As an added bonus, we\ndon't need to check anymore if a camera has been specified when capture\nis requested, as that's now enforced by the option parser.\n\nThis change prepares for support of multiple cameras.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\nChanges since v1:\n\n- Drop extraneous semicolon\n---\n src/cam/camera_session.cpp | 22 ++++++++--------\n src/cam/camera_session.h   |  6 ++++-\n src/cam/main.cpp           | 53 +++++++++++++++++++++-----------------\n 3 files changed, 45 insertions(+), 36 deletions(-)","diff":"diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp\nindex ceb2c3ab3a92..f2383567af3b 100644\n--- a/src/cam/camera_session.cpp\n+++ b/src/cam/camera_session.cpp\n@@ -21,11 +21,11 @@\n using namespace libcamera;\n \n CameraSession::CameraSession(CameraManager *cm,\n+\t\t\t     const std::string &cameraId,\n \t\t\t     const OptionsParser::Options &options)\n-\t: last_(0), queueCount_(0), captureCount_(0),\n+\t: options_(options), last_(0), queueCount_(0), captureCount_(0),\n \t  captureLimit_(0), printMetadata_(false)\n {\n-\tconst std::string &cameraId = options[OptCamera];\n \tchar *endptr;\n \tunsigned long index = strtoul(cameraId.c_str(), &endptr, 10);\n \tif (*endptr == '\\0' && index > 0 && index <= cm->cameras().size())\n@@ -44,7 +44,7 @@ CameraSession::CameraSession(CameraManager *cm,\n \t\treturn;\n \t}\n \n-\tStreamRoles roles = StreamKeyValueParser::roles(options[OptStream]);\n+\tStreamRoles roles = StreamKeyValueParser::roles(options_[OptStream]);\n \n \tstd::unique_ptr<CameraConfiguration> config =\n \t\tcamera_->generateConfiguration(roles);\n@@ -56,12 +56,12 @@ CameraSession::CameraSession(CameraManager *cm,\n \n \t/* Apply configuration if explicitly requested. */\n \tif (StreamKeyValueParser::updateConfiguration(config.get(),\n-\t\t\t\t\t\t      options[OptStream])) {\n+\t\t\t\t\t\t      options_[OptStream])) {\n \t\tstd::cerr << \"Failed to update configuration\" << std::endl;\n \t\treturn;\n \t}\n \n-\tbool strictFormats = options.isSet(OptStrictFormats);\n+\tbool strictFormats = options_.isSet(OptStrictFormats);\n \n \tswitch (config->validate()) {\n \tcase CameraConfiguration::Valid:\n@@ -134,14 +134,14 @@ void CameraSession::infoConfiguration() const\n \t}\n }\n \n-int CameraSession::start(const OptionsParser::Options &options)\n+int CameraSession::start()\n {\n \tint ret;\n \n \tqueueCount_ = 0;\n \tcaptureCount_ = 0;\n-\tcaptureLimit_ = options[OptCapture].toInteger();\n-\tprintMetadata_ = options.isSet(OptMetadata);\n+\tcaptureLimit_ = options_[OptCapture].toInteger();\n+\tprintMetadata_ = options_.isSet(OptMetadata);\n \n \tret = camera_->configure(config_.get());\n \tif (ret < 0) {\n@@ -157,9 +157,9 @@ int CameraSession::start(const OptionsParser::Options &options)\n \n \tcamera_->requestCompleted.connect(this, &CameraSession::requestComplete);\n \n-\tif (options.isSet(OptFile)) {\n-\t\tif (!options[OptFile].toString().empty())\n-\t\t\twriter_ = std::make_unique<BufferWriter>(options[OptFile]);\n+\tif (options_.isSet(OptFile)) {\n+\t\tif (!options_[OptFile].toString().empty())\n+\t\t\twriter_ = std::make_unique<BufferWriter>(options_[OptFile]);\n \t\telse\n \t\t\twriter_ = std::make_unique<BufferWriter>();\n \t}\ndiff --git a/src/cam/camera_session.h b/src/cam/camera_session.h\nindex 6221aadadf90..b31363834f68 100644\n--- a/src/cam/camera_session.h\n+++ b/src/cam/camera_session.h\n@@ -9,6 +9,7 @@\n \n #include <memory>\n #include <stdint.h>\n+#include <string>\n #include <vector>\n \n #include <libcamera/base/signal.h>\n@@ -27,10 +28,12 @@ class CameraSession\n {\n public:\n \tCameraSession(libcamera::CameraManager *cm,\n+\t\t      const std::string &cameraId,\n \t\t      const OptionsParser::Options &options);\n \t~CameraSession();\n \n \tbool isValid() const { return config_ != nullptr; }\n+\tconst OptionsParser::Options &options() { return options_; }\n \n \tlibcamera::Camera *camera() { return camera_.get(); }\n \tlibcamera::CameraConfiguration *config() { return config_.get(); }\n@@ -39,7 +42,7 @@ public:\n \tvoid listProperties() const;\n \tvoid infoConfiguration() const;\n \n-\tint start(const OptionsParser::Options &options);\n+\tint start();\n \tvoid stop();\n \n \tlibcamera::Signal<> captureDone;\n@@ -51,6 +54,7 @@ private:\n \tvoid requestComplete(libcamera::Request *request);\n \tvoid processRequest(libcamera::Request *request);\n \n+\tconst OptionsParser::Options &options_;\n \tstd::shared_ptr<libcamera::Camera> camera_;\n \tstd::unique_ptr<libcamera::CameraConfiguration> config_;\n \ndiff --git a/src/cam/main.cpp b/src/cam/main.cpp\nindex 6d7d45e11499..7688fa5540ea 100644\n--- a/src/cam/main.cpp\n+++ b/src/cam/main.cpp\n@@ -113,19 +113,6 @@ int CamApp::parseOptions(int argc, char *argv[])\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(OptCapture, OptionInteger,\n-\t\t\t \"Capture until interrupted by user or until <count> frames captured\",\n-\t\t\t \"capture\", ArgumentOptional, \"count\");\n-\tparser.addOption(OptFile, OptionString,\n-\t\t\t \"Write captured frames to disk\\n\"\n-\t\t\t \"If the file name ends with a '/', it sets the directory in which\\n\"\n-\t\t\t \"to write files, using the default file name. Otherwise it sets the\\n\"\n-\t\t\t \"full file path and name. The first '#' character in the file name\\n\"\n-\t\t\t \"is expanded to the stream name and frame sequence number.\\n\"\n-\t\t\t \"The default file name is 'frame-#.bin'.\",\n-\t\t\t \"file\", ArgumentOptional, \"filename\");\n-\tparser.addOption(OptStream, &streamKeyValue,\n-\t\t\t \"Set configuration of a camera stream\", \"stream\", true);\n \tparser.addOption(OptHelp, OptionNone, \"Display this help message\",\n \t\t\t \"help\");\n \tparser.addOption(OptInfo, OptionNone,\n@@ -138,12 +125,32 @@ int CamApp::parseOptions(int argc, char *argv[])\n \tparser.addOption(OptMonitor, OptionNone,\n \t\t\t \"Monitor for hotplug and unplug camera events\",\n \t\t\t \"monitor\");\n+\n+\t/* Sub-options of OptCamera: */\n+\tparser.addOption(OptCapture, OptionInteger,\n+\t\t\t \"Capture until interrupted by user or until <count> frames captured\",\n+\t\t\t \"capture\", ArgumentOptional, \"count\", false,\n+\t\t\t OptCamera);\n+\tparser.addOption(OptFile, OptionString,\n+\t\t\t \"Write captured frames to disk\\n\"\n+\t\t\t \"If the file name ends with a '/', it sets the directory in which\\n\"\n+\t\t\t \"to write files, using the default file name. Otherwise it sets the\\n\"\n+\t\t\t \"full file path and name. The first '#' character in the file name\\n\"\n+\t\t\t \"is expanded to the stream name and frame sequence number.\\n\"\n+\t\t\t \"The default file name is 'frame-#.bin'.\",\n+\t\t\t \"file\", ArgumentOptional, \"filename\", false,\n+\t\t\t OptCamera);\n+\tparser.addOption(OptStream, &streamKeyValue,\n+\t\t\t \"Set configuration of a camera stream\", \"stream\", true,\n+\t\t\t OptCamera);\n \tparser.addOption(OptStrictFormats, OptionNone,\n \t\t\t \"Do not allow requested stream format(s) to be adjusted\",\n-\t\t\t \"strict-formats\");\n+\t\t\t \"strict-formats\", ArgumentNone, nullptr, false,\n+\t\t\t OptCamera);\n \tparser.addOption(OptMetadata, OptionNone,\n \t\t\t \"Print the metadata for completed requests\",\n-\t\t\t \"metadata\");\n+\t\t\t \"metadata\", ArgumentNone, nullptr, false,\n+\t\t\t OptCamera);\n \n \toptions_ = parser.parse(argc, argv);\n \tif (!options_.valid())\n@@ -192,7 +199,10 @@ int CamApp::run()\n \tstd::unique_ptr<CameraSession> session;\n \n \tif (options_.isSet(OptCamera)) {\n-\t\tsession = std::make_unique<CameraSession>(cm_.get(), options_);\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(),\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@@ -223,13 +233,8 @@ int CamApp::run()\n \t}\n \n \t/* 4. Start capture. */\n-\tif (options_.isSet(OptCapture)) {\n-\t\tif (!session) {\n-\t\t\tstd::cout << \"Can't capture without a camera\" << std::endl;\n-\t\t\treturn -ENODEV;\n-\t\t}\n-\n-\t\tret = session->start(options_);\n+\tif (session && session->options().isSet(OptCapture)) {\n+\t\tret = session->start();\n \t\tif (ret) {\n \t\t\tstd::cout << \"Failed to start camera session\" << std::endl;\n \t\t\treturn ret;\n@@ -253,7 +258,7 @@ int CamApp::run()\n \t\tloop_.exec();\n \n \t/* 6. Stop capture. */\n-\tif (options_.isSet(OptCapture))\n+\tif (session && session->options().isSet(OptCapture))\n \t\tsession->stop();\n \n \treturn 0;\n","prefixes":["libcamera-devel","v2","28/30"]}