Remove everything related to the C API, including ipa_context, ipa_context_wrapper, and IPAInterfaceWrapper. Also remove relevant documentation. ipaCreate() provided by IPA implementations, and createInterface() provided by IPAModule (wrapper around IPA implementation) both now return a C++ object IPAInterface instead of struct ipa_context. Although IPAInterfaceWrapper is the only component of libipa, the skeleton and build files for libipa are retained. After converting the C API to the C++-only API, make all pipeline handlers and IPAs use the new API. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- This is a combination of 21 commits: --- libcamera: IPAModule: Replace ipa_context with IPAInterface With the new IPC infrastructure, we no longer need the C interface as provided by struct ipa_context. Make ipaCreate_() and createInterface() return IPAInterface. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: ipa_context_wrapper: Remove ipa_context_wrapper Since ipa_context has been replaced with custom IPAInterfaces, it is not longer needed. Remove it. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: IPAInterface: remove ipa_context and functions from documentation Remove all the documentation related to ipa_context and the C IPA API, as well as the documentation about the functions in the IPAInterface. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> --- libcamera: IPAInterface: Remove all functions from IPAInterface Now that all the functions in the IPA interface are defined in the data definition file and a specialized IPAInterface is generated per pipeline handler, remove all the functions from the base IPAInterface. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: IPAInterface: make ipaCreate return IPAInterface With the new IPC infrastructure, we no longer need the C interface as provided by struct ipa_context. Make ipaCreate return IPAinterface. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> --- ipa: remove IPAInterfaceWrapper As every pipeline has its own proxy, IPAInterfaceWrapper is no longer necessary. Remove it. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Acked-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> --- libcamera: IPAProxy: Remove stop() override Since stop() is part of the IPA interface, and the IPA interface is now generated based on the data definition file per pipeline, this no longer needs to be overrided by the base IPAProxy. Remove it. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: IPAProxy, IPAManager: Switch to one-proxy-per-pipeline scheme IPAProxy is changed in two major ways: - Every pipeline has its own proxy, to support each pipeline's IPA interface - IPAProxy implementations always encapsulate IPA modules, and switch internally for isolation or threaded The IPAProxy registration mechanism is removed, as each pipeline will have its own proxy, so the pipeline can pass the specialized class name of the IPAProxy to the IPAManager for construction. IPAManager is changed accordingly to support these changes: - createIPA is a template function that takes an IPAProxy class, and always returns an IPAProxy - IPAManager no longer decides on isolation, and simply creates an IPAProxy instance while passing the isolation flag Consequently, the old IPAProxy classes (IPAProxyThread and IPAProxyLinux) are removed. The IPAInterfaceTest is updated to use the new IPAManager interface, and to construct a ProcessManager as no single global instance is created anymore. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> --- libcamera: IPAProxy: Add isolate parameter to create() Since IPAProxy implementations now always encapsulate IPA modules, add a parameter to create() to signal if the proxy should isolate the IPA or not. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: IPAManager: Fetch IPAProxy corresponding to pipeline Now that each pipeline handler has its own IPAProxy implementation, make the IPAManager fetch the IPAProxy based on the pipeline handler name. Also, since the IPAProxy is used regardless of isolation or no isolation, remove the isolation check from the proxy selection. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> --- libcamera: IPAManager: add isolation flag to proxy creation When the IPA proxy is created, it needs to know whether to isolate or not. Feed the flag at creation of the IPA proxy. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: IPAManager: Make createIPA return proxy directly Since every pipeline knows the type of the proxy that it needs, and since all IPAs are to be wrapped in a proxy, IPAManager no longer needs to search in the factory list to fetch the proxy factory to construct a factory. Instead, we define createIPA as a template function, and the pipeline handler can declare the proxy type when it calls createIPA. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: IPAProxy: Remove registration mechanism Implementations of IPA proxies use a registration mechanism to register themselves with the main IPA proxy factory. This registration declares static objects, causing a risk of things being constructed before the proper libcamera facilities are ready. Since each pipeline handler has its own IPA proxy and knows the type, it isn't necessary to have a proxy factory. Remove it to alleviate the risk of early construction. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: proxy: Remove IPAProxyLinux and IPAProxyThread We have now changed the proxy from per-IPC mechanism to per-pipeline. The per-IPC mechanism proxies are thus no longer needed; remove them. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- tests: ipa_interface_test: Update to use new createIPA Update the IPA interface test to use the new createIPA function from IPAManager. Also create an instance of ProcessManager, as no single global instance is created automatically anymore. Update meson.build to to depend on the generated IPA interface headers. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: PipelineHandler: Remove IPA from base class Since pipeline handlers now have their own IPA interface types, it can no longer be defined in the base class, and each pipeline handler implementation must declare it and its type themselves. Remove it from the base class. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- ipa: raspberrypi: Add mojom data definition file Add a mojom data definition for raspberrypi pipeline handler's IPAs. This simplifies the API between the raspberrypi pipeline handler and the IPA, and is not a direct translation of what was used before with IPAOperationData. Also move the enums from raspberrypi.h to raspberrypi.mojom Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: pipeline, ipa: raspberrypi: Use new data definition Now that we can generate custom functions and data structures with mojo, switch the raspberrypi pipeline handler and IPA to use the custom data structures as defined in the mojom data definition file. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: pipeline, ipa: vimc: Support the new IPC mechanism Add support to vimc pipeline handler and IPA for the new IPC mechanism. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> --- libcamera: pipeline, ipa: rkisp1: Support the new IPC mechanism Add support to the rkisp1 pipeline handler and IPA for the new IPC mechanism. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- libcamera: pipeline, ipa: ipu3: Support the new IPC mechanism Add support to ipu3 pipeline handler and IPA for the new IPC mechanism. [Original version] Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> [Fixed commit message and small changes] Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
486 lines
12 KiB
C++
486 lines
12 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* ipa_module.cpp - Image Processing Algorithm module
|
|
*/
|
|
|
|
#include "libcamera/internal/ipa_module.h"
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <ctype.h>
|
|
#include <dlfcn.h>
|
|
#include <elf.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <link.h>
|
|
#include <string.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
|
|
#include <libcamera/span.h>
|
|
|
|
#include "libcamera/internal/file.h"
|
|
#include "libcamera/internal/log.h"
|
|
#include "libcamera/internal/pipeline_handler.h"
|
|
#include "libcamera/internal/utils.h"
|
|
|
|
/**
|
|
* \file ipa_module.h
|
|
* \brief Image Processing Algorithm module
|
|
*/
|
|
|
|
/**
|
|
* \file ipa_module_info.h
|
|
* \brief Image Processing Algorithm module information
|
|
*/
|
|
|
|
namespace libcamera {
|
|
|
|
LOG_DEFINE_CATEGORY(IPAModule)
|
|
|
|
namespace {
|
|
|
|
template<typename T>
|
|
typename std::remove_extent_t<T> *elfPointer(Span<const uint8_t> elf,
|
|
off_t offset, size_t objSize)
|
|
{
|
|
size_t size = offset + objSize;
|
|
if (size > elf.size() || size < objSize)
|
|
return nullptr;
|
|
|
|
return reinterpret_cast<typename std::remove_extent_t<T> *>
|
|
(reinterpret_cast<const char *>(elf.data()) + offset);
|
|
}
|
|
|
|
template<typename T>
|
|
typename std::remove_extent_t<T> *elfPointer(Span<const uint8_t> elf,
|
|
off_t offset)
|
|
{
|
|
return elfPointer<T>(elf, offset, sizeof(T));
|
|
}
|
|
|
|
int elfVerifyIdent(Span<const uint8_t> elf)
|
|
{
|
|
const char *e_ident = elfPointer<const char[EI_NIDENT]>(elf, 0);
|
|
if (!e_ident)
|
|
return -ENOEXEC;
|
|
|
|
if (e_ident[EI_MAG0] != ELFMAG0 ||
|
|
e_ident[EI_MAG1] != ELFMAG1 ||
|
|
e_ident[EI_MAG2] != ELFMAG2 ||
|
|
e_ident[EI_MAG3] != ELFMAG3 ||
|
|
e_ident[EI_VERSION] != EV_CURRENT)
|
|
return -ENOEXEC;
|
|
|
|
int bitClass = sizeof(unsigned long) == 4 ? ELFCLASS32 : ELFCLASS64;
|
|
if (e_ident[EI_CLASS] != bitClass)
|
|
return -ENOEXEC;
|
|
|
|
int a = 1;
|
|
unsigned char endianness = *reinterpret_cast<char *>(&a) == 1
|
|
? ELFDATA2LSB : ELFDATA2MSB;
|
|
if (e_ident[EI_DATA] != endianness)
|
|
return -ENOEXEC;
|
|
|
|
return 0;
|
|
}
|
|
|
|
const ElfW(Shdr) *elfSection(Span<const uint8_t> elf, const ElfW(Ehdr) *eHdr,
|
|
ElfW(Half) idx)
|
|
{
|
|
if (idx >= eHdr->e_shnum)
|
|
return nullptr;
|
|
|
|
off_t offset = eHdr->e_shoff + idx *
|
|
static_cast<uint32_t>(eHdr->e_shentsize);
|
|
return elfPointer<const ElfW(Shdr)>(elf, offset);
|
|
}
|
|
|
|
/**
|
|
* \brief Retrieve address and size of a symbol from an mmap'ed ELF file
|
|
* \param[in] elf Address and size of mmap'ed ELF file
|
|
* \param[in] symbol Symbol name
|
|
*
|
|
* \return The memory region storing the symbol on success, or an empty span
|
|
* otherwise
|
|
*/
|
|
Span<const uint8_t> elfLoadSymbol(Span<const uint8_t> elf, const char *symbol)
|
|
{
|
|
const ElfW(Ehdr) *eHdr = elfPointer<const ElfW(Ehdr)>(elf, 0);
|
|
if (!eHdr)
|
|
return {};
|
|
|
|
const ElfW(Shdr) *sHdr = elfSection(elf, eHdr, eHdr->e_shstrndx);
|
|
if (!sHdr)
|
|
return {};
|
|
off_t shnameoff = sHdr->sh_offset;
|
|
|
|
/* Locate .dynsym section header. */
|
|
const ElfW(Shdr) *dynsym = nullptr;
|
|
for (unsigned int i = 0; i < eHdr->e_shnum; i++) {
|
|
sHdr = elfSection(elf, eHdr, i);
|
|
if (!sHdr)
|
|
return {};
|
|
|
|
off_t offset = shnameoff + sHdr->sh_name;
|
|
const char *name = elfPointer<const char[8]>(elf, offset);
|
|
if (!name)
|
|
return {};
|
|
|
|
if (sHdr->sh_type == SHT_DYNSYM && !strcmp(name, ".dynsym")) {
|
|
dynsym = sHdr;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (dynsym == nullptr) {
|
|
LOG(IPAModule, Error) << "ELF has no .dynsym section";
|
|
return {};
|
|
}
|
|
|
|
sHdr = elfSection(elf, eHdr, dynsym->sh_link);
|
|
if (!sHdr)
|
|
return {};
|
|
off_t dynsym_nameoff = sHdr->sh_offset;
|
|
|
|
/* Locate symbol in the .dynsym section. */
|
|
const ElfW(Sym) *targetSymbol = nullptr;
|
|
unsigned int dynsym_num = dynsym->sh_size / dynsym->sh_entsize;
|
|
for (unsigned int i = 0; i < dynsym_num; i++) {
|
|
off_t offset = dynsym->sh_offset + dynsym->sh_entsize * i;
|
|
const ElfW(Sym) *sym = elfPointer<const ElfW(Sym)>(elf, offset);
|
|
if (!sym)
|
|
return {};
|
|
|
|
offset = dynsym_nameoff + sym->st_name;
|
|
const char *name = elfPointer<const char>(elf, offset,
|
|
strlen(symbol) + 1);
|
|
if (!name)
|
|
return {};
|
|
|
|
if (!strcmp(name, symbol) &&
|
|
sym->st_info & STB_GLOBAL) {
|
|
targetSymbol = sym;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (targetSymbol == nullptr) {
|
|
LOG(IPAModule, Error) << "Symbol " << symbol << " not found";
|
|
return {};
|
|
}
|
|
|
|
/* Locate and return data of symbol. */
|
|
sHdr = elfSection(elf, eHdr, targetSymbol->st_shndx);
|
|
if (!sHdr)
|
|
return {};
|
|
off_t offset = sHdr->sh_offset + (targetSymbol->st_value - sHdr->sh_addr);
|
|
const uint8_t *data = elfPointer<const uint8_t>(elf, offset,
|
|
targetSymbol->st_size);
|
|
if (!data)
|
|
return {};
|
|
|
|
return { data, targetSymbol->st_size };
|
|
}
|
|
|
|
} /* namespace */
|
|
|
|
/**
|
|
* \def IPA_MODULE_API_VERSION
|
|
* \brief The IPA module API version
|
|
*
|
|
* This version number specifies the version for the layout of
|
|
* struct IPAModuleInfo. The IPA module shall use this macro to
|
|
* set its moduleAPIVersion field.
|
|
*
|
|
* \sa IPAModuleInfo::moduleAPIVersion
|
|
*/
|
|
|
|
/**
|
|
* \struct IPAModuleInfo
|
|
* \brief Information of an IPA module
|
|
*
|
|
* This structure contains the information of an IPA module. It is loaded,
|
|
* read, and validated before anything else is loaded from the shared object.
|
|
*
|
|
* \var IPAModuleInfo::moduleAPIVersion
|
|
* \brief The IPA module API version that the IPA module implements
|
|
*
|
|
* This version number specifies the version for the layout of
|
|
* struct IPAModuleInfo. The IPA module shall report here the version that
|
|
* it was built for, using the macro IPA_MODULE_API_VERSION.
|
|
*
|
|
* \var IPAModuleInfo::pipelineVersion
|
|
* \brief The pipeline handler version that the IPA module is for
|
|
*
|
|
* \var IPAModuleInfo::pipelineName
|
|
* \brief The name of the pipeline handler that the IPA module is for
|
|
*
|
|
* This name is used to match a pipeline handler with the module.
|
|
*
|
|
* \var IPAModuleInfo::name
|
|
* \brief The name of the IPA module
|
|
*
|
|
* The name may be used to build file system paths to IPA-specific resources.
|
|
* It shall only contain printable characters, and may not contain '/', '*',
|
|
* '?' or '\'. For IPA modules included in libcamera, it shall match the
|
|
* directory of the IPA module in the source tree.
|
|
*
|
|
* \todo Allow user to choose to isolate open source IPAs
|
|
*/
|
|
|
|
/**
|
|
* \var ipaModuleInfo
|
|
* \brief Information of an IPA module
|
|
*
|
|
* An IPA module must export a struct IPAModuleInfo of this name.
|
|
*/
|
|
|
|
/**
|
|
* \class IPAModule
|
|
* \brief Wrapper around IPA module shared object
|
|
*/
|
|
|
|
/**
|
|
* \brief Construct an IPAModule instance
|
|
* \param[in] libPath path to IPA module shared object
|
|
*
|
|
* Loads the IPAModuleInfo from the IPA module shared object at libPath.
|
|
* The IPA module shared object file must be of the same endianness and
|
|
* bitness as libcamera.
|
|
*
|
|
* The caller shall call the isValid() method after constructing an
|
|
* IPAModule instance to verify the validity of the IPAModule.
|
|
*/
|
|
IPAModule::IPAModule(const std::string &libPath)
|
|
: libPath_(libPath), valid_(false), loaded_(false),
|
|
dlHandle_(nullptr), ipaCreate_(nullptr)
|
|
{
|
|
if (loadIPAModuleInfo() < 0)
|
|
return;
|
|
|
|
valid_ = true;
|
|
}
|
|
|
|
IPAModule::~IPAModule()
|
|
{
|
|
if (dlHandle_)
|
|
dlclose(dlHandle_);
|
|
}
|
|
|
|
int IPAModule::loadIPAModuleInfo()
|
|
{
|
|
File file{ libPath_ };
|
|
if (!file.open(File::ReadOnly)) {
|
|
LOG(IPAModule, Error) << "Failed to open IPA library: "
|
|
<< strerror(-file.error());
|
|
return file.error();
|
|
}
|
|
|
|
Span<const uint8_t> data = file.map();
|
|
int ret = elfVerifyIdent(data);
|
|
if (ret) {
|
|
LOG(IPAModule, Error) << "IPA module is not an ELF file";
|
|
return ret;
|
|
}
|
|
|
|
Span<const uint8_t> info = elfLoadSymbol(data, "ipaModuleInfo");
|
|
if (info.size() != sizeof(info_)) {
|
|
LOG(IPAModule, Error) << "IPA module has no valid info";
|
|
return -EINVAL;
|
|
}
|
|
|
|
memcpy(&info_, info.data(), info.size());
|
|
|
|
if (info_.moduleAPIVersion != IPA_MODULE_API_VERSION) {
|
|
LOG(IPAModule, Error) << "IPA module API version mismatch";
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Validate the IPA module name. */
|
|
std::string ipaName = info_.name;
|
|
auto iter = std::find_if_not(ipaName.begin(), ipaName.end(),
|
|
[](unsigned char c) -> bool {
|
|
return isprint(c) && c != '/' &&
|
|
c != '?' && c != '*' &&
|
|
c != '\\';
|
|
});
|
|
if (iter != ipaName.end()) {
|
|
LOG(IPAModule, Error)
|
|
<< "Invalid IPA module name '" << ipaName << "'";
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Load the signature. Failures are not fatal. */
|
|
File sign{ libPath_ + ".sign" };
|
|
if (!sign.open(File::ReadOnly)) {
|
|
LOG(IPAModule, Debug)
|
|
<< "IPA module " << libPath_ << " is not signed";
|
|
return 0;
|
|
}
|
|
|
|
data = sign.map(0, -1, File::MapPrivate);
|
|
signature_.resize(data.size());
|
|
memcpy(signature_.data(), data.data(), data.size());
|
|
|
|
LOG(IPAModule, Debug) << "IPA module " << libPath_ << " is signed";
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* \brief Check if the IPAModule instance is valid
|
|
*
|
|
* An IPAModule instance is valid if the IPA module shared object exists and
|
|
* the IPA module information it contains was successfully retrieved and
|
|
* validated.
|
|
*
|
|
* \return True if the IPAModule is valid, false otherwise
|
|
*/
|
|
bool IPAModule::isValid() const
|
|
{
|
|
return valid_;
|
|
}
|
|
|
|
/**
|
|
* \brief Retrieve the IPA module information
|
|
*
|
|
* The content of the IPA module information is loaded from the module,
|
|
* and is valid only if the module is valid (as returned by isValid()).
|
|
* Calling this function on an invalid module is an error.
|
|
*
|
|
* \return the IPA module information
|
|
*/
|
|
const struct IPAModuleInfo &IPAModule::info() const
|
|
{
|
|
return info_;
|
|
}
|
|
|
|
/**
|
|
* \brief Retrieve the IPA module signature
|
|
*
|
|
* The IPA module signature is stored alongside the IPA module in a file with a
|
|
* '.sign' suffix, and is loaded when the IPAModule instance is created. This
|
|
* function returns the signature without verifying it. If the signature is
|
|
* missing, the returned vector will be empty.
|
|
*
|
|
* \return The IPA module signature
|
|
*/
|
|
const std::vector<uint8_t> IPAModule::signature() const
|
|
{
|
|
return signature_;
|
|
}
|
|
|
|
/**
|
|
* \brief Retrieve the IPA module path
|
|
*
|
|
* The IPA module path is the file name and path of the IPA module shared
|
|
* object from which the IPA module was created.
|
|
*
|
|
* \return The IPA module path
|
|
*/
|
|
const std::string &IPAModule::path() const
|
|
{
|
|
return libPath_;
|
|
}
|
|
|
|
/**
|
|
* \brief Load the IPA implementation factory from the shared object
|
|
*
|
|
* The IPA module shared object implements an IPAInterface object to be used
|
|
* by pipeline handlers. This method loads the factory function from the
|
|
* shared object. Later, createInterface() can be called to instantiate the
|
|
* IPAInterface.
|
|
*
|
|
* This method only needs to be called successfully once, after which
|
|
* createInterface() can be called as many times as IPAInterface instances are
|
|
* needed.
|
|
*
|
|
* Calling this function on an invalid module (as returned by isValid()) is
|
|
* an error.
|
|
*
|
|
* \return True if load was successful, or already loaded, and false otherwise
|
|
*/
|
|
bool IPAModule::load()
|
|
{
|
|
if (!valid_)
|
|
return false;
|
|
|
|
if (loaded_)
|
|
return true;
|
|
|
|
dlHandle_ = dlopen(libPath_.c_str(), RTLD_LAZY);
|
|
if (!dlHandle_) {
|
|
LOG(IPAModule, Error)
|
|
<< "Failed to open IPA module shared object: "
|
|
<< dlerror();
|
|
return false;
|
|
}
|
|
|
|
void *symbol = dlsym(dlHandle_, "ipaCreate");
|
|
if (!symbol) {
|
|
LOG(IPAModule, Error)
|
|
<< "Failed to load ipaCreate() from IPA module shared object: "
|
|
<< dlerror();
|
|
dlclose(dlHandle_);
|
|
dlHandle_ = nullptr;
|
|
return false;
|
|
}
|
|
|
|
ipaCreate_ = reinterpret_cast<IPAIntfFactory>(symbol);
|
|
|
|
loaded_ = true;
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* \brief Instantiate an IPA interface
|
|
*
|
|
* After loading the IPA module with load(), this method creates an instance of
|
|
* the IPA module interface.
|
|
*
|
|
* Calling this function on a module that has not yet been loaded, or an
|
|
* invalid module (as returned by load() and isValid(), respectively) is
|
|
* an error.
|
|
*
|
|
* \return The IPA interface on success, or nullptr on error
|
|
*/
|
|
IPAInterface *IPAModule::createInterface()
|
|
{
|
|
if (!valid_ || !loaded_)
|
|
return nullptr;
|
|
|
|
return ipaCreate_();
|
|
}
|
|
|
|
/**
|
|
* \brief Verify if the IPA module matches a given pipeline handler
|
|
* \param[in] pipe Pipeline handler to match with
|
|
* \param[in] minVersion Minimum acceptable version of IPA module
|
|
* \param[in] maxVersion Maximum acceptable version of IPA module
|
|
*
|
|
* This method checks if this IPA module matches the \a pipe pipeline handler,
|
|
* and the input version range.
|
|
*
|
|
* \return True if the pipeline handler matches the IPA module, or false otherwise
|
|
*/
|
|
bool IPAModule::match(PipelineHandler *pipe,
|
|
uint32_t minVersion, uint32_t maxVersion) const
|
|
{
|
|
return info_.pipelineVersion >= minVersion &&
|
|
info_.pipelineVersion <= maxVersion &&
|
|
!strcmp(info_.pipelineName, pipe->name());
|
|
}
|
|
|
|
std::string IPAModule::logPrefix() const
|
|
{
|
|
return utils::basename(libPath_.c_str());
|
|
}
|
|
|
|
} /* namespace libcamera */
|