{"id":17971,"url":"https://patchwork.libcamera.org/api/1.1/patches/17971/?format=json","web_url":"https://patchwork.libcamera.org/patch/17971/","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":"<20221209090050.19441-8-naush@raspberrypi.com>","date":"2022-12-09T09:00:45","name":"[libcamera-devel,v4,07/12] 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/17971/mbox/","series":[{"id":3663,"url":"https://patchwork.libcamera.org/api/1.1/series/3663/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3663","date":"2022-12-09T09:00:38","name":"Raspberry Pi: Platform configuration and buffer allocation improvements","version":4,"mbox":"https://patchwork.libcamera.org/series/3663/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17971/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17971/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 BDB11BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  9 Dec 2022 09:01:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6324D63360;\n\tFri,  9 Dec 2022 10:01:40 +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 981CC6335F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  9 Dec 2022 10:01:34 +0100 (CET)","by mail-wm1-x330.google.com with SMTP id n7so3061423wms.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 09 Dec 2022 01:01:34 -0800 (PST)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tbd10-20020a05600c1f0a00b003cf774c31a0sm7773674wmb.16.2022.12.09.01.01.32\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 09 Dec 2022 01:01:33 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1670576500;\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=e99bKO3mPvLhpfiZTBaiMQOsyTdC1zNTo18XQzOLoQP+XDHWuWMXrBYk1nIw93iEg\n\t9qzS4g7Cn8wPDDkdACh9AXODZP/ZD3p/khojkWVmyO8xtlQZu5E59p1kckNePyvEsl\n\tCKUakp4wt1NXb3lKJ8X4ykyAVVy+8dn41IWVCxAXuF+i7XHcD9QApllmjVGWLEIPij\n\txXIhQAK2basJl0KKRox2KS8sFsIrK85+6zcZXLQgW43sNUTXyVRI70ZUs7a0if6oEP\n\tXpFXR4QIHSin3kZjLsOswYBtP6Gp+je2dK94ykX96jxFoqL1uspCHcdy23JaWvauKL\n\trMqh7DW0HsLDg==","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=DQQSbHoe51UA3tDonwfFql9HVVgQ8wPaFO+/DBT9CVHzWVDPbvzQx0E5cypwBJ2AV+\n\tDP5NKpGet/AgGfJYGfGZ+muRogqgl614x6e6v9tSBNlQ/8pyTGhUJssW84m1L+58fxkl\n\tm9uyfeEl1SAFC/iDzDA81Rcxk6dLwlGYp5aerbbfSGSgOUtuz+w4oxY55gLXFdTS6Jaz\n\tebmwcm3QzBCSY0FmymQhd2JdeIYTSqBvoZIMfUUQGr9FA12Uek4nf175FG7kQ1epdS/a\n\tiimslcFwPwP86ku6WL5DyVF6NGMX+pHTH00qxyir4scg5KneSD2xACnYjwJ6YLIu9Bit\n\t0apg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"DQQSbHoe\"; 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=sX2mC4FtfT8ymE3VlyWfY9h9o8QD2CNX88nucIA4Ma0gCu6ZOaehfyc2kA+O95Ne/V\n\trC2OBY5I+MnDxbgVtx0k75pvzQczvNSmzUV4K+At744VyCwSJtKr1gHCAWwufCvGfYjf\n\tf4vdi7U3gLcROBawHhw4pGklCAKoZYLaR8yxp7igsUtmXBHSNBLuhV7NT4xAh+om9O8Y\n\tACn9VKnInol45lM0uMTsMksGmkkYRjcalr41gYzRQmMCeoukI2eYCwbwLav3CcMxrG4F\n\tSLU2n5rvbCf6vd7tZDX9+pc5/IXbT0CsJdMSrGE5H3YOLZh4F1RIorBxdHm4rue+9vW3\n\tmZyg==","X-Gm-Message-State":"ANoB5pl1ouAro4d7Lnm80z0pp+7x/+iMtRWamUlT+byKyEC52ugjD0I9\n\tmADVg1kTWaba1ToufEycVq0o4QStgshoDUlb","X-Google-Smtp-Source":"AA0mqf6aBOuTLf6hR7xhtKA6QAWg6nE7K/OixmWTh4P6iZZrmdvfVeCyfe3PirlsCJxDzBeejj0fqw==","X-Received":"by 2002:a05:600c:4e50:b0:3c6:e63e:23f6 with SMTP id\n\te16-20020a05600c4e5000b003c6e63e23f6mr4397490wmq.37.1670576493820; \n\tFri, 09 Dec 2022 01:01:33 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  9 Dec 2022 09:00:45 +0000","Message-Id":"<20221209090050.19441-8-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20221209090050.19441-1-naush@raspberrypi.com>","References":"<20221209090050.19441-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 07/12] 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","v4","07/12"]}