libcamera  v0.3.2+116-83c5ad0f
Supporting cameras in Linux since 2019
camera_sensor.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2019, Google Inc.
4  *
5  * A camera sensor
6  */
7 
8 #pragma once
9 
10 #include <memory>
11 #include <string>
12 #include <variant>
13 #include <vector>
14 
15 #include <libcamera/base/class.h>
16 
17 #include <libcamera/control_ids.h>
18 #include <libcamera/controls.h>
19 #include <libcamera/geometry.h>
20 #include <libcamera/orientation.h>
21 #include <libcamera/transform.h>
22 
25 
26 namespace libcamera {
27 
28 class CameraLens;
29 class MediaEntity;
30 class SensorConfiguration;
31 
32 enum class Orientation;
33 
34 struct IPACameraSensorInfo;
35 
37 {
38 public:
39  virtual ~CameraSensor();
40 
41  virtual const std::string &model() const = 0;
42  virtual const std::string &id() const = 0;
43 
44  virtual const MediaEntity *entity() const = 0;
45  virtual V4L2Subdevice *device() = 0;
46 
47  virtual CameraLens *focusLens() = 0;
48 
49  virtual const std::vector<unsigned int> &mbusCodes() const = 0;
50  virtual std::vector<Size> sizes(unsigned int mbusCode) const = 0;
51  virtual Size resolution() const = 0;
52 
53  virtual V4L2SubdeviceFormat
54  getFormat(const std::vector<unsigned int> &mbusCodes,
55  const Size &size) const = 0;
56  virtual int setFormat(V4L2SubdeviceFormat *format,
57  Transform transform = Transform::Identity) = 0;
58  virtual int tryFormat(V4L2SubdeviceFormat *format) const = 0;
59 
60  virtual int applyConfiguration(const SensorConfiguration &config,
61  Transform transform = Transform::Identity,
62  V4L2SubdeviceFormat *sensorFormat = nullptr) = 0;
63 
64  virtual const ControlList &properties() const = 0;
65  virtual int sensorInfo(IPACameraSensorInfo *info) const = 0;
66  virtual Transform computeTransform(Orientation *orientation) const = 0;
67  virtual BayerFormat::Order bayerOrder(Transform t) const = 0;
68 
69  virtual const ControlInfoMap &controls() const = 0;
70  virtual ControlList getControls(const std::vector<uint32_t> &ids) = 0;
71  virtual int setControls(ControlList *ctrls) = 0;
72 
73  virtual const std::vector<controls::draft::TestPatternModeEnum> &
74  testPatternModes() const = 0;
76 };
77 
79 {
80 public:
81  CameraSensorFactoryBase(const char *name, int priority);
82  virtual ~CameraSensorFactoryBase() = default;
83 
84  static std::unique_ptr<CameraSensor> create(MediaEntity *entity);
85 
86  const std::string &name() const { return name_; }
87  int priority() const { return priority_; }
88 
89 private:
91 
92  static std::vector<CameraSensorFactoryBase *> &factories();
93 
94  static void registerFactory(CameraSensorFactoryBase *factory);
95 
96  virtual std::variant<std::unique_ptr<CameraSensor>, int>
97  match(MediaEntity *entity) const = 0;
98 
99  std::string name_;
100  int priority_;
101 };
102 
103 template<typename _CameraSensor>
105 {
106 public:
107  CameraSensorFactory(const char *name, int priority)
108  : CameraSensorFactoryBase(name, priority)
109  {
110  }
111 
112 private:
113  std::variant<std::unique_ptr<CameraSensor>, int>
114  match(MediaEntity *entity) const override
115  {
116  return _CameraSensor::match(entity);
117  }
118 };
119 
120 #define REGISTER_CAMERA_SENSOR(sensor, priority) \
121 static CameraSensorFactory<sensor> global_##sensor##Factory{ #sensor, priority };
122 
123 } /* namespace libcamera */
Utilities to help constructing class interfaces.
virtual std::vector< Size > sizes(unsigned int mbusCode) const =0
Retrieve the supported frame sizes for a media bus code.
Report the image sensor characteristics.
Definition: core_ipa_interface.h:28
virtual V4L2SubdeviceFormat getFormat(const std::vector< unsigned int > &mbusCodes, const Size &size) const =0
Retrieve the best sensor format for a desired output.
Image orientation definition.
virtual const MediaEntity * entity() const =0
Retrieve the sensor media entity.
Camera controls identifiers.
Top-level libcamera namespace.
Definition: backtrace.h:17
virtual const ControlInfoMap & controls() const =0
Retrieve the supported V4L2 controls and their information.
virtual ~CameraSensor()
Destroy a CameraSensor.
Base class for camera sensor factories.
Definition: camera_sensor.h:78
Describe a two-dimensional size.
Definition: geometry.h:52
Transform
Enum to represent a 2D plane transform.
Definition: transform.h:14
int priority() const
Retrieve the priority value for the factory.
Definition: camera_sensor.h:87
virtual const std::vector< controls::draft::TestPatternModeEnum > & testPatternModes() const =0
Retrieve all the supported test pattern modes of the camera sensor The test pattern mode values corre...
virtual int tryFormat(V4L2SubdeviceFormat *format) const =0
Try the sensor output format.
Orientation
The image orientation in a memory buffer.
Definition: orientation.h:14
virtual BayerFormat::Order bayerOrder(Transform t) const =0
Compute the Bayer order that results from the given Transform.
virtual int setFormat(V4L2SubdeviceFormat *format, Transform transform=Transform::Identity)=0
Set the sensor output format.
A map of ControlId to ControlInfo.
Definition: controls.h:336
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:96
CameraSensorFactory(const char *name, int priority)
Construct a camera sensor factory.
Definition: camera_sensor.h:107
Registration of CameraSensorFactory classes and creation of instances.
Definition: camera_sensor.h:104
virtual Transform computeTransform(Orientation *orientation) const =0
Compute the Transform that gives the requested orientation.
A abstract camera sensor.
Definition: camera_sensor.h:36
virtual V4L2Subdevice * device()=0
Retrieve the camera sensor device.
V4L2 Subdevice API.
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Enum to represent and manipulate 2D plane transforms.
virtual const std::string & model() const =0
Retrieve the sensor model name.
virtual int applyConfiguration(const SensorConfiguration &config, Transform transform=Transform::Identity, V4L2SubdeviceFormat *sensorFormat=nullptr)=0
Apply a sensor configuration to the camera sensor.
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:63
Class to represent Bayer formats and manipulate them.
virtual int setControls(ControlList *ctrls)=0
Write V4L2 controls to the sensor.
TestPatternModeEnum
Supported TestPatternMode values.
Definition: control_ids.h:313
virtual ControlList getControls(const std::vector< uint32_t > &ids)=0
Read V4L2 controls from the sensor.
virtual int sensorInfo(IPACameraSensorInfo *info) const =0
Assemble and return the camera sensor info.
virtual const std::string & id() const =0
Retrieve the sensor ID.
A camera lens based on V4L2 subdevices.
Definition: camera_lens.h:22
const std::string & name() const
Retrieve the camera sensor factory name.
Definition: camera_sensor.h:86
Order
The order of the colour channels in the Bayer pattern.
Definition: bayer_format.h:25
Associate a list of ControlId with their values for an object.
Definition: controls.h:380
virtual const std::vector< unsigned int > & mbusCodes() const =0
Retrieve the media bus codes supported by the camera sensor.
Framework to manage controls related to an object.
virtual const ControlList & properties() const =0
Retrieve the camera sensor properties.
virtual int setTestPatternMode(controls::draft::TestPatternModeEnum mode)=0
Set the test pattern mode for the camera sensor.
Data structures related to geometric objects.
Camera sensor configuration.
Definition: camera.h:35
virtual Size resolution() const =0
Retrieve the camera sensor resolution.
virtual CameraLens * focusLens()=0
Retrieve the focus lens controller.
A V4L2 subdevice as exposed by the Linux kernel.
Definition: v4l2_subdevice.h:73