Patch Detail
Show a patch.
GET /api/patches/17383/?format=api
{ "id": 17383, "url": "https://patchwork.libcamera.org/api/patches/17383/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17383/", "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": "<20220920173817.37821-1-jacopo@jmondi.org>", "date": "2022-09-20T17:38:17", "name": "[libcamera-devel] cam: capture_script: Support parsing array controls", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "13b3f864d1ea3143caadf41eb147a01ae5a09771", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/17383/mbox/", "series": [ { "id": 3494, "url": "https://patchwork.libcamera.org/api/series/3494/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3494", "date": "2022-09-20T17:38:17", "name": "[libcamera-devel] cam: capture_script: Support parsing array controls", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3494/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17383/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17383/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 68169C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 20 Sep 2022 17:38:28 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A68C9621BC;\n\tTue, 20 Sep 2022 19:38:27 +0200 (CEST)", "from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9219E6218B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 20 Sep 2022 19:38:26 +0200 (CEST)", "(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 0C29E200003;\n\tTue, 20 Sep 2022 17:38:25 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1663695507;\n\tbh=Hw47yEgUjbbpETUGy4owHlmixbEq6CPMsr0ToF2G+b0=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=dlErYoomHu6X8Otz6KmnYEhB0Gm0kDJM22twqVYg1/XSRtkKY++fgRA6phAEVYKPm\n\tEkel+0Ed+6+shIaSNxyNlpJ4PyP2Z+nt1SY4Fp30sD7v/4rKHIYA8YqrZuHFoMWILi\n\tY2V8qYx9zeIEoNcfYJ3MyMUvJkB8+4aSl3UgAIkaGmTpuaw7xLmKA9SjsR4VmSqmQt\n\tFaCAdBwQjZhSQfMlprIVNvW6vUAXLW0z96IEWA7sdsnMRWP5lWohzKGsHzPFJnhXg9\n\tA09BaceZzVLLwnPBDc9qk2/aTmxBO2LEiQrxP45+40suSRXTJLTwH2rQjmMoCCN2oa\n\ts1KquiHNltVCg==", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 20 Sep 2022 19:38:17 +0200", "Message-Id": "<20220920173817.37821-1-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.30.2", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH] cam: capture_script: Support parsing\n\tarray controls", "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>", "From": "Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Jacopo Mondi <jacopo@jmondi.org>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Add support for parsing array controls to the cam capture script.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/cam/capture_script.cpp | 156 +++++++++++++++++++++++++++++++++----\n src/cam/capture_script.h | 5 ++\n 2 files changed, 144 insertions(+), 17 deletions(-)", "diff": "diff --git a/src/cam/capture_script.cpp b/src/cam/capture_script.cpp\nindex 5a27361ce4d9..2feb0a535835 100644\n--- a/src/cam/capture_script.cpp\n+++ b/src/cam/capture_script.cpp\n@@ -454,24 +454,9 @@ void CaptureScript::unpackFailure(const ControlId *id, const std::string &repr)\n \t\t << typeName << \" control \" << id->name() << std::endl;\n }\n \n-ControlValue CaptureScript::unpackControl(const ControlId *id)\n+ControlValue CaptureScript::parseScalarControl(const ControlId *id,\n+\t\t\t\t\t const std::string repr)\n {\n-\t/* Parse complex types. */\n-\tswitch (id->type()) {\n-\tcase ControlTypeRectangle:\n-\t\treturn parseRectangles();\n-\tcase ControlTypeSize:\n-\t\t/* \\todo Parse Sizes. */\n-\t\treturn {};\n-\tdefault:\n-\t\tbreak;\n-\t}\n-\n-\t/* Parse basic types represented by a single scalar. */\n-\tconst std::string repr = parseScalar();\n-\tif (repr.empty())\n-\t\treturn {};\n-\n \tControlValue value{};\n \n \tswitch (id->type()) {\n@@ -524,6 +509,143 @@ ControlValue CaptureScript::unpackControl(const ControlId *id)\n \treturn value;\n }\n \n+ControlValue CaptureScript::parseArrayControl(const ControlId *id,\n+\t\t\t\t\t const std::vector<std::string> &repr)\n+{\n+\tControlValue value{};\n+\n+\tswitch (id->type()) {\n+\tcase ControlTypeNone:\n+\t\tbreak;\n+\tcase ControlTypeBool: {\n+\t\t/*\n+\t\t * This is unpleasant, but we cannot use an std::vector<> as its\n+\t\t * boolean type overload does not allow to access the raw data.\n+\t\t * As we need a contiguous memory region to wrap in a span,\n+\t\t * use an array instead but be strict about not overflowing it\n+\t\t * by limiting the number of controls we can store.\n+\t\t *\n+\t\t * Be loud but do not fail, as the issue would present at\n+\t\t * runtime only.\n+\t\t */\n+\t\tstatic constexpr unsigned int kMaxNumBooleanControls = 1024;\n+\t\tstd::array<bool, kMaxNumBooleanControls> values;\n+\t\tunsigned int idx = 0;\n+\n+\t\tfor (const std::string &s : repr) {\n+\t\t\tbool val;\n+\n+\t\t\tif (s == \"true\") {\n+\t\t\t\tval = true;\n+\t\t\t} else if (s == \"false\") {\n+\t\t\t\tval = false;\n+\t\t\t} else {\n+\t\t\t\tunpackFailure(id, s);\n+\t\t\t\treturn value;\n+\t\t\t}\n+\n+\t\t\tif (idx == kMaxNumBooleanControls) {\n+\t\t\t\tstd::cerr << \"Cannot parse more than \"\n+\t\t\t\t\t << kMaxNumBooleanControls\n+\t\t\t\t\t << \" boolean controls\" << std::endl;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tvalues[idx++] = val;\n+\t\t}\n+\n+\t\tvalue = Span<bool>(values.data(), values.size());\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeByte: {\n+\t\tstd::vector<uint8_t> values;\n+\t\tfor (const std::string &s : repr) {\n+\t\t\tuint8_t val = strtoll(s.c_str(), NULL, 10);\n+\t\t\tvalues.push_back(val);\n+\t\t}\n+\n+\t\tvalue = Span<const uint8_t>(values.data(), values.size());\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeInteger32: {\n+\t\tstd::vector<int32_t> values;\n+\t\tfor (const std::string &s : repr) {\n+\t\t\tint32_t val = strtoll(s.c_str(), NULL, 10);\n+\t\t\tvalues.push_back(val);\n+\t\t}\n+\n+\t\tvalue = Span<const int32_t>(values.data(), values.size());\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeInteger64: {\n+\t\tstd::vector<int64_t> values;\n+\t\tfor (const std::string &s : repr) {\n+\t\t\tint64_t val = strtoll(s.c_str(), NULL, 10);\n+\t\t\tvalues.push_back(val);\n+\t\t}\n+\n+\t\tvalue = Span<const int64_t>(values.data(), values.size());\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeFloat: {\n+\t\tstd::vector<float> values;\n+\t\tfor (const std::string &s : repr)\n+\t\t\tvalues.push_back(strtof(s.c_str(), NULL));\n+\n+\t\tvalue = Span<const float>(values.data(), values.size());\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeString: {\n+\t\tvalue = Span<const std::string>(repr.data(), repr.size());\n+\t\tbreak;\n+\t}\n+\tdefault:\n+\t\tstd::cerr << \"Unsupported control type\" << std::endl;\n+\t\tbreak;\n+\t}\n+\n+\treturn value;\n+}\n+\n+ControlValue CaptureScript::unpackControl(const ControlId *id)\n+{\n+\t/* Parse complex types. */\n+\tswitch (id->type()) {\n+\tcase ControlTypeRectangle:\n+\t\treturn parseRectangles();\n+\tcase ControlTypeSize:\n+\t\t/* \\todo Parse Sizes. */\n+\t\treturn {};\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\t/* Check if the control has a single scalar value or is an array. */\n+\tEventPtr event = nextEvent();\n+\tif (!event)\n+\t\treturn {};\n+\n+\tswitch (event->type) {\n+\tcase YAML_SCALAR_EVENT: {\n+\t\tconst std::string repr = eventScalarValue(event);\n+\t\tif (repr.empty())\n+\t\t\treturn {};\n+\n+\t\treturn parseScalarControl(id, repr);\n+\t}\n+\tcase YAML_SEQUENCE_START_EVENT: {\n+\t\tstd::vector<std::string> array = parseSingleArray();\n+\t\tif (array.empty())\n+\t\t\treturn {};\n+\n+\t\treturn parseArrayControl(id, array);\n+\t}\n+\tdefault:\n+\t\tstd::cerr << \"Unexpected event type: \" << event->type << std::endl;\n+\t\treturn {};\n+\t}\n+}\n+\n libcamera::Rectangle CaptureScript::unpackRectangle(const std::vector<std::string> &strVec)\n {\n \tint x = strtol(strVec[0].c_str(), NULL, 10);\ndiff --git a/src/cam/capture_script.h b/src/cam/capture_script.h\nindex 7a0ddebb00b5..40042c0330f0 100644\n--- a/src/cam/capture_script.h\n+++ b/src/cam/capture_script.h\n@@ -56,6 +56,11 @@ private:\n \tint parseFrame(EventPtr event);\n \tint parseControl(EventPtr event, libcamera::ControlList &controls);\n \n+\tlibcamera::ControlValue parseScalarControl(const libcamera::ControlId *id,\n+\t\t\t\t\t\t const std::string repr);\n+\tlibcamera::ControlValue parseArrayControl(const libcamera::ControlId *id,\n+\t\t\t\t\t\t const std::vector<std::string> &repr);\n+\n \tstd::string parseScalar();\n \tlibcamera::ControlValue parseRectangles();\n \tstd::vector<std::vector<std::string>> parseArrays();\n", "prefixes": [ "libcamera-devel" ] }