Patch Detail
Show a patch.
GET /api/patches/3580/?format=api
{ "id": 3580, "url": "https://patchwork.libcamera.org/api/patches/3580/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3580/", "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": "<20200427220529.1085074-4-niklas.soderlund@ragnatech.se>", "date": "2020-04-27T22:05:27", "name": "[libcamera-devel,v2,3/5] cam: Add helper class to parse stream configuration", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "7ad99ce69fe8a35c4f5e75efc1224598be197ecc", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3580/mbox/", "series": [ { "id": 838, "url": "https://patchwork.libcamera.org/api/series/838/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=838", "date": "2020-04-27T22:05:24", "name": "{cam, qcam}: Unify stream option parsing", "version": 2, "mbox": "https://patchwork.libcamera.org/series/838/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3580/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3580/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0535860B02\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Apr 2020 00:06:17 +0200 (CEST)", "from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de\n\t[79.202.35.146]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 40eb94df-88d3-11ea-b7d8-005056917a89;\n\tTue, 28 Apr 2020 00:05:49 +0200 (CEST)" ], "X-Halon-ID": "40eb94df-88d3-11ea-b7d8-005056917a89", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 28 Apr 2020 00:05:27 +0200", "Message-Id": "<20200427220529.1085074-4-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.26.0", "In-Reply-To": "<20200427220529.1085074-1-niklas.soderlund@ragnatech.se>", "References": "<20200427220529.1085074-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 3/5] cam: Add helper class to parse\n\tstream configuration", "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>", "X-List-Received-Date": "Mon, 27 Apr 2020 22:06:18 -0000" }, "content": "Create a new helper class StreamKeyValueParser to parse command line\noptions describing stream configurations. The goal is to share this new\nclass between cam and qcam.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/cam/meson.build | 1 +\n src/cam/stream_options.cpp | 133 +++++++++++++++++++++++++++++++++++++\n src/cam/stream_options.h | 32 +++++++++\n 3 files changed, 166 insertions(+)\n create mode 100644 src/cam/stream_options.cpp\n create mode 100644 src/cam/stream_options.h", "diff": "diff --git a/src/cam/meson.build b/src/cam/meson.build\nindex 2419d648bc17e02b..162d6333f94e4851 100644\n--- a/src/cam/meson.build\n+++ b/src/cam/meson.build\n@@ -4,6 +4,7 @@ cam_sources = files([\n 'event_loop.cpp',\n 'main.cpp',\n 'options.cpp',\n+ 'stream_options.cpp',\n ])\n \n cam = executable('cam', cam_sources,\ndiff --git a/src/cam/stream_options.cpp b/src/cam/stream_options.cpp\nnew file mode 100644\nindex 0000000000000000..9f726a7e70628648\n--- /dev/null\n+++ b/src/cam/stream_options.cpp\n@@ -0,0 +1,133 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n+ *\n+ * stream_options.cpp - Helper to parse options for streams\n+ */\n+#include \"stream_options.h\"\n+\n+#include <iostream>\n+\n+using namespace libcamera;\n+\n+StreamKeyValueParser::StreamKeyValueParser()\n+{\n+\taddOption(\"role\", OptionString,\n+\t\t \"Role for the stream (viewfinder, video, still, stillraw)\",\n+\t\t ArgumentRequired);\n+\taddOption(\"width\", OptionInteger, \"Width in pixels\",\n+\t\t ArgumentRequired);\n+\taddOption(\"height\", OptionInteger, \"Height in pixels\",\n+\t\t ArgumentRequired);\n+\taddOption(\"pixelformat\", OptionInteger, \"Pixel format\",\n+\t\t ArgumentRequired);\n+}\n+\n+KeyValueParser::Options StreamKeyValueParser::parse(const char *arguments)\n+{\n+\tKeyValueParser::Options options = KeyValueParser::parse(arguments);\n+\tStreamRole role;\n+\n+\tif (options.valid() && options.isSet(\"role\") &&\n+\t parseRole(&role, options)) {\n+\t\tstd::cerr << \"Unknown stream role \"\n+\t\t\t << options[\"role\"].toString() << std::endl;\n+\t\toptions.invalidate();\n+\t}\n+\n+\treturn options;\n+}\n+\n+StreamRoles StreamKeyValueParser::roles(const OptionValue &values)\n+{\n+\tconst std::vector<OptionValue> &streamParameters = values.toArray();\n+\n+\t/* If no configuration values to examine default to viewfinder. */\n+\tif (!streamParameters.size())\n+\t\treturn { StreamRole::Viewfinder };\n+\n+\tStreamRoles roles;\n+\tfor (auto const &value : streamParameters) {\n+\t\tKeyValueParser::Options opts = value.toKeyValues();\n+\t\tStreamRole role;\n+\n+\t\t/* If role is invalid or not set default to viewfinder. */\n+\t\tif (parseRole(&role, value))\n+\t\t\trole = StreamRole::Viewfinder;\n+\n+\t\troles.push_back(role);\n+\t}\n+\n+\treturn roles;\n+}\n+\n+int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config,\n+\t\t\t\t\t const OptionValue &values)\n+{\n+\tconst std::vector<OptionValue> &streamParameters = values.toArray();\n+\n+\tif (!config) {\n+\t\tstd::cerr << \"No configuration provided\" << std::endl;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* If no configuration values nothing to do. */\n+\tif (!streamParameters.size())\n+\t\treturn 0;\n+\n+\tif (config->size() != streamParameters.size()) {\n+\t\tstd::cerr\n+\t\t\t<< \"Number of streams in configuration \"\n+\t\t\t<< config->size()\n+\t\t\t<< \" does not match number of streams parsed \"\n+\t\t\t<< streamParameters.size()\n+\t\t\t<< std::endl;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tunsigned int i = 0;\n+\tfor (auto const &value : streamParameters) {\n+\t\tKeyValueParser::Options opts = value.toKeyValues();\n+\t\tStreamConfiguration &cfg = config->at(i++);\n+\n+\t\tif (opts.isSet(\"width\") && opts.isSet(\"height\")) {\n+\t\t\tcfg.size.width = opts[\"width\"];\n+\t\t\tcfg.size.height = opts[\"height\"];\n+\t\t}\n+\n+\t\t/* TODO: Translate 4CC string to ID. */\n+\t\tif (opts.isSet(\"pixelformat\"))\n+\t\t\tcfg.pixelFormat = PixelFormat(opts[\"pixelformat\"]);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int StreamKeyValueParser::parseRole(StreamRole *role,\n+\t\t\t\t const KeyValueParser::Options &options)\n+{\n+\tbool found = false;\n+\n+\tif (options.isSet(\"role\")) {\n+\t\tstd::string name = options[\"role\"].toString();\n+\n+\t\tif (name == \"viewfinder\") {\n+\t\t\t*role = StreamRole::Viewfinder;\n+\t\t\tfound = true;\n+\t\t}\n+\t\tif (name == \"video\") {\n+\t\t\t*role = StreamRole::VideoRecording;\n+\t\t\tfound = true;\n+\t\t}\n+\t\tif (name == \"still\") {\n+\t\t\t*role = StreamRole::StillCapture;\n+\t\t\tfound = true;\n+\t\t}\n+\t\tif (name == \"stillraw\") {\n+\t\t\t*role = StreamRole::StillCaptureRaw;\n+\t\t\tfound = true;\n+\t\t}\n+\t}\n+\n+\treturn found ? 0 : -EINVAL;\n+}\ndiff --git a/src/cam/stream_options.h b/src/cam/stream_options.h\nnew file mode 100644\nindex 0000000000000000..c90d8c4dc595814d\n--- /dev/null\n+++ b/src/cam/stream_options.h\n@@ -0,0 +1,32 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n+ *\n+ * stream_options.h - Helper to parse options for streams\n+ */\n+#ifndef __CAM_STREAM_OPTIONS_H__\n+#define __CAM_STREAM_OPTIONS_H__\n+\n+#include <libcamera/camera.h>\n+\n+#include \"options.h\"\n+\n+using namespace libcamera;\n+\n+class StreamKeyValueParser : public KeyValueParser\n+{\n+public:\n+\tStreamKeyValueParser();\n+\n+\tKeyValueParser::Options parse(const char *arguments) override;\n+\n+\tstatic StreamRoles roles(const OptionValue &values);\n+\tstatic int updateConfiguration(CameraConfiguration *config,\n+\t\t\t\t const OptionValue &values);\n+\n+private:\n+\tstatic int parseRole(StreamRole *role,\n+\t\t\t const KeyValueParser::Options &options);\n+};\n+\n+#endif /* __CAM_STREAM_OPTIONS_H__ */\n", "prefixes": [ "libcamera-devel", "v2", "3/5" ] }