Files
external_libcamera/include/libcamera/internal/ipa_manager.h
Laurent Pinchart 1045522af9 libcamera: ipa_manager: Remove singleton requirement
The IPAManager class implements a singleton pattern due to the need of
accessing the instance in a static member function. The function now
takes a pointer to a PipelineHandler, which we can use to access the
CameraManager, and from there, the IPAManager.

Add accessors to the internal API to expose the CameraManager from the
PipelineHandler, and the IPAManager from the CameraManager. This
requires allocating the IPAManager dynamically to avoid a loop in
includes. Use those accessors to replace the IPAManager singleton.

Update the IPA interface unit test to instantiate a CameraManager
instead of an IPAManager and ProcessManager, to reflect the new way that
the IPAManager is accessed.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2024-08-07 18:58:55 +03:00

79 lines
1.7 KiB
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* Image Processing Algorithm module manager
*/
#pragma once
#include <stdint.h>
#include <vector>
#include <libcamera/base/log.h>
#include <libcamera/ipa/ipa_interface.h>
#include <libcamera/ipa/ipa_module_info.h>
#include "libcamera/internal/camera_manager.h"
#include "libcamera/internal/ipa_module.h"
#include "libcamera/internal/pipeline_handler.h"
#include "libcamera/internal/pub_key.h"
namespace libcamera {
LOG_DECLARE_CATEGORY(IPAManager)
class IPAManager
{
public:
IPAManager();
~IPAManager();
template<typename T>
static std::unique_ptr<T> createIPA(PipelineHandler *pipe,
uint32_t minVersion,
uint32_t maxVersion)
{
CameraManager *cm = pipe->cameraManager();
IPAManager *self = cm->_d()->ipaManager();
IPAModule *m = self->module(pipe, minVersion, maxVersion);
if (!m)
return nullptr;
std::unique_ptr<T> proxy = std::make_unique<T>(m, !self->isSignatureValid(m));
if (!proxy->isValid()) {
LOG(IPAManager, Error) << "Failed to load proxy";
return nullptr;
}
return proxy;
}
#if HAVE_IPA_PUBKEY
static const PubKey &pubKey()
{
return pubKey_;
}
#endif
private:
void parseDir(const char *libDir, unsigned int maxDepth,
std::vector<std::string> &files);
unsigned int addDir(const char *libDir, unsigned int maxDepth = 0);
IPAModule *module(PipelineHandler *pipe, uint32_t minVersion,
uint32_t maxVersion);
bool isSignatureValid(IPAModule *ipa) const;
std::vector<IPAModule *> modules_;
#if HAVE_IPA_PUBKEY
static const uint8_t publicKeyData_[];
static const PubKey pubKey_;
#endif
};
} /* namespace libcamera */