Show a patch.

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

{
    "id": 17600,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17600/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17600/",
    "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": "<20221014131846.27169-5-naush@raspberrypi.com>",
    "date": "2022-10-14T13:18:40",
    "name": "[libcamera-devel,v1,04/10] pipeline: raspberrypi: Read config parameters from a file",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "baa73ca6d36ec26d401f533b030309b38e1d4f3d",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17600/mbox/",
    "series": [
        {
            "id": 3555,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3555/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3555",
            "date": "2022-10-14T13:18:37",
            "name": "Raspberry Pi: Platform configuration and buffer allocation improvements",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3555/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17600/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17600/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 C92E5C327C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 14 Oct 2022 13:19:00 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6C9F362DD4;\n\tFri, 14 Oct 2022 15:19:00 +0200 (CEST)",
            "from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com\n\t[IPv6:2a00:1450:4864:20::32b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6A2B262DC2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 14 Oct 2022 15:18:55 +0200 (CEST)",
            "by mail-wm1-x32b.google.com with SMTP id\n\tl16-20020a05600c4f1000b003c6c0d2a445so3490143wmq.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 14 Oct 2022 06:18:55 -0700 (PDT)",
            "from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tg17-20020a05600c001100b003c6bbe910fdsm8282458wmc.9.2022.10.14.06.18.54\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 14 Oct 2022 06:18:54 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1665753540;\n\tbh=nz3wJ1qW+PINInuZKlj5y+yw3Z7lfUw7r92acE02Cog=;\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=P6nUguKBTFllMLulI0nHtDTSdP8Vb6rpvppicF6ZHtobB+AQQtzO1NrojRvgJkSng\n\toBa9H5JXTgUMJgTr5vbv8t+w3zyZfmujBnd7csLyORxlWx/PIMhXr5h61tSD8cOTKM\n\t+4Bce+yEUgsNewFxfMM9k442xDlxAMDfZ7jAhLOQWa35nEKiyBcRbbdHKyc0BSOAo/\n\tH9QA1QZ+luNcXNQ3w2y+hnsPUWBQFbVMZSF+vy9CpBbTotwzSaUGoWf44RE/ZHAq4y\n\tQnE64Pgf0OJdF4K8UfZNL3wZ/TEtzLTFmn068Lv8aWy4DXu9IpZ/k7QHFiFLjxD2EK\n\t7i4fXgI67pj2w==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=xz66QQBqRMHVmsLde1uoiES/yRhcr0v24H45LmZwNm0=;\n\tb=E6qtY5AIUBKqauKjRhUmMFBsLl31Ruiaf/kZCUAExBJYxRHPZd16pLLgphUmEpjkhg\n\txHeK3uLPqwDG5dK+JTu64ci7QAfPGLXhor1MYiDcJiG+DaKPXJFUIjpEQXc9XSEFZ1Mr\n\tcc34fDsoZsMIL5/FBbiWeynH0s/6/MuvZ5DsM0uCbIHnJlyrgTeIYK5EBXIi3mRixwJD\n\tH2A+hs8sXGWV/ulM4Y3X5aZoc+5AtGULfDVggxN9uHfF7LOeXOCbMX7iDdSDa+SuGBN6\n\tiBt1qGVkzHtpWB0/Nb9ebgYO+VIWNiWlnherXeAnS6qHj/uqrzOcfyXrlrD/fn3rYjuk\n\toJtg=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"E6qtY5AI\"; dkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=xz66QQBqRMHVmsLde1uoiES/yRhcr0v24H45LmZwNm0=;\n\tb=JZ4CFS03G+Q6HDxgxUmPebzq279xiki/MRzUm+TDVGCNyw+CQXdwCsiWGj7WpziSwe\n\t1BxNjB3dZpxMSvsDrZHWNg+wF7h5UVDmeV4Tssl8d2/Bn2tNeWUYxu4q4c8vEh4QrwCW\n\tsEupPbC53HqLa6Ybq6kNZ6q0jkECWxLXGEtT+m9Wc0htcycqQtx8R9V12FT2AlA40aic\n\tMgKAhOoIyZWefoaCynVch5IyiayV46z7ZNKxzdZjIwWZdnl2brdw16WfReoaAu/m8ICk\n\t9pof3m/7GGfuPXPO/5esisC2vvY889RiDnCburd3CsOXyHzIGpBKaxwYh9k9psJDL2zO\n\tZqpg==",
        "X-Gm-Message-State": "ACrzQf3lo0V74V9Bxli3BHzpkQYuf7vXPeIgOApxKDDX6xIbObBCslSl\n\tzxguwanvUblxdgvm5qKE2pM8D7ch7/cjCw==",
        "X-Google-Smtp-Source": "AMsMyM6o7YSWlcNXiq4QkSnh5oAYeY8gc9lttQZuCfTPbZgTy1RBNJ3yP1yr37+AjTRCfVs7igwcyw==",
        "X-Received": "by 2002:a05:600c:4194:b0:3c3:d0ed:2d44 with SMTP id\n\tp20-20020a05600c419400b003c3d0ed2d44mr10652925wmh.151.1665753534792; \n\tFri, 14 Oct 2022 06:18:54 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 14 Oct 2022 14:18:40 +0100",
        "Message-Id": "<20221014131846.27169-5-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20221014131846.27169-1-naush@raspberrypi.com>",
        "References": "<20221014131846.27169-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v1 04/10] pipeline: raspberrypi: Read\n\tconfig parameters from a file",
        "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": "Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Naushir Patuck <naush@raspberrypi.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Read the platform configuration parameters from default.json config file. Use\nthe PipelineHandler::configurationFile() helper to determine the full path of\nthe file. The default.json filename can be overridden by the user setting the\nLIBCAMERA_RPI_CONFIG_FILE environment variable giving the full path of the\ncustom file.\n\nAdd config parameter validation to ensure bad parameters cannot cause the\npipeline handler to stop working.\n\nCurrently three parameters are available through the json file:\n\n\"min_unicam_buffers\"\nThe minimum number of internal Unicam buffers to allocate.\n\n\"min_total_unicam_buffers\"\nThe minimum number of internal + external Unicam buffers that must be allocated.\n\n\"num_output0_buffers\"\nNumber of internal ISP Output0 buffers to allocate.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/data/default.json    | 20 +++++++\n .../pipeline/raspberrypi/data/meson.build     |  8 +++\n .../pipeline/raspberrypi/meson.build          |  2 +\n .../pipeline/raspberrypi/raspberrypi.cpp      | 56 +++++++++++++++++++\n 4 files changed, 86 insertions(+)\n create mode 100644 src/libcamera/pipeline/raspberrypi/data/default.json\n create mode 100644 src/libcamera/pipeline/raspberrypi/data/meson.build",
    "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/data/default.json b/src/libcamera/pipeline/raspberrypi/data/default.json\nnew file mode 100644\nindex 000000000000..d709e31850af\n--- /dev/null\n+++ b/src/libcamera/pipeline/raspberrypi/data/default.json\n@@ -0,0 +1,20 @@\n+{\n+        \"version\": 1.0,\n+        \"target\": \"bcm2835\",\n+\n+        \"pipeline_handler\":\n+        {\n+                # The minimum number of internal buffers to be allocated for Unicam.\n+                # This value must be greater than 0, but less than or equal to min_total_unicam_buffers.\n+                \"min_unicam_buffers\": 2,\n+\n+                # The minimum total (internal + external) buffer count used for Unicam.\n+                # The number of internal buffers allocated for Unicam is given by:\n+                # internal buffer count = max(min_unicam_buffers,\n+                #                             min_total_unicam_buffers - external buffer count)\n+                \"min_total_unicam_buffers\": 4,\n+                \n+                # The number of internal buffers used for ISP Output0. This must be set to 1.\n+                \"num_output0_buffers\": 1\n+        }\n+}\ndiff --git a/src/libcamera/pipeline/raspberrypi/data/meson.build b/src/libcamera/pipeline/raspberrypi/data/meson.build\nnew file mode 100644\nindex 000000000000..232f8b43c5fd\n--- /dev/null\n+++ b/src/libcamera/pipeline/raspberrypi/data/meson.build\n@@ -0,0 +1,8 @@\n+# SPDX-License-Identifier: CC0-1.0\n+\n+conf_files = files([\n+    'default.json',\n+])\n+\n+install_data(conf_files,\n+             install_dir : libcamera_datadir / 'pipeline/raspberrypi')\ndiff --git a/src/libcamera/pipeline/raspberrypi/meson.build b/src/libcamera/pipeline/raspberrypi/meson.build\nindex f1a2f5ee72c2..48235f887501 100644\n--- a/src/libcamera/pipeline/raspberrypi/meson.build\n+++ b/src/libcamera/pipeline/raspberrypi/meson.build\n@@ -5,3 +5,5 @@ libcamera_sources += files([\n     'raspberrypi.cpp',\n     'rpi_stream.cpp',\n ])\n+\n+subdir('data')\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 450029197b11..bac7a66ba900 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -14,6 +14,7 @@\n #include <unordered_set>\n #include <utility>\n \n+#include <libcamera/base/file.h>\n #include <libcamera/base/shared_fd.h>\n #include <libcamera/base/utils.h>\n \n@@ -40,6 +41,7 @@\n #include \"libcamera/internal/media_device.h\"\n #include \"libcamera/internal/pipeline_handler.h\"\n #include \"libcamera/internal/v4l2_videodevice.h\"\n+#include \"libcamera/internal/yaml_parser.h\"\n \n #include \"dma_heaps.h\"\n #include \"rpi_stream.h\"\n@@ -301,6 +303,7 @@ public:\n \t};\n \n \tConfig config_;\n+\tunsigned int numUnicamBuffers;\n \n private:\n \tvoid checkRequestCompleted();\n@@ -1140,6 +1143,19 @@ int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request)\n \t\t\t */\n \t\t\tstream->setExternalBuffer(buffer);\n \t\t}\n+\n+\t\tif (!buffer) {\n+\t\t\tif (stream == &data->isp_[Isp::Output0] && !data->config_.numOutput0Buffers) {\n+\t\t\t\tLOG(RPI, Error) << \"Output0 buffer must be provided in the request.\";\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\n+\t\t\tif (stream == &data->unicam_[Unicam::Image] && !data->numUnicamBuffers) {\n+\t\t\t\tLOG(RPI, Error) << \"Unicam Image buffer must be provided in the request.\";\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\t\t}\n+\n \t\t/*\n \t\t * If no buffer is provided by the request for this stream, we\n \t\t * queue a nullptr to the stream to signify that it must use an\n@@ -1398,6 +1414,7 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me\n int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data)\n {\n \tRPiCameraData::Config &config = data->config_;\n+\tstd::string filename;\n \n \tconfig = {\n \t\t.minUnicamBuffers = 2,\n@@ -1405,6 +1422,44 @@ int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data)\n \t\t.numOutput0Buffers = 1,\n \t};\n \n+\tchar const *configFromEnv = utils::secure_getenv(\"LIBCAMERA_RPI_CONFIG_FILE\");\n+\tif (!configFromEnv || *configFromEnv == '\\0')\n+\t\tfilename = configurationFile(\"raspberrypi/default.json\");\n+\telse\n+\t\tfilename = std::string(configFromEnv);\n+\n+\tif (filename.empty())\n+\t\treturn -EINVAL;\n+\n+\tFile file(filename);\n+\tif (!file.open(File::OpenModeFlag::ReadOnly)) {\n+\t\tLOG(RPI, Error) << \"Failed to open configuration file '\" << filename << \"'\";\n+\t\treturn -EIO;\n+\t}\n+\n+\tLOG(RPI, Info) << \"Using configuration file '\" << filename << \"'\";\n+\n+\tstd::unique_ptr<YamlObject> root = YamlParser::parse(file);\n+\tif (!root) {\n+\t\tLOG(RPI, Error) << \"Failed to parse configuration file, using defaults!\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tASSERT((*root)[\"version\"].get<double>() == 1.0);\n+\n+\tconst YamlObject &phConfig = (*root)[\"pipeline_handler\"];\n+\tconfig.minUnicamBuffers =\n+\t\tphConfig[\"min_unicam_buffers\"].get<unsigned int>(config.minUnicamBuffers);\n+\tconfig.minTotalUnicamBuffers =\n+\t\tphConfig[\"min_total_unicam_buffers\"].get<unsigned int>(config.minTotalUnicamBuffers);\n+\tconfig.numOutput0Buffers =\n+\t\tphConfig[\"num_output0_buffers\"].get<unsigned int>(config.numOutput0Buffers);\n+\n+\tif (config.minTotalUnicamBuffers < config.minUnicamBuffers || config.minTotalUnicamBuffers < 1) {\n+\t\tLOG(RPI, Error) << \"Invalid Unicam buffer configuration used!\";\n+\t\treturn -EINVAL;\n+\t}\n+\n \treturn 0;\n }\n \n@@ -1471,6 +1526,7 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n \t\t\t */\n \t\t\tnumBuffers = std::max<int>(data->config_.minUnicamBuffers,\n \t\t\t\t\t\t   minBuffers - numRawBuffers);\n+\t\t\tdata->numUnicamBuffers = numBuffers;\n \t\t} else if (stream == &data->isp_[Isp::Input]) {\n \t\t\t/*\n \t\t\t * ISP input buffers are imported from Unicam, so follow\n",
    "prefixes": [
        "libcamera-devel",
        "v1",
        "04/10"
    ]
}