From patchwork Fri Dec 9 09:00:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17971 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BDB11BDE6B for ; Fri, 9 Dec 2022 09:01:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6324D63360; Fri, 9 Dec 2022 10:01:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1670576500; bh=T2AFAJs4vn9DNlKuZuL/tmptwUv4dxoMe2SbNdHpca4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=e99bKO3mPvLhpfiZTBaiMQOsyTdC1zNTo18XQzOLoQP+XDHWuWMXrBYk1nIw93iEg 9qzS4g7Cn8wPDDkdACh9AXODZP/ZD3p/khojkWVmyO8xtlQZu5E59p1kckNePyvEsl CKUakp4wt1NXb3lKJ8X4ykyAVVy+8dn41IWVCxAXuF+i7XHcD9QApllmjVGWLEIPij xXIhQAK2basJl0KKRox2KS8sFsIrK85+6zcZXLQgW43sNUTXyVRI70ZUs7a0if6oEP XpFXR4QIHSin3kZjLsOswYBtP6Gp+je2dK94ykX96jxFoqL1uspCHcdy23JaWvauKL rMqh7DW0HsLDg== Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 981CC6335F for ; Fri, 9 Dec 2022 10:01:34 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DQQSbHoe"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id n7so3061423wms.3 for ; Fri, 09 Dec 2022 01:01:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AXCdNqevCR4XHkTMpqcZ3r5O13khl/GMC4Xe7cZRkzE=; b=DQQSbHoe51UA3tDonwfFql9HVVgQ8wPaFO+/DBT9CVHzWVDPbvzQx0E5cypwBJ2AV+ DP5NKpGet/AgGfJYGfGZ+muRogqgl614x6e6v9tSBNlQ/8pyTGhUJssW84m1L+58fxkl m9uyfeEl1SAFC/iDzDA81Rcxk6dLwlGYp5aerbbfSGSgOUtuz+w4oxY55gLXFdTS6Jaz ebmwcm3QzBCSY0FmymQhd2JdeIYTSqBvoZIMfUUQGr9FA12Uek4nf175FG7kQ1epdS/a iimslcFwPwP86ku6WL5DyVF6NGMX+pHTH00qxyir4scg5KneSD2xACnYjwJ6YLIu9Bit 0apg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AXCdNqevCR4XHkTMpqcZ3r5O13khl/GMC4Xe7cZRkzE=; b=sX2mC4FtfT8ymE3VlyWfY9h9o8QD2CNX88nucIA4Ma0gCu6ZOaehfyc2kA+O95Ne/V rC2OBY5I+MnDxbgVtx0k75pvzQczvNSmzUV4K+At744VyCwSJtKr1gHCAWwufCvGfYjf f4vdi7U3gLcROBawHhw4pGklCAKoZYLaR8yxp7igsUtmXBHSNBLuhV7NT4xAh+om9O8Y ACn9VKnInol45lM0uMTsMksGmkkYRjcalr41gYzRQmMCeoukI2eYCwbwLav3CcMxrG4F SLU2n5rvbCf6vd7tZDX9+pc5/IXbT0CsJdMSrGE5H3YOLZh4F1RIorBxdHm4rue+9vW3 mZyg== X-Gm-Message-State: ANoB5pl1ouAro4d7Lnm80z0pp+7x/+iMtRWamUlT+byKyEC52ugjD0I9 mADVg1kTWaba1ToufEycVq0o4QStgshoDUlb X-Google-Smtp-Source: AA0mqf6aBOuTLf6hR7xhtKA6QAWg6nE7K/OixmWTh4P6iZZrmdvfVeCyfe3PirlsCJxDzBeejj0fqw== X-Received: by 2002:a05:600c:4e50:b0:3c6:e63e:23f6 with SMTP id e16-20020a05600c4e5000b003c6e63e23f6mr4397490wmq.37.1670576493820; Fri, 09 Dec 2022 01:01:33 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id bd10-20020a05600c1f0a00b003cf774c31a0sm7773674wmb.16.2022.12.09.01.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 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 Subject: [libcamera-devel] [PATCH v4 07/12] pipeline: raspberrypi: Read config parameters from a file X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add the ability to read the platform configuration parameters from a config file provided by the user through the LIBCAMERA_RPI_CONFIG_FILE environment variable. Use the PipelineHandler::configurationFile() helper to determine the full path of the file. Provide an example configuration file named example.yaml. Currently two parameters are available through the json file: "min_unicam_buffers" The minimum number of internal Unicam buffers to allocate. "min_total_unicam_buffers" The minimum number of internal + external Unicam buffers that must be allocated. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- .../pipeline/raspberrypi/data/example.yaml | 20 +++++++++ .../pipeline/raspberrypi/data/meson.build | 8 ++++ .../pipeline/raspberrypi/meson.build | 2 + .../pipeline/raspberrypi/raspberrypi.cpp | 45 +++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 src/libcamera/pipeline/raspberrypi/data/example.yaml create mode 100644 src/libcamera/pipeline/raspberrypi/data/meson.build diff --git a/src/libcamera/pipeline/raspberrypi/data/example.yaml b/src/libcamera/pipeline/raspberrypi/data/example.yaml new file mode 100644 index 000000000000..001a906af528 --- /dev/null +++ b/src/libcamera/pipeline/raspberrypi/data/example.yaml @@ -0,0 +1,20 @@ +{ + "version": 1.0, + "target": "bcm2835", + + "pipeline_handler": + { + # The minimum number of internal buffers to be allocated for + # Unicam. This value must be greater than 0, but less than or + # equal to min_total_unicam_buffers. + "min_unicam_buffers": 2, + + # The minimum total (internal + external) buffer count used for + # Unicam. The number of internal buffers allocated for Unicam is + # given by: + # + # internal buffer count = max(min_unicam_buffers, + # min_total_unicam_buffers - external buffer count) + "min_total_unicam_buffers": 4 + } +} diff --git a/src/libcamera/pipeline/raspberrypi/data/meson.build b/src/libcamera/pipeline/raspberrypi/data/meson.build new file mode 100644 index 000000000000..1c70433bbcbc --- /dev/null +++ b/src/libcamera/pipeline/raspberrypi/data/meson.build @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: CC0-1.0 + +conf_files = files([ + 'example.yaml', +]) + +install_data(conf_files, + install_dir : pipeline_data_dir / 'raspberrypi') diff --git a/src/libcamera/pipeline/raspberrypi/meson.build b/src/libcamera/pipeline/raspberrypi/meson.build index f1a2f5ee72c2..48235f887501 100644 --- a/src/libcamera/pipeline/raspberrypi/meson.build +++ b/src/libcamera/pipeline/raspberrypi/meson.build @@ -5,3 +5,5 @@ libcamera_sources += files([ 'raspberrypi.cpp', 'rpi_stream.cpp', ]) + +subdir('data') diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 8be46962e825..9a316eda6fea 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -40,6 +41,7 @@ #include "libcamera/internal/media_device.h" #include "libcamera/internal/pipeline_handler.h" #include "libcamera/internal/v4l2_videodevice.h" +#include "libcamera/internal/yaml_parser.h" #include "dma_heaps.h" #include "rpi_stream.h" @@ -1149,6 +1151,7 @@ int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) */ stream->setExternalBuffer(buffer); } + /* * If no buffer is provided by the request for this stream, we * queue a nullptr to the stream to signify that it must use an @@ -1682,6 +1685,48 @@ int RPiCameraData::configurePipeline() .minTotalUnicamBuffers = 4, }; + char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RPI_CONFIG_FILE"); + if (!configFromEnv || *configFromEnv == '\0') + return 0; + + std::string filename = std::string(configFromEnv); + File file(filename); + + if (!file.open(File::OpenModeFlag::ReadOnly)) { + LOG(RPI, Error) << "Failed to open configuration file '" << filename << "'"; + return -EIO; + } + + LOG(RPI, Info) << "Using configuration file '" << filename << "'"; + + std::unique_ptr root = YamlParser::parse(file); + if (!root) { + LOG(RPI, Error) << "Failed to parse configuration file, using defaults"; + return -EINVAL; + } + + std::optional ver = (*root)["version"].get(); + if (!ver || *ver != 1.0) { + LOG(RPI, Error) << "Unexpected configuration file version reported"; + return -EINVAL; + } + + const YamlObject &phConfig = (*root)["pipeline_handler"]; + config_.minUnicamBuffers = + phConfig["min_unicam_buffers"].get(config_.minUnicamBuffers); + config_.minTotalUnicamBuffers = + phConfig["min_total_unicam_buffers"].get(config_.minTotalUnicamBuffers); + + if (config_.minTotalUnicamBuffers < config_.minUnicamBuffers) { + LOG(RPI, Error) << "Invalid configuration: min_total_unicam_buffers must be >= min_unicam_buffers"; + return -EINVAL; + } + + if (config_.minTotalUnicamBuffers < 1) { + LOG(RPI, Error) << "Invalid configuration: min_total_unicam_buffers must be >= 1"; + return -EINVAL; + } + return 0; }