From patchwork Tue Dec 6 13:54:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17945 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 8CF2CBE08B for ; Tue, 6 Dec 2022 13:55:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E29CF63348; Tue, 6 Dec 2022 14:55:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1670334908; 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=e56UvPGTKOcRiyYmvuQfd/emd3Y/LI966nYU2BLjHFqWofgs4vUy4As9E3cs8IIm+ /gCwt0xqGbqI1BeNbXAiAKsHgYtjmRgldYRPl1YaIPlT2Q9pyuvdttWLnigqeu5fwt 7OnlcN6U8GJdjDFBqeay3A2zPQ3+IC7TtrQ7aWXmh6rPO4el7hD4jcuwhprbQuG3zb PYmIUfas+w77ASHfvXSAydIpIf+cRNP4FM3Gp6hYgv51esJVCi+kVWs2qK+Zc6CeDr IuSS+NGBiZn9jhL4he2MU7SibtymRTZMNMRoz/+hEI8rbits0p2K/ntqfq63c4dwna djnt2rzSrellQ== Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4CB4263339 for ; Tue, 6 Dec 2022 14:55:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Wy20ClN5"; dkim-atps=neutral Received: by mail-wm1-x32f.google.com with SMTP id h8-20020a1c2108000000b003d1efd60b65so854302wmh.0 for ; Tue, 06 Dec 2022 05:55:07 -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=Wy20ClN5o6fkskoBBcqhHpoLE2PjRegwAaGM80tounQw+yN0xEFBWL9U4J/lNuxWl/ xypL1rf7kL3Q5JOInYIMu0HS3rWXTw24sem/PVQcY64OBucgPRpe3rWuleyjZG5WOBaA VzA9gxzHC+gWaiCyTk62kM1avUU/kUcfwu9kmfVoc8OZPxUKSo0HB03o+q4W88ns6itd tbPeEVDo1Od3ZNWf3nalcr4+aoZmoy4Sq/S2pIE/Ioedd0ok/Z9lAcPvvq39lo2TSgGU BhlrHCYyAg4Ro2X752aRXEnR6NpvAPKo29lSMQbLerYqfWAvtK5lWW6EuCmA9AJu6zg2 +1Tw== 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=NOLgE6TmUUmSPidplqjr8Nj6TrBWUlNU3Lhje9geBdkFn2WXi/ebYfGcp7KYvi8Qdm HrrskVEjQJcyLnNEw+Hcyie16LGzX5ygBbqxb5Nxulvs6AoqM3yIjN1Ljag2duK67u/O ughJDbUfaB763CnLlb6i1N1+739IYGBLIXpuO6KfsEunue8z5xyJHxSEHYfXciQfznkJ i6VGWsTEjf86rqGR8UsRlfCYpYuqae1S93oIdZebRARzwEe10XhescIjF1gVCIVxaF3V qJOz/lNRhRf46yvI7uYyidYlLOzKDHiw+i3etCAZMqQR6SLIm9EaGYsRfO9WrcBWfGyJ znCg== X-Gm-Message-State: ANoB5pnQ/eDGogHiqhf7ia51yeTprp3N5nHmhWy2OjxWZ+GK+jsJkTZi aVddspFXWYiOxrmcJxxEhHnM4XRWLsTu8Rjk X-Google-Smtp-Source: AA0mqf7VoXjA7ELQ+kjHxzSPtvYVh3yhxVHxKirY5adYql/nUgqh4hSe8hgWvJ8og+yudin9YRQ0mQ== X-Received: by 2002:a05:600c:2284:b0:3d0:837c:8561 with SMTP id 4-20020a05600c228400b003d0837c8561mr14397919wmf.168.1670334906673; Tue, 06 Dec 2022 05:55:06 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q6-20020a05600c2e4600b003c6bd91caa5sm19444059wmf.17.2022.12.06.05.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 05:55:06 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 6 Dec 2022 13:54:48 +0000 Message-Id: <20221206135459.25521-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221206135459.25521-1-naush@raspberrypi.com> References: <20221206135459.25521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 02/13] 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