{"id":17950,"url":"https://patchwork.libcamera.org/api/1.1/patches/17950/?format=json","web_url":"https://patchwork.libcamera.org/patch/17950/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20221206135459.25521-8-naush@raspberrypi.com>","date":"2022-12-06T13:54:53","name":"[libcamera-devel,v3,07/13] pipeline: raspberrypi: Read config parameters from a file","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"092d1cb941f3b54ba9720a0101f2e8c9f1c216c1","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17950/mbox/","series":[{"id":3659,"url":"https://patchwork.libcamera.org/api/1.1/series/3659/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3659","date":"2022-12-06T13:54:46","name":"Raspberry Pi: Platform configuration and buffer allocation improvements","version":3,"mbox":"https://patchwork.libcamera.org/series/3659/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17950/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17950/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 B587BBE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  6 Dec 2022 13:55:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5584C63353;\n\tTue,  6 Dec 2022 14:55:16 +0100 (CET)","from mail-wm1-x330.google.com (mail-wm1-x330.google.com\n\t[IPv6:2a00:1450:4864:20::330])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F407663346\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  6 Dec 2022 14:55:10 +0100 (CET)","by mail-wm1-x330.google.com with SMTP id ay40so4512171wmb.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 06 Dec 2022 05:55:10 -0800 (PST)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tq6-20020a05600c2e4600b003c6bd91caa5sm19444059wmf.17.2022.12.06.05.55.09\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 06 Dec 2022 05:55:09 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1670334916;\n\tbh=T2AFAJs4vn9DNlKuZuL/tmptwUv4dxoMe2SbNdHpca4=;\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=OkcEbUM+fWIlzaaP7bhs3+GOBL31OnXN9EgLz5u0gmpTsSfQ4EUEcyidUcpW0KXri\n\tQIGchV3o6TfLevrvG90QyGgGwVceknJnjO9RUOie3Th8MrSIM3US1oZYQ06m2Xj4eq\n\t4RJ19BIZd3SDtiI70fC7cGFdCpOMz3UZn+O9KmHiUW10d79JDNaZS/8gXiKO1euu7P\n\tD+dsaholFzk3Nlzleg5DJof4La+BmJoGJsh37zCQEhyZoWplNgHdcoscvwcDY3LgRq\n\tt1gO3P80/OcCr8+vVo+KpGUqEYngMuh2Qj9jeX0/eC9eAe3M05dws633HQZg8Hkseq\n\tTZUEcZ8XRHvEQ==","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=AXCdNqevCR4XHkTMpqcZ3r5O13khl/GMC4Xe7cZRkzE=;\n\tb=pBIedDe8+VW2lmM+8OjM0sOXemknz061tzewvoZ0Whgc9ouLSwTpcP85OWmVJWkACh\n\tSsu1sZ94pDJVQ6TDdbmPWqsX7PbZzCS6n4jre+sY1mcigxl8KlUOLdkIq5bBGl9yjxUG\n\tVg0g6DKT5PIg15pPG0PcqAp61sfAOjcK4Hby8cpsmmOnC2q7++eMApUSEOmrJfe6cLDN\n\t/BJq+LL9Fl7MwpVpcRQeQidaet5Seh0cooDnJyPLtbV5cw/FHgnjrI9xSGwSDucnXvP8\n\tBZgLdiUG1RN1pW8yIWOkRdtWWirAeYNpCVKAh0weox7aqF88HiBK+L82tmRzwRPtv2I/\n\t0MBg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"pBIedDe8\"; 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=AXCdNqevCR4XHkTMpqcZ3r5O13khl/GMC4Xe7cZRkzE=;\n\tb=T65KYhH+3LhjdfbKc83yglvv/U7EVQfj3SxwRUKD99k/P8PkW2QjF5AV25lmy4RTCF\n\tdrMTIJbQ1B+5s/U1tojSnyk6QsmJkN7cYk8FTxaWvAWhRs+nZFLmCjnoEMmDtvd7r9fh\n\tpwr6nuDxjwGLD6IdBrtcecUUmMdMhaURXjN9Yx0NwYmtakx64pa9hAlK9N3t5dDeItJ8\n\t6voqIiNYmqElXB6j+8x2N7ZKFUSzOtZ+je1+X3Rr6d/RHQohEjevLFzoK59a5wRntL0Y\n\t9k2eXuMX9nfUml7iI4DPluDlEFgXf/uECWczbSVnHM+NCbyu/xiWrg5uReWYRDG1goCq\n\tzmNA==","X-Gm-Message-State":"ANoB5pkCrPoYC2NLvR7IoOUuYyithOWNJsTW8Itsz9uQYzaakag8jx7Z\n\t4HRbar25EW6nxRmetg3aEGhGlpEx9VbDxWtN","X-Google-Smtp-Source":"AA0mqf4oluQT2Gn0YuXxIBecPuY5aqoGwi/MWcQTkzvhl+pcoOVAMAcHQJUkXQ+5aghaoufUxTXm1A==","X-Received":"by 2002:a05:600c:1d1e:b0:3d0:4720:5293 with SMTP id\n\tl30-20020a05600c1d1e00b003d047205293mr36946703wms.176.1670334910367; \n\tTue, 06 Dec 2022 05:55:10 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  6 Dec 2022 13:54:53 +0000","Message-Id":"<20221206135459.25521-8-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20221206135459.25521-1-naush@raspberrypi.com>","References":"<20221206135459.25521-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 07/13] 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":"Add the ability to read the platform configuration parameters from a config\nfile provided by the user through the LIBCAMERA_RPI_CONFIG_FILE environment\nvariable. Use the PipelineHandler::configurationFile() helper to determine the\nfull path of the file.\n\nProvide an example configuration file named example.yaml. Currently two\nparameters 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\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../pipeline/raspberrypi/data/example.yaml    | 20 +++++++++\n .../pipeline/raspberrypi/data/meson.build     |  8 ++++\n .../pipeline/raspberrypi/meson.build          |  2 +\n .../pipeline/raspberrypi/raspberrypi.cpp      | 45 +++++++++++++++++++\n 4 files changed, 75 insertions(+)\n create mode 100644 src/libcamera/pipeline/raspberrypi/data/example.yaml\n create mode 100644 src/libcamera/pipeline/raspberrypi/data/meson.build","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/data/example.yaml b/src/libcamera/pipeline/raspberrypi/data/example.yaml\nnew file mode 100644\nindex 000000000000..001a906af528\n--- /dev/null\n+++ b/src/libcamera/pipeline/raspberrypi/data/example.yaml\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\n+                # Unicam. This value must be greater than 0, but less than or\n+                # equal to min_total_unicam_buffers.\n+                \"min_unicam_buffers\": 2,\n+\n+                # The minimum total (internal + external) buffer count used for\n+                # Unicam. The number of internal buffers allocated for Unicam is\n+                # given by:\n+                #\n+                # internal buffer count = max(min_unicam_buffers,\n+                #         min_total_unicam_buffers - external buffer count)\n+                \"min_total_unicam_buffers\": 4\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..1c70433bbcbc\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+    'example.yaml',\n+])\n+\n+install_data(conf_files,\n+             install_dir : pipeline_data_dir / '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 8be46962e825..9a316eda6fea 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@@ -1149,6 +1151,7 @@ int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request)\n \t\t\t */\n \t\t\tstream->setExternalBuffer(buffer);\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@@ -1682,6 +1685,48 @@ int RPiCameraData::configurePipeline()\n \t\t.minTotalUnicamBuffers = 4,\n \t};\n \n+\tchar const *configFromEnv = utils::secure_getenv(\"LIBCAMERA_RPI_CONFIG_FILE\");\n+\tif (!configFromEnv || *configFromEnv == '\\0')\n+\t\treturn 0;\n+\n+\tstd::string filename = std::string(configFromEnv);\n+\tFile file(filename);\n+\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+\tstd::optional<double> ver = (*root)[\"version\"].get<double>();\n+\tif (!ver || *ver != 1.0) {\n+\t\tLOG(RPI, Error) << \"Unexpected configuration file version reported\";\n+\t\treturn -EINVAL;\n+\t}\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+\n+\tif (config_.minTotalUnicamBuffers < config_.minUnicamBuffers) {\n+\t\tLOG(RPI, Error) << \"Invalid configuration: min_total_unicam_buffers must be >= min_unicam_buffers\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (config_.minTotalUnicamBuffers < 1) {\n+\t\tLOG(RPI, Error) << \"Invalid configuration: min_total_unicam_buffers must be >= 1\";\n+\t\treturn -EINVAL;\n+\t}\n+\n \treturn 0;\n }\n \n","prefixes":["libcamera-devel","v3","07/13"]}