{"id":17911,"url":"https://patchwork.libcamera.org/api/patches/17911/?format=json","web_url":"https://patchwork.libcamera.org/patch/17911/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20221129134534.2933-5-naush@raspberrypi.com>","date":"2022-11-29T13:45:28","name":"[libcamera-devel,v2,04/10] pipeline: raspberrypi: Read config parameters from a file","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"dd0804e380d76c3db903f1a965f1acd3e41fcfbb","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17911/mbox/","series":[{"id":3647,"url":"https://patchwork.libcamera.org/api/series/3647/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3647","date":"2022-11-29T13:45:24","name":"Raspberry Pi: Platform configuration and buffer allocation improvements","version":2,"mbox":"https://patchwork.libcamera.org/series/3647/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17911/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17911/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 3D63FC3286\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Nov 2022 13:45:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6736F6333F;\n\tTue, 29 Nov 2022 14:45:44 +0100 (CET)","from mail-wr1-x433.google.com (mail-wr1-x433.google.com\n\t[IPv6:2a00:1450:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 418F96333F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Nov 2022 14:45:41 +0100 (CET)","by mail-wr1-x433.google.com with SMTP id o5so13157447wrm.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Nov 2022 05:45:41 -0800 (PST)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tn8-20020a05600c3b8800b003cfbbd54178sm3565636wms.2.2022.11.29.05.45.40\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 29 Nov 2022 05:45:40 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1669729544;\n\tbh=1EA1gvNx34pZxdnIB7ZSD4Wdr6IySmZ/YynJ3Jr6Q6U=;\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=enynkB3gZNsUiif6sHzz42DmU6ZyUfKS/fvydLw6TIsRN9ehURiOd/BWEL4WG7Uvd\n\t7gAL3PIGWwJ+UDjMf7dlARHsV900oO8IqwkCNxGBDo4VIMpLx09x8itrvcAQGiCP7I\n\tWiuK181jbaMKssLbMvX+skDhCNQuPIv/VF+hEAy1luHNXpbxp4+1tpYzj3sTsKfSfS\n\tAnBb9cyUcnr9g2xbWOAsJAQ10RQ+bPjuX4Vns0MExHJQHXz0t5gX3y+OvXrNU57Vn9\n\tW9GfYvWVeUXKYRiENFs2vhR7xzZGyhymWE7WMs6ijpDboRzGRhu/kXd5QyhwPuYRLK\n\t/N2rPK3KVTXUg==","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=dkxuoYbUAgoPHTxggyZSVJLmHd9EHdyyBvKcOavddOY=;\n\tb=XIF19mHaGq1E4KuSfYVKpvTX/ZzQBKRoB27mn6q6uEaI+TEBiJ7Esxf81fmBYAe3eu\n\tPtsWGQtlhYW/H659R0fa4XZj+wzIjMhWrTcjWU4zLVMRmh6koA/gEuM4bogxTSYzfeu0\n\tq/LmGAOsI4mtDbckCq4+to01TRraqXTtdTHugveVyT3/5nkNoNKE0GOJjoHHpxIHKBXb\n\tgMyTwGgmvnMpKPk0FM0mQ8z+7usAhNKjlZJCTfL0duImHj64Zkxow7nhjSgcNSZ9lBRU\n\tDa+ySwMURnkOiBfQAa/xhcoNJ399iaI+Ni781yOGCM4fUQdrxLgSO7GOMC4l6AbSpmy5\n\t7QjQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"XIF19mHa\"; 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=dkxuoYbUAgoPHTxggyZSVJLmHd9EHdyyBvKcOavddOY=;\n\tb=3W1Y/deR3IPX5itefDqIogNF0lfgZjBTSKFnWcSbS+nSGYUcyAymybm/e2eJDI579i\n\tohWiXrIbIUhycyzI0Uc8PO52ayIdiwttx3OfBX1guaQfy+CTNy5pDWSljMQYoT1+IS2r\n\t6KEqfXIBuCJ7pkdQIMXRsy3pcJ5Ta7klBCQy26oPvA1T9s6wPPMUReDKqAufUHrQYlWU\n\tmwryLdpuh4dzSz+QuXkWed/lqd/BK/857Xuk1+okDZe0fur1meJszwHWp1BRYtMWrUJs\n\tgQsLQN6U4ly2b5ZeYEMBMtGhSdW+U6LCqKwfzMbgdn34D1QVYtDIGwzVSZfgrXWO/8ax\n\t/I9A==","X-Gm-Message-State":"ANoB5pnVuRlb6zGnhKk3JAuk74A6DvS7/d+5XbRr9UgONX6hvoBMyo0c\n\tpB/++2iiuBcrwJPfEtnkSDRQ2QEg/GvQyA==","X-Google-Smtp-Source":"AA0mqf46rZJoMI4+hsthmbEvHxcGpVhNE628tZlPO7OvKyByX0dI3AyChVgxduhloXsTx696OuLo0A==","X-Received":"by 2002:adf:eb88:0:b0:22e:3e3b:24fe with SMTP id\n\tt8-20020adfeb88000000b0022e3e3b24femr32906375wrn.668.1669729540598; \n\tTue, 29 Nov 2022 05:45:40 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 29 Nov 2022 13:45:28 +0000","Message-Id":"<20221129134534.2933-5-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20221129134534.2933-1-naush@raspberrypi.com>","References":"<20221129134534.2933-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 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>\nReviewed-by: David Plowman <david.plowman@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      | 61 +++++++++++++++++++\n 4 files changed, 91 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 f2b695af2399..ce411453db0a 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@@ -313,6 +315,7 @@ public:\n \t};\n \n \tConfig config_;\n+\tunsigned int numUnicamBuffers;\n \n private:\n \tvoid checkRequestCompleted();\n@@ -1154,6 +1157,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@@ -1419,6 +1435,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@@ -1426,6 +1443,49 @@ 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) {\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@@ -1492,6 +1552,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","v2","04/10"]}