From patchwork Mon Oct 3 21:21:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17511 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 DAA0BC327C for ; Mon, 3 Oct 2022 21:21:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 96B0C601D0; Mon, 3 Oct 2022 23:21:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664832095; bh=P9y3UMgZ4IJhFKqKTFUxi/rvpJp6ryIoDA6yp7h1+w8=; 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=gewhZMmahmp5TKQ07LS4imNtt7xKy6X6nyYM+yYcTJITJr08gv7IfjvcvtiICB/Wf vD2PwPigV/zT0BpPMiqzUrfin8j1Z6t2hZWNHTBIUiNUYwqFjRKMtNqSX5/WVTzQFX 7aWxy4Jj/RIRSPUOYFKKZmRWddYFwwEhA07zXPHddY72WTx6xc8msBn7iLhRsObNGg AqVguGqUlwgCOmtg9VH3RWrcWYkHzEgLqTHon3kpE+pRy4sRISJtx2tvFPICheft0E e7iAWljiJKvaBapoz65lnxVv64yuk4QzP/VUbNCrwzzjYIE0Fz4rIvPZIAJlgLjH2w qAAwviqAgPn6w== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E54E601CD for ; Mon, 3 Oct 2022 23:21:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uv223wU3"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E3C8C440 for ; Mon, 3 Oct 2022 23:21:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664832093; bh=P9y3UMgZ4IJhFKqKTFUxi/rvpJp6ryIoDA6yp7h1+w8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uv223wU3tdLoCPVg8D/aViArPS35zr25d9ISBGOe/VdiisrjJAk3NcDMWva73chwF 7+OTsj1ChidXAaLedH2i66ESSgPMtt6ThuAy6sPD2uV0c4YMspvP1yFOiqovVSmeKn W0cKUYpvAZGgpX4PdQ+/4Uwrevs4ZkN+6hdibWT8= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Oct 2022 00:21:21 +0300 Message-Id: <20221003212128.32429-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> References: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/8] ipa: camera_sensor_helper: Make factory createInstance() function const 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraSensorHelperFactory::createIsntace() function has no need to modify the factory instance. Make it const. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- src/ipa/libipa/camera_sensor_helper.cpp | 6 +++--- src/ipa/libipa/camera_sensor_helper.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index d4dba4975e17..fde9bf5b8892 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -254,10 +254,10 @@ CameraSensorHelperFactory::CameraSensorHelperFactory(const std::string name) */ std::unique_ptr CameraSensorHelperFactory::create(const std::string &name) { - std::vector &factories = + const std::vector &factories = CameraSensorHelperFactory::factories(); - for (CameraSensorHelperFactory *factory : factories) { + for (const CameraSensorHelperFactory *factory : factories) { if (name != factory->name_) continue; @@ -299,7 +299,7 @@ std::vector &CameraSensorHelperFactory::factories() } /** - * \fn CameraSensorHelperFactory::createInstance() + * \fn CameraSensorHelperFactory::createInstance() const * \brief Create an instance of the CameraSensorHelper corresponding to the * factory * diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h index 7351fc7c2928..2042847f29e8 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -70,7 +70,7 @@ public: static std::vector &factories(); protected: - virtual CameraSensorHelper *createInstance() = 0; + virtual CameraSensorHelper *createInstance() const = 0; private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactory) @@ -85,7 +85,7 @@ public: \ helper##Factory() : CameraSensorHelperFactory(name) {} \ \ private: \ - CameraSensorHelper *createInstance() \ + CameraSensorHelper *createInstance() const \ { \ return new helper(); \ } \ From patchwork Mon Oct 3 21:21:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17512 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 DFA07C3285 for ; Mon, 3 Oct 2022 21:21:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1E03F601CD; Mon, 3 Oct 2022 23:21:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664832096; bh=KvqcdANCeqMf88XLPLtbLZi/p5eiyr6xbGwNV6d227I=; 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=ovdgyiVS16NfksNO3hhUxeQBKpJNsVqis9uOR9c65Ko4oejjrWPHuTfj5glAaOCsP nRm47Cyk7YFQXRmhS4eYtb/JvqYixK6F/crA+sXh7AKb8+6MXl3q1i+66MW3LJUD+7 S+Jf51wdxbkFIabdk+WFKxLWRZlJWBnETWvo0ZB8UucPn0Dmh7TwvGWPeVxuYGP31g 2500dVDMXJdr7JjCGmckZyFWgnIRbSmsO+OrLSCJ09O+TvoPKFVTWrcGLVG4y5hGFc MaW024UKSqFt66a9UNComrMMrup4MVbyedV4SAc1k1s2aOxF4ilV5A7ASTNu11jwt1 jVcw6cGLloZDg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CB5AB601C8 for ; Mon, 3 Oct 2022 23:21:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qJ7Qlysf"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 57016519 for ; Mon, 3 Oct 2022 23:21:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664832094; bh=KvqcdANCeqMf88XLPLtbLZi/p5eiyr6xbGwNV6d227I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qJ7Qlysf9+4+F79lmznrGvuKthiKPuT+k02uONEtiw98DcPY8eOdqs/6juKWD+RZ3 Y1306Agy4DZHktTSBHREAIhoNRU6xIaCWEZBfDgbQkysGwUSZl+o1fKyX3zIo0EWqu Uxpg/FigNnQvqdptx1zXKI88PnkAK3PBjLGARylk= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Oct 2022 00:21:22 +0300 Message-Id: <20221003212128.32429-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> References: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/8] ipa: camera_sensor_helper: Make registerType() and createInstance() private 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraSensorHelperFactory registerType() and createInstance() functions are called by the CameraSensorHelperFactory class only. Make them private. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- src/ipa/libipa/camera_sensor_helper.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h index 2042847f29e8..410156efb2ea 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -66,15 +66,15 @@ public: static std::unique_ptr create(const std::string &name); - static void registerType(CameraSensorHelperFactory *factory); static std::vector &factories(); -protected: - virtual CameraSensorHelper *createInstance() const = 0; - private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactory) + static void registerType(CameraSensorHelperFactory *factory); + + virtual CameraSensorHelper *createInstance() const = 0; + std::string name_; }; From patchwork Mon Oct 3 21:21:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17513 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 01575BD16B for ; Mon, 3 Oct 2022 21:21:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B9260601C7; Mon, 3 Oct 2022 23:21:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664832098; bh=8NocbKuZ5437S7CzPy5r1JD5H2NzdLJnsKimXgve9OQ=; 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=Zk210YQFYHpS4PhfbO4b7Zd0qfqgsBp0TnXpODIu7vhUYcXL/+ZlyzRpn9vgMZTEV 9fpbGuY5NiB1VLJ13efw3Ijv5siWrgTlNOZxVdBmE4u0bc8EXYTDCQ181i3Fjg/7MR SpYpk+hN1kLBJ5vBLu8TvZWdvb0YGtGRE8XpWJHJo2OmKHtGyZTHQkDW+i3c4VgxC8 0Jxww26QyxRJYdeT/lNP1W39Ri38v1Njm3elCsKzkxhXH8C+A1ZghWijgYAFlYGtab icE0/JnHJzBBlhIyAZi6cbDpX/I1BAa4yk/QEm4w3pTO4q0UIF3HEC35NBPe1Sby9A UGLUt8vII2Kdg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4EE6B60A70 for ; Mon, 3 Oct 2022 23:21:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eu4M2CwL"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CBDF8440 for ; Mon, 3 Oct 2022 23:21:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664832096; bh=8NocbKuZ5437S7CzPy5r1JD5H2NzdLJnsKimXgve9OQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=eu4M2CwL3yhFbydgaLj8BIdAVIOUNT7qkDtcUIGX6VUm3q1PDs8uLrp/2D7kxTiUo CtTz7O135/y3x74TXNfylIp1VBjzQBhOraYsf8Jrfbz3wN3bKllINPgtTcM7nuwpHe iDFKH0SV3zFdH6l1zap3Jah3Wq70FWD4DCD6Rc7Q= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Oct 2022 00:21:23 +0300 Message-Id: <20221003212128.32429-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> References: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/8] ipa: camera_sensor_helper: Return unique_ptr from createInstance 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Avoid naked pointer with memory allocation by returning a unique_ptr from CameraSensorHelperFactory::createInstance(), in order to increase memory allocation safety. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- src/ipa/libipa/camera_sensor_helper.cpp | 7 +++---- src/ipa/libipa/camera_sensor_helper.h | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index fde9bf5b8892..3a7d701d8616 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -261,8 +261,7 @@ std::unique_ptr CameraSensorHelperFactory::create(const std: if (name != factory->name_) continue; - CameraSensorHelper *helper = factory->createInstance(); - return std::unique_ptr(helper); + return factory->createInstance(); } return nullptr; @@ -307,8 +306,8 @@ std::vector &CameraSensorHelperFactory::factories() * macro. It creates a camera sensor helper instance associated with the camera * sensor model. * - * \return A pointer to a newly constructed instance of the CameraSensorHelper - * subclass corresponding to the factory + * \return A unique pointer to a newly constructed instance of the + * CameraSensorHelper subclass corresponding to the factory */ /** diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h index 410156efb2ea..21ee43cc9f9f 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -73,7 +73,7 @@ private: static void registerType(CameraSensorHelperFactory *factory); - virtual CameraSensorHelper *createInstance() const = 0; + virtual std::unique_ptr createInstance() const = 0; std::string name_; }; @@ -85,9 +85,9 @@ public: \ helper##Factory() : CameraSensorHelperFactory(name) {} \ \ private: \ - CameraSensorHelper *createInstance() const \ + std::unique_ptr createInstance() const \ { \ - return new helper(); \ + return std::make_unique(); \ } \ }; \ static helper##Factory global_##helper##Factory; From patchwork Mon Oct 3 21:21:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17514 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 91D31C3286 for ; Mon, 3 Oct 2022 21:21:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 32F7160A74; Mon, 3 Oct 2022 23:21:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664832099; bh=O7o9URYdWuQuB+HNYJT6a9yPYDRG53BY52xPUmesJIw=; 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=DDU+GDcNuTTkige29Y3OTmNgopt+Y9PIyfonUT5KYGjyDuW8SXkYXSMUW7fBF7K+N ngupPrLQCxhVN0afdWy3+IagX5VLJbl1wGLz1JVD/dUo0IGtsj7qnsNAIOXzWvC2it 2V1H2OfiVZnNnGLuy2WHEYOd7nFGD1sYUOhwVxgAi2F6je0yl4Q/N2yBCfb0Zw4lxA MWc+HtQTfgtkDh+10AqA15mGVy92bEoe3E4D+R4DhpE6EpbE3C1efFcUpgNqaZBANa zjHbesVgQYqw06EQlMER5tLteAODaOEDvRU7dw/Ivz6OGZSnlwoASaSQ1U1NIzgtWi jDTvUurclVDnw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9D905604FE for ; Mon, 3 Oct 2022 23:21:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Nua3s/jb"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 286E3519 for ; Mon, 3 Oct 2022 23:21:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664832097; bh=O7o9URYdWuQuB+HNYJT6a9yPYDRG53BY52xPUmesJIw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Nua3s/jb5fejjb51GFf+OrNenifBVhcntnGn/WOI3suLa15DyHW8tOcIUd5GjD3aq THfxgNZMLboxLrlvPtbEe41StUp3I+EkEGI6SNII5lZYyJa0PeIQiiOF8SIhAq1QLz a0L3pXgGyEOAdKDCRKwSFGzigQTGIV0l/ZHz1B0g= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Oct 2022 00:21:24 +0300 Message-Id: <20221003212128.32429-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> References: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/8] ipa: camera_sensor_helper: Implement factories through class templates 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The REGISTER_CAMERA_SENSOR_HELPER() macro defines a class type that inherits from the CameraSensorHelperFactory class, and implements a constructor and createInstance() function. Replace the code generation through macro with the C++ equivalent, a class template, as done by the Algorithm factory. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- src/ipa/ipu3/ipu3.cpp | 2 +- src/ipa/libipa/camera_sensor_helper.cpp | 79 +++++++++++++++---------- src/ipa/libipa/camera_sensor_helper.h | 43 ++++++++------ src/ipa/rkisp1/rkisp1.cpp | 2 +- 4 files changed, 75 insertions(+), 51 deletions(-) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index b93a09d40c39..852deb710956 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -326,7 +326,7 @@ int IPAIPU3::init(const IPASettings &settings, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls) { - camHelper_ = CameraSensorHelperFactory::create(settings.sensorModel); + camHelper_ = CameraSensorHelperFactoryBase::create(settings.sensorModel); if (camHelper_ == nullptr) { LOG(IPAIPU3, Error) << "Failed to create camera sensor helper for " diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index 3a7d701d8616..e655be255f2b 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -43,7 +43,8 @@ namespace ipa { * \brief Construct a CameraSensorHelper instance * * CameraSensorHelper derived class instances shall never be constructed - * manually but always through the CameraSensorHelperFactory::create() function. + * manually but always through the CameraSensorHelperFactoryBase::create() + * function. */ /** @@ -217,27 +218,25 @@ double CameraSensorHelper::gain(uint32_t gainCode) const */ /** - * \class CameraSensorHelperFactory - * \brief Registration of CameraSensorHelperFactory classes and creation of instances + * \class CameraSensorHelperFactoryBase + * \brief Base class for camera sensor helper factories * - * To facilitate discovery and instantiation of CameraSensorHelper classes, the - * CameraSensorHelperFactory class maintains a registry of camera sensor helper - * sub-classes. Each CameraSensorHelper subclass shall register itself using the - * REGISTER_CAMERA_SENSOR_HELPER() macro, which will create a corresponding - * instance of a CameraSensorHelperFactory subclass and register it with the - * static list of factories. + * The CameraSensorHelperFactoryBase class is the base of all specializations of + * the CameraSensorHelperFactory class template. It implements the factory + * registration, maintains a registry of factories, and provides access to the + * registered factories. */ /** - * \brief Construct a camera sensor helper factory + * \brief Construct a camera sensor helper factory base * \param[in] name Name of the camera sensor helper class * - * Creating an instance of the factory registers it with the global list of + * Creating an instance of the factory base registers it with the global list of * factories, accessible through the factories() function. * * The factory \a name is used for debug purpose and shall be unique. */ -CameraSensorHelperFactory::CameraSensorHelperFactory(const std::string name) +CameraSensorHelperFactoryBase::CameraSensorHelperFactoryBase(const std::string name) : name_(name) { registerType(this); @@ -252,12 +251,12 @@ CameraSensorHelperFactory::CameraSensorHelperFactory(const std::string name) * corresponding to the named factory or a null pointer if no such factory * exists */ -std::unique_ptr CameraSensorHelperFactory::create(const std::string &name) +std::unique_ptr CameraSensorHelperFactoryBase::create(const std::string &name) { - const std::vector &factories = - CameraSensorHelperFactory::factories(); + const std::vector &factories = + CameraSensorHelperFactoryBase::factories(); - for (const CameraSensorHelperFactory *factory : factories) { + for (const CameraSensorHelperFactoryBase *factory : factories) { if (name != factory->name_) continue; @@ -274,10 +273,10 @@ std::unique_ptr CameraSensorHelperFactory::create(const std: * The caller is responsible to guarantee the uniqueness of the camera sensor * helper name. */ -void CameraSensorHelperFactory::registerType(CameraSensorHelperFactory *factory) +void CameraSensorHelperFactoryBase::registerType(CameraSensorHelperFactoryBase *factory) { - std::vector &factories = - CameraSensorHelperFactory::factories(); + std::vector &factories = + CameraSensorHelperFactoryBase::factories(); factories.push_back(factory); } @@ -286,35 +285,55 @@ void CameraSensorHelperFactory::registerType(CameraSensorHelperFactory *factory) * \brief Retrieve the list of all camera sensor helper factories * \return The list of camera sensor helper factories */ -std::vector &CameraSensorHelperFactory::factories() +std::vector &CameraSensorHelperFactoryBase::factories() { /* * The static factories map is defined inside the function to ensure * it gets initialized on first use, without any dependency on link * order. */ - static std::vector factories; + static std::vector factories; return factories; } +/** + * \var CameraSensorHelperFactoryBase::name_ + * \brief The name of the factory + */ + +/** + * \class CameraSensorHelperFactory + * \brief Registration of CameraSensorHelperFactory classes and creation of instances + * \tparam _Helper The camera sensor helepr class type for this factory + * + * To facilitate discovery and instantiation of CameraSensorHelper classes, the + * CameraSensorHelperFactory class implements auto-registration of camera sensor + * helpers. Each CameraSensorHelper subclass shall register itself using the + * REGISTER_CAMERA_SENSOR_HELPER() macro, which will create a corresponding + * instance of a CameraSensorHelperFactory subclass and register it with the + * static list of factories. + */ + +/** + * \fn CameraSensorHelperFactory::CameraSensorHelperFactory(const char *name) + * \brief Construct a camera sensor helper factory + * \param[in] name Name of the camera sensor helper class + * + * Creating an instance of the factory registers it with the global list of + * factories, accessible through the factories() function. + * + * The factory \a name is used for debug purpose and shall be unique. + */ + /** * \fn CameraSensorHelperFactory::createInstance() const * \brief Create an instance of the CameraSensorHelper corresponding to the * factory * - * This virtual function is implemented by the REGISTER_CAMERA_SENSOR_HELPER() - * macro. It creates a camera sensor helper instance associated with the camera - * sensor model. - * * \return A unique pointer to a newly constructed instance of the * CameraSensorHelper subclass corresponding to the factory */ -/** - * \var CameraSensorHelperFactory::name_ - * \brief The name of the factory - */ - /** * \def REGISTER_CAMERA_SENSOR_HELPER * \brief Register a camera sensor helper with the camera sensor helper factory diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h index 21ee43cc9f9f..3ea1806cb1fd 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -58,39 +58,44 @@ private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper) }; -class CameraSensorHelperFactory +class CameraSensorHelperFactoryBase { public: - CameraSensorHelperFactory(const std::string name); - virtual ~CameraSensorHelperFactory() = default; + CameraSensorHelperFactoryBase(const std::string name); + virtual ~CameraSensorHelperFactoryBase() = default; static std::unique_ptr create(const std::string &name); - static std::vector &factories(); + static std::vector &factories(); private: - LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactory) + LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactoryBase) - static void registerType(CameraSensorHelperFactory *factory); + static void registerType(CameraSensorHelperFactoryBase *factory); virtual std::unique_ptr createInstance() const = 0; std::string name_; }; -#define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \ -class helper##Factory final : public CameraSensorHelperFactory \ -{ \ -public: \ - helper##Factory() : CameraSensorHelperFactory(name) {} \ - \ -private: \ - std::unique_ptr createInstance() const \ - { \ - return std::make_unique(); \ - } \ -}; \ -static helper##Factory global_##helper##Factory; +template +class CameraSensorHelperFactory final : public CameraSensorHelperFactoryBase +{ +public: + CameraSensorHelperFactory(const char *name) + : CameraSensorHelperFactoryBase(name) + { + } + +private: + std::unique_ptr createInstance() const + { + return std::make_unique<_Helper>(); + } +}; + +#define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \ +static CameraSensorHelperFactory global_##helper##Factory(name); } /* namespace ipa */ diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 1335e3d14df2..9451cb03a285 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -143,7 +143,7 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision, /* Cache the value to set it in configure. */ hwRevision_ = static_cast(hwRevision); - camHelper_ = CameraSensorHelperFactory::create(settings.sensorModel); + camHelper_ = CameraSensorHelperFactoryBase::create(settings.sensorModel); if (!camHelper_) { LOG(IPARkISP1, Error) << "Failed to create camera sensor helper for " From patchwork Mon Oct 3 21:21:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17515 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 27AC6C327C for ; Mon, 3 Oct 2022 21:21:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B829860A7B; Mon, 3 Oct 2022 23:21:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664832100; bh=jHUug7L17lPRLcPRGS03wEx6CP6ZMUfB7Em4rB37JqU=; 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=mTZA/r4bX1xjI/gT1/Hu6bJLf4zuXr3y1yDGqacpurjiDEIZdaogtOJQ5rFXDK6Ei oYxw/tZuz96j/VoGvtOtYFXCoErgCoDeZ3KXVjH8bSZF3Xn1Pfbj8XI9UEHsHFsH+T anKISYKZ7YgZjeWok8rPdIx2UttYajWnHUuF+fSYzhyAXOp99hAO6fryGWBepauv3T UbmtYhF4OGmVRsyxuOLN6opN7JNZ8pAjHTXxqM5lEwUVz7wBB9+FMzHiYRI2WVAmOy xFnBWjToiGee1mgtIk3ncyQ8somEvVJs5/C62GJRSzBN8VRdIL1me6+LuaSnzA/zrl s4KtkhP09T8RA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0172D60A76 for ; Mon, 3 Oct 2022 23:21:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IuKQtgWz"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7F455440 for ; Mon, 3 Oct 2022 23:21:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664832098; bh=jHUug7L17lPRLcPRGS03wEx6CP6ZMUfB7Em4rB37JqU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IuKQtgWzbzq2pq2BHhtAh2UwsIOZ99Xvbg+lTmaM6hVIFOGJdAicHRcq9TABjvk72 KXSyzirxBNaT1lQGFnOSSpcaWXR1mA4JCcv6800+aSipiJQCYcSDlOHic1YTd3q25W xFOTVAWaAfVQzAkePfjhzRj1jT5OexJimzJb/hgk= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Oct 2022 00:21:25 +0300 Message-Id: <20221003212128.32429-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> References: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/8] libcamera: pipeline_handler: Make factory create() function const 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The PipelineHandlerFactory::create() function has no need to modify the factory instance. Make it const, as well as the createInstance() function. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- include/libcamera/internal/pipeline_handler.h | 6 +++--- src/libcamera/pipeline_handler.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 20f1cbb07fea..46df69dc789a 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -104,7 +104,7 @@ public: PipelineHandlerFactory(const char *name); virtual ~PipelineHandlerFactory() = default; - std::shared_ptr create(CameraManager *manager); + std::shared_ptr create(CameraManager *manager) const; const std::string &name() const { return name_; } @@ -112,7 +112,7 @@ public: static std::vector &factories(); private: - virtual PipelineHandler *createInstance(CameraManager *manager) = 0; + virtual PipelineHandler *createInstance(CameraManager *manager) const = 0; std::string name_; }; @@ -124,7 +124,7 @@ public: \ handler##Factory() : PipelineHandlerFactory(#handler) {} \ \ private: \ - PipelineHandler *createInstance(CameraManager *manager) \ + PipelineHandler *createInstance(CameraManager *manager) const \ { \ return new handler(manager); \ } \ diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index e5cb751cc743..4470e9041e8e 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -676,7 +676,7 @@ PipelineHandlerFactory::PipelineHandlerFactory(const char *name) * \return A shared pointer to a new instance of the PipelineHandler subclass * corresponding to the factory */ -std::shared_ptr PipelineHandlerFactory::create(CameraManager *manager) +std::shared_ptr PipelineHandlerFactory::create(CameraManager *manager) const { PipelineHandler *handler = createInstance(manager); handler->name_ = name_.c_str(); @@ -719,7 +719,7 @@ std::vector &PipelineHandlerFactory::factories() } /** - * \fn PipelineHandlerFactory::createInstance() + * \fn PipelineHandlerFactory::createInstance() const * \brief Create an instance of the PipelineHandler corresponding to the factory * \param[in] manager The camera manager * From patchwork Mon Oct 3 21:21:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17516 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 B4A83C3285 for ; Mon, 3 Oct 2022 21:21:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 54BC060A7E; Mon, 3 Oct 2022 23:21:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664832102; bh=pGyIItIRE998V56f3sGwDeui2rRJe44G2CURlcpOr0k=; 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=xxpUpLPIr8rxk/5POz5eA6IG8b4h0/fSbfnuMOtPNXSkaXnruoT4r5JGnqTllZccF +5ucK9BmFYaQMsWTS9VRe8thPpSmzinrkHw14IV7aH0sPE88fIT+L0P0w8nC+sD8kb 2qGbuRJ4jt+Ul5NWzRtGuBX9OyOV9UvoH75Kk0aFBtJT3JtkkDIrsRb40xozrLgXIo zUIYYvRZUYiCMLuMia0X+xuENXhQcMHJsJD3ya2Oqx8twRYiQTji0AZvoTpKfN9q6d irOjAqUqMkJ6VjCntKUfYXnBwDCKPt5N5T7NhJ1E5tGD8+7sZ/CJFMmX6iQMGrustt 1wGlQU54HMOXQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 87A11601CB for ; Mon, 3 Oct 2022 23:21:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NduYlbWG"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0F0D3A4C for ; Mon, 3 Oct 2022 23:21:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664832100; bh=pGyIItIRE998V56f3sGwDeui2rRJe44G2CURlcpOr0k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NduYlbWGJs/6a8/NljgL0Uw+THh8kz77Rrf2sUk3RigGf5S9j4VjXvgXitQxrmvIC LMRLmPQV8DwTGhl+D03YjxE04Jd4pxztTWi2xEGbsidOdBMPbBcec9ljQhWTprwUjZ HQ6+olK+slOBb1G5PBE9jG7J+OtyX5eqjFfN2sxg= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Oct 2022 00:21:26 +0300 Message-Id: <20221003212128.32429-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> References: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/8] libcamera: pipeline_handler: Make registerType() private 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The PipelineHandlerFactory::registerType() function is called by the PipelineHandlerFactory class only. Make it private. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- include/libcamera/internal/pipeline_handler.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 46df69dc789a..ebbdf2aa391f 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -108,10 +108,11 @@ public: const std::string &name() const { return name_; } - static void registerType(PipelineHandlerFactory *factory); static std::vector &factories(); private: + static void registerType(PipelineHandlerFactory *factory); + virtual PipelineHandler *createInstance(CameraManager *manager) const = 0; std::string name_; From patchwork Mon Oct 3 21:21:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17517 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 1971ABD16B for ; Mon, 3 Oct 2022 21:21:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C42F860A82; Mon, 3 Oct 2022 23:21:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664832103; bh=k/1FbOie6DtkP1kevsnc+h35qGdJPDCcnLW792JXDGo=; 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=DAmzqw7ErDYeUdHFz9iVPFPHA3WTBEnuAG+LL/C3sfl2mbLh11gfUbHXD2eJNjfyZ u7kVbToWJ9R9JXmMMCc/WrxUVagg5Eefn0h00pj3nPrXGJ7T6RwiXDCQ/ws7vaIwZT 8TdDCW/SRfABsW25ybedz/j2e1mf1DGQ8ZK0Vtn6wYhr+4vbviNUEb7J+Q3jEB9M/U RihcHKj61mM8gi+pthAXZmxn6jiU5uPUZ/jsOs4Nq6XJs/egynKsHu+laCPYkr+DkL lJ+zhbkyR8tF8TZpCAkxnMBKTuQI18NejDER101D7iq98c25fiydBI8+P/ig469zp2 OasAxHuy1shsA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 239C660A7C for ; Mon, 3 Oct 2022 23:21:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TCgBl5/m"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A50BA519 for ; Mon, 3 Oct 2022 23:21:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664832101; bh=k/1FbOie6DtkP1kevsnc+h35qGdJPDCcnLW792JXDGo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TCgBl5/m15Y/rX1NlzcO+EIBMOGbuYVH6/MGYuLyhCSExSmggPG8uoLqqcfLNpKS/ mGYzwNJNODu20J02Pl64dtkMlMpY1HlKVfe83uNlOLfTpH8ynNPhyNKKGdakA16QQd +VubniA0jeQMBnIDz0FTpW9iroV/m/7JUkcLYSBs= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Oct 2022 00:21:27 +0300 Message-Id: <20221003212128.32429-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> References: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 7/8] libcamera: pipeline_handler: Return unique_ptr from createInstance 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Avoid naked pointer with memory allocation by returning a unique_ptr from PipelineHandlerFactory::createInstance(), in order to increase memory allocation safety. This allows iterating over factories in the CameraManager and unit tests using const pointers. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- include/libcamera/internal/pipeline_handler.h | 8 +++++--- src/libcamera/camera_manager.cpp | 4 ++-- src/libcamera/pipeline_handler.cpp | 8 ++++---- test/ipa/ipa_interface_test.cpp | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index ebbdf2aa391f..ad74dc823290 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -113,7 +113,8 @@ public: private: static void registerType(PipelineHandlerFactory *factory); - virtual PipelineHandler *createInstance(CameraManager *manager) const = 0; + virtual std::unique_ptr + createInstance(CameraManager *manager) const = 0; std::string name_; }; @@ -125,9 +126,10 @@ public: \ handler##Factory() : PipelineHandlerFactory(#handler) {} \ \ private: \ - PipelineHandler *createInstance(CameraManager *manager) const \ + std::unique_ptr \ + createInstance(CameraManager *manager) const \ { \ - return new handler(manager); \ + return std::make_unique(manager); \ } \ }; \ static handler##Factory global_##handler##Factory; diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 7ff4bc6fd019..2c3f2d86c469 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -142,10 +142,10 @@ void CameraManager::Private::createPipelineHandlers() * file and only fallback on all handlers if there is no * configuration file. */ - std::vector &factories = + const std::vector &factories = PipelineHandlerFactory::factories(); - for (PipelineHandlerFactory *factory : factories) { + for (const PipelineHandlerFactory *factory : factories) { LOG(Camera, Debug) << "Found registered pipeline handler '" << factory->name() << "'"; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 4470e9041e8e..488dd8d32cdf 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -678,9 +678,9 @@ PipelineHandlerFactory::PipelineHandlerFactory(const char *name) */ std::shared_ptr PipelineHandlerFactory::create(CameraManager *manager) const { - PipelineHandler *handler = createInstance(manager); + std::unique_ptr handler = createInstance(manager); handler->name_ = name_.c_str(); - return std::shared_ptr(handler); + return std::shared_ptr(std::move(handler)); } /** @@ -727,8 +727,8 @@ std::vector &PipelineHandlerFactory::factories() * macro. It creates a pipeline handler instance associated with the camera * \a manager. * - * \return a pointer to a newly constructed instance of the PipelineHandler - * subclass corresponding to the factory + * \return A unique pointer to a newly constructed instance of the + * PipelineHandler subclass corresponding to the factory */ /** diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp index 3c0df843ea61..a629abc28da7 100644 --- a/test/ipa/ipa_interface_test.cpp +++ b/test/ipa/ipa_interface_test.cpp @@ -52,9 +52,9 @@ protected: ipaManager_ = make_unique(); /* Create a pipeline handler for vimc. */ - std::vector &factories = + const std::vector &factories = PipelineHandlerFactory::factories(); - for (PipelineHandlerFactory *factory : factories) { + for (const PipelineHandlerFactory *factory : factories) { if (factory->name() == "PipelineHandlerVimc") { pipe_ = factory->create(nullptr); break; From patchwork Mon Oct 3 21:21:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17518 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 A5F94C3286 for ; Mon, 3 Oct 2022 21:21:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4FC6C60A86; Mon, 3 Oct 2022 23:21:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664832105; bh=Y+UrL7/BUdya+hm4IVrhHl5+vkkku68PkiPAjiycm0c=; 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=LgdxIbTT0mCLfMbDcwaiM+jFNceeZ4A1qpdD4vbOmTSy5rkjDIkx+0ZHQCgKTFiNk kBj9y+ysZ4gaP+tkR2P9RUfCYBkkTdNM0JItgDwNMkZvLyM20OMQON3+kgCrbGp9IK PsQyFaQqh/pNq3oYoi9OERwBs0RedbnP9gSrLmmuJFa4f8Tg27tBn3T70Hw4Dfoql8 spj3cIkuz0jtklty+jWyJ6KuUrSxIUUQ75BP0ERLrpZIZ9woNkLAr0Q+0UHy6Ug0zI 3gP4/RGyu0KwiYcwpACtgTJeYfdiDfoZzlSUsNvTr4r0iz/wGbwQqn1Jcharp558eN MSe2lJnqaiNuA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 78EE060A73 for ; Mon, 3 Oct 2022 23:21:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RVgrMY9p"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 053A4519 for ; Mon, 3 Oct 2022 23:21:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664832103; bh=Y+UrL7/BUdya+hm4IVrhHl5+vkkku68PkiPAjiycm0c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RVgrMY9pISbl6RsEgejJfrJzD9MxtG2xmr80LO+wiYxLWl4648ZuFE/Ft5+RxXanj eLDJfrSCi1Hw6nLOQ2L36B2OfyII9NjXRCnZ1khhSqwyWMqr97bTGOqbx0drQUVHYv Z+RjNHFYtwvfFxYNvXU+OqAlEmFzJFih5BwyTniA= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Oct 2022 00:21:28 +0300 Message-Id: <20221003212128.32429-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> References: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 8/8] libcamera: pipeline_handler: Implement factories through class templates 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The REGISTER_PIPELINE_HANDLER() macro defines a class type that inherits from the PipelineHandlerFactory class, and implements a constructor and a createInstance() function. Replace the code generation through macro with the C++ equivalent, a class template, as done in libipa with the Algorithm and CameraSensorHelper factories. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- include/libcamera/internal/pipeline_handler.h | 44 +++++++------ src/libcamera/camera_manager.cpp | 6 +- src/libcamera/pipeline_handler.cpp | 65 ++++++++++++------- test/ipa/ipa_interface_test.cpp | 6 +- 4 files changed, 71 insertions(+), 50 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index ad74dc823290..b6139a88d421 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -95,23 +95,23 @@ private: Mutex lock_; unsigned int useCount_ LIBCAMERA_TSA_GUARDED_BY(lock_); - friend class PipelineHandlerFactory; + friend class PipelineHandlerFactoryBase; }; -class PipelineHandlerFactory +class PipelineHandlerFactoryBase { public: - PipelineHandlerFactory(const char *name); - virtual ~PipelineHandlerFactory() = default; + PipelineHandlerFactoryBase(const char *name); + virtual ~PipelineHandlerFactoryBase() = default; std::shared_ptr create(CameraManager *manager) const; const std::string &name() const { return name_; } - static std::vector &factories(); + static std::vector &factories(); private: - static void registerType(PipelineHandlerFactory *factory); + static void registerType(PipelineHandlerFactoryBase *factory); virtual std::unique_ptr createInstance(CameraManager *manager) const = 0; @@ -119,19 +119,23 @@ private: std::string name_; }; -#define REGISTER_PIPELINE_HANDLER(handler) \ -class handler##Factory final : public PipelineHandlerFactory \ -{ \ -public: \ - handler##Factory() : PipelineHandlerFactory(#handler) {} \ - \ -private: \ - std::unique_ptr \ - createInstance(CameraManager *manager) const \ - { \ - return std::make_unique(manager); \ - } \ -}; \ -static handler##Factory global_##handler##Factory; +template +class PipelineHandlerFactory final : public PipelineHandlerFactoryBase +{ +public: + PipelineHandlerFactory(const char *name) + : PipelineHandlerFactoryBase(name) + { + } + + std::unique_ptr + createInstance(CameraManager *manager) const override + { + return std::make_unique<_PipelineHandler>(manager); + } +}; + +#define REGISTER_PIPELINE_HANDLER(handler) \ +static PipelineHandlerFactory global_##handler##Factory(#handler); } /* namespace libcamera */ diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 2c3f2d86c469..2c100c24af4d 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -142,10 +142,10 @@ void CameraManager::Private::createPipelineHandlers() * file and only fallback on all handlers if there is no * configuration file. */ - const std::vector &factories = - PipelineHandlerFactory::factories(); + const std::vector &factories = + PipelineHandlerFactoryBase::factories(); - for (const PipelineHandlerFactory *factory : factories) { + for (const PipelineHandlerFactoryBase *factory : factories) { LOG(Camera, Debug) << "Found registered pipeline handler '" << factory->name() << "'"; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 488dd8d32cdf..44f6fc531ad7 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -64,8 +64,7 @@ LOG_DEFINE_CATEGORY(Pipeline) * * In order to honour the std::enable_shared_from_this<> contract, * PipelineHandler instances shall never be constructed manually, but always - * through the PipelineHandlerFactory::create() function implemented by the - * respective factories. + * through the PipelineHandlerFactoryBase::create() function. */ PipelineHandler::PipelineHandler(CameraManager *manager) : manager_(manager), useCount_(0) @@ -643,27 +642,25 @@ void PipelineHandler::disconnect() */ /** - * \class PipelineHandlerFactory - * \brief Registration of PipelineHandler classes and creation of instances + * \class PipelineHandlerFactoryBase + * \brief Base class for pipeline handler factories * - * To facilitate discovery and instantiation of PipelineHandler classes, the - * PipelineHandlerFactory class maintains a registry of pipeline handler - * classes. Each PipelineHandler subclass shall register itself using the - * REGISTER_PIPELINE_HANDLER() macro, which will create a corresponding - * instance of a PipelineHandlerFactory subclass and register it with the - * static list of factories. + * The PipelineHandlerFactoryBase class is the base of all specializations of + * the PipelineHandlerFactory class template. It implements the factory + * registration, maintains a registry of factories, and provides access to the + * registered factories. */ /** - * \brief Construct a pipeline handler factory + * \brief Construct a pipeline handler factory base * \param[in] name Name of the pipeline handler class * - * Creating an instance of the factory registers is with the global list of + * Creating an instance of the factory base registers is with the global list of * factories, accessible through the factories() function. * * The factory \a name is used for debug purpose and shall be unique. */ -PipelineHandlerFactory::PipelineHandlerFactory(const char *name) +PipelineHandlerFactoryBase::PipelineHandlerFactoryBase(const char *name) : name_(name) { registerType(this); @@ -676,7 +673,7 @@ PipelineHandlerFactory::PipelineHandlerFactory(const char *name) * \return A shared pointer to a new instance of the PipelineHandler subclass * corresponding to the factory */ -std::shared_ptr PipelineHandlerFactory::create(CameraManager *manager) const +std::shared_ptr PipelineHandlerFactoryBase::create(CameraManager *manager) const { std::unique_ptr handler = createInstance(manager); handler->name_ = name_.c_str(); @@ -684,7 +681,7 @@ std::shared_ptr PipelineHandlerFactory::create(CameraManager *m } /** - * \fn PipelineHandlerFactory::name() + * \fn PipelineHandlerFactoryBase::name() * \brief Retrieve the factory name * \return The factory name */ @@ -696,9 +693,10 @@ std::shared_ptr PipelineHandlerFactory::create(CameraManager *m * The caller is responsible to guarantee the uniqueness of the pipeline handler * name. */ -void PipelineHandlerFactory::registerType(PipelineHandlerFactory *factory) +void PipelineHandlerFactoryBase::registerType(PipelineHandlerFactoryBase *factory) { - std::vector &factories = PipelineHandlerFactory::factories(); + std::vector &factories = + PipelineHandlerFactoryBase::factories(); factories.push_back(factory); } @@ -707,26 +705,45 @@ void PipelineHandlerFactory::registerType(PipelineHandlerFactory *factory) * \brief Retrieve the list of all pipeline handler factories * \return the list of pipeline handler factories */ -std::vector &PipelineHandlerFactory::factories() +std::vector &PipelineHandlerFactoryBase::factories() { /* * The static factories map is defined inside the function to ensure * it gets initialized on first use, without any dependency on * link order. */ - static std::vector factories; + static std::vector factories; return factories; } +/** + * \class PipelineHandlerFactory + * \brief Registration of PipelineHandler classes and creation of instances + * \tparam _PipelineHandler The pipeline handler class type for this factory + * + * To facilitate discovery and instantiation of PipelineHandler classes, the + * PipelineHandlerFactory class implements auto-registration of pipeline + * handlers. Each PipelineHandler subclass shall register itself using the + * REGISTER_PIPELINE_HANDLER() macro, which will create a corresponding + * instance of a PipelineHandlerFactory and register it with the static list of + * factories. + */ + +/** + * \fn PipelineHandlerFactory::PipelineHandlerFactory(const char *name) + * \brief Construct a pipeline handler factory + * \param[in] name Name of the pipeline handler class + * + * Creating an instance of the factory registers is with the global list of + * factories, accessible through the factories() function. + * + * The factory \a name is used for debug purpose and shall be unique. + */ + /** * \fn PipelineHandlerFactory::createInstance() const * \brief Create an instance of the PipelineHandler corresponding to the factory * \param[in] manager The camera manager - * - * This virtual function is implemented by the REGISTER_PIPELINE_HANDLER() - * macro. It creates a pipeline handler instance associated with the camera - * \a manager. - * * \return A unique pointer to a newly constructed instance of the * PipelineHandler subclass corresponding to the factory */ diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp index a629abc28da7..6b93e976a587 100644 --- a/test/ipa/ipa_interface_test.cpp +++ b/test/ipa/ipa_interface_test.cpp @@ -52,9 +52,9 @@ protected: ipaManager_ = make_unique(); /* Create a pipeline handler for vimc. */ - const std::vector &factories = - PipelineHandlerFactory::factories(); - for (const PipelineHandlerFactory *factory : factories) { + const std::vector &factories = + PipelineHandlerFactoryBase::factories(); + for (const PipelineHandlerFactoryBase *factory : factories) { if (factory->name() == "PipelineHandlerVimc") { pipe_ = factory->create(nullptr); break;