From patchwork Fri Jan 27 15:43:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18207 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 DB633C3297 for ; Fri, 27 Jan 2023 15:43:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 56DEE62608; Fri, 27 Jan 2023 16:43:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674834226; bh=/5OUM1/xRqXPdDagWUAFW17IXHeqW1pka9Exg+IwItU=; 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=avPnl92JgsBajeVKCQQUp/QZyLIZwKmQt1QZIClMNBaXpHBoAR9gvFOKH3sGPQPk6 ts15pwQIG51RoBaAcHfG2v8ZSWFhRpf8/MxsCLcnEKwaZvEZRIw1EVsjIcPRpt/NUG Xhbx8JWOl3bZmsEM+6wFpxRRQU1sblTPYsQsTqL0KRfCauYl9C067uAIvNWAPtxwAk 8Hiel5ErROK5/p7sGZf3vmjQoKcZSYzysPgo6c2KX42FBRdbmNxtKkrcNfRolzizyZ JTDI/N55Wvp8KEsRJYjDQ37fesqba5beCKyfnqfKHIMv6/E0qcHsFeWw4dScUalest KnSOS1p/dRMVw== Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A8CC61EF9 for ; Fri, 27 Jan 2023 16:43:40 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="a9n94iy0"; dkim-atps=neutral Received: by mail-wm1-x329.google.com with SMTP id j17so3774960wms.0 for ; Fri, 27 Jan 2023 07:43:40 -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=E6dHlkOnJMQJvyJm8IaDqSUyf4r2Yg8uomKDc/nSU+s=; b=a9n94iy0MEoEPY2hhySvXgI8sph+Vl3eCzOW17jxM34oFCOb7nbNgQyZuLqstZo6UD AmAWS2RiaLwXfMxrZP0tB3oaWACsKA2WU2sonDY0cRTQ8qUmhhQHIuY9gO+lQPbtAQXd ANmImXJEv9pDXawPQdizgvZUcexlnO2WvTj5XVypKLsR8smWxgMF8DJqr13IRtWlpGiG /l4YOKSy/b5ZtE65NbkYYhoCqsGQIq/Zet2ROpOtknRt1avUu6ED1HUfI/b0pNR6xr2x rA235VZktlJzJA60l/rGESOUueXfZTkFpm59akUFUI9DEaYaq2XxZGdUFiVulhSjY6na P6gg== 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=E6dHlkOnJMQJvyJm8IaDqSUyf4r2Yg8uomKDc/nSU+s=; b=INMxRm2ROqFjK8pqAEzdmePhJqwyjsCypzSqyyo+3KTQXv0vQetSkgrVMVrdItinnn tpsa9juz24E16Z5QEsBiFQS01OTjCTnhtUnPl/u6G68W200vAOFtZUjB8yVGJUVaKbXU fiDoSBJXT7kDlCkaw71bU+PxsY+sOMobaycSUYMknuZSMj0/Yij1d+jNVCvdT23q4umw 8RfNB2CzLPXoTbdTDqrfuYyDsPI5jIXOFQ9lTS1g+pjtlc7OH9HbqRVDUBFecTdsGhSZ PGtjt+PHzYslM1Co0joAxAqGPy1sPnYLAjH5mX6wFtvd/Oswp07pBGMsLilRupIZM1K9 qVug== X-Gm-Message-State: AFqh2kq0vqykjjBduWOGwDWZGaW2PPDKXU22vJaleV+VUS+nCTIvYK6s 3g+Nrh55H9LPa+DFUaW8xrULqCIcNFaO0C6sVG8= X-Google-Smtp-Source: AMrXdXv5roefk4Zi+s+gIbQRgSK3gZQXqGrDsNDQmirGcsQfvTJL4QV454AW493PegC5aj424HwR6A== X-Received: by 2002:a05:600c:3ac8:b0:3da:270b:ba6b with SMTP id d8-20020a05600c3ac800b003da270bba6bmr41411738wms.41.1674834219684; Fri, 27 Jan 2023 07:43:39 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id h18-20020a05600c30d200b003c21ba7d7d6sm4549566wmn.44.2023.01.27.07.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 07:43:39 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 27 Jan 2023 15:43:14 +0000 Message-Id: <20230127154322.29019-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230127154322.29019-1-naush@raspberrypi.com> References: <20230127154322.29019-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 07/15] 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 --- Documentation/environment_variables.rst | 5 +++ .../pipeline/raspberrypi/data/example.yaml | 32 +++++++++++++ .../pipeline/raspberrypi/data/meson.build | 8 ++++ .../pipeline/raspberrypi/meson.build | 2 + .../pipeline/raspberrypi/raspberrypi.cpp | 45 +++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 src/libcamera/pipeline/raspberrypi/data/example.yaml create mode 100644 src/libcamera/pipeline/raspberrypi/data/meson.build diff --git a/Documentation/environment_variables.rst b/Documentation/environment_variables.rst index f092cbbd29c5..ceeb251a2ac0 100644 --- a/Documentation/environment_variables.rst +++ b/Documentation/environment_variables.rst @@ -37,6 +37,11 @@ LIBCAMERA_IPA_MODULE_PATH Example value: ``${HOME}/.libcamera/lib:/opt/libcamera/vendor/lib`` +LIBCAMERA_RPI_CONFIG_FILE + Define a custom configuration file to use in the Raspberry Pi pipeline handler. + + Example value: ``/usr/local/share/libcamera/pipeline/raspberrypi/minimal_mem.yaml`` + Further details --------------- diff --git a/src/libcamera/pipeline/raspberrypi/data/example.yaml b/src/libcamera/pipeline/raspberrypi/data/example.yaml new file mode 100644 index 000000000000..4662136e0be0 --- /dev/null +++ b/src/libcamera/pipeline/raspberrypi/data/example.yaml @@ -0,0 +1,32 @@ +{ + "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. + # + # A larger number of internal buffers can reduce the occurrence + # of frame drops during high CPU loads, but might also cause + # additional latency in the system. + # + # Note that the pipeline handler might override this value and + # not allocate any internal buffers if it knows they will never + # be used. For example if the RAW stream is marked as mandatory + # and there are no dropped frames signalled for algorithm + # convergence. + # + # "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 6064a3f00122..59e8fb18c555 100644 --- a/src/libcamera/pipeline/raspberrypi/meson.build +++ b/src/libcamera/pipeline/raspberrypi/meson.build @@ -6,3 +6,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 44b1727678c7..83e82bd2880d 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -39,6 +40,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 "delayed_controls.h" #include "dma_heaps.h" @@ -1154,6 +1156,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 @@ -1687,6 +1690,48 @@ int RPiCameraData::loadPipelineConfiguration() .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, Warning) << "Failed to parse configuration file, using defaults"; + return 0; + } + + 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; }