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

libcamera v0.7.1 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 <stdint.h>
12#include <string>
13#include <variant>
14#include <vector>
15
16#include <libcamera/base/class.h>
17#include <libcamera/base/span.h>
18
19#include <libcamera/control_ids.h>
20#include <libcamera/controls.h>
21#include <libcamera/geometry.h>
22#include <libcamera/orientation.h>
23#include <libcamera/transform.h>
24
25#include "libcamera/internal/bayer_format.h"
26#include "libcamera/internal/camera_sensor_properties.h"
27#include "libcamera/internal/v4l2_subdevice.h"
28
29namespace libcamera {
30
31class CameraLens;
32class MediaEntity;
33class SensorConfiguration;
34
35enum class Orientation;
36
37struct IPACameraSensorInfo;
38
39 class CameraSensor
40{
41public:
42 virtual ~CameraSensor();
43
44 virtual const std::string &model() const = 0;
45 virtual const std::string &id() const = 0;
46
47 virtual const MediaEntity *entity() const = 0;
48 virtual V4L2Subdevice *device() = 0;
49
50 virtual CameraLens *focusLens() = 0;
51
52 virtual const std::vector<unsigned int> &mbusCodes() const = 0;
53 virtual std::vector<Size> sizes(unsigned int mbusCode) const = 0;
54 virtual Size resolution() const = 0;
55
56 virtual V4L2SubdeviceFormat
57 getFormat(Span<const unsigned int> mbusCodes,
58 const Size &size, const Size maxSize = Size()) const = 0;
59 virtual int setFormat(V4L2SubdeviceFormat *format,
60 Transform transform = Transform::Identity) = 0;
61 virtual int tryFormat(V4L2SubdeviceFormat *format) const = 0;
62
63 virtual int applyConfiguration(const SensorConfiguration &config,
64 Transform transform = Transform::Identity,
65 V4L2SubdeviceFormat *sensorFormat = nullptr) = 0;
66
67 virtual V4L2Subdevice::Stream imageStream() const;
68 virtual std::optional<V4L2Subdevice::Stream> embeddedDataStream() const;
69 virtual V4L2SubdeviceFormat embeddedDataFormat() const;
70 virtual int setEmbeddedDataEnabled(bool enable);
71
72 virtual const ControlList &properties() const = 0;
73 virtual int sensorInfo(IPACameraSensorInfo *info) const = 0;
74 virtual Transform computeTransform(Orientation *orientation) const = 0;
75 virtual BayerFormat::Order bayerOrder(Transform t) const = 0;
76 virtual Orientation mountingOrientation() const = 0;
77
78 virtual const ControlInfoMap &controls() const = 0;
79 virtual ControlList getControls(Span<const uint32_t> ids) = 0;
80 virtual int setControls(ControlList *ctrls) = 0;
81
82 virtual const std::vector<controls::draft::TestPatternModeEnum> &
83 testPatternModes() const = 0;
84 virtual int setTestPatternMode(controls::draft::TestPatternModeEnum mode) = 0;
85 virtual const CameraSensorProperties::SensorDelays &sensorDelays() = 0;
86};
87
88 class CameraSensorFactoryBase
89{
90public:
91 CameraSensorFactoryBase(const char *name, int priority);
92 virtual ~CameraSensorFactoryBase() = default;
93
94 static std::unique_ptr<CameraSensor> create(MediaEntity *entity);
95
96 const std::string &name() const { return name_; }
97 int priority() const { return priority_; }
98
99private:
100 LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorFactoryBase)
101
102 static std::vector<CameraSensorFactoryBase *> &factories();
103
104 static void registerFactory(CameraSensorFactoryBase *factory);
105
106 virtual std::variant<std::unique_ptr<CameraSensor>, int>
107 match(MediaEntity *entity) const = 0;
108
109 std::string name_;
110 int priority_;
111};
112
113template<typename _CameraSensor>
114 class CameraSensorFactory final : public CameraSensorFactoryBase
115{
116public:
117 CameraSensorFactory(const char *name, int priority)
118 : CameraSensorFactoryBase(name, priority)
119 {
120 }
121
122private:
123 std::variant<std::unique_ptr<CameraSensor>, int>
124 match(MediaEntity *entity) const override
125 {
126 return _CameraSensor::match(entity);
127 }
128};
129
130#define REGISTER_CAMERA_SENSOR(sensor, priority) \
131static CameraSensorFactory<sensor> global_##sensor##Factory{ #sensor, priority };
132
133} /* 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:24
libcamera::CameraSensorFactoryBase
Base class for camera sensor factories.
Definition camera_sensor.h:89
libcamera::CameraSensorFactoryBase::name
const std::string & name() const
Retrieve the camera sensor factory name.
Definition camera_sensor.h:96
libcamera::CameraSensorFactoryBase::priority
int priority() const
Retrieve the priority value for the factory.
Definition camera_sensor.h:97
libcamera::CameraSensorFactoryBase::CameraSensorFactoryBase
CameraSensorFactoryBase(const char *name, int priority)
Construct a camera sensor factory base.
Definition camera_sensor.cpp:447
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:466
libcamera::CameraSensorFactory::CameraSensorFactory
CameraSensorFactory(const char *name, int priority)
Construct a camera sensor factory.
Definition camera_sensor.h:117
libcamera::CameraSensor
A abstract camera sensor.
Definition camera_sensor.h:40
libcamera::CameraSensor::setControls
virtual int setControls(ControlList *ctrls)=0
Write V4L2 controls to the sensor.
libcamera::CameraSensor::imageStream
virtual V4L2Subdevice::Stream imageStream() const
Retrieve the image source stream.
Definition camera_sensor.cpp:212
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::model
virtual const std::string & model() const =0
Retrieve the sensor model name.
libcamera::CameraSensor::mountingOrientation
virtual Orientation mountingOrientation() const =0
Fetch the mounting orientation of the sensor.
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::getFormat
virtual V4L2SubdeviceFormat getFormat(Span< const unsigned int > mbusCodes, const Size &size, const Size maxSize=Size()) const =0
Retrieve the best sensor format for a desired output.
libcamera::CameraSensor::mbusCodes
virtual const std::vector< unsigned int > & mbusCodes() const =0
Retrieve the media bus codes supported by the camera sensor.
libcamera::CameraSensor::embeddedDataStream
virtual std::optional< V4L2Subdevice::Stream > embeddedDataStream() const
Retrieve the embedded data source stream.
Definition camera_sensor.cpp:227
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::setEmbeddedDataEnabled
virtual int setEmbeddedDataEnabled(bool enable)
Enable or disable the embedded data stream.
Definition camera_sensor.cpp:264
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::getControls
virtual ControlList getControls(Span< const uint32_t > ids)=0
Read V4L2 controls from the sensor.
libcamera::CameraSensor::entity
virtual const MediaEntity * entity() const =0
Retrieve the sensor media entity.
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::CameraSensor::embeddedDataFormat
virtual V4L2SubdeviceFormat embeddedDataFormat() const
Retrieve the format on the embedded data stream.
Definition camera_sensor.cpp:245
libcamera::ControlInfoMap
A map of ControlId to ControlInfo.
Definition controls.h:365
libcamera::ControlList
Associate a list of ControlId with their values for an object.
Definition controls.h:409
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:51
libcamera::V4L2Subdevice
A V4L2 subdevice as exposed by the Linux kernel.
Definition v4l2_subdevice.h:76
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:409
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:31
libcamera::V4L2SubdeviceFormat
The V4L2 sub-device image format and sizes.
Definition v4l2_subdevice.h:65
libcamera::V4L2Subdevice::Stream
V4L2 subdevice stream.
Definition v4l2_subdevice.h:85
transform.h
Enum to represent and manipulate 2D plane transforms.
v4l2_subdevice.h
V4L2 Subdevice API.