Show a patch.

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

{
    "id": 15975,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/15975/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15975/",
    "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": "<20220518171921.244168-2-jacopo@jmondi.org>",
    "date": "2022-05-18T17:19:17",
    "name": "[libcamera-devel,1/5] cam: Add a parser for capture scripts",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "bcf51a77e57b14d505c09c8c578a415a70f7cfdc",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/15975/mbox/",
    "series": [
        {
            "id": 3125,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3125/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3125",
            "date": "2022-05-18T17:19:16",
            "name": "cam: Add support for capture scripts",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3125/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15975/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15975/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 CC1C9C326C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 May 2022 17:19:33 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EB43D6565C;\n\tWed, 18 May 2022 19:19:30 +0200 (CEST)",
            "from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5D00465656\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 May 2022 19:19:29 +0200 (CEST)",
            "(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 891FD240012;\n\tWed, 18 May 2022 17:19:28 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1652894370;\n\tbh=FYmJbgOwMo3b8+Y4Ss0p3R4ccq6wZMoksZrM8tx0Tl8=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=3L5s6Ffiav5n3H08HGcy9n4HTyxbvcesioF5LAQ7WwJywP0FUfP4a+qFxux9hckyp\n\t3WZ8ks4FKfaIWhvPJHibmssnm4JepY0iOBL/DRN+AvYBjN6vAvOFIcV72h8jKDYFiX\n\teROiw2kctZpBU45N1TB0vH6rh7m/pBk2N0KmRjx0QzGdc66hIAeHV4Z93akFgFEvc7\n\tOXOUgm555c1Ht/xYifa5GWJSpQtWdPysf+8J+222an4mFx/jTbrj5Lh3y01eO/lHFd\n\tYFWRKl6a/WpY1Kv7Rdqhs6Kg3bvZVVxSJ/qlgk7C9XcoZj94jo/GHhJ1t0mDoT5ThU\n\tDDyjDYEBWUD2A==",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 18 May 2022 19:19:17 +0200",
        "Message-Id": "<20220518171921.244168-2-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.35.1",
        "In-Reply-To": "<20220518171921.244168-1-jacopo@jmondi.org>",
        "References": "<20220518171921.244168-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 1/5] cam: Add a parser for capture scripts",
        "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 a parser class to the cam test application to control the capture\noperations through a yaml script.\n\nThe capture script currently allow to specify a list of controls and\ntheir associated values to be applied per-frame.\n\nAlso add a trivial capture script example to showcase the intended\nscript structure.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/cam/capture-script.yaml |  44 ++++\n src/cam/capture_script.cpp  | 447 ++++++++++++++++++++++++++++++++++++\n src/cam/capture_script.h    |  57 +++++\n src/cam/meson.build         |   2 +\n 4 files changed, 550 insertions(+)\n create mode 100644 src/cam/capture-script.yaml\n create mode 100644 src/cam/capture_script.cpp\n create mode 100644 src/cam/capture_script.h",
    "diff": "diff --git a/src/cam/capture-script.yaml b/src/cam/capture-script.yaml\nnew file mode 100644\nindex 000000000000..48eac5fedd46\n--- /dev/null\n+++ b/src/cam/capture-script.yaml\n@@ -0,0 +1,44 @@\n+# Capture scrip example\n+#\n+# A capture script allows to associate a list of controls and their values\n+# to frame numbers.\n+\n+# \\todo Formally define the capture script structure with a schema\n+\n+# Notes:\n+# - Controls have to be specified by name, as defined in the\n+#   libcamera::controls:: enumeration\n+# - Controls not supported by the camera currently operated are ignored\n+# - Frame numbers shall be monotonically incrementing, gaps are allowed\n+\n+# Example:\n+frames:\n+  - 1:\n+      Brightness: 0.0\n+\n+  - 40:\n+      Brightness: 0.2\n+\n+  - 80:\n+      Brightness: 0.4\n+\n+  - 120:\n+      Brightness: 0.8\n+\n+  - 160:\n+      Brightness: 0.4\n+\n+  - 200:\n+      Brightness: 0.2\n+\n+  - 240:\n+      Brightness: 0.0\n+\n+  - 280:\n+      Brightness: -0.2\n+\n+  - 300:\n+      Brightness: -0.4\n+\n+  - 340:\n+      Brightness: -0.8\ndiff --git a/src/cam/capture_script.cpp b/src/cam/capture_script.cpp\nnew file mode 100644\nindex 000000000000..d153dac7b0de\n--- /dev/null\n+++ b/src/cam/capture_script.cpp\n@@ -0,0 +1,447 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * capture_script.cpp - Capture session configuration script\n+ */\n+\n+#include \"capture_script.h\"\n+\n+#include <iostream>\n+#include <stdio.h>\n+#include <stdlib.h>\n+\n+using namespace libcamera;\n+\n+namespace {\n+\n+/*\n+ * Schema error debug function\n+ * From: https://www.wpsoftware.net/andrew/pages/libyaml.html\n+ */\n+void printToken(yaml_token_t &token)\n+{\n+\tstd::string type;\n+\n+\tswitch (token.type) {\n+\tcase YAML_KEY_TOKEN:\n+\t\tprintf(\"(Key token)   \");\n+\t\tbreak;\n+\tcase YAML_VALUE_TOKEN:\n+\t\tprintf(\"(Value token) \");\n+\t\tbreak;\n+\tcase YAML_BLOCK_SEQUENCE_START_TOKEN:\n+\t\tputs(\"<b>Start Block (Sequence)</b>\");\n+\t\tbreak;\n+\tcase YAML_BLOCK_ENTRY_TOKEN:\n+\t\tputs(\"<b>Start Block (Entry)</b>\");\n+\t\tbreak;\n+\tcase YAML_BLOCK_END_TOKEN:\n+\t\tputs(\"<b>End block</b>\");\n+\t\tbreak;\n+\tcase YAML_BLOCK_MAPPING_START_TOKEN:\n+\t\tputs(\"[Block mapping]\");\n+\t\tbreak;\n+\tcase YAML_SCALAR_TOKEN:\n+\t\tprintf(\"scalar %s \\n\", token.data.scalar.value);\n+\t\tbreak;\n+\tdefault:\n+\t\tprintf(\"Token type %u \\n\", token.type);\n+\t\tbreak;\n+\t}\n+\tstd::cerr << std::endl;\n+}\n+\n+} /* namespace */\n+\n+CaptureScript::CaptureScript(std::shared_ptr<Camera> camera, std::string fileName)\n+\t: camera_(camera), scriptPath_(fileName), valid_(false)\n+{\n+\tif (!std::filesystem::is_regular_file(scriptPath_)) {\n+\t\tstd::cerr << \"Capture script file not found: \"\n+\t\t\t  << scriptPath_ << std::endl;\n+\t\treturn;\n+\t}\n+\n+\tFILE *fh = fopen(scriptPath_.c_str(), \"r\");\n+\tif (!fh) {\n+\t\tint ret = -errno;\n+\t\tstd::cerr << \"Failed to open capture script \" << scriptPath_\n+\t\t\t  << \": \" << strerror(-ret) << std::endl;\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * Map the camera's controls to their name so that they can be\n+\t * easily identified when parsing the script file.\n+\t */\n+\tfor (const auto &[control, info] : camera_->controls())\n+\t\tcontrols_[control->name()] = control;\n+\n+\tint ret = parseScript(fh);\n+\tfclose(fh);\n+\tif (ret)\n+\t\treturn;\n+\n+\tvalid_ = true;\n+}\n+\n+/* Retrieve the control list associated with a frame number. */\n+const ControlList &CaptureScript::frameControls(unsigned int frame)\n+{\n+\tstatic ControlList controls{};\n+\n+\tauto it = frameControls_.find(frame);\n+\tif (it == frameControls_.end())\n+\t\treturn controls;\n+\n+\treturn it->second;\n+}\n+\n+int CaptureScript::parseScript(FILE *script)\n+{\n+\tint ret = yaml_parser_initialize(&parser_);\n+\tif (!ret) {\n+\t\tstd::cerr << \"Failed to initialize yaml parser\" << std::endl;\n+\t\treturn ret;\n+\t}\n+\n+\tyaml_parser_set_input_file(&parser_, script);\n+\n+\tyaml_token_t token;\n+\tyaml_parser_scan(&parser_, &token);\n+\tif (token.type != YAML_STREAM_START_TOKEN) {\n+\t\tstd::cerr << \"Configuration file not valid\" << std::endl;\n+\t\tprintToken(token);\n+\t\tyaml_token_delete(&token);\n+\t\tyaml_parser_delete(&parser_);\n+\t\treturn -EINVAL;\n+\t}\n+\tyaml_token_delete(&token);\n+\n+\tyaml_parser_scan(&parser_, &token);\n+\tif (token.type != YAML_BLOCK_MAPPING_START_TOKEN) {\n+\t\tstd::cerr << \"Configuration file not valid\" << std::endl;\n+\t\tprintToken(token);\n+\t\tyaml_token_delete(&token);\n+\t\tyaml_parser_delete(&parser_);\n+\t\treturn -EINVAL;\n+\t}\n+\tyaml_token_delete(&token);\n+\n+\t/* Capture script shall start with the \"frames\" key. */\n+\tstd::string section = parseKey();\n+\tif (section != \"frames\") {\n+\t\tstd::cerr << \"Unsupported section: \" << section << std::endl;\n+\t\tyaml_token_delete(&token);\n+\t\tyaml_parser_delete(&parser_);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tyaml_parser_scan(&parser_, &token);\n+\tif (token.type != YAML_VALUE_TOKEN) {\n+\t\tstd::cerr << \"Configuration file not valid\" << std::endl;\n+\t\tprintToken(token);\n+\t\tyaml_token_delete(&token);\n+\t\tyaml_parser_delete(&parser_);\n+\t\treturn -EINVAL;\n+\t}\n+\tyaml_token_delete(&token);\n+\n+\tparseFrames();\n+\n+\t/* Consume the tokens on the stack until we don't hit an STREAM_END */\n+\tdo {\n+\t\tret = 0;\n+\n+\t\tyaml_parser_scan(&parser_, &token);\n+\t\tswitch (token.type) {\n+\t\tcase YAML_STREAM_END_TOKEN:\n+\t\t\tret = -ENOENT;\n+\t\t\t[[fallthrough]];\n+\t\tdefault:\n+\t\t\tyaml_token_delete(&token);\n+\t\t\tbreak;\n+\t\t}\n+\t} while (ret >= 0);\n+\n+\treturn 0;\n+}\n+\n+int CaptureScript::parseFrames()\n+{\n+\tint ret;\n+\n+\tyaml_token_t token;\n+\tyaml_parser_scan(&parser_, &token);\n+\tif (token.type != YAML_BLOCK_SEQUENCE_START_TOKEN) {\n+\t\tstd::cerr << \"Configuration file not valid\" << std::endl;\n+\t\tprintToken(token);\n+\t\tyaml_token_delete(&token);\n+\t\tyaml_parser_delete(&parser_);\n+\t\treturn -EINVAL;\n+\t}\n+\tyaml_token_delete(&token);\n+\n+\tdo {\n+\t\tyaml_parser_scan(&parser_, &token);\n+\t\tswitch (token.type) {\n+\t\tcase YAML_BLOCK_ENTRY_TOKEN:\n+\t\t\tret = parseFrame();\n+\t\t\tyaml_token_delete(&token);\n+\t\t\tbreak;\n+\t\tcase YAML_BLOCK_END_TOKEN:\n+\t\t\tret = -ENODEV;\n+\t\t\tyaml_token_delete(&token);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tret = -EINVAL;\n+\t\t\tstd::cerr << \"Configuration file not valid\" << std::endl;\n+\t\t\tprintToken(token);\n+\t\t\tyaml_token_delete(&token);\n+\t\t\tyaml_parser_delete(&parser_);\n+\t\t}\n+\t} while (ret == 0);\n+\n+\treturn ret != -ENODEV ? ret : 0;\n+}\n+\n+int CaptureScript::parseFrame()\n+{\n+\tyaml_token_t token;\n+\n+\tyaml_parser_scan(&parser_, &token);\n+\tif (token.type != YAML_BLOCK_MAPPING_START_TOKEN) {\n+\t\tstd::cerr << \"Configuration file not valid\" << std::endl;\n+\t\tprintToken(token);\n+\t\tyaml_token_delete(&token);\n+\t\tyaml_parser_delete(&parser_);\n+\t\treturn -EINVAL;\n+\t}\n+\tyaml_token_delete(&token);\n+\n+\tstd::string key = parseKey();\n+\tunsigned int frameId = atoi(key.c_str());\n+\n+\tframeControls_[frameId] = parseControls();\n+\n+\treturn 0;\n+}\n+\n+ControlList CaptureScript::parseControls()\n+{\n+\tControlList controls{};\n+\tyaml_token_t token;\n+\n+\tyaml_parser_scan(&parser_, &token);\n+\tif (token.type != YAML_VALUE_TOKEN) {\n+\t\tstd::cerr << \"Configuration file not valid\" << std::endl;\n+\t\tprintToken(token);\n+\t\tyaml_token_delete(&token);\n+\t\tyaml_parser_delete(&parser_);\n+\t\treturn controls;\n+\t}\n+\tyaml_token_delete(&token);\n+\n+\t/*\n+\t * Whenever we get an unbalanced block_end token, we're done\n+\t * parsing the controls.\n+\t */\n+\tint blockCounter = 0;\n+\n+\tdo {\n+\t\tyaml_parser_scan(&parser_, &token);\n+\n+\t\tswitch (token.type) {\n+\t\tcase YAML_BLOCK_MAPPING_START_TOKEN:\n+\t\t\tblockCounter++;\n+\t\t\tyaml_token_delete(&token);\n+\t\t\tbreak;\n+\t\tcase YAML_BLOCK_END_TOKEN:\n+\t\t\tblockCounter--;\n+\t\t\tyaml_token_delete(&token);\n+\t\t\tbreak;\n+\t\tcase YAML_KEY_TOKEN: {\n+\t\t\t/* We expect a value after a key. */\n+\t\t\tstd::string controlName = parseKey(token);\n+\t\t\tstd::string controlRepr = parseValue();\n+\n+\t\t\t/*\n+\t\t\t * If the camera does not support the control just\n+\t\t\t * ignore it.\n+\t\t\t */\n+\t\t\tauto controlIt = controls_.find(controlName);\n+\t\t\tif (controlIt == controls_.end()) {\n+\t\t\t\tstd::cerr << \"Unsupported control: \"\n+\t\t\t\t\t  << controlName << std::endl;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tconst ControlId *controlId = controlIt->second;\n+\t\t\tControlValue val = unpackControl(controlId, controlRepr);\n+\t\t\tcontrols.set(controlId->id(), val);\n+\t\t\tbreak;\n+\t\t}\n+\t\tdefault:\n+\t\t\t/* Error condition */\n+\t\t\tyaml_token_delete(&token);\n+\t\t\tbreak;\n+\t\t}\n+\t} while (blockCounter >= 0);\n+\n+\treturn controls;\n+}\n+\n+std::string CaptureScript::parseKey(yaml_token_t &token)\n+{\n+\t/* Make sure the token type is a key and get its value. */\n+\tif (token.type != YAML_KEY_TOKEN) {\n+\t\tstd::cerr << \"Configuration file not valid\" << std::endl;\n+\t\tprintToken(token);\n+\t\tyaml_token_delete(&token);\n+\t\tyaml_parser_delete(&parser_);\n+\t\treturn \"\";\n+\t}\n+\tyaml_token_delete(&token);\n+\n+\tyaml_parser_scan(&parser_, &token);\n+\tif (token.type != YAML_SCALAR_TOKEN) {\n+\t\tyaml_token_delete(&token);\n+\t\treturn \"\";\n+\t}\n+\n+\tstd::string value(reinterpret_cast<char *>(token.data.scalar.value),\n+\t\t\t  token.data.scalar.length);\n+\tyaml_token_delete(&token);\n+\n+\treturn value;\n+}\n+\n+std::string CaptureScript::parseKey()\n+{\n+\tyaml_token_t token;\n+\n+\tyaml_parser_scan(&parser_, &token);\n+\treturn parseKey(token);\n+}\n+\n+std::string CaptureScript::parseValue()\n+{\n+\tyaml_token_t token;\n+\n+\t/* Make sure the token type is a value and get its content. */\n+\tyaml_parser_scan(&parser_, &token);\n+\tif (token.type != YAML_VALUE_TOKEN) {\n+\t\tstd::cerr << \"Configuration file not valid\" << std::endl;\n+\t\tprintToken(token);\n+\t\tyaml_token_delete(&token);\n+\t\tyaml_parser_delete(&parser_);\n+\t\treturn \"\";\n+\t}\n+\tyaml_token_delete(&token);\n+\n+\tyaml_parser_scan(&parser_, &token);\n+\tif (token.type != YAML_SCALAR_TOKEN) {\n+\t\tyaml_token_delete(&token);\n+\t\treturn \"\";\n+\t}\n+\n+\tstd::string value(reinterpret_cast<char *>(token.data.scalar.value),\n+\t\t\t  token.data.scalar.length);\n+\tyaml_token_delete(&token);\n+\n+\treturn value;\n+}\n+\n+void CaptureScript::unpackFailure(const ControlId *id, std::string repr)\n+{\n+\tstd::string ctrlType;\n+\n+\tswitch (id->type()) {\n+\tcase ControlTypeNone:\n+\t\tctrlType = \"none\";\n+\t\tbreak;\n+\tcase ControlTypeBool:\n+\t\tctrlType = \"bool\";\n+\t\tbreak;\n+\tcase ControlTypeByte:\n+\t\tctrlType = \"byte\";\n+\t\tbreak;\n+\tcase ControlTypeInteger32:\n+\t\tctrlType = \"int32\";\n+\t\tbreak;\n+\tcase ControlTypeInteger64:\n+\t\tctrlType = \"int64\";\n+\t\tbreak;\n+\tcase ControlTypeFloat:\n+\t\tctrlType = \"float\";\n+\t\tbreak;\n+\tcase ControlTypeString:\n+\t\tctrlType = \"string\";\n+\t\tbreak;\n+\tcase ControlTypeRectangle:\n+\t\tctrlType = \"Rectangle\";\n+\t\tbreak;\n+\tcase ControlTypeSize:\n+\t\tctrlType = \"Size\";\n+\t\tbreak;\n+\t}\n+\n+\tstd::cerr << \"Unsupported control \\'\" << repr <<\"\\'\" << \" for \"\n+\t\t  << ctrlType << \" control \" << id->name() << std::endl;\n+}\n+\n+ControlValue CaptureScript::unpackControl(const ControlId *id, std::string repr)\n+{\n+\tControlValue value{};\n+\n+\tswitch (id->type()) {\n+\tcase ControlTypeNone:\n+\t\tbreak;\n+\tcase ControlTypeBool: {\n+\t\tbool val;\n+\n+\t\tif (repr == \"true\") {\n+\t\t\tval = true;\n+\t\t} else if (repr == \"false\") {\n+\t\t\tval = false;\n+\t\t} else {\n+\t\t\tunpackFailure(id, repr);\n+\t\t\treturn value;\n+\t\t}\n+\n+\t\tvalue.set<bool>(val);\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeByte: {\n+\t\tuint8_t val = strtol(repr.c_str(), NULL, 10);\n+\t\tvalue.set<uint8_t>(val);\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeInteger32: {\n+\t\tint32_t val = strtol(repr.c_str(), NULL, 10);\n+\t\tvalue.set<int32_t>(val);\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeInteger64: {\n+\t\tint64_t val = strtoll(repr.c_str(), NULL, 10);\n+\t\tvalue.set<int64_t>(val);\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeFloat: {\n+\t\tfloat val = strtof(repr.c_str(), NULL);\n+\t\tvalue.set<float>(val);\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeString: {\n+\t\tvalue.set<std::string>(repr);\n+\t\tbreak;\n+\t}\n+\tcase ControlTypeRectangle:\n+\t\t/* \\todo Parse rectangles. */\n+\t\tbreak;\n+\tcase ControlTypeSize:\n+\t\t/* \\todo Parse Sizes. */\n+\t\tbreak;\n+\t}\n+\n+\treturn value;\n+}\ndiff --git a/src/cam/capture_script.h b/src/cam/capture_script.h\nnew file mode 100644\nindex 000000000000..39fded1250a6\n--- /dev/null\n+++ b/src/cam/capture_script.h\n@@ -0,0 +1,57 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * capture_script.h - Capture session configuration script\n+ */\n+\n+#pragma once\n+\n+#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 8\n+#include <experimental/filesystem>\n+namespace std {\n+namespace filesystem = std::experimental::filesystem;\n+}\n+#else\n+#include <filesystem>\n+#endif\n+\n+#include <map>\n+#include <memory>\n+#include <string>\n+\n+#include <libcamera/camera.h>\n+#include <libcamera/controls.h>\n+\n+#include <yaml.h>\n+\n+class CaptureScript\n+{\n+public:\n+\tCaptureScript(std::shared_ptr<libcamera::Camera> camera,\n+\t\t      std::string fileName);\n+\n+\tbool valid() const { return valid_; }\n+\n+\tconst libcamera::ControlList &frameControls(unsigned int frame);\n+\n+private:\n+\tstd::map<std::string, const libcamera::ControlId *> controls_;\n+\tstd::map<unsigned int, libcamera::ControlList> frameControls_;\n+\tstd::shared_ptr<libcamera::Camera> camera_;\n+\tstd::filesystem::path scriptPath_;\n+\tyaml_parser_t parser_;\n+\tbool valid_;\n+\n+\tint parseScript(FILE *script);\n+\n+\tlibcamera::ControlList parseControls();\n+\tint parseFrames();\n+\tint parseFrame();\n+\n+\tstd::string parseKey(yaml_token_t &token);\n+\tstd::string parseKey();\n+\tstd::string parseValue();\n+\n+\tvoid unpackFailure(const libcamera::ControlId *id, std::string repr);\n+\tlibcamera::ControlValue unpackControl(const libcamera::ControlId *id,\n+\t\t\t\t\t      std::string repr);\n+};\ndiff --git a/src/cam/meson.build b/src/cam/meson.build\nindex afc0ea9f397a..60ecbdca0c38 100644\n--- a/src/cam/meson.build\n+++ b/src/cam/meson.build\n@@ -11,6 +11,7 @@ cam_enabled = true\n \n cam_sources = files([\n     'camera_session.cpp',\n+    'capture_script.cpp',\n     'event_loop.cpp',\n     'file_sink.cpp',\n     'frame_sink.cpp',\n@@ -59,6 +60,7 @@ cam  = executable('cam', cam_sources,\n                       libsdl2,\n                       libsdl2_image,\n                       libevent,\n+                      libyaml,\n                   ],\n                   cpp_args : cam_cpp_args,\n                   install : true)\n",
    "prefixes": [
        "libcamera-devel",
        "1/5"
    ]
}