libcamera  v0.0.0
Supporting cameras in Linux since 2019
algorithm.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2021, Ideas On Board
4  *
5  * algorithm.h - ISP control algorithm interface
6  */
7 #pragma once
8 
9 #include <memory>
10 #include <string>
11 
12 #include <libcamera/controls.h>
13 
14 namespace libcamera {
15 
16 class YamlObject;
17 
18 namespace ipa {
19 
20 template<typename _Module>
21 class Algorithm
22 {
23 public:
24  using Module = _Module;
25 
26  virtual ~Algorithm() {}
27 
28  virtual int init([[maybe_unused]] typename Module::Context &context,
29  [[maybe_unused]] const YamlObject &tuningData)
30  {
31  return 0;
32  }
33 
34  virtual int configure([[maybe_unused]] typename Module::Context &context,
35  [[maybe_unused]] const typename Module::Config &configInfo)
36  {
37  return 0;
38  }
39 
40  virtual void prepare([[maybe_unused]] typename Module::Context &context,
41  [[maybe_unused]] typename Module::Params *params)
42  {
43  }
44 
45  virtual void queueRequest([[maybe_unused]] typename Module::Context &context,
46  [[maybe_unused]] const uint32_t frame,
47  [[maybe_unused]] const ControlList &controls)
48  {
49  }
50 
51  virtual void process([[maybe_unused]] typename Module::Context &context,
52  [[maybe_unused]] typename Module::FrameContext *frameContext,
53  [[maybe_unused]] const typename Module::Stats *stats)
54  {
55  }
56 };
57 
58 template<typename _Module>
59 class AlgorithmFactoryBase
60 {
61 public:
62  AlgorithmFactoryBase(const char *name)
63  : name_(name)
64  {
65  _Module::registerAlgorithm(this);
66  }
67 
68  virtual ~AlgorithmFactoryBase() = default;
69 
70  const std::string &name() const { return name_; }
71 
72  virtual std::unique_ptr<Algorithm<_Module>> create() const = 0;
73 
74 private:
75  std::string name_;
76 };
77 
78 template<typename _Algorithm>
79 class AlgorithmFactory : public AlgorithmFactoryBase<typename _Algorithm::Module>
80 {
81 public:
82  AlgorithmFactory(const char *name)
83  : AlgorithmFactoryBase<typename _Algorithm::Module>(name)
84  {
85  }
86 
87  ~AlgorithmFactory() = default;
88 
89  std::unique_ptr<Algorithm<typename _Algorithm::Module>> create() const override
90  {
91  return std::make_unique<_Algorithm>();
92  }
93 };
94 
95 #define REGISTER_IPA_ALGORITHM(algorithm, name) \
96 static AlgorithmFactory<algorithm> global_##algorithm##Factory(name);
97 
98 } /* namespace ipa */
99 
100 } /* namespace libcamera */
Associate a list of ControlId with their values for an object.
Definition: controls.h:350
A class representing the tree structure of the YAML content.
Definition: yaml_parser.h:26
Registration of Algorithm classes and creation of instances.
Definition: algorithm.h:80
std::unique_ptr< Algorithm< typename _Algorithm::Module > > create() const override
Create an instance of the Algorithm corresponding to the factory.
Definition: algorithm.h:89
AlgorithmFactory(const char *name)
Construct an algorithm factory.
Definition: algorithm.h:82
The base class for all IPA algorithms.
Definition: algorithm.h:22
virtual void process([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] typename Module::FrameContext *frameContext, [[maybe_unused]] const typename Module::Stats *stats)
Process ISP statistics, and run algorithm operations.
Definition: algorithm.h:51
virtual int init([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const YamlObject &tuningData)
Initialize the Algorithm with tuning data.
Definition: algorithm.h:28
virtual void prepare([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] typename Module::Params *params)
Fill the params buffer with ISP processing parameters for a frame.
Definition: algorithm.h:40
virtual void queueRequest([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] const ControlList &controls)
Provide control values to the algorithm.
Definition: algorithm.h:45
_Module Module
The IPA module type for this class of algorithms.
Definition: algorithm.h:24
virtual int configure([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const typename Module::Config &configInfo)
Configure the Algorithm given an IPAConfigInfo.
Definition: algorithm.h:34
The base class for all IPA modules.
Definition: module.h:31
_Context Context
The type of the shared IPA context.
Definition: module.h:33
_Params Params
The type of the ISP specific parameters.
Definition: module.h:36
_FrameContext FrameContext
The type of the frame context.
Definition: module.h:34
_Config Config
The type of the IPA configuration data.
Definition: module.h:35
_Stats Stats
The type of the IPA statistics and ISP results.
Definition: module.h:37
Framework to manage controls related to an object.
const ControlIdMap controls
List of all supported libcamera controls.
Definition: control_ids.cpp:1301
Top-level libcamera namespace.
Definition: backtrace.h:17