From patchwork Wed Jan 18 08:59:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18134 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 3BEBFC3294 for ; Wed, 18 Jan 2023 09:01:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C72C9625E8; Wed, 18 Jan 2023 10:01:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674032486; bh=2BVu3khsD0IidZZis0CYJfsB9vWYAIIJPnK1/awr90k=; 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=f3e7CkYa/wLAY+fXha/699TgzJf2/ZU1Z5NlAkEbMl/nuVRfmYtgYuoOQtTGcsMJx 21biNK4yrvzTV+wI6jdUmijke9c0jjLjtUYKBmjV+W8fAxPbMKchetpwJXJXerlLRs 7TluVtIAwSQG38+qFOyJdQl66TbwWL4ui9aAArdhpWNqPjGGkHXNk5whBds3ZBs+2t dywZhJsVN84epEYx9QrxQ1SgvbfvbXMRanvITZkumD4Pnvw70/OASIyFEDxUNGNsDr OIPAkUN6AE5pB4tCIbwqC7ZfK9qVsHVO3oCgfh82XkYNQbLPiiRzDmtNlufejaIDno Uv2ysDv9Wc4ww== Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BA893625F3 for ; Wed, 18 Jan 2023 10:01:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lo9G4s1l"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id e3so23962098wru.13 for ; Wed, 18 Jan 2023 01:01:20 -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=XEl4otV2Go+V21qaL70bccDWfHDHc7iqcSfag6Wgyg0=; b=lo9G4s1lzAj4ZiD8InZ/89EoDTI4Fo7rm1b3Mcy8BXPmtbGzK3VzGA654m1/reHUND eYzKX17EkTxmOLR0gvNbn09jOIcBSEltX4fBPeOt3dpxXzPMXB/+q01DsKRQ5/mG4JYv 9TnvSfwOW12PUeSMzV8ElO1e3vUFZSgmYcH8N+GFNswsPx7F+O14bbhonekqRTNoOHP8 eUsMEril0UYHrQv0c1QswWthjYyKqOPPaDjF7T6Vv0eDh3Ubbhvaw7T3aObrInJxRCMs I//YAla4y/r/6ZlQLdr6FCHFvfC3irXfXfpN980retqpPq0cQ75h09roCj/7xiU0umJj gUsA== 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=XEl4otV2Go+V21qaL70bccDWfHDHc7iqcSfag6Wgyg0=; b=hAFP/wRzk0pM3H71HQVpAJJpdODUWP3cV4POOwKtjAIkdPXbaJYlYOziWnNGAB/HVA wGCtySN95qOwHpTsRv+/ksWalbliUMXyBA6dY23pXA2XjK3I1RcCveMBYgzva+nZTgUJ sI/Ss7vZpVcrKojEq7GH9Vpx3b8xy5cEcknOmCL5t/rKWJvwwu4k1C25wLW41fToGyLS ODg7YEX+sRZuWICon1b1YHYMseikvZqwG90gQLubL1l8Mv50iHHs2aCaFAK+faOUVepM gxktAMzvvxUG91jJbGqDbSBxqW62aIAm9F3EuCfUitnPfYlY49/pu1As8+uijPs59idl +glA== X-Gm-Message-State: AFqh2krqHtZYyODhxr5pMbc+c+O2bskFugC0NanHU5gt+cYl+CDUrW3q ww+lshXG6K0unJuei9OW7izgy4BwHC4EOc905Xk= X-Google-Smtp-Source: AMrXdXv0RhUSuTIuoAnsK21m0wa9spfyY3GyWK0KavjyJP2DbeRFw9R+6058gQrzrRjbYSaGyQrayA== X-Received: by 2002:a05:6000:608:b0:2bd:db84:d663 with SMTP id bn8-20020a056000060800b002bddb84d663mr1729047wrb.5.1674032479875; Wed, 18 Jan 2023 01:01:19 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id i6-20020adfe486000000b002423dc3b1a9sm30312464wrm.52.2023.01.18.01.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 01:01:19 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Wed, 18 Jan 2023 08:59:48 +0000 Message-Id: <20230118085953.7027-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230118085953.7027-1-naush@raspberrypi.com> References: <20230118085953.7027-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 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 6ed4cc2c7ba7..2b396f1db9b6 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" @@ -1150,6 +1152,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 @@ -1683,6 +1686,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; }