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

libcamera v0.0.3 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
32struct CameraSensorProperties;
33
34 class CameraSensor : protected Loggable
35{
36public:
37 explicit CameraSensor(const MediaEntity *entity);
38 ~CameraSensor();
39
40 int init();
41
42 const std::string &model() const { return model_; }
43 const std::string &id() const { return id_; }
44 const MediaEntity *entity() const { return entity_; }
45 const std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }
46 std::vector<Size> sizes(unsigned int mbusCode) const;
47 Size resolution() const;
48 const std::vector<controls::draft::TestPatternModeEnum> &testPatternModes() const
49 {
50 return testPatternModes_;
51 }
52 int setTestPatternMode(controls::draft::TestPatternModeEnum mode);
53
54 V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
55 const Size &size) const;
56 int setFormat(V4L2SubdeviceFormat *format);
57
58 const ControlInfoMap &controls() const;
59 ControlList getControls(const std::vector<uint32_t> &ids);
60 int setControls(ControlList *ctrls);
61
62 V4L2Subdevice *device() { return subdev_.get(); }
63
64 const ControlList &properties() const { return properties_; }
65 int sensorInfo(IPACameraSensorInfo *info) const;
66
67 void updateControlInfo();
68
69 CameraLens *focusLens() { return focusLens_.get(); }
70
71protected:
72 std::string logPrefix() const override;
73
74private:
75 LIBCAMERA_DISABLE_COPY(CameraSensor)
76
77 int generateId();
78 int validateSensorDriver();
79 void initVimcDefaultProperties();
80 void initStaticProperties();
81 void initTestPatternModes();
82 int initProperties();
83 int applyTestPatternMode(controls::draft::TestPatternModeEnum mode);
84 int discoverAncillaryDevices();
85
86 const MediaEntity *entity_;
87 std::unique_ptr<V4L2Subdevice> subdev_;
88 unsigned int pad_;
89
90 const CameraSensorProperties *staticProps_;
91
92 std::string model_;
93 std::string id_;
94
95 V4L2Subdevice::Formats formats_;
96 std::vector<unsigned int> mbusCodes_;
97 std::vector<Size> sizes_;
98 std::vector<controls::draft::TestPatternModeEnum> testPatternModes_;
99 controls::draft::TestPatternModeEnum testPatternMode_;
100
101 Size pixelArraySize_;
102 Rectangle activeArea_;
103 const BayerFormat *bayerFormat_;
104
105 ControlList properties_;
106
107 std::unique_ptr<CameraLens> focusLens_;
108};
109
110} /* 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:35
libcamera::CameraSensor::properties
const ControlList & properties() const
Retrieve the camera sensor properties.
Definition: camera_sensor.h:64
libcamera::CameraSensor::entity
const MediaEntity * entity() const
Retrieve the sensor media entity.
Definition: camera_sensor.h:44
libcamera::CameraSensor::setControls
int setControls(ControlList *ctrls)
Write V4L2 controls to the sensor.
Definition: camera_sensor.cpp:824
libcamera::CameraSensor::setTestPatternMode
int setTestPatternMode(controls::draft::TestPatternModeEnum mode)
Set the test pattern mode for the camera sensor.
Definition: camera_sensor.cpp:612
libcamera::CameraSensor::setFormat
int setFormat(V4L2SubdeviceFormat *format)
Set the sensor output format.
Definition: camera_sensor.cpp:750
libcamera::CameraSensor::updateControlInfo
void updateControlInfo()
Update the sensor's ControlInfoMap in case they have changed.
Definition: camera_sensor.cpp:936
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:561
libcamera::CameraSensor::controls
const ControlInfoMap & controls() const
Retrieve the supported V4L2 controls and their information.
Definition: camera_sensor.cpp:771
libcamera::CameraSensor::resolution
Size resolution() const
Retrieve the camera sensor resolution.
Definition: camera_sensor.cpp:591
libcamera::CameraSensor::logPrefix
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: camera_sensor.cpp:949
libcamera::CameraSensor::~CameraSensor
~CameraSensor()
Destroy a CameraSensor.
Definition: camera_sensor.cpp:65
libcamera::CameraSensor::sensorInfo
int sensorInfo(IPACameraSensorInfo *info) const
Assemble and return the camera sensor info.
Definition: camera_sensor.cpp:860
libcamera::CameraSensor::model
const std::string & model() const
Retrieve the sensor model name.
Definition: camera_sensor.h:42
libcamera::CameraSensor::init
int init()
Initialize the camera sensor instance.
Definition: camera_sensor.cpp:77
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:48
libcamera::CameraSensor::device
V4L2Subdevice * device()
Retrieve the camera sensor device.
Definition: camera_sensor.h:62
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:690
libcamera::CameraSensor::mbusCodes
const std::vector< unsigned int > & mbusCodes() const
Retrieve the media bus codes supported by the camera sensor.
Definition: camera_sensor.h:45
libcamera::CameraSensor::focusLens
CameraLens * focusLens()
Retrieve the focus lens controller.
Definition: camera_sensor.h:69
libcamera::CameraSensor::id
const std::string & id() const
Retrieve the sensor ID.
Definition: camera_sensor.h:43
libcamera::CameraSensor::getControls
ControlList getControls(const std::vector< uint32_t > &ids)
Read V4L2 controls from the sensor.
Definition: camera_sensor.cpp:794
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: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:249
libcamera
Top-level libcamera namespace.
Definition: backtrace.h:17
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
v4l2_subdevice.h
V4L2 Subdevice API.