libcamera v0.2.0 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 * camera_sensor.h - 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/formats.h"
26#include "libcamera/internal/v4l2_subdevice.h"
27
28 namespace libcamera {
29
30 class BayerFormat;
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 const MediaEntity *entity() const { return entity_; }
50 const std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }
51 std::vector<Size> sizes(unsigned int mbusCode) const;
52 Size resolution() const;
53 const std::vector<controls::draft::TestPatternModeEnum> &testPatternModes() const
54 {
55 return testPatternModes_;
56 }
57 int setTestPatternMode(controls::draft::TestPatternModeEnum mode);
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 ControlInfoMap &controls() const;
70 ControlList getControls(const std::vector<uint32_t> &ids);
71 int setControls(ControlList *ctrls);
72
73 V4L2Subdevice *device() { return subdev_.get(); }
74
75 const ControlList &properties() const { return properties_; }
76 int sensorInfo(IPACameraSensorInfo *info) const;
77
78 void updateControlInfo();
79
80 CameraLens *focusLens() { return focusLens_.get(); }
81
82 Transform computeTransform(Orientation *orientation) const;
83
84 protected:
85 std::string logPrefix() const override;
86
87 private:
88 LIBCAMERA_DISABLE_COPY(CameraSensor)
89
90 int generateId();
91 int validateSensorDriver();
92 void initVimcDefaultProperties();
93 void initStaticProperties();
94 void initTestPatternModes();
95 int initProperties();
96 int applyTestPatternMode(controls::draft::TestPatternModeEnum mode);
97 int discoverAncillaryDevices();
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 Orientation mountingOrientation_;
119
120 ControlList properties_;
121
122 std::unique_ptr<CameraLens> focusLens_;
123};
124
125} /* namespace libcamera */
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::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:40
libcamera::CameraSensor::properties
const ControlList & properties() const
Retrieve the camera sensor properties.
Definition camera_sensor.h:75
libcamera::CameraSensor::entity
const MediaEntity * entity() const
Retrieve the sensor media entity.
Definition camera_sensor.h:49
libcamera::CameraSensor::setControls
int setControls(ControlList *ctrls)
Write V4L2 controls to the sensor.
Definition camera_sensor.cpp:986
libcamera::CameraSensor::setTestPatternMode
int setTestPatternMode(controls::draft::TestPatternModeEnum mode)
Set the test pattern mode for the camera sensor.
Definition camera_sensor.cpp:651
libcamera::CameraSensor::setFormat
int setFormat(V4L2SubdeviceFormat *format, Transform transform=Transform::Identity)
Set the sensor output format.
Definition camera_sensor.cpp:796
libcamera::CameraSensor::CameraSensor
CameraSensor(const MediaEntity *entity)
Construct a CameraSensor.
Definition camera_sensor.cpp:58
libcamera::CameraSensor::updateControlInfo
void updateControlInfo()
Update the sensor's ControlInfoMap in case they have changed.
Definition camera_sensor.cpp:1101
libcamera::CameraSensor::computeTransform
Transform computeTransform(Orientation *orientation) const
Compute the Transform that gives the requested orientation.
Definition camera_sensor.cpp:1140
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:600
libcamera::CameraSensor::controls
const ControlInfoMap & controls() const
Retrieve the supported V4L2 controls and their information.
Definition camera_sensor.cpp:933
libcamera::CameraSensor::resolution
Size resolution() const
Retrieve the camera sensor resolution.
Definition camera_sensor.cpp:630
libcamera::CameraSensor::logPrefix
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition camera_sensor.cpp:1173
libcamera::CameraSensor::~CameraSensor
~CameraSensor()
Destroy a CameraSensor.
Definition camera_sensor.cpp:68
libcamera::CameraSensor::sensorInfo
int sensorInfo(IPACameraSensorInfo *info) const
Assemble and return the camera sensor info.
Definition camera_sensor.cpp:1022
libcamera::CameraSensor::model
const std::string & model() const
Retrieve the sensor model name.
Definition camera_sensor.h:47
libcamera::CameraSensor::init
int init()
Initialize the camera sensor instance.
Definition camera_sensor.cpp:80
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:853
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:53
libcamera::CameraSensor::device
V4L2Subdevice * device()
Retrieve the camera sensor device.
Definition camera_sensor.h:73
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:729
libcamera::CameraSensor::tryFormat
int tryFormat(V4L2SubdeviceFormat *format) const
Try the sensor output format.
Definition camera_sensor.cpp:832
libcamera::CameraSensor::mbusCodes
const std::vector< unsigned int > & mbusCodes() const
Retrieve the media bus codes supported by the camera sensor.
Definition camera_sensor.h:50
libcamera::CameraSensor::focusLens
CameraLens * focusLens()
Retrieve the focus lens controller.
Definition camera_sensor.h:80
libcamera::CameraSensor::id
const std::string & id() const
Retrieve the sensor ID.
Definition camera_sensor.h:48
libcamera::CameraSensor::getControls
ControlList getControls(const std::vector< uint32_t > &ids)
Read V4L2 controls from the sensor.
Definition camera_sensor.cpp:956
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:89
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:55
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:57
control_ids.h
Camera control 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.
formats.h
Types and helper functions to handle libcamera image formats.
log.h
Logging infrastructure.
libcamera::controls::draft::TestPatternModeEnum
TestPatternModeEnum
Supported TestPatternMode values.
Definition control_ids.h:278
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::Transform
Transform
Enum to represent a 2D plane transform.
Definition transform.h:16
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:24
libcamera::V4L2SubdeviceFormat
The V4L2 sub-device image format and sizes.
Definition v4l2_subdevice.h:43
transform.h
Enum to represent and manipulate 2D plane transforms.
v4l2_subdevice.h
V4L2 Subdevice API.