Show a patch.

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

{
    "id": 22149,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/22149/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22149/",
    "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": "<20241202133404.41431-4-jacopo.mondi@ideasonboard.com>",
    "date": "2024-12-02T13:34:02",
    "name": "[v2,3/4] apps: cam: Add support for loading configuration from capture script",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "8202634e2f6212fbed31fa4bac795a3fb820500e",
    "submitter": {
        "id": 143,
        "url": "https://patchwork.libcamera.org/api/1.1/people/143/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo.mondi@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/22149/mbox/",
    "series": [
        {
            "id": 4837,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4837/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4837",
            "date": "2024-12-02T13:33:59",
            "name": "libcamera: Add support for dumping capture script in YAML",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4837/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/22149/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22149/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 906CCBEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  2 Dec 2024 13:34:19 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EA05A6606B;\n\tMon,  2 Dec 2024 14:34:15 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C69B566069\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  2 Dec 2024 14:34:11 +0100 (CET)",
            "from ideasonboard.com (mob-5-90-236-68.net.vodafone.it\n\t[5.90.236.68])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E84C075A;\n\tMon,  2 Dec 2024 14:33:44 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"KWLiToFF\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1733146425;\n\tbh=aWjmbJ5uWaEHu7I2VK301HOo61XBr2nudYUCccqvl0Y=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=KWLiToFFGdJFn1+7oF3zvRmFFNXGQdTaSNWpD9HmmJ9SwnXJhh7W0+l6Yaxw9Uyri\n\tFZIx/p6ioyqpOcL+PJCFRb9rrtoPPqGrGCvyks2vD744cxRYn9OvvKqFkwGIdkv391\n\tYyvUDBJY6D+n5Wq4EtIbmzwUalJlxQ71j8818K20=",
        "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>",
        "Subject": "[PATCH v2 3/4] apps: cam: Add support for loading configuration from\n\tcapture script",
        "Date": "Mon,  2 Dec 2024 14:34:02 +0100",
        "Message-ID": "<20241202133404.41431-4-jacopo.mondi@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.47.0",
        "In-Reply-To": "<20241202133404.41431-1-jacopo.mondi@ideasonboard.com>",
        "References": "<20241202133404.41431-1-jacopo.mondi@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "From: Paul Elder <paul.elder@ideasonboard.com>\n\nAdd support to the cam application for loading the camera configuration\nfrom a capture script. These are not expected to be written by hand, but\nrather dumped via the LIBCAMERA_DUMP_CAPTURE_SCRIPT environment\nvariable.\n\nIf any configuration options are specified by command line parameters,\nthose will take precedence.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/apps/cam/camera_session.cpp |  22 +++--\n src/apps/cam/capture_script.cpp | 164 ++++++++++++++++++++++++++++++++\n src/apps/cam/capture_script.h   |   8 ++\n 3 files changed, 184 insertions(+), 10 deletions(-)",
    "diff": "diff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp\nindex 6e9890ccfda1..f31b5282c706 100644\n--- a/src/apps/cam/camera_session.cpp\n+++ b/src/apps/cam/camera_session.cpp\n@@ -70,6 +70,18 @@ CameraSession::CameraSession(CameraManager *cm,\n \t\treturn;\n \t}\n \n+\tif (options_.isSet(OptCaptureScript)) {\n+\t\tstd::string scriptName = options_[OptCaptureScript].toString();\n+\t\tscript_ = std::make_unique<CaptureScript>(camera_, scriptName);\n+\t\tif (!script_->valid()) {\n+\t\t\tstd::cerr << \"Invalid capture script '\" << scriptName\n+\t\t\t\t  << \"'\" << std::endl;\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tscript_->populateConfiguration(config.get());\n+\t}\n+\n \tif (options_.isSet(OptOrientation)) {\n \t\tstd::string orientOpt = options_[OptOrientation].toString();\n \t\tstatic const std::map<std::string, libcamera::Orientation> orientations{\n@@ -119,16 +131,6 @@ CameraSession::CameraSession(CameraManager *cm,\n \t}\n #endif\n \n-\tif (options_.isSet(OptCaptureScript)) {\n-\t\tstd::string scriptName = options_[OptCaptureScript].toString();\n-\t\tscript_ = std::make_unique<CaptureScript>(camera_, scriptName);\n-\t\tif (!script_->valid()) {\n-\t\t\tstd::cerr << \"Invalid capture script '\" << scriptName\n-\t\t\t\t  << \"'\" << std::endl;\n-\t\t\treturn;\n-\t\t}\n-\t}\n-\n \tswitch (config->validate()) {\n \tcase CameraConfiguration::Valid:\n \t\tbreak;\ndiff --git a/src/apps/cam/capture_script.cpp b/src/apps/cam/capture_script.cpp\nindex fc1dfa75f2d4..5455e35f37b1 100644\n--- a/src/apps/cam/capture_script.cpp\n+++ b/src/apps/cam/capture_script.cpp\n@@ -7,6 +7,7 @@\n \n #include \"capture_script.h\"\n \n+#include <algorithm>\n #include <iostream>\n #include <stdio.h>\n #include <stdlib.h>\n@@ -162,6 +163,10 @@ int CaptureScript::parseScript(FILE *script)\n \t\t\tret = parseFrames();\n \t\t\tif (ret)\n \t\t\t\treturn ret;\n+\t\t} else if (section == \"configuration\") {\n+\t\t\tret = parseConfiguration();\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n \t\t} else {\n \t\t\tstd::cerr << \"Unsupported section '\" << section << \"'\"\n \t\t\t\t  << std::endl;\n@@ -322,6 +327,165 @@ int CaptureScript::parseControl(EventPtr event, ControlList &controls)\n \treturn 0;\n }\n \n+int CaptureScript::parseOrientation(EventPtr event)\n+{\n+\tstatic const std::map<std::string, libcamera::Orientation> orientations{\n+\t\t{ \"Rotate0\", libcamera::Orientation::Rotate0 },\n+\t\t{ \"Rotate0Mirror\", libcamera::Orientation::Rotate0Mirror },\n+\t\t{ \"Rotate180\", libcamera::Orientation::Rotate180 },\n+\t\t{ \"Rotate180Mirror\", libcamera::Orientation::Rotate180Mirror },\n+\t\t{ \"Rotate90Mirror\", libcamera::Orientation::Rotate90Mirror },\n+\t\t{ \"Rotate270\", libcamera::Orientation::Rotate270 },\n+\t\t{ \"Rotate270Mirror\", libcamera::Orientation::Rotate270Mirror },\n+\t\t{ \"Rotate90\", libcamera::Orientation::Rotate90 },\n+\t};\n+\n+\tstd::string orientation = eventScalarValue(event);\n+\n+\tauto it = orientations.find(orientation);\n+\tif (it == orientations.end()) {\n+\t\tstd::cerr << \"Invalid orientation '\" << orientation\n+\t\t\t  << \"' in capture script\" << std::endl;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\torientation_ = it->second;\n+\n+\treturn 0;\n+}\n+\n+int CaptureScript::parseStream(EventPtr event, unsigned int index)\n+{\n+\tif (!checkEvent(event, YAML_MAPPING_START_EVENT))\n+\t\treturn -EINVAL;\n+\n+\tStreamConfiguration config;\n+\twhile (1) {\n+\t\tevent = nextEvent();\n+\t\tif (!event)\n+\t\t\treturn -EINVAL;\n+\t\tif (event->type == YAML_MAPPING_END_EVENT)\n+\t\t\tbreak;\n+\n+\t\tstd::string key = eventScalarValue(event);\n+\n+\t\tevent = nextEvent();\n+\t\tif (!event)\n+\t\t\treturn -EINVAL;\n+\t\tif (event->type == YAML_MAPPING_END_EVENT)\n+\t\t\tbreak;\n+\n+\t\tstd::string value = eventScalarValue(event);\n+\n+\t\tif (key == \"pixelFormat\") {\n+\t\t\tconfig.pixelFormat = libcamera::PixelFormat::fromString(value);\n+\t\t} else if (key == \"size\") {\n+\t\t\tauto split = value.find(\"x\");\n+\t\t\tif (split == std::string::npos) {\n+\t\t\t\tstd::cerr << \"Invalid size '\" << value\n+\t\t\t\t\t  << \"' in stream configuration \"\n+\t\t\t\t\t  << index << std::endl;\n+\t\t\t}\n+\n+\t\t\tstd::string width = value.substr(0, split);\n+\t\t\tstd::string height = value.substr(split + 1);\n+\t\t\tconfig.size = Size(std::stoi(width), std::stoi(height));\n+\t\t} else if (key == \"stride\") {\n+\t\t\tconfig.stride = std::stoi(value);\n+\t\t} else if (key == \"frameSize\") {\n+\t\t\tconfig.frameSize = std::stoi(value);\n+\t\t} else if (key == \"bufferCount\") {\n+\t\t\tconfig.bufferCount = std::stoi(value);\n+\t\t} else if (key == \"colorSpace\") {\n+\t\t\tconfig.colorSpace = libcamera::ColorSpace::fromString(value);\n+\t\t} else {\n+\t\t\tstd::cerr << \"Unknown key-value pair '\"\n+\t\t\t\t  << key << \"': '\" << value\n+\t\t\t\t  << \"' in stream configuration \"\n+\t\t\t\t  << index << std::endl;\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t}\n+\n+\tstreamConfigs_.push_back(config);\n+\n+\treturn 0;\n+}\n+\n+int CaptureScript::parseStreams(EventPtr event)\n+{\n+\tif (!checkEvent(event, YAML_SEQUENCE_START_EVENT))\n+\t\treturn -EINVAL;\n+\n+\tunsigned int index = 0;\n+\twhile (1) {\n+\t\tevent = nextEvent();\n+\t\tif (!event)\n+\t\t\treturn -EINVAL;\n+\t\tif (event->type == YAML_SEQUENCE_END_EVENT)\n+\t\t\treturn 0;\n+\n+\t\tif (event->type == YAML_MAPPING_START_EVENT) {\n+\t\t\tparseStream(std::move(event), index++);\n+\t\t\tcontinue;\n+\t\t} else {\n+\t\t\tstd::cerr << \"UNKNOWN TYPE\" << std::endl;\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int CaptureScript::parseConfiguration()\n+{\n+\tint ret;\n+\n+\tEventPtr event = nextEvent(YAML_MAPPING_START_EVENT);\n+\tif (!event)\n+\t\treturn -EINVAL;\n+\n+\twhile (1) {\n+\t\tevent = nextEvent();\n+\t\tif (!event)\n+\t\t\treturn -EINVAL;\n+\t\tif (event->type == YAML_MAPPING_END_EVENT)\n+\t\t\tbreak;\n+\n+\t\tstd::string key = eventScalarValue(event);\n+\n+\t\tevent = nextEvent();\n+\t\tif (!event)\n+\t\t\treturn -EINVAL;\n+\t\tif (event->type == YAML_MAPPING_END_EVENT)\n+\t\t\tbreak;\n+\n+\t\t/* TODO Load sensor configuration */\n+\t\tif (key == \"orientation\") {\n+\t\t\tret = parseOrientation(std::move(event));\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\t\t} else if (key == \"streams\") {\n+\t\t\tret = parseStreams(std::move(event));\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+void CaptureScript::populateConfiguration(CameraConfiguration *configuration) const\n+{\n+\tif (!configuration)\n+\t\treturn;\n+\n+\tconfiguration->orientation = orientation_;\n+\n+\tfor (unsigned int i = 0; i < streamConfigs_.size(); i++)\n+\t\t(*configuration)[i] = streamConfigs_[i];\n+}\n+\n std::string CaptureScript::parseScalar()\n {\n \tEventPtr event = nextEvent(YAML_SCALAR_EVENT);\ndiff --git a/src/apps/cam/capture_script.h b/src/apps/cam/capture_script.h\nindex 294b920363ba..4ba862d742cf 100644\n--- a/src/apps/cam/capture_script.h\n+++ b/src/apps/cam/capture_script.h\n@@ -26,6 +26,7 @@ public:\n \n \tconst libcamera::ControlList &frameControls(unsigned int frame);\n \n+\tvoid populateConfiguration(libcamera::CameraConfiguration *configuration) const;\n private:\n \tstruct EventDeleter {\n \t\tvoid operator()(yaml_event_t *event) const\n@@ -43,6 +44,9 @@ private:\n \tunsigned int loop_;\n \tbool valid_;\n \n+\tlibcamera::Orientation orientation_;\n+\tstd::vector<libcamera::StreamConfiguration> streamConfigs_;\n+\n \tEventPtr nextEvent(yaml_event_type_t expectedType = YAML_NO_EVENT);\n \tbool checkEvent(const EventPtr &event, yaml_event_type_t expectedType) const;\n \tstatic std::string eventScalarValue(const EventPtr &event);\n@@ -55,6 +59,10 @@ private:\n \tint parseFrames();\n \tint parseFrame(EventPtr event);\n \tint parseControl(EventPtr event, libcamera::ControlList &controls);\n+\tint parseConfiguration();\n+\tint parseOrientation(EventPtr event);\n+\tint parseStreams(EventPtr event);\n+\tint parseStream(EventPtr event, unsigned int index);\n \n \tlibcamera::ControlValue parseScalarControl(const libcamera::ControlId *id,\n \t\t\t\t\t\t   const std::string repr);\n",
    "prefixes": [
        "v2",
        "3/4"
    ]
}