libcamera v0.0.0+3240-f2a18172-dirty (2022-05-14T03:06:40+00:00)
Supporting cameras in Linux since 2019
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#ifndef __LIBCAMERA_INTERNAL_CAMERA_SENSOR_H__
8#define __LIBCAMERA_INTERNAL_CAMERA_SENSOR_H__
9
10#include <memory>
11#include <string>
12#include <vector>
13
15#include <libcamera/base/log.h>
16
17#include <libcamera/controls.h>
18#include <libcamera/geometry.h>
20
23
24namespace libcamera {
25
26class BayerFormat;
27class MediaEntity;
28
29class CameraSensor : protected Loggable
30{
31public:
32 explicit CameraSensor(const MediaEntity *entity);
34
35 int init();
36
37 const std::string &model() const { return model_; }
38 const std::string &id() const { return id_; }
39 const MediaEntity *entity() const { return entity_; }
40 const std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }
41 const std::vector<Size> sizes(unsigned int mbusCode) const;
42 Size resolution() const;
43 const std::vector<int32_t> &testPatternModes() const
44 {
45 return testPatternModes_;
46 }
47
48 V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
49 const Size &size) const;
50 int setFormat(V4L2SubdeviceFormat *format);
51
52 const ControlInfoMap &controls() const;
53 ControlList getControls(const std::vector<uint32_t> &ids);
54 int setControls(ControlList *ctrls);
55
56 V4L2Subdevice *device() { return subdev_.get(); }
57
58 const ControlList &properties() const { return properties_; }
59 int sensorInfo(IPACameraSensorInfo *info) const;
60
61 void updateControlInfo();
62
63protected:
64 std::string logPrefix() const override;
65
66private:
68
69 int generateId();
70 int validateSensorDriver();
71 void initVimcDefaultProperties();
72 void initStaticProperties();
73 void initTestPatternModes(
74 const std::map<int32_t, int32_t> &testPatternModeMap);
75 int initProperties();
76
77 const MediaEntity *entity_;
78 std::unique_ptr<V4L2Subdevice> subdev_;
79 unsigned int pad_;
80
81 std::string model_;
82 std::string id_;
83
85 std::vector<unsigned int> mbusCodes_;
86 std::vector<Size> sizes_;
87 std::vector<int32_t> testPatternModes_;
88
89 Size pixelArraySize_;
90 Rectangle activeArea_;
91 const BayerFormat *bayerFormat_;
92
93 ControlList properties_;
94};
95
96} /* namespace libcamera */
97
98#endif /* __LIBCAMERA_INTERNAL_CAMERA_SENSOR_H__ */
Utilities to help constructing class interfaces.
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
Class to represent a raw image Bayer format.
Definition: bayer_format.h:22
A camera sensor based on V4L2 subdevices.
Definition: camera_sensor.h:30
const ControlList & properties() const
Retrieve the camera sensor properties.
Definition: camera_sensor.h:58
const MediaEntity * entity() const
Retrieve the sensor media entity.
Definition: camera_sensor.h:39
int setControls(ControlList *ctrls)
Write V4L2 controls to the sensor.
Definition: camera_sensor.cpp:703
int setFormat(V4L2SubdeviceFormat *format)
Set the sensor output format.
Definition: camera_sensor.cpp:629
CameraSensor(const MediaEntity *entity)
Construct a CameraSensor.
Definition: camera_sensor.cpp:56
void updateControlInfo()
Update the sensor's ControlInfoMap in case they have changed.
Definition: camera_sensor.cpp:813
const ControlInfoMap & controls() const
Retrieve the supported V4L2 controls and their information.
Definition: camera_sensor.cpp:650
Size resolution() const
Retrieve the camera sensor resolution.
Definition: camera_sensor.cpp:521
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: camera_sensor.cpp:818
~CameraSensor()
Destroy a CameraSensor.
Definition: camera_sensor.cpp:65
int sensorInfo(IPACameraSensorInfo *info) const
Assemble and return the camera sensor info.
Definition: camera_sensor.cpp:739
const std::string & model() const
Retrieve the sensor model name.
Definition: camera_sensor.h:37
int init()
Initialize the camera sensor instance.
Definition: camera_sensor.cpp:77
const std::vector< int32_t > & testPatternModes() const
Retrieve all the supported test pattern modes of the camera sensor The test pattern mode values corre...
Definition: camera_sensor.h:43
V4L2Subdevice * device()
Retrieve the camera sensor device.
Definition: camera_sensor.h:56
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:570
const std::vector< Size > sizes(unsigned int mbusCode) const
Retrieve the supported frame sizes for a media bus code.
Definition: camera_sensor.cpp:491
const std::vector< unsigned int > & mbusCodes() const
Retrieve the media bus codes supported by the camera sensor.
Definition: camera_sensor.h:40
const std::string & id() const
Retrieve the sensor ID.
Definition: camera_sensor.h:38
ControlList getControls(const std::vector< uint32_t > &ids)
Read V4L2 controls from the sensor.
Definition: camera_sensor.cpp:673
A map of ControlId to ControlInfo.
Definition: controls.h:306
Associate a list of ControlId with their values for an object.
Definition: controls.h:350
Base class to support log message extensions.
Definition: log.h:86
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:89
Describe a rectangle's position and dimensions.
Definition: geometry.h:237
Describe a two-dimensional size.
Definition: geometry.h:51
A V4L2 subdevice as exposed by the Linux kernel.
Definition: v4l2_subdevice.h:36
std::map< unsigned int, std::vector< SizeRange > > Formats
A map of supported media bus formats to frame sizes.
Definition: v4l2_subdevice.h:38
Framework to manage controls related to an object.
libcamera structs for IPAs
Data structures related to geometric objects.
Types and helper functions to handle libcamera image formats.
Logging infrastructure.
Top-level libcamera namespace.
Definition: backtrace.h:17
Report the image sensor characteristics.
Definition: core_ipa_interface.h:25
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:27
V4L2 Subdevice API.