libcamera: include/libcamera/internal/camera_sensor.h Source File

libcamera v0.4.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 * 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
23#include "libcamera/internal/bayer_format.h"
24#include "libcamera/internal/camera_sensor_properties.h"
25#include "libcamera/internal/v4l2_subdevice.h"
26
27namespace libcamera {
28
29class CameraLens;
30class MediaEntity;
31class SensorConfiguration;
32
33enum class Orientation;
34
35struct IPACameraSensorInfo;
36
37 class CameraSensor
38{
39public:
40 virtual ~CameraSensor();
41
42 virtual const std::string &model() const = 0;
43 virtual const std::string &id() const = 0;
44
45 virtual const MediaEntity *entity() const = 0;
46 virtual V4L2Subdevice *device() = 0;
47
48 virtual CameraLens *focusLens() = 0;
49
50 virtual const std::vector<unsigned int> &mbusCodes() const = 0;
51 virtual std::vector<Size> sizes(unsigned int mbusCode) const = 0;
52 virtual Size resolution() const = 0;
53
54 virtual V4L2SubdeviceFormat
55 getFormat(const std::vector<unsigned int> &mbusCodes,
56 const Size &size, const Size maxSize = Size()) const = 0;
57 virtual int setFormat(V4L2SubdeviceFormat *format,
58 Transform transform = Transform::Identity) = 0;
59 virtual int tryFormat(V4L2SubdeviceFormat *format) const = 0;
60
61 virtual int applyConfiguration(const SensorConfiguration &config,
62 Transform transform = Transform::Identity,
63 V4L2SubdeviceFormat *sensorFormat = nullptr) = 0;
64
65 virtual const ControlList &properties() const = 0;
66 virtual int sensorInfo(IPACameraSensorInfo *info) const = 0;
67 virtual Transform computeTransform(Orientation *orientation) const = 0;
68 virtual BayerFormat::Order bayerOrder(Transform t) const = 0;
69
70 virtual const ControlInfoMap &controls() const = 0;
71 virtual ControlList getControls(const std::vector<uint32_t> &ids) = 0;
72 virtual int setControls(ControlList *ctrls) = 0;
73
74 virtual const std::vector<controls::draft::TestPatternModeEnum> &
75 testPatternModes() const = 0;
76 virtual int setTestPatternMode(controls::draft::TestPatternModeEnum mode) = 0;
77 virtual const CameraSensorProperties::SensorDelays &sensorDelays() = 0;
78};
79
80 class CameraSensorFactoryBase
81{
82public:
83 CameraSensorFactoryBase(const char *name, int priority);
84 virtual ~CameraSensorFactoryBase() = default;
85
86 static std::unique_ptr<CameraSensor> create(MediaEntity *entity);
87
88 const std::string &name() const { return name_; }
89 int priority() const { return priority_; }
90
91private:
92 LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorFactoryBase)
93
94 static std::vector<CameraSensorFactoryBase *> &factories();
95
96 static void registerFactory(CameraSensorFactoryBase *factory);
97
98 virtual std::variant<std::unique_ptr<CameraSensor>, int>
99 match(MediaEntity *entity) const = 0;
100
101 std::string name_;
102 int priority_;
103};
104
105template<typename _CameraSensor>
106 class CameraSensorFactory final : public CameraSensorFactoryBase
107{
108public:
109 CameraSensorFactory(const char *name, int priority)
110 : CameraSensorFactoryBase(name, priority)
111 {
112 }
113
114private:
115 std::variant<std::unique_ptr<CameraSensor>, int>
116 match(MediaEntity *entity) const override
117 {
118 return _CameraSensor::match(entity);
119 }
120};
121
122#define REGISTER_CAMERA_SENSOR(sensor, priority) \
123static CameraSensorFactory<sensor> global_##sensor##Factory{ #sensor, priority };
124
125} /* namespace libcamera */
bayer_format.h
Class to represent Bayer formats and manipulate them.
camera_sensor_properties.h
Database of camera sensor properties.
class.h
Utilities to help constructing class interfaces.
LIBCAMERA_DISABLE_COPY_AND_MOVE
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Definition class.h:29
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::CameraSensorFactoryBase
Base class for camera sensor factories.
Definition camera_sensor.h:81
libcamera::CameraSensorFactoryBase::name
const std::string & name() const
Retrieve the camera sensor factory name.
Definition camera_sensor.h:88
libcamera::CameraSensorFactoryBase::priority
int priority() const
Retrieve the priority value for the factory.
Definition camera_sensor.h:89
libcamera::CameraSensorFactoryBase::CameraSensorFactoryBase
CameraSensorFactoryBase(const char *name, int priority)
Construct a camera sensor factory base.
Definition camera_sensor.cpp:372
libcamera::CameraSensorFactoryBase::create
static std::unique_ptr< CameraSensor > create(MediaEntity *entity)
Create an instance of the CameraSensor corresponding to a media entity.
Definition camera_sensor.cpp:391
libcamera::CameraSensorFactory::CameraSensorFactory
CameraSensorFactory(const char *name, int priority)
Construct a camera sensor factory.
Definition camera_sensor.h:109
libcamera::CameraSensor
A abstract camera sensor.
Definition camera_sensor.h:38
libcamera::CameraSensor::setControls
virtual int setControls(ControlList *ctrls)=0
Write V4L2 controls to the sensor.
libcamera::CameraSensor::computeTransform
virtual Transform computeTransform(Orientation *orientation) const =0
Compute the Transform that gives the requested orientation.
libcamera::CameraSensor::properties
virtual const ControlList & properties() const =0
Retrieve the camera sensor properties.
libcamera::CameraSensor::getControls
virtual ControlList getControls(const std::vector< uint32_t > &ids)=0
Read V4L2 controls from the sensor.
libcamera::CameraSensor::model
virtual const std::string & model() const =0
Retrieve the sensor model name.
libcamera::CameraSensor::bayerOrder
virtual BayerFormat::Order bayerOrder(Transform t) const =0
Compute the Bayer order that results from the given Transform.
libcamera::CameraSensor::id
virtual const std::string & id() const =0
Retrieve the sensor ID.
libcamera::CameraSensor::controls
virtual const ControlInfoMap & controls() const =0
Retrieve the supported V4L2 controls and their information.
libcamera::CameraSensor::tryFormat
virtual int tryFormat(V4L2SubdeviceFormat *format) const =0
Try the sensor output format.
libcamera::CameraSensor::~CameraSensor
virtual ~CameraSensor()
Destroy a CameraSensor.
libcamera::CameraSensor::resolution
virtual Size resolution() const =0
Retrieve the camera sensor resolution.
libcamera::CameraSensor::setFormat
virtual int setFormat(V4L2SubdeviceFormat *format, Transform transform=Transform::Identity)=0
Set the sensor output format.
libcamera::CameraSensor::testPatternModes
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...
libcamera::CameraSensor::sensorDelays
virtual const CameraSensorProperties::SensorDelays & sensorDelays()=0
Fetch the sensor delay values.
libcamera::CameraSensor::mbusCodes
virtual const std::vector< unsigned int > & mbusCodes() const =0
Retrieve the media bus codes supported by the camera sensor.
libcamera::CameraSensor::setTestPatternMode
virtual int setTestPatternMode(controls::draft::TestPatternModeEnum mode)=0
Set the test pattern mode for the camera sensor.
libcamera::CameraSensor::applyConfiguration
virtual int applyConfiguration(const SensorConfiguration &config, Transform transform=Transform::Identity, V4L2SubdeviceFormat *sensorFormat=nullptr)=0
Apply a sensor configuration to the camera sensor.
libcamera::CameraSensor::focusLens
virtual CameraLens * focusLens()=0
Retrieve the focus lens controller.
libcamera::CameraSensor::sizes
virtual std::vector< Size > sizes(unsigned int mbusCode) const =0
Retrieve the supported frame sizes for a media bus code.
libcamera::CameraSensor::entity
virtual const MediaEntity * entity() const =0
Retrieve the sensor media entity.
libcamera::CameraSensor::getFormat
virtual V4L2SubdeviceFormat getFormat(const std::vector< unsigned int > &mbusCodes, const Size &size, const Size maxSize=Size()) const =0
Retrieve the best sensor format for a desired output.
libcamera::CameraSensor::sensorInfo
virtual int sensorInfo(IPACameraSensorInfo *info) const =0
Assemble and return the camera sensor info.
libcamera::CameraSensor::device
virtual V4L2Subdevice * device()=0
Retrieve the camera sensor device.
libcamera::ControlInfoMap
A map of ControlId to ControlInfo.
Definition controls.h:367
libcamera::ControlList
Associate a list of ControlId with their values for an object.
Definition controls.h:411
libcamera::MediaEntity
The MediaEntity represents an entity in the media graph.
Definition media_object.h:97
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
control_ids.h
Camera controls identifiers.
controls.h
Framework to manage controls related to an object.
geometry.h
Data structures related to geometric objects.
libcamera::controls::draft::TestPatternModeEnum
TestPatternModeEnum
Supported TestPatternMode values.
Definition control_ids.h:313
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
Definition transform.h:15
libcamera::Orientation
Orientation
The image orientation in a memory buffer.
Definition orientation.h:14
orientation.h
Image orientation definition.
libcamera::CameraSensorProperties::SensorDelays
Sensor control application delay values.
Definition camera_sensor_properties.h:20
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.