libcamera  v0.4.0
Supporting cameras in Linux since 2019
camera.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2018, Google Inc.
4  *
5  * Camera object interface
6  */
7 
8 #pragma once
9 
10 #include <initializer_list>
11 #include <memory>
12 #include <optional>
13 #include <set>
14 #include <stdint.h>
15 #include <string>
16 
17 #include <libcamera/base/class.h>
18 #include <libcamera/base/flags.h>
19 #include <libcamera/base/object.h>
20 #include <libcamera/base/signal.h>
21 
22 #include <libcamera/controls.h>
23 #include <libcamera/geometry.h>
24 #include <libcamera/orientation.h>
25 #include <libcamera/request.h>
26 #include <libcamera/stream.h>
27 
28 namespace libcamera {
29 
30 class FrameBuffer;
31 class FrameBufferAllocator;
32 class PipelineHandler;
33 class Request;
34 
36 {
37 public:
38  unsigned int bitDepth = 0;
39 
41 
42  struct {
43  unsigned int binX = 1;
44  unsigned int binY = 1;
45  } binning;
46 
47  struct {
48  unsigned int xOddInc = 1;
49  unsigned int xEvenInc = 1;
50  unsigned int yOddInc = 1;
51  unsigned int yEvenInc = 1;
52  } skipping;
53 
55 
56  bool isValid() const;
57 };
58 
60 {
61 public:
62  enum Status {
66  };
67 
68  using iterator = std::vector<StreamConfiguration>::iterator;
69  using const_iterator = std::vector<StreamConfiguration>::const_iterator;
70 
71  virtual ~CameraConfiguration();
72 
73  void addConfiguration(const StreamConfiguration &cfg);
74  virtual Status validate() = 0;
75 
76  StreamConfiguration &at(unsigned int index);
77  const StreamConfiguration &at(unsigned int index) const;
78  StreamConfiguration &operator[](unsigned int index)
79  {
80  return at(index);
81  }
82  const StreamConfiguration &operator[](unsigned int index) const
83  {
84  return at(index);
85  }
86 
87  iterator begin();
88  const_iterator begin() const;
89  iterator end();
90  const_iterator end() const;
91 
92  bool empty() const;
93  std::size_t size() const;
94 
95  std::optional<SensorConfiguration> sensorConfig;
97 
98 protected:
100 
101  enum class ColorSpaceFlag {
102  None,
103  StreamsShareColorSpace,
104  };
105 
107 
108  Status validateColorSpaces(ColorSpaceFlags flags = ColorSpaceFlag::None);
109 
110  std::vector<StreamConfiguration> config_;
111 };
112 
113 class Camera final : public Object, public std::enable_shared_from_this<Camera>,
114  public Extensible
115 {
117 
118 public:
119  static std::shared_ptr<Camera> create(std::unique_ptr<Private> d,
120  const std::string &id,
121  const std::set<Stream *> &streams);
122 
123  const std::string &id() const;
124 
128 
129  int acquire();
130  int release();
131 
132  const ControlInfoMap &controls() const;
133  const ControlList &properties() const;
134 
135  const std::set<Stream *> &streams() const;
136 
137  std::unique_ptr<CameraConfiguration>
138  generateConfiguration(Span<const StreamRole> roles = {});
139 
140  std::unique_ptr<CameraConfiguration>
141  generateConfiguration(std::initializer_list<StreamRole> roles)
142  {
143  return generateConfiguration(Span(roles.begin(), roles.end()));
144  }
145 
146  int configure(CameraConfiguration *config);
147 
148  std::unique_ptr<Request> createRequest(uint64_t cookie = 0);
149  int queueRequest(Request *request);
150 
151  int start(const ControlList *controls = nullptr);
152  int stop();
153 
154 private:
156 
157  Camera(std::unique_ptr<Private> d, const std::string &id,
158  const std::set<Stream *> &streams);
159  ~Camera();
160 
161  friend class PipelineHandler;
162  void disconnect();
163  void requestComplete(Request *request);
164 
165  friend class FrameBufferAllocator;
166  int exportFrameBuffers(Stream *stream,
167  std::vector<std::unique_ptr<FrameBuffer>> *buffers);
168 };
169 
170 } /* namespace libcamera */
Utilities to help constructing class interfaces.
std::unique_ptr< CameraConfiguration > generateConfiguration(std::initializer_list< StreamRole > roles)
Definition: camera.h:141
struct libcamera::SensorConfiguration::@0 binning
Sensor binning configuration.
unsigned int yEvenInc
Vertical increment for even columns. Default to 1.
Definition: camera.h:51
Rectangle analogCrop
The analog crop rectangle.
Definition: camera.h:40
FrameBuffer allocator for applications.
Definition: framebuffer_allocator.h:22
unsigned int binX
Horizontal binning factor.
Definition: camera.h:43
Video stream for a camera.
Definition: stream.h:75
Image orientation definition.
Top-level libcamera namespace.
Definition: backtrace.h:17
std::vector< StreamConfiguration >::iterator iterator
Iterator for the stream configurations in the camera configuration.
Definition: camera.h:68
Status
Validity of a camera configuration.
Definition: camera.h:62
Describe a two-dimensional size.
Definition: geometry.h:52
Video stream for a Camera.
Hold configuration for streams of the camera.
Definition: camera.h:59
const StreamConfiguration & operator[](unsigned int index) const
Retrieve a const reference to a stream configuration.
Definition: camera.h:82
Orientation
The image orientation in a memory buffer.
Definition: orientation.h:14
Size outputSize
The frame output (visible) size.
Definition: camera.h:54
A map of ControlId to ControlInfo.
Definition: controls.h:366
unsigned int yOddInc
Vertical increment for odd columns. Default to 1.
Definition: camera.h:50
#define LIBCAMERA_DECLARE_PRIVATE()
Declare private data for a public class.
unsigned int xEvenInc
Horizontal increment for even rows. Default to 1.
Definition: camera.h:49
struct libcamera::SensorConfiguration::@1 skipping
The sensor skipping configuration.
A frame capture request.
Definition: request.h:29
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
Signal & slot implementation.
Describe a rectangle&#39;s position and dimensions.
Definition: geometry.h:242
bool isValid() const
Check if the sensor configuration is valid.
Definition: camera.cpp:243
ColorSpaceFlag
Specify the behaviour of validateColorSpaces.
Definition: camera.h:101
Create and manage cameras based on a set of media devices.
Definition: pipeline_handler.h:33
Camera device.
Definition: camera.h:113
Base class to manage private data through a d-pointer.
Definition: class.h:61
std::optional< SensorConfiguration > sensorConfig
The camera sensor configuration.
Definition: camera.h:95
const ControlIdMap properties
List of all supported libcamera properties.
Definition: property_ids.cpp:844
Signal< Request *, FrameBuffer * > bufferCompleted
Signal emitted when a buffer for a request queued to the camera has completed.
Definition: camera.h:125
unsigned int binY
Vertical binning factor.
Definition: camera.h:44
Base object to support automatic signal disconnection.
Orientation orientation
The desired orientation of the images produced by the camera.
Definition: camera.h:96
Generic signal and slot communication mechanism.
Definition: object.h:20
unsigned int bitDepth
The sensor image format bit depth.
Definition: camera.h:38
const ControlIdMap controls
List of all supported libcamera controls.
Definition: control_ids.cpp:1985
Describes a frame capture request to be processed by a camera.
Enum-based bit fields.
Signal disconnected
Signal emitted when the camera is disconnected from the system.
Definition: camera.h:127
Associate a list of ControlId with their values for an object.
Definition: controls.h:410
Framework to manage controls related to an object.
Signal< Request * > requestCompleted
Signal emitted when a request queued to the camera has completed.
Definition: camera.h:126
Type-safe container for enum-based bitfields.
Definition: flags.h:15
Data structures related to geometric objects.
Camera sensor configuration.
Definition: camera.h:35
unsigned int xOddInc
Horizontal increment for odd rows. Default to 1.
Definition: camera.h:48
Base object to support automatic signal disconnection.
Definition: object.h:24
StreamConfiguration & operator[](unsigned int index)
Retrieve a reference to a stream configuration.
Definition: camera.h:78
std::vector< StreamConfiguration > config_
The vector of stream configurations.
Definition: camera.h:110
Configuration parameters for a stream.
Definition: stream.h:40
std::vector< StreamConfiguration >::const_iterator const_iterator
Const iterator for the stream configuration in the camera configuration.
Definition: camera.h:69