Patch Detail
Show a patch.
GET /api/patches/12841/?format=api
{ "id": 12841, "url": "https://patchwork.libcamera.org/api/patches/12841/?format=api", "web_url": "https://patchwork.libcamera.org/patch/12841/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210707021941.20804-29-laurent.pinchart@ideasonboard.com>", "date": "2021-07-07T02:19:39", "name": "[libcamera-devel,28/30] cam: Make camera-related options sub-options of OptCamera", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "7a3c8516cc455f8b0fa90b6ee22fe762da702c5a", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/12841/mbox/", "series": [ { "id": 2213, "url": "https://patchwork.libcamera.org/api/series/2213/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2213", "date": "2021-07-07T02:19:12", "name": "Multi-camera support in the cam application", "version": 1, "mbox": "https://patchwork.libcamera.org/series/2213/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/12841/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/12841/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 D3D8BC3227\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 7 Jul 2021 02:20:56 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8E3106852B;\n\tWed, 7 Jul 2021 04:20:56 +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 1709B68536\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 7 Jul 2021 04:20:42 +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 A18642E4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 7 Jul 2021 04:20:41 +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=\"qcWRn4TY\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1625624441;\n\tbh=JpgTQHbuM1ji3mUNwppJieiSGtt+LXGadzwraXro01g=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=qcWRn4TYxlNZX7U0s5HP2cOlWwpIPP7GyobslcqyRdRh9v5O9F1hN9AUsyxW8HlVQ\n\t1Uii7EOOdhWE6v7YmkH6b1s41HcAuocLfPNLk3O82lDPxUL4bUmz9GmVTkSrdv+q5S\n\twXuc3zmAqDbMTpUM0tmCmFB8Op3iiZZAJmF0O4t4=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 7 Jul 2021 05:19:39 +0300", "Message-Id": "<20210707021941.20804-29-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.31.1", "In-Reply-To": "<20210707021941.20804-1-laurent.pinchart@ideasonboard.com>", "References": "<20210707021941.20804-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 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>\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..f137279ab421 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", "28/30" ] }