libcamera v0.3.2 Supporting cameras in Linux since 2019

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