libcamera  v0.3.1+12-19bbca3c
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 <vector>
13 
14 #include <libcamera/base/class.h>
15 #include <libcamera/base/log.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 
24 
28 
29 namespace libcamera {
30 
31 class CameraLens;
32 class MediaEntity;
33 class SensorConfiguration;
34 
35 struct CameraSensorProperties;
36 
37 enum class Orientation;
38 
39 class CameraSensor : protected Loggable
40 {
41 public:
42  explicit CameraSensor(const MediaEntity *entity);
43  ~CameraSensor();
44 
45  int init();
46 
47  const std::string &model() const { return model_; }
48  const std::string &id() const { return id_; }
49 
50  const MediaEntity *entity() const { return entity_; }
51  V4L2Subdevice *device() { return subdev_.get(); }
52 
53  CameraLens *focusLens() { return focusLens_.get(); }
54 
55  const std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }
56  std::vector<Size> sizes(unsigned int mbusCode) const;
57  Size resolution() const;
58 
59  V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
60  const Size &size) const;
61  int setFormat(V4L2SubdeviceFormat *format,
62  Transform transform = Transform::Identity);
63  int tryFormat(V4L2SubdeviceFormat *format) const;
64 
65  int applyConfiguration(const SensorConfiguration &config,
66  Transform transform = Transform::Identity,
67  V4L2SubdeviceFormat *sensorFormat = nullptr);
68 
69  const ControlList &properties() const { return properties_; }
70  int sensorInfo(IPACameraSensorInfo *info) const;
71  Transform computeTransform(Orientation *orientation) const;
73 
74  const ControlInfoMap &controls() const;
75  ControlList getControls(const std::vector<uint32_t> &ids);
76  int setControls(ControlList *ctrls);
77 
78  const std::vector<controls::draft::TestPatternModeEnum> &testPatternModes() const
79  {
80  return testPatternModes_;
81  }
83 
84 protected:
85  std::string logPrefix() const override;
86 
87 private:
89 
90  int generateId();
91  int validateSensorDriver();
92  void initVimcDefaultProperties();
93  void initStaticProperties();
94  void initTestPatternModes();
95  int initProperties();
96  int discoverAncillaryDevices();
97  int applyTestPatternMode(controls::draft::TestPatternModeEnum mode);
98 
99  const MediaEntity *entity_;
100  std::unique_ptr<V4L2Subdevice> subdev_;
101  unsigned int pad_;
102 
103  const CameraSensorProperties *staticProps_;
104 
105  std::string model_;
106  std::string id_;
107 
108  V4L2Subdevice::Formats formats_;
109  std::vector<unsigned int> mbusCodes_;
110  std::vector<Size> sizes_;
111  std::vector<controls::draft::TestPatternModeEnum> testPatternModes_;
112  controls::draft::TestPatternModeEnum testPatternMode_;
113 
114  Size pixelArraySize_;
115  Rectangle activeArea_;
116  const BayerFormat *bayerFormat_;
117  bool supportFlips_;
118  bool flipsAlterBayerOrder_;
119  Orientation mountingOrientation_;
120 
121  ControlList properties_;
122 
123  std::unique_ptr<CameraLens> focusLens_;
124 };
125 
126 } /* namespace libcamera */
Utilities to help constructing class interfaces.
Report the image sensor characteristics.
Definition: core_ipa_interface.h:23
const std::vector< unsigned int > & mbusCodes() const
Retrieve the media bus codes supported by the camera sensor.
Definition: camera_sensor.h:55
Image orientation definition.
const std::string & model() const
Retrieve the sensor model name.
Definition: camera_sensor.h:47
Base class to support log message extensions.
Definition: log.h:91
Camera control identifiers.
Top-level libcamera namespace.
Definition: backtrace.h:17
const ControlInfoMap & controls() const
Retrieve the supported V4L2 controls and their information.
Definition: camera_sensor.cpp:1086
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: camera_sensor.cpp:1202
CameraSensor(const MediaEntity *entity)
Construct a CameraSensor.
Definition: camera_sensor.cpp:58
~CameraSensor()
Destroy a CameraSensor.
Definition: camera_sensor.cpp:68
std::vector< Size > sizes(unsigned int mbusCode) const
Retrieve the supported frame sizes for a media bus code.
Definition: camera_sensor.cpp:631
BayerFormat::Order bayerOrder(Transform t) const
Compute the Bayer order that results from the given Transform.
Definition: camera_sensor.cpp:1061
Describe a two-dimensional size.
Definition: geometry.h:52
Transform
Enum to represent a 2D plane transform.
Definition: transform.h:16
std::map< unsigned int, std::vector< SizeRange > > Formats
A map of supported media bus formats to frame sizes.
Definition: v4l2_subdevice.h:76
ControlList getControls(const std::vector< uint32_t > &ids)
Read V4L2 controls from the sensor.
Definition: camera_sensor.cpp:1109
const ControlList & properties() const
Retrieve the camera sensor properties.
Definition: camera_sensor.h:69
const std::string & id() const
Retrieve the sensor ID.
Definition: camera_sensor.h:48
Orientation
The image orientation in a memory buffer.
Definition: orientation.h:14
A map of ControlId to ControlInfo.
Definition: controls.h:305
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:88
int setFormat(V4L2SubdeviceFormat *format, Transform transform=Transform::Identity)
Set the sensor output format.
Definition: camera_sensor.cpp:769
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
int applyConfiguration(const SensorConfiguration &config, Transform transform=Transform::Identity, V4L2SubdeviceFormat *sensorFormat=nullptr)
Apply a sensor configuration to the camera sensor.
Definition: camera_sensor.cpp:826
libcamera structs for IPAs
Describe a rectangle&#39;s position and dimensions.
Definition: geometry.h:242
const std::vector< controls::draft::TestPatternModeEnum > & testPatternModes() const
Retrieve all the supported test pattern modes of the camera sensor The test pattern mode values corre...
Definition: camera_sensor.h:78
A camera sensor based on V4L2 subdevices.
Definition: camera_sensor.h:39
int sensorInfo(IPACameraSensorInfo *info) const
Assemble and return the camera sensor info.
Definition: camera_sensor.cpp:915
V4L2Subdevice * device()
Retrieve the camera sensor device.
Definition: camera_sensor.h:51
V4L2 Subdevice API.
Size resolution() const
Retrieve the camera sensor resolution.
Definition: camera_sensor.cpp:661
Enum to represent and manipulate 2D plane transforms.
V4L2SubdeviceFormat getFormat(const std::vector< unsigned int > &mbusCodes, const Size &size) const
Retrieve the best sensor format for a desired output.
Definition: camera_sensor.cpp:702
int setControls(ControlList *ctrls)
Write V4L2 controls to the sensor.
Definition: camera_sensor.cpp:1139
int init()
Initialize the camera sensor instance.
Definition: camera_sensor.cpp:80
CameraLens * focusLens()
Retrieve the focus lens controller.
Definition: camera_sensor.h:53
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:63
int tryFormat(V4L2SubdeviceFormat *format) const
Try the sensor output format.
Definition: camera_sensor.cpp:805
Class to represent Bayer formats and manipulate them.
const MediaEntity * entity() const
Retrieve the sensor media entity.
Definition: camera_sensor.h:50
TestPatternModeEnum
Supported TestPatternMode values.
Definition: control_ids.h:303
Transform computeTransform(Orientation *orientation) const
Compute the Transform that gives the requested orientation.
Definition: camera_sensor.cpp:1016
A camera lens based on V4L2 subdevices.
Definition: camera_lens.h:22
Database of camera sensor properties.
Definition: camera_sensor_properties.h:18
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:349
Framework to manage controls related to an object.
Data structures related to geometric objects.
Camera sensor configuration.
Definition: camera.h:35
Types and helper functions to handle libcamera image formats.
Logging infrastructure.
int setTestPatternMode(controls::draft::TestPatternModeEnum mode)
Set the test pattern mode for the camera sensor.
Definition: camera_sensor.cpp:1160
A V4L2 subdevice as exposed by the Linux kernel.
Definition: v4l2_subdevice.h:73
Class to represent a raw image Bayer format.
Definition: bayer_format.h:22