libcamera  v0.0.0
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 
14 #include <libcamera/controls.h>
15 #include <libcamera/geometry.h>
16 
18 #include "libcamera/internal/log.h"
19 
20 namespace libcamera {
21 
22 class MediaEntity;
23 class V4L2Subdevice;
24 
25 struct V4L2SubdeviceFormat;
26 
28  std::string model;
29 
30  uint32_t bitsPerPixel;
31 
35 
36  uint64_t pixelRate;
37  uint32_t lineLength;
38 };
39 
40 class CameraSensor : protected Loggable
41 {
42 public:
43  explicit CameraSensor(const MediaEntity *entity);
44  ~CameraSensor();
45 
46  CameraSensor(const CameraSensor &) = delete;
47  CameraSensor &operator=(const CameraSensor &) = delete;
48 
49  int init();
50 
51  const std::string &model() const { return model_; }
52  const MediaEntity *entity() const { return entity_; }
53  const std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }
54  const std::vector<Size> &sizes() const { return sizes_; }
55  const Size &resolution() const { return resolution_; }
56 
57  V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
58  const Size &size) const;
59  int setFormat(V4L2SubdeviceFormat *format);
60 
61  const ControlInfoMap &controls() const;
62  ControlList getControls(const std::vector<uint32_t> &ids);
63  int setControls(ControlList *ctrls);
64 
65  const ControlList &properties() const { return properties_; }
66  int sensorInfo(CameraSensorInfo *info) const;
67 
68 protected:
69  std::string logPrefix() const override;
70 
71 private:
72  const MediaEntity *entity_;
73  std::unique_ptr<V4L2Subdevice> subdev_;
74  unsigned int pad_;
75 
76  std::string model_;
77 
78  ImageFormats formats_;
79  Size resolution_;
80  std::vector<unsigned int> mbusCodes_;
81  std::vector<Size> sizes_;
82 
83  ControlList properties_;
84 };
85 
86 } /* namespace libcamera */
87 
88 #endif /* __LIBCAMERA_INTERNAL_CAMERA_SENSOR_H__ */
A camera sensor based on V4L2 subdevices.
Definition: camera_sensor.h:41
const ControlList & properties() const
Retrieve the camera sensor properties.
Definition: camera_sensor.h:65
const MediaEntity * entity() const
Retrieve the sensor media entity.
Definition: camera_sensor.h:52
int setControls(ControlList *ctrls)
Write controls to the sensor.
Definition: camera_sensor.cpp:471
const std::vector< Size > & sizes() const
Retrieve the frame sizes supported by the camera sensor.
Definition: camera_sensor.h:54
int setFormat(V4L2SubdeviceFormat *format)
Set the sensor output format.
Definition: camera_sensor.cpp:405
CameraSensor(const MediaEntity *entity)
Construct a CameraSensor.
Definition: camera_sensor.cpp:132
const ControlInfoMap & controls() const
Retrieve the supported V4L2 controls and their information.
Definition: camera_sensor.cpp:414
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: camera_sensor.cpp:538
~CameraSensor()
Destroy a CameraSensor.
Definition: camera_sensor.cpp:140
const std::string & model() const
Retrieve the sensor model name.
Definition: camera_sensor.h:51
int init()
Initialize the camera sensor instance.
Definition: camera_sensor.cpp:152
int sensorInfo(CameraSensorInfo *info) const
Assemble and return the camera sensor info.
Definition: camera_sensor.cpp:485
const Size & resolution() const
Retrieve the camera sensor resolution.
Definition: camera_sensor.h:55
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:351
const std::vector< unsigned int > & mbusCodes() const
Retrieve the media bus codes supported by the camera sensor.
Definition: camera_sensor.h:53
ControlList getControls(const std::vector< uint32_t > &ids)
Read controls from the sensor.
Definition: camera_sensor.cpp:436
A map of ControlId to ControlInfo.
Definition: controls.h:297
Associate a list of ControlId with their values for an object.
Definition: controls.h:342
Describe V4L2Device and V4L2SubDevice image formats.
Definition: formats.h:22
Base class to support log message extensions.
Definition: log.h:83
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:86
Framework to manage controls related to an object.
Data structures related to geometric objects.
Types and helper methods to handle libcamera image formats.
Logging infrastructure.
Report the image sensor characteristics.
Definition: camera_sensor.h:27
uint32_t bitsPerPixel
The number of bits per pixel of the image format produced by the image sensor.
Definition: camera_sensor.h:30
uint64_t pixelRate
The number of pixels produced in a second.
Definition: camera_sensor.h:36
std::string model
The image sensor model name.
Definition: camera_sensor.h:28
Size outputSize
The size of the images produced by the camera sensor.
Definition: camera_sensor.h:34
Rectangle analogCrop
The portion of the pixel array active area which is read-out and processed.
Definition: camera_sensor.h:33
Size activeAreaSize
The size of the pixel array active area of the sensor.
Definition: camera_sensor.h:32
uint32_t lineLength
Total line length in pixels.
Definition: camera_sensor.h:37
Describe a rectangle's position and dimensions.
Definition: geometry.h:15
Describe a two-dimensional size.
Definition: geometry.h:30
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:24