[{"id":12590,"web_url":"https://patchwork.libcamera.org/comment/12590/","msgid":"<20200919124540.GW1850958@oden.dyn.berto.se>","date":"2020-09-19T12:45:40","subject":"Re: [libcamera-devel] [PATCH 21/23] libcamera: IPAManager: Make\n\tcreateIPA return proxy directly","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Paul,\n\nThanks for your work.\n\nOn 2020-09-15 23:20:36 +0900, Paul Elder wrote:\n> Since every pipeline knows the type of the proxy that it needs, and\n> since all IPAs are to be wrapped in a proxy, IPAManager no longer needs\n> to search in the factory list to fetch the proxy factory to construct a\n> factory. Instead, we define createIPA as a template function, and the\n> pipeline handler can declare the proxy type when it calls createIPA.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  include/libcamera/internal/ipa_manager.h      | 31 ++++++++++--\n>  src/libcamera/ipa_manager.cpp                 | 48 +------------------\n>  .../pipeline/raspberrypi/raspberrypi.cpp      |  3 +-\n>  3 files changed, 30 insertions(+), 52 deletions(-)\n> \n> diff --git a/include/libcamera/internal/ipa_manager.h b/include/libcamera/internal/ipa_manager.h\n> index 4a143b6a..297a8a58 100644\n> --- a/include/libcamera/internal/ipa_manager.h\n> +++ b/include/libcamera/internal/ipa_manager.h\n> @@ -14,20 +14,45 @@\n>  #include <libcamera/ipa/ipa_module_info.h>\n>  \n>  #include \"libcamera/internal/ipa_module.h\"\n> +#include \"libcamera/internal/log.h\"\n>  #include \"libcamera/internal/pipeline_handler.h\"\n>  #include \"libcamera/internal/pub_key.h\"\n>  \n>  namespace libcamera {\n>  \n> +LOG_DECLARE_CATEGORY(IPAManager)\n> +\n>  class IPAManager\n>  {\n>  public:\n>  \tIPAManager();\n>  \t~IPAManager();\n>  \n> -\tstatic std::unique_ptr<IPAProxy> createIPA(PipelineHandler *pipe,\n> -\t\t\t\t\t\t   uint32_t maxVersion,\n> -\t\t\t\t\t\t   uint32_t minVersion);\n> +\ttemplate<class P>\n> +\tstatic std::unique_ptr<P> createIPA(PipelineHandler *pipe,\n> +\t\t\t\t\t    uint32_t maxVersion,\n> +\t\t\t\t\t    uint32_t minVersion)\n> +\t{\n> +\t\tIPAModule *m = nullptr;\n> +\n> +\t\tfor (IPAModule *module : self_->modules_) {\n> +\t\t\tif (module->match(pipe, minVersion, maxVersion)) {\n> +\t\t\t\tm = module;\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t}\n> +\n> +\t\tif (!m)\n> +\t\t\treturn nullptr;\n> +\n> +\t\tstd::unique_ptr<P> proxy = std::make_unique<P>(m, !self_->isSignatureValid(m));\n> +\t\tif (!proxy->isValid()) {\n> +\t\t\tLOG(IPAManager, Error) << \"Failed to load proxy\";\n> +\t\t\treturn nullptr;\n> +\t\t}\n> +\n> +\t\treturn proxy;\n> +\t}\n>  \n>  private:\n>  \tstatic IPAManager *self_;\n> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\n> index 26458153..0d518443 100644\n> --- a/src/libcamera/ipa_manager.cpp\n> +++ b/src/libcamera/ipa_manager.cpp\n> @@ -245,6 +245,7 @@ unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth)\n>  }\n>  \n>  /**\n> + * \\fn IPAManager::createIPA()\n>   * \\brief Create an IPA proxy that matches a given pipeline handler\n>   * \\param[in] pipe The pipeline handler that wants a matching IPA proxy\n>   * \\param[in] minVersion Minimum acceptable version of IPA module\n> @@ -253,53 +254,6 @@ unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth)\n>   * \\return A newly created IPA proxy, or nullptr if no matching IPA module is\n>   * found or if the IPA proxy fails to initialize\n>   */\n> -std::unique_ptr<IPAProxy> IPAManager::createIPA(PipelineHandler *pipe,\n> -\t\t\t\t\t\tuint32_t maxVersion,\n> -\t\t\t\t\t\tuint32_t minVersion)\n> -{\n> -\tIPAModule *m = nullptr;\n> -\n> -\tfor (IPAModule *module : self_->modules_) {\n> -\t\tif (module->match(pipe, minVersion, maxVersion)) {\n> -\t\t\tm = module;\n> -\t\t\tbreak;\n> -\t\t}\n> -\t}\n> -\n> -\tif (!m)\n> -\t\treturn nullptr;\n> -\n> -\t/*\n> -\t * Load and run the IPA module in a thread if it has a valid signature,\n> -\t * or isolate it in a separate process otherwise.\n> -\t *\n> -\t * \\todo Implement a better proxy selection\n> -\t */\n> -\tstd::string pipeName(pipe->name());\n> -\tconst char *proxyName = pipeName.replace(0, 15, \"IPAProxy\").c_str();\n> -\tIPAProxyFactory *pf = nullptr;\n> -\n> -\tfor (IPAProxyFactory *factory : IPAProxyFactory::factories()) {\n> -\t\tif (!strcmp(factory->name().c_str(), proxyName)) {\n> -\t\t\tpf = factory;\n> -\t\t\tbreak;\n> -\t\t}\n> -\t}\n> -\n> -\tif (!pf) {\n> -\t\tLOG(IPAManager, Error) << \"Failed to get proxy factory\";\n> -\t\treturn nullptr;\n> -\t}\n> -\n> -\tstd::unique_ptr<IPAProxy> proxy =\n> -\t\tpf->create(m, !self_->isSignatureValid(m));\n> -\tif (!proxy->isValid()) {\n> -\t\tLOG(IPAManager, Error) << \"Failed to load proxy\";\n> -\t\treturn nullptr;\n> -\t}\n> -\n> -\treturn proxy;\n> -}\n>  \n>  bool IPAManager::isSignatureValid([[maybe_unused]] IPAModule *ipa) const\n>  {\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 70bb6fcc..19755e8c 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -1108,8 +1108,7 @@ void RPiCameraData::frameStarted(uint32_t sequence)\n>  \n>  int RPiCameraData::loadIPA()\n>  {\n> -\tstd::unique_ptr<IPAProxy> ptr = IPAManager::createIPA(pipe_, 1, 1);\n> -\tipa_ = std::unique_ptr<IPAProxyRPi>{static_cast<IPAProxyRPi*>(std::move(ptr).release())};\n> +\tipa_ = IPAManager::createIPA<IPAProxyRPi>(pipe_, 1, 1);\n>  \n>  \tif (!ipa_)\n>  \t\treturn -ENOENT;\n> -- \n> 2.27.0\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 987DFBF01C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 19 Sep 2020 12:45:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5CA7E62FBF;\n\tSat, 19 Sep 2020 14:45:43 +0200 (CEST)","from mail-lj1-x232.google.com (mail-lj1-x232.google.com\n\t[IPv6:2a00:1450:4864:20::232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0FBDC60367\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 19 Sep 2020 14:45:42 +0200 (CEST)","by mail-lj1-x232.google.com with SMTP id a15so7272849ljk.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 19 Sep 2020 05:45:42 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tt2sm1261787lff.157.2020.09.19.05.45.40\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSat, 19 Sep 2020 05:45:41 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"fZ6lDOdT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=BDTf8iL/QFneuD045q5npn/+CGgvWaSj4lbqLB0nLKo=;\n\tb=fZ6lDOdTDiwGSu8wLsrrYUoeA7/rUIC5Ov63XY7VBXUF/dYPMK6XE2ydAf4Zsu/9T2\n\tkBDDD7lTgcNNtcVzI0yr7u8l2h6NS90UW+6iBwm8bBgneXHJnjVtyQA/IpdT/eamMwla\n\tqPEOrct2w8MLyHub8l4WTPQNseFc7dIpvAz3NPOBomQ7s9mTtXwaPyoEuYuoJ0fdxpZm\n\ttnXZ9RJgVd1OgybU6sBdDNSA539QPlfM1C47GZgBIJ1w03KC9w0mNVF9rP8R+ebHpBDu\n\tIJNAdx7l773FOoFjtlrIMO40ByMeSB3CJcdlcg+mKxpCbWQ271XKqU4QoRxAwE2T+XiD\n\t/rBA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=BDTf8iL/QFneuD045q5npn/+CGgvWaSj4lbqLB0nLKo=;\n\tb=JnLzrqcgkBvU8nGkSO7W07kbM/EsJT/sGLf9PJ/HCamSL8+ggZklQz4GWqqK+QcaZs\n\tTBj3zRst3A/I1nzwJxOj48eYc6hHwJJ0fN+5fwuJRmHM6waevRlpbN8QN2RwtuICxNDW\n\t7jbzv3OB/EUgxbuVfkWp5hDhS0rui+2Qk8VXvCRaLxRc8Yg2pKCLqunlwV1RpNK4d+4L\n\tOS/Nk8lTI9SDAlnLHbbZQYiFiTYPv6nilMVsI9GBrUhPpzcMOmfewV9zDMwIquYnV/GL\n\teYqo/3Zx1/FgE1fq9Pw72mlfcGjFgY7EnmqWaoJJfuxuZ1KGiM6W4WekpHX0lq5cCIYP\n\tu1cQ==","X-Gm-Message-State":"AOAM532722XEeOJ3G9LRUMWdgdOr9nxqzUeee74QGrvi3QhVO1zUX61J\n\tK8yuc7HYXitc6iBMdSk5UW2dRA==","X-Google-Smtp-Source":"ABdhPJxqZofZ+YZqkHl1S9EM3Mn/MJtgBRQeZ5a8kH3H1C4m1ZBksYwCTxhS27dzn1LDe0jk4799Xg==","X-Received":"by 2002:a2e:b8d4:: with SMTP id\n\ts20mr12291066ljp.232.1600519541423; \n\tSat, 19 Sep 2020 05:45:41 -0700 (PDT)","Date":"Sat, 19 Sep 2020 14:45:40 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20200919124540.GW1850958@oden.dyn.berto.se>","References":"<20200915142038.28757-1-paul.elder@ideasonboard.com>\n\t<20200915142038.28757-22-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200915142038.28757-22-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 21/23] libcamera: IPAManager: Make\n\tcreateIPA return proxy directly","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]