libcamera  v0.0.1
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 <stdint.h>
11 #include <string>
12 
13 #include <libcamera/controls.h>
14 
15 namespace libcamera {
16 
17 class YamlObject;
18 
19 namespace ipa {
20 
21 template<typename _Module>
22 class Algorithm
23 {
24 public:
25  using Module = _Module;
26 
27  virtual ~Algorithm() {}
28 
29  virtual int init([[maybe_unused]] typename Module::Context &context,
30  [[maybe_unused]] const YamlObject &tuningData)
31  {
32  return 0;
33  }
34 
35  virtual int configure([[maybe_unused]] typename Module::Context &context,
36  [[maybe_unused]] const typename Module::Config &configInfo)
37  {
38  return 0;
39  }
40 
41  virtual void prepare([[maybe_unused]] typename Module::Context &context,
42  [[maybe_unused]] const uint32_t frame,
43  [[maybe_unused]] typename Module::FrameContext &frameContext,
44  [[maybe_unused]] typename Module::Params *params)
45  {
46  }
47 
48  virtual void queueRequest([[maybe_unused]] typename Module::Context &context,
49  [[maybe_unused]] const uint32_t frame,
50  [[maybe_unused]] typename Module::FrameContext &frameContext,
51  [[maybe_unused]] const ControlList &controls)
52  {
53  }
54 
55  virtual void process([[maybe_unused]] typename Module::Context &context,
56  [[maybe_unused]] const uint32_t frame,
57  [[maybe_unused]] typename Module::FrameContext &frameContext,
58  [[maybe_unused]] const typename Module::Stats *stats)
59  {
60  }
61 };
62 
63 template<typename _Module>
64 class AlgorithmFactoryBase
65 {
66 public:
67  AlgorithmFactoryBase(const char *name)
68  : name_(name)
69  {
70  _Module::registerAlgorithm(this);
71  }
72 
73  virtual ~AlgorithmFactoryBase() = default;
74 
75  const std::string &name() const { return name_; }
76 
77  virtual std::unique_ptr<Algorithm<_Module>> create() const = 0;
78 
79 private:
80  std::string name_;
81 };
82 
83 template<typename _Algorithm>
84 class AlgorithmFactory : public AlgorithmFactoryBase<typename _Algorithm::Module>
85 {
86 public:
87  AlgorithmFactory(const char *name)
88  : AlgorithmFactoryBase<typename _Algorithm::Module>(name)
89  {
90  }
91 
92  ~AlgorithmFactory() = default;
93 
94  std::unique_ptr<Algorithm<typename _Algorithm::Module>> create() const override
95  {
96  return std::make_unique<_Algorithm>();
97  }
98 };
99 
100 #define REGISTER_IPA_ALGORITHM(algorithm, name) \
101 static AlgorithmFactory<algorithm> global_##algorithm##Factory(name);
102 
103 } /* namespace ipa */
104 
105 } /* 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:85
std::unique_ptr< Algorithm< typename _Algorithm::Module > > create() const override
Create an instance of the Algorithm corresponding to the factory.
Definition: algorithm.h:94
AlgorithmFactory(const char *name)
Construct an algorithm factory.
Definition: algorithm.h:87
The base class for all IPA algorithms.
Definition: algorithm.h:23
virtual void prepare([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] typename Module::FrameContext &frameContext, [[maybe_unused]] typename Module::Params *params)
Fill the params buffer with ISP processing parameters for a frame.
Definition: algorithm.h:41
virtual int init([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const YamlObject &tuningData)
Initialize the Algorithm with tuning data.
Definition: algorithm.h:29
virtual void queueRequest([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] typename Module::FrameContext &frameContext, [[maybe_unused]] const ControlList &controls)
Provide control values to the algorithm.
Definition: algorithm.h:48
_Module Module
The IPA module type for this class of algorithms.
Definition: algorithm.h:25
virtual void process([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] typename Module::FrameContext &frameContext, [[maybe_unused]] const typename Module::Stats *stats)
Process ISP statistics, and run algorithm operations.
Definition: algorithm.h:55
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:35
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