From patchwork Tue Nov 29 13:45:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17908 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 3F5A9BE08B for ; Tue, 29 Nov 2022 13:45:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 37F296333E; Tue, 29 Nov 2022 14:45:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669729540; bh=sEBfzHnphfZAo4fHYpOPsUdpXVpRV0xOAvTaMkFcF/E=; 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=TJejGBUBKtzWH14+2e/spCCnJxG/7F853a4Gwb3KRF+Y1X16GL/SsMn0tkv0FdVSZ 2rCiRvwaGnWPLCt+dTr06iL3/a0tqDQ9cpaOh1TcLlLo2KhKTzTEYN1J6goMwhmu1x EfCER+z8iHq1Nrbuv0QPNnaCW7gqmDLgmJJXqpsKiI/o2mHcYJXaTwn3KjPh60PBoJ MjZ8X/5xVsFKg2MEQ+JiKr24F9qH89AoBK2KkDlc2/R+A2R7++q4azPlF+znBhzEOW LUpVLWCYJDjl7fNz5TIwcRXgftQndvO6N5pyz5CYIxb8Dc1NDqqun2hQCsKefZ4Wmw keoGde0jnHItw== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F35A863331 for ; Tue, 29 Nov 2022 14:45:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="CeGxy6sk"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id 5so10931800wmo.1 for ; Tue, 29 Nov 2022 05:45:38 -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=juEPIBZJVl2IlKL+jRo+h/Z5jZ0Qb5/58kfmj36PGFs=; b=CeGxy6sk4CS14gmqzUlAov5/Yc0UvR1U9rmdExWhs/FyD615T++r9LlIL4Faeb74bh 5GweChlosWGmcUXJPUwbo/znfkHBgoM1QA6USwVYGnG0SDqRYYPHRIhr9uXKIDHcIG30 JzaNd8dsc6RcFttdeNq7sIGtgIz4XvTZI1LojSRvfZrq3PSlDRVjBpI4/emcz5mt0zuc ElxUu2iEVZAJudVbWIpbNnYavn0VUgB1ft3tAr8P5ZMV1OpzI2Ma+wrmkYl+Lo+F5Lff qt9S6RZFaCoiMYFSvKrGAXdN6p8BKTGkme9dKt9Gge5aPPDGSdQseO1mMMQEkSAVUKzE sJXw== 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=juEPIBZJVl2IlKL+jRo+h/Z5jZ0Qb5/58kfmj36PGFs=; b=EatBzoUVLVQfDZMREs38efZ47TqHW4gSZM1bitF1s320J/CDD2kVIsVTOx8KFRzoK6 J1QOkhC12UWGfsPrRA4+fwwB6YNofo7QngPZruDzLrhhRVUYZyx7OjSHczv0dfoyvTIb wDpsYpb0XqUbJcVLRnTehb4PZo68DxJMyhEH7rvzUJKE0jGfPP7Iikp9nScfm/vP7kbm b3z7qC/3Y56/NNj9NPSYWO2pN2FJ2dDzyU1LnDwRSMBoEW7HTNkau8Z0S5So5pKT8v0r rWptTczRx/8ABO/OJxW66BudB5qviOzVOU77sI1E1waB44gAHx4eCiI+L6+y2iMWcIaQ /R1Q== X-Gm-Message-State: ANoB5pme1iNZ/bCzxEi9DgUwDqG1XyqSQ/pZ8oUloEixqcVJJzIZh7H5 tcNycEWdVx7xJcuDXkLKGugs/rF8LyV3pw== X-Google-Smtp-Source: AA0mqf7jC0eBG+7BoD4kp8j8AsmJDY/mC367rFMYTl2NnunG4ktbUPcaCUMbPmEnQfs2RyZvfigtwg== X-Received: by 2002:a05:600c:4e06:b0:3cf:703e:1d88 with SMTP id b6-20020a05600c4e0600b003cf703e1d88mr29731194wmq.155.1669729538330; Tue, 29 Nov 2022 05:45:38 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id n8-20020a05600c3b8800b003cfbbd54178sm3565636wms.2.2022.11.29.05.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 05:45:37 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Nov 2022 13:45:25 +0000 Message-Id: <20221129134534.2933-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221129134534.2933-1-naush@raspberrypi.com> References: <20221129134534.2933-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 01/10] 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..cd27bcf944d6 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -76,6 +76,9 @@ protected: virtual void releaseDevice(Camera *camera); + std::string configurationFile(const std::string &subdir, + const std::string &name) const; + CameraManager *manager_; private: diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index cfade4908118..b4579671ba5a 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 @@ -638,6 +639,65 @@ void PipelineHandler::disconnect() } } +/** + * \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(); +} + /** * \var PipelineHandler::manager_ * \brief The Camera manager associated with the pipeline handler