Show a patch.

GET /api/1.1/patches/3645/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 3645,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/3645/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/3645/",
    "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": "<20200501023432.90032-4-niklas.soderlund@ragnatech.se>",
    "date": "2020-05-01T02:34:29",
    "name": "[libcamera-devel,v3,3/6] cam: Add helper class to parse stream configuration",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "0e85d97f4123f4119c6917df4dfbd9cb8985b5f5",
    "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/3645/mbox/",
    "series": [
        {
            "id": 864,
            "url": "https://patchwork.libcamera.org/api/1.1/series/864/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=864",
            "date": "2020-05-01T02:34:27",
            "name": "{cam, qcam}: Unify stream option parsing",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/864/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/3645/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/3645/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 277FA6148D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  1 May 2020 04:34:44 +0200 (CEST)",
            "from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de\n\t[79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 4f9a3cbd-8b54-11ea-89d0-0050569116f7;\n\tFri, 01 May 2020 04:34:41 +0200 (CEST)"
        ],
        "X-Halon-ID": "4f9a3cbd-8b54-11ea-89d0-0050569116f7",
        "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,  1 May 2020 04:34:29 +0200",
        "Message-Id": "<20200501023432.90032-4-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.26.2",
        "In-Reply-To": "<20200501023432.90032-1-niklas.soderlund@ragnatech.se>",
        "References": "<20200501023432.90032-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 3/6] 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": "Fri, 01 May 2020 02:34:44 -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>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n* Changes since v2\n- Return bool from parseRole()\n- s/TODO/\\\\todo/\n- s/!streamParameters.size()/streamParameters.empty()/\n- Rework logic in parseRole()\n---\n src/cam/meson.build        |   1 +\n src/cam/stream_options.cpp | 129 +++++++++++++++++++++++++++++++++++++\n src/cam/stream_options.h   |  32 +++++++++\n 3 files changed, 162 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..bd12c8fdb48e7135\n--- /dev/null\n+++ b/src/cam/stream_options.cpp\n@@ -0,0 +1,129 @@\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.empty())\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 pixelformat with modifier. */\n+\t\tif (opts.isSet(\"pixelformat\"))\n+\t\t\tcfg.pixelFormat = PixelFormat(opts[\"pixelformat\"]);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+bool StreamKeyValueParser::parseRole(StreamRole *role,\n+\t\t\t\t     const KeyValueParser::Options &options)\n+{\n+\tif (!options.isSet(\"role\"))\n+\t\treturn false;\n+\n+\tstd::string name = options[\"role\"].toString();\n+\n+\tif (name == \"viewfinder\") {\n+\t\t*role = StreamRole::Viewfinder;\n+\t\treturn true;\n+\t} else if (name == \"video\") {\n+\t\t*role = StreamRole::VideoRecording;\n+\t\treturn true;\n+\t} else if (name == \"still\") {\n+\t\t*role = StreamRole::StillCapture;\n+\t\treturn true;\n+\t} else if (name == \"stillraw\") {\n+\t\t*role = StreamRole::StillCaptureRaw;\n+\t\treturn true;\n+\t}\n+\n+\treturn false;\n+}\ndiff --git a/src/cam/stream_options.h b/src/cam/stream_options.h\nnew file mode 100644\nindex 0000000000000000..577391f05570e85c\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 bool parseRole(StreamRole *role,\n+\t\t\t      const KeyValueParser::Options &options);\n+};\n+\n+#endif /* __CAM_STREAM_OPTIONS_H__ */\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "3/6"
    ]
}