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

libcamera v0.0.4 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
21#include <libcamera/ipa/core_ipa_interface.h>
22
23#include "libcamera/internal/formats.h"
24#include "libcamera/internal/v4l2_subdevice.h"
25
26namespace libcamera {
27
28class BayerFormat;
29class CameraLens;
30class MediaEntity;
31
32enum class Transform;
33
34struct CameraSensorProperties;
35
36 class CameraSensor : protected Loggable
37{
38public:
39 explicit CameraSensor(const MediaEntity *entity);
40 ~CameraSensor();
41
42 int init();
43
44 const std::string &model() const { return model_; }
45 const std::string &id() const { return id_; }
46 const MediaEntity *entity() const { return entity_; }
47 const std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }
48 std::vector<Size> sizes(unsigned int mbusCode) const;
49 Size resolution() const;
50 const std::vector<controls::draft::TestPatternModeEnum> &testPatternModes() const
51 {
52 return testPatternModes_;
53 }
54 int setTestPatternMode(controls::draft::TestPatternModeEnum mode);
55
56 V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
57 const Size &size) const;
58 int setFormat(V4L2SubdeviceFormat *format);
59
60 const ControlInfoMap &controls() const;
61 ControlList getControls(const std::vector<uint32_t> &ids);
62 int setControls(ControlList *ctrls);
63
64 V4L2Subdevice *device() { return subdev_.get(); }
65
66 const ControlList &properties() const { return properties_; }
67 int sensorInfo(IPACameraSensorInfo *info) const;
68
69 void updateControlInfo();
70
71 CameraLens *focusLens() { return focusLens_.get(); }
72
73 Transform validateTransform(Transform *transform) const;
74
75protected:
76 std::string logPrefix() const override;
77
78private:
79 LIBCAMERA_DISABLE_COPY(CameraSensor)
80
81 int generateId();
82 int validateSensorDriver();
83 void initVimcDefaultProperties();
84 void initStaticProperties();
85 void initTestPatternModes();
86 int initProperties();
87 int applyTestPatternMode(controls::draft::TestPatternModeEnum mode);
88 int discoverAncillaryDevices();
89
90 const MediaEntity *entity_;
91 std::unique_ptr<V4L2Subdevice> subdev_;
92 unsigned int pad_;
93
94 const CameraSensorProperties *staticProps_;
95
96 std::string model_;
97 std::string id_;
98
99 V4L2Subdevice::Formats formats_;
100 std::vector<unsigned int> mbusCodes_;
101 std::vector<Size> sizes_;
102 std::vector<controls::draft::TestPatternModeEnum> testPatternModes_;
103 controls::draft::TestPatternModeEnum testPatternMode_;
104
105 Size pixelArraySize_;
106 Rectangle activeArea_;
107 const BayerFormat *bayerFormat_;
108 bool supportFlips_;
109
110 ControlList properties_;
111
112 std::unique_ptr<CameraLens> focusLens_;
113};
114
115} /* 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.
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:37
libcamera::CameraSensor::properties
const ControlList & properties() const
Retrieve the camera sensor properties.
Definition: camera_sensor.h:66
libcamera::CameraSensor::entity
const MediaEntity * entity() const
Retrieve the sensor media entity.
Definition: camera_sensor.h:46
libcamera::CameraSensor::setControls
int setControls(ControlList *ctrls)
Write V4L2 controls to the sensor.
Definition: camera_sensor.cpp:864
libcamera::CameraSensor::setTestPatternMode
int setTestPatternMode(controls::draft::TestPatternModeEnum mode)
Set the test pattern mode for the camera sensor.
Definition: camera_sensor.cpp:629
libcamera::CameraSensor::setFormat
int setFormat(V4L2SubdeviceFormat *format)
Set the sensor output format.
Definition: camera_sensor.cpp:773
libcamera::CameraSensor::updateControlInfo
void updateControlInfo()
Update the sensor's ControlInfoMap in case they have changed.
Definition: camera_sensor.cpp:976
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:578
libcamera::CameraSensor::controls
const ControlInfoMap & controls() const
Retrieve the supported V4L2 controls and their information.
Definition: camera_sensor.cpp:811
libcamera::CameraSensor::resolution
Size resolution() const
Retrieve the camera sensor resolution.
Definition: camera_sensor.cpp:608
libcamera::CameraSensor::logPrefix
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: camera_sensor.cpp:1060
libcamera::CameraSensor::~CameraSensor
~CameraSensor()
Destroy a CameraSensor.
Definition: camera_sensor.cpp:67
libcamera::CameraSensor::sensorInfo
int sensorInfo(IPACameraSensorInfo *info) const
Assemble and return the camera sensor info.
Definition: camera_sensor.cpp:900
libcamera::CameraSensor::model
const std::string & model() const
Retrieve the sensor model name.
Definition: camera_sensor.h:44
libcamera::CameraSensor::init
int init()
Initialize the camera sensor instance.
Definition: camera_sensor.cpp:79
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:50
libcamera::CameraSensor::device
V4L2Subdevice * device()
Retrieve the camera sensor device.
Definition: camera_sensor.h:64
libcamera::CameraSensor::validateTransform
Transform validateTransform(Transform *transform) const
Validate a transform request against the sensor capabilities.
Definition: camera_sensor.cpp:1011
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:707
libcamera::CameraSensor::mbusCodes
const std::vector< unsigned int > & mbusCodes() const
Retrieve the media bus codes supported by the camera sensor.
Definition: camera_sensor.h:47
libcamera::CameraSensor::focusLens
CameraLens * focusLens()
Retrieve the focus lens controller.
Definition: camera_sensor.h:71
libcamera::CameraSensor::id
const std::string & id() const
Retrieve the sensor ID.
Definition: camera_sensor.h:45
libcamera::CameraSensor::getControls
ControlList getControls(const std::vector< uint32_t > &ids)
Read V4L2 controls from the sensor.
Definition: camera_sensor.cpp:834
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::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:57
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:59
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:249
libcamera
Top-level libcamera namespace.
Definition: backtrace.h:17
libcamera::Transform
Transform
Enum to represent a 2D plane transform.
Definition: transform.h:14
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:44
v4l2_subdevice.h
V4L2 Subdevice API.