From patchwork Fri Oct 14 13:18:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17600 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 C92E5C327C for ; Fri, 14 Oct 2022 13:19:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6C9F362DD4; Fri, 14 Oct 2022 15:19:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665753540; bh=nz3wJ1qW+PINInuZKlj5y+yw3Z7lfUw7r92acE02Cog=; 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=P6nUguKBTFllMLulI0nHtDTSdP8Vb6rpvppicF6ZHtobB+AQQtzO1NrojRvgJkSng oBa9H5JXTgUMJgTr5vbv8t+w3zyZfmujBnd7csLyORxlWx/PIMhXr5h61tSD8cOTKM +4Bce+yEUgsNewFxfMM9k442xDlxAMDfZ7jAhLOQWa35nEKiyBcRbbdHKyc0BSOAo/ H9QA1QZ+luNcXNQ3w2y+hnsPUWBQFbVMZSF+vy9CpBbTotwzSaUGoWf44RE/ZHAq4y QnE64Pgf0OJdF4K8UfZNL3wZ/TEtzLTFmn068Lv8aWy4DXu9IpZ/k7QHFiFLjxD2EK 7i4fXgI67pj2w== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6A2B262DC2 for ; Fri, 14 Oct 2022 15:18:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="E6qtY5AI"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id l16-20020a05600c4f1000b003c6c0d2a445so3490143wmq.4 for ; Fri, 14 Oct 2022 06:18:55 -0700 (PDT) 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=xz66QQBqRMHVmsLde1uoiES/yRhcr0v24H45LmZwNm0=; b=E6qtY5AIUBKqauKjRhUmMFBsLl31Ruiaf/kZCUAExBJYxRHPZd16pLLgphUmEpjkhg xHeK3uLPqwDG5dK+JTu64ci7QAfPGLXhor1MYiDcJiG+DaKPXJFUIjpEQXc9XSEFZ1Mr cc34fDsoZsMIL5/FBbiWeynH0s/6/MuvZ5DsM0uCbIHnJlyrgTeIYK5EBXIi3mRixwJD H2A+hs8sXGWV/ulM4Y3X5aZoc+5AtGULfDVggxN9uHfF7LOeXOCbMX7iDdSDa+SuGBN6 iBt1qGVkzHtpWB0/Nb9ebgYO+VIWNiWlnherXeAnS6qHj/uqrzOcfyXrlrD/fn3rYjuk oJtg== 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=xz66QQBqRMHVmsLde1uoiES/yRhcr0v24H45LmZwNm0=; b=JZ4CFS03G+Q6HDxgxUmPebzq279xiki/MRzUm+TDVGCNyw+CQXdwCsiWGj7WpziSwe 1BxNjB3dZpxMSvsDrZHWNg+wF7h5UVDmeV4Tssl8d2/Bn2tNeWUYxu4q4c8vEh4QrwCW sEupPbC53HqLa6Ybq6kNZ6q0jkECWxLXGEtT+m9Wc0htcycqQtx8R9V12FT2AlA40aic MgKAhOoIyZWefoaCynVch5IyiayV46z7ZNKxzdZjIwWZdnl2brdw16WfReoaAu/m8ICk 9pof3m/7GGfuPXPO/5esisC2vvY889RiDnCburd3CsOXyHzIGpBKaxwYh9k9psJDL2zO Zqpg== X-Gm-Message-State: ACrzQf3lo0V74V9Bxli3BHzpkQYuf7vXPeIgOApxKDDX6xIbObBCslSl zxguwanvUblxdgvm5qKE2pM8D7ch7/cjCw== X-Google-Smtp-Source: AMsMyM6o7YSWlcNXiq4QkSnh5oAYeY8gc9lttQZuCfTPbZgTy1RBNJ3yP1yr37+AjTRCfVs7igwcyw== X-Received: by 2002:a05:600c:4194:b0:3c3:d0ed:2d44 with SMTP id p20-20020a05600c419400b003c3d0ed2d44mr10652925wmh.151.1665753534792; Fri, 14 Oct 2022 06:18:54 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id g17-20020a05600c001100b003c6bbe910fdsm8282458wmc.9.2022.10.14.06.18.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 06:18:54 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 14 Oct 2022 14:18:40 +0100 Message-Id: <20221014131846.27169-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221014131846.27169-1-naush@raspberrypi.com> References: <20221014131846.27169-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 04/10] 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" Read the platform configuration parameters from default.json config file. Use the PipelineHandler::configurationFile() helper to determine the full path of the file. The default.json filename can be overridden by the user setting the LIBCAMERA_RPI_CONFIG_FILE environment variable giving the full path of the custom file. Add config parameter validation to ensure bad parameters cannot cause the pipeline handler to stop working. Currently three 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. "num_output0_buffers" Number of internal ISP Output0 buffers to allocate. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- .../pipeline/raspberrypi/data/default.json | 20 +++++++ .../pipeline/raspberrypi/data/meson.build | 8 +++ .../pipeline/raspberrypi/meson.build | 2 + .../pipeline/raspberrypi/raspberrypi.cpp | 56 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 src/libcamera/pipeline/raspberrypi/data/default.json create mode 100644 src/libcamera/pipeline/raspberrypi/data/meson.build diff --git a/src/libcamera/pipeline/raspberrypi/data/default.json b/src/libcamera/pipeline/raspberrypi/data/default.json new file mode 100644 index 000000000000..d709e31850af --- /dev/null +++ b/src/libcamera/pipeline/raspberrypi/data/default.json @@ -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, + + # The number of internal buffers used for ISP Output0. This must be set to 1. + "num_output0_buffers": 1 + } +} diff --git a/src/libcamera/pipeline/raspberrypi/data/meson.build b/src/libcamera/pipeline/raspberrypi/data/meson.build new file mode 100644 index 000000000000..232f8b43c5fd --- /dev/null +++ b/src/libcamera/pipeline/raspberrypi/data/meson.build @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: CC0-1.0 + +conf_files = files([ + 'default.json', +]) + +install_data(conf_files, + install_dir : libcamera_datadir / 'pipeline/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 450029197b11..bac7a66ba900 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" @@ -301,6 +303,7 @@ public: }; Config config_; + unsigned int numUnicamBuffers; private: void checkRequestCompleted(); @@ -1140,6 +1143,19 @@ int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) */ stream->setExternalBuffer(buffer); } + + if (!buffer) { + if (stream == &data->isp_[Isp::Output0] && !data->config_.numOutput0Buffers) { + LOG(RPI, Error) << "Output0 buffer must be provided in the request."; + return -EINVAL; + } + + if (stream == &data->unicam_[Unicam::Image] && !data->numUnicamBuffers) { + LOG(RPI, Error) << "Unicam Image buffer must be provided in the request."; + return -EINVAL; + } + } + /* * 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 @@ -1398,6 +1414,7 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data) { RPiCameraData::Config &config = data->config_; + std::string filename; config = { .minUnicamBuffers = 2, @@ -1405,6 +1422,44 @@ int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data) .numOutput0Buffers = 1, }; + char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RPI_CONFIG_FILE"); + if (!configFromEnv || *configFromEnv == '\0') + filename = configurationFile("raspberrypi/default.json"); + else + filename = std::string(configFromEnv); + + if (filename.empty()) + return -EINVAL; + + 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; + } + + ASSERT((*root)["version"].get() == 1.0); + + 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); + config.numOutput0Buffers = + phConfig["num_output0_buffers"].get(config.numOutput0Buffers); + + if (config.minTotalUnicamBuffers < config.minUnicamBuffers || config.minTotalUnicamBuffers < 1) { + LOG(RPI, Error) << "Invalid Unicam buffer configuration used!"; + return -EINVAL; + } + return 0; } @@ -1471,6 +1526,7 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera) */ numBuffers = std::max(data->config_.minUnicamBuffers, minBuffers - numRawBuffers); + data->numUnicamBuffers = numBuffers; } else if (stream == &data->isp_[Isp::Input]) { /* * ISP input buffers are imported from Unicam, so follow