From patchwork Fri Dec 9 09:00: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: 17966 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 E6E4CBDE6B for ; Fri, 9 Dec 2022 09:01:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 76DB46335A; Fri, 9 Dec 2022 10:01:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1670576493; bh=aPx61EyK5426KHTbbJ5ftutp6M7sRBs01qIVaRATqP8=; 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=Q1mQ+0s84kxml93hA37Ye5kDN3Vbbb3n16TgH0ugW1Rb8P8OYDM5jfgPw8M5AOtjC n1gqLbyI2gWNhFCY595BEvIt6zwBbdTT1VDkA44o85tg/oicfuTSyuxHYkpLYjUyoX IPS5TGzwSNBR8L6iGamtKk/5VAe6+8AJyVIWETzPGLDyRMKDG0wcggJmzGF7WqABI5 LaixJKH79CJ8j3NFXbbkcW7Wmsmo6T2CIidvwTnJq+DAt+oA5LFwQk9aktbDXjQ3Sq SyO2g+GhUWp9SIHRPq8KUp+8x0j3EvoqtBtvw4VhXejsA0b8mrfIKWxArsnkiGTzGe mZSIE3LL7/rHg== Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D3BB61F1E for ; Fri, 9 Dec 2022 10:01:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="fSS9WgmG"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id v124-20020a1cac82000000b003cf7a4ea2caso5258199wme.5 for ; Fri, 09 Dec 2022 01:01:30 -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=gYE4rAs6mWLRRzePAtTOx6PsgAWDmX1Qry7rwDpq1OM=; b=fSS9WgmGx/w2uBE7dksCGM9VWJOUEO0d/LYazmZ2RZH5E/TOoM70o9YRwG2xQCunUR PQtxtXiPFTFvUdsxNbi13uMMN0lQozeO0QArjdLn/G4+wtdtZuVQdsrsg1OkRtSYVvTS fvM3L6g2WVEth9bsC9iuA7/DsJe7v/2lnZvRWzY+H2jlM0qebKS2bEA8utEufa/iCkv7 PD6aU8ajL1prJxIcP0+93XVUpIb4AAmOjnzbbDoeWikRRzkI7Y3GCWNflx/V8cHGWAcQ G2j1oQOQ4rjmVmHf3M/vtlRu4Ue2nwpPTwlDuKeWL4faYksS0yBZE+7kEYie/kIKTVl2 OOYQ== 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=gYE4rAs6mWLRRzePAtTOx6PsgAWDmX1Qry7rwDpq1OM=; b=ZvAe7CmE2LaRLoH9qKM391sXh1V/zMWFSyrHHbVIZphFZhZyQaCVmamx08H7LViV9u XbbrppTleQPNkq5e38X8PMBQ2LCt1CXmAx2O9NccHdWNsP9qDm0lR3V3rTslXmf9fiAc FbsAc8GX+1ITz4v3hV6oKDzFMlaIv2EnzmdJBPyQ6SI7QbukabhG+rZxrTe8iv6E2xk+ rVhF8X+CDUBpanvLuOkkJgGAWysRQnVpYLgkGKfQ7+dM0IdsrFTzdkCczR8gO3PqzP53 HP8r80aQ28s2x3O46Id7ZuBskkEQ0+PjKf9Y+XdQ4dKdin7B8Z3dsc19NkOdp/aWnTQe 518A== X-Gm-Message-State: ANoB5plyrff5OYbGA/m+MUsiDAe5NND+P+2ys41xcJ8RXCRDhEhSITcK KTaTz7ubbL6DygAU3yravtRb2NdPdUU/sDCa X-Google-Smtp-Source: AA0mqf5c9063c+cCV0nhviTdCoLr9+rXzu9TdP6/8gK0CXvBNAEx6/w28V66vKd+7tMdokN/jl4MAw== X-Received: by 2002:a1c:7316:0:b0:3c6:e60f:3f66 with SMTP id d22-20020a1c7316000000b003c6e60f3f66mr4282831wmb.29.1670576489598; Fri, 09 Dec 2022 01:01:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 01:01:28 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 9 Dec 2022 09:00:40 +0000 Message-Id: <20221209090050.19441-3-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 02/12] libcamera: pipeline: Add a platform configuration file helper 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 a new helper function PipelineHandler::configurationFile() that returns the full path of a named configuration file. This configuration file may be read by pipeline handlers for platform specific configuration parameters on initialisation. The mechanism for searching for the configuration file is similar to the IPA configuration file: - In the source tree if libcamera is not installed - Otherwise in standard system locations (etc and share directories). When stored in the source tree, configuration files shall be located in a 'data' subdirectory of their respective pipeline handler directory. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- include/libcamera/internal/pipeline_handler.h | 3 + src/libcamera/pipeline_handler.cpp | 60 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index ec4f662d7399..4c4dfe62a680 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -65,6 +65,9 @@ public: bool completeBuffer(Request *request, FrameBuffer *buffer); void completeRequest(Request *request); + std::string configurationFile(const std::string &subdir, + const std::string &name) const; + const char *name() const { return name_; } protected: diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index cfade4908118..a515ad5ecffb 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -8,6 +8,7 @@ #include "libcamera/internal/pipeline_handler.h" #include +#include #include #include @@ -534,6 +535,65 @@ void PipelineHandler::completeRequest(Request *request) } } +/** + * \brief Retrieve the absolute path to a platform configuration file + * \param[in] subdir The pipeline handler specific subdirectory name + * \param[in] name The configuration file name + * + * This function locates a named platform configuration file and returns + * its absolute path to the pipeline handler. It searches the following + * directories, in order: + * + * - If libcamera is not installed, the src/libcamera/pipeline//data/ + * directory within the source tree ; otherwise + * - The system data (share/libcamera/pipeline/) directory. + * + * The system directories are not searched if libcamera is not installed. + * + * \return The full path to the pipeline handler configuration file, or an empty + * string if no configuration file can be found + */ +std::string PipelineHandler::configurationFile(const std::string &subdir, + const std::string &name) const +{ + std::string confPath; + struct stat statbuf; + int ret; + + std::string root = utils::libcameraSourcePath(); + if (!root.empty()) { + /* + * When libcamera is used before it is installed, load + * configuration files from the source directory. The + * configuration files are then located in the 'data' + * subdirectory of the corresponding pipeline handler. + */ + std::string confDir = root + "src/libcamera/pipeline/"; + confPath = confDir + subdir + "/data/" + name; + + LOG(Pipeline, Info) + << "libcamera is not installed. Loading platform configuration file from '" + << confPath << "'"; + + ret = stat(confPath.c_str(), &statbuf); + if (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG) + return confPath; + } else { + /* Else look in the system locations. */ + confPath = std::string(LIBCAMERA_DATA_DIR) + + "/pipeline/" + subdir + '/' + name; + ret = stat(confPath.c_str(), &statbuf); + if (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG) + return confPath; + } + + LOG(Pipeline, Error) + << "Configuration file '" << confPath + << "' not found for pipeline handler '" << PipelineHandler::name() << "'"; + + return std::string(); +} + /** * \brief Register a camera to the camera manager and pipeline handler * \param[in] camera The camera to be added