libcamera
v0.7.2
Supporting cameras in Linux since 2019
Toggle main menu visibility
Loading...
Searching...
No Matches
module.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
/*
3
* Copyright (C) 2022, Ideas On Board
4
*
5
* IPA module
6
*/
7
8
#pragma once
9
10
#include <list>
11
#include <memory>
12
#include <string>
13
#include <vector>
14
15
#include <
libcamera/base/log.h
>
16
#include <
libcamera/base/utils.h
>
17
18
#include "
libcamera/internal/value_node.h
"
19
20
#include "
algorithm.h
"
21
22
namespace
libcamera
{
23
24
LOG_DECLARE_CATEGORY
(IPAModuleAlgo)
25
26
namespace
ipa
{
27
28
template
<
typename
_Context,
typename
_FrameContext,
typename
_Config,
29
typename
_Params,
typename
_Stats>
30
class
Module
:
public
Loggable
31
{
32
public
:
33
using
Context
= _Context;
34
using
FrameContext
= _FrameContext;
35
using
Config
= _Config;
36
using
Params
= _Params;
37
using
Stats
= _Stats;
38
39
virtual
~Module
() {}
40
41
const
std::list<std::unique_ptr<Algorithm<Module>>> &
algorithms
()
const
42
{
43
return
algorithms_;
44
}
45
46
int
createAlgorithms
(
Context
&context,
const
ValueNode
&
algorithms
)
47
{
48
const
auto
&list =
algorithms
.
asList
();
49
50
for
(
const
auto
&[i, algo] :
utils::enumerate
(list)) {
51
if
(!algo.isDictionary()) {
52
LOG
(IPAModuleAlgo, Error)
53
<<
"Invalid tuning data syntax for algorithm "
<< i;
54
algorithms_.clear();
55
return
-EINVAL;
56
}
57
58
int
ret = createAlgorithm(context, algo);
59
if
(ret) {
60
algorithms_.clear();
61
return
ret;
62
}
63
}
64
65
return
0;
66
}
67
68
static
void
registerAlgorithm
(AlgorithmFactoryBase<Module> *factory)
69
{
70
factories().push_back(factory);
71
}
72
73
private
:
74
int
createAlgorithm(
Context
&context,
const
ValueNode
&data)
75
{
76
const
auto
&[name, algoData] = *data.
asDict
().begin();
77
78
/*
79
* Optionally, algorithms can be disabled via the tuning file
80
* by including enabled: false as a parameter within the
81
* algorithm tuning data. This is not an error, so we return 0.
82
*/
83
if
(!algoData[
"enabled"
].get<bool>(
true
)) {
84
LOG
(IPAModuleAlgo, Info)
85
<<
"Algorithm '"
<< name <<
"' disabled via tuning file"
;
86
return
0;
87
}
88
89
std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
90
if
(!algo) {
91
LOG
(IPAModuleAlgo, Error)
92
<<
"Algorithm '"
<< name <<
"' not found"
;
93
return
-EINVAL;
94
}
95
96
int
ret = algo->init(context, algoData);
97
if
(ret) {
98
LOG
(IPAModuleAlgo, Error)
99
<<
"Algorithm '"
<< name <<
"' failed to initialize"
;
100
return
ret;
101
}
102
103
LOG
(IPAModuleAlgo, Debug)
104
<<
"Instantiated algorithm '"
<< name <<
"'"
;
105
106
algorithms_.push_back(std::move(algo));
107
return
0;
108
}
109
110
static
std::unique_ptr<Algorithm<Module>> createAlgorithm(
const
std::string &name)
111
{
112
for
(
const
AlgorithmFactoryBase<Module> *factory : factories()) {
113
if
(factory->name() == name)
114
return
factory->create();
115
}
116
117
return
nullptr
;
118
}
119
120
static
std::vector<AlgorithmFactoryBase<Module> *> &factories()
121
{
122
/*
123
* The static factories map is defined inside the function to ensure
124
* it gets initialized on first use, without any dependency on
125
* link order.
126
*/
127
static
std::vector<AlgorithmFactoryBase<Module> *> factories;
128
return
factories;
129
}
130
131
std::list<std::unique_ptr<Algorithm<Module>>> algorithms_;
132
};
133
134
}
/* namespace ipa */
135
136
}
/* namespace libcamera */
libcamera::Loggable
Base class to support log message extensions.
Definition
log.h:105
libcamera::ValueNode
A class representing a tree structure of values.
Definition
value_node.h:27
libcamera::ValueNode::asList
ListAdapter asList()
Wrap a list ValueNode in an adapter that exposes iterators.
Definition
value_node.h:230
libcamera::ValueNode::asDict
DictAdapter asDict()
Wrap a dictionary ValueNode in an adapter that exposes iterators.
Definition
value_node.h:229
libcamera::ipa::Module
The base class for all IPA modules.
Definition
module.h:31
libcamera::ipa::Module< IPAContext, IPAFrameContext, IPAConfigInfo, ipu3_uapi_params, ipu3_uapi_stats_3a >::FrameContext
IPAFrameContext FrameContext
Definition
module.h:34
libcamera::ipa::Module::algorithms
const std::list< std::unique_ptr< Algorithm< Module > > > & algorithms() const
Retrieve the list of instantiated algorithms.
Definition
module.h:41
libcamera::ipa::Module< IPAContext, IPAFrameContext, IPAConfigInfo, ipu3_uapi_params, ipu3_uapi_stats_3a >::Params
ipu3_uapi_params Params
Definition
module.h:36
libcamera::ipa::Module< IPAContext, IPAFrameContext, IPAConfigInfo, ipu3_uapi_params, ipu3_uapi_stats_3a >::Context
IPAContext Context
Definition
module.h:33
libcamera::ipa::Module< IPAContext, IPAFrameContext, IPAConfigInfo, ipu3_uapi_params, ipu3_uapi_stats_3a >::Stats
ipu3_uapi_stats_3a Stats
Definition
module.h:37
libcamera::ipa::Module::registerAlgorithm
static void registerAlgorithm(AlgorithmFactoryBase< Module > *factory)
Add an algorithm factory class to the list of available algorithms.
Definition
module.h:68
libcamera::ipa::Module< IPAContext, IPAFrameContext, IPAConfigInfo, ipu3_uapi_params, ipu3_uapi_stats_3a >::Config
IPAConfigInfo Config
Definition
module.h:35
libcamera::ipa::Module::createAlgorithms
int createAlgorithms(Context &context, const ValueNode &algorithms)
Create algorithms from tuning data.
Definition
module.h:46
algorithm.h
Algorithm common interface.
log.h
Logging infrastructure.
LOG_DECLARE_CATEGORY
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
Definition
log.h:51
LOG
#define LOG(category, severity)
Log a message.
Definition
log.h:155
libcamera::ipa
The IPA (Image Processing Algorithm) namespace.
Definition
af.cpp:58
libcamera
Top-level libcamera namespace.
Definition
backtrace.h:17
utils.h
Miscellaneous utility functions.
libcamera::utils::enumerate
auto enumerate(T &iterable)
Wrap an iterable to enumerate index and value in a range-based loop.
Definition
utils.h:325
value_node.h
Data structure to manage tree of values.
src
ipa
libipa
module.h
Generated by
1.18.0