@@ -14,20 +14,45 @@
#include <libcamera/ipa/ipa_module_info.h>
#include "libcamera/internal/ipa_module.h"
+#include "libcamera/internal/log.h"
#include "libcamera/internal/pipeline_handler.h"
#include "libcamera/internal/pub_key.h"
namespace libcamera {
+LOG_DECLARE_CATEGORY(IPAManager)
+
class IPAManager
{
public:
IPAManager();
~IPAManager();
- static std::unique_ptr<IPAProxy> createIPA(PipelineHandler *pipe,
- uint32_t maxVersion,
- uint32_t minVersion);
+ template<class P>
+ static std::unique_ptr<P> createIPA(PipelineHandler *pipe,
+ uint32_t maxVersion,
+ uint32_t minVersion)
+ {
+ IPAModule *m = nullptr;
+
+ for (IPAModule *module : self_->modules_) {
+ if (module->match(pipe, minVersion, maxVersion)) {
+ m = module;
+ break;
+ }
+ }
+
+ if (!m)
+ return nullptr;
+
+ std::unique_ptr<P> proxy = std::make_unique<P>(m, !self_->isSignatureValid(m));
+ if (!proxy->isValid()) {
+ LOG(IPAManager, Error) << "Failed to load proxy";
+ return nullptr;
+ }
+
+ return proxy;
+ }
private:
static IPAManager *self_;
@@ -245,6 +245,7 @@ unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth)
}
/**
+ * \fn IPAManager::createIPA()
* \brief Create an IPA proxy that matches a given pipeline handler
* \param[in] pipe The pipeline handler that wants a matching IPA proxy
* \param[in] minVersion Minimum acceptable version of IPA module
@@ -253,53 +254,6 @@ unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth)
* \return A newly created IPA proxy, or nullptr if no matching IPA module is
* found or if the IPA proxy fails to initialize
*/
-std::unique_ptr<IPAProxy> IPAManager::createIPA(PipelineHandler *pipe,
- uint32_t maxVersion,
- uint32_t minVersion)
-{
- IPAModule *m = nullptr;
-
- for (IPAModule *module : self_->modules_) {
- if (module->match(pipe, minVersion, maxVersion)) {
- m = module;
- break;
- }
- }
-
- if (!m)
- return nullptr;
-
- /*
- * Load and run the IPA module in a thread if it has a valid signature,
- * or isolate it in a separate process otherwise.
- *
- * \todo Implement a better proxy selection
- */
- std::string pipeName(pipe->name());
- const char *proxyName = pipeName.replace(0, 15, "IPAProxy").c_str();
- IPAProxyFactory *pf = nullptr;
-
- for (IPAProxyFactory *factory : IPAProxyFactory::factories()) {
- if (!strcmp(factory->name().c_str(), proxyName)) {
- pf = factory;
- break;
- }
- }
-
- if (!pf) {
- LOG(IPAManager, Error) << "Failed to get proxy factory";
- return nullptr;
- }
-
- std::unique_ptr<IPAProxy> proxy =
- pf->create(m, !self_->isSignatureValid(m));
- if (!proxy->isValid()) {
- LOG(IPAManager, Error) << "Failed to load proxy";
- return nullptr;
- }
-
- return proxy;
-}
bool IPAManager::isSignatureValid([[maybe_unused]] IPAModule *ipa) const
{