Patch Detail
Show a patch.
GET /api/1.1/patches/3509/?format=api
{ "id": 3509, "url": "https://patchwork.libcamera.org/api/1.1/patches/3509/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3509/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20200424011656.2889720-2-niklas.soderlund@ragnatech.se>", "date": "2020-04-24T01:16:54", "name": "[libcamera-devel,1/3] cam: Add helper class to parse stream configuration", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "a78d332cbc47e46711651f990ece13163fdea64e", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3509/mbox/", "series": [ { "id": 820, "url": "https://patchwork.libcamera.org/api/1.1/series/820/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=820", "date": "2020-04-24T01:16:53", "name": "{cam, qcam}: Unify stream option parsing", "version": 1, "mbox": "https://patchwork.libcamera.org/series/820/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3509/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3509/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 34269603F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Apr 2020 03:17:06 +0200 (CEST)", "from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de\n\t[79.202.35.146]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 48f292dc-85c9-11ea-aeed-005056917f90;\n\tFri, 24 Apr 2020 03:16:54 +0200 (CEST)" ], "X-Halon-ID": "48f292dc-85c9-11ea-aeed-005056917f90", "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": "Fri, 24 Apr 2020 03:16:54 +0200", "Message-Id": "<20200424011656.2889720-2-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.26.0", "In-Reply-To": "<20200424011656.2889720-1-niklas.soderlund@ragnatech.se>", "References": "<20200424011656.2889720-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 1/3] cam: Add helper class to parse stream\n\tconfiguration", "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": "Fri, 24 Apr 2020 01:17:06 -0000" }, "content": "Create a new helper class StreamOptionsParser to parse command line\noptions describing stream configurations. The goal is to share this new\nclass between cam and qcam.\n\nThe parser inherits from OptionsParser which it aims to replace and\nallows for a common command line argument syntax to be inserted anywhere\nin the argument list with addStreamOptions(), still allowing for any\nshort and long option name.\n\nThe Options data carrier returned inherits from OptionsParser::Options\nand extends it with new functions; roles() and applyCameraParameters().\nThe new functions makes it easy to generate and override the default\nvalues of a camera configuration.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/cam/meson.build | 1 +\n src/cam/stream_options.cpp | 116 +++++++++++++++++++++++++++++++++++++\n src/cam/stream_options.h | 63 ++++++++++++++++++++\n 3 files changed, 180 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..22bf61f2c13d10c1\n--- /dev/null\n+++ b/src/cam/stream_options.cpp\n@@ -0,0 +1,116 @@\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 stremas\n+ */\n+#include \"stream_options.h\"\n+\n+#include <iostream>\n+\n+using namespace libcamera;\n+\n+int StreamOptionsParser::Options::applyCameraParameters(CameraConfiguration *config) const\n+{\n+\tif (!config) {\n+\t\tstd::cerr << \"No configuration provided\" << std::endl;\n+\t\treturn -EINVAL;\n+\t}\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 ¶m : streamParameters_) {\n+\t\tStreamConfiguration &cfg = config->at(i++);\n+\n+\t\tif (param.size.width && param.size.height)\n+\t\t\tcfg.size = param.size;\n+\n+\t\tif (param.pixelFormat.isValid())\n+\t\t\tcfg.pixelFormat = param.pixelFormat;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int StreamOptionsParser::addStreamOptions(int opt, const char *name)\n+{\n+\tif (opt_)\n+\t\treturn -EINVAL;\n+\n+\topt_ = opt;\n+\n+\tstreamKeyValue_.addOption(\"role\", OptionString,\n+\t\t\t\t \"Role for the stream (viewfinder, video, still, stillraw)\",\n+\t\t\t\t ArgumentRequired);\n+\tstreamKeyValue_.addOption(\"width\", OptionInteger, \"Width in pixels\",\n+\t\t\t\t ArgumentRequired);\n+\tstreamKeyValue_.addOption(\"height\", OptionInteger, \"Height in pixels\",\n+\t\t\t\t ArgumentRequired);\n+\tstreamKeyValue_.addOption(\"pixelformat\", OptionInteger, \"Pixel format\",\n+\t\t\t\t ArgumentRequired);\n+\n+\treturn addOption(opt_, &streamKeyValue_,\n+\t\t\t \"Set configuration of a camera stream\", name, true);\n+}\n+\n+StreamOptionsParser::Options StreamOptionsParser::parse(int argc, char *argv[])\n+{\n+\tOptionsParser::Options options = OptionsParser::parse(argc, argv);\n+\n+\tif (!opt_ || !options.isSet(opt_))\n+\t\treturn Options(options, {StreamRole::Viewfinder});\n+\n+\tStreamRoles roles;\n+\tstd::vector<Options::Parameters> parameters;\n+\n+\tfor (auto const &value : options[opt_].toArray()) {\n+\t\tKeyValueParser::Options opts = value.toKeyValues();\n+\t\tOptions::Parameters param;\n+\n+\t\tif (opts.isSet(\"width\") && opts.isSet(\"height\")) {\n+\t\t\tparam.size.width = opts[\"width\"];\n+\t\t\tparam.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\tparam.pixelFormat = PixelFormat(opts[\"pixelformat\"]);\n+\n+\t\troles.push_back(parseRole(opts));\n+\t\tparameters.push_back(param);\n+\t}\n+\n+\treturn Options(options, roles, parameters);\n+}\n+\n+StreamRole StreamOptionsParser::parseRole(KeyValueParser::Options opts)\n+{\n+\tif (!opts.isSet(\"role\"))\n+\t\treturn StreamRole::Viewfinder;\n+\n+\tstd::string role = opts[\"role\"].toString();\n+\n+\tif (role == \"viewfinder\")\n+\t\treturn StreamRole::Viewfinder;\n+\tif (role == \"video\")\n+\t\treturn StreamRole::VideoRecording;\n+\tif (role == \"still\")\n+\t\treturn StreamRole::StillCapture;\n+\tif (role == \"stillraw\")\n+\t\treturn StreamRole::StillCaptureRaw;\n+\n+\t/* No stream role found, warn and default to viewfinder. */\n+\tstd::cerr << \"Unknown stream role \" << role\n+\t\t << \", adjusted to viewfinder\" << std::endl;\n+\n+\treturn StreamRole::Viewfinder;\n+}\ndiff --git a/src/cam/stream_options.h b/src/cam/stream_options.h\nnew file mode 100644\nindex 0000000000000000..a0f8a456b44fe275\n--- /dev/null\n+++ b/src/cam/stream_options.h\n@@ -0,0 +1,63 @@\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 stremas\n+ */\n+#ifndef __CAM_STREAM_OPTIONS_H__\n+#define __CAM_STREAM_OPTIONS_H__\n+\n+#include <libcamera/camera.h>\n+#include <libcamera/stream.h>\n+\n+#include \"options.h\"\n+\n+using namespace libcamera;\n+\n+class StreamOptionsParser : public OptionsParser\n+{\n+public:\n+\tclass Options : public OptionsParser::Options\n+\t{\n+\tpublic:\n+\t\tstruct Parameters {\n+\t\t\tPixelFormat pixelFormat;\n+\t\t\tSize size;\n+\t\t};\n+\n+\t\tOptions()\n+\t\t\t: OptionsParser::Options()\n+\t\t{\n+\t\t}\n+\n+\t\tOptions(OptionsParser::Options options, StreamRoles roles = {},\n+\t\t\tstd::vector<Parameters> parameters = {})\n+\t\t\t: OptionsParser::Options(options), roles_(roles),\n+\t\t\t streamParameters_(parameters)\n+\t\t{\n+\t\t}\n+\n+\t\tconst StreamRoles &roles() const { return roles_; }\n+\t\tint applyCameraParameters(CameraConfiguration *config) const;\n+\n+\tprivate:\n+\t\tStreamRoles roles_;\n+\t\tstd::vector<Parameters> streamParameters_;\n+\t};\n+\n+\tStreamOptionsParser()\n+\t\t: opt_(0)\n+\t{\n+\t}\n+\n+\tint addStreamOptions(int opt, const char *name = nullptr);\n+\tOptions parse(int argc, char *argv[]);\n+\n+private:\n+\tStreamRole parseRole(KeyValueParser::Options opts);\n+\n+\tint opt_;\n+\tKeyValueParser streamKeyValue_;\n+};\n+\n+#endif /* __CAM_STREAM_OPTIONS_H__ */\n", "prefixes": [ "libcamera-devel", "1/3" ] }