libcamera: include/libcamera/camera.h Source File

libcamera v0.7.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
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#include <libcamera/base/span.h>
22
23#include <libcamera/controls.h>
24#include <libcamera/geometry.h>
25#include <libcamera/orientation.h>
26#include <libcamera/request.h>
27#include <libcamera/stream.h>
28
29namespace libcamera {
30
31class FrameBuffer;
32class FrameBufferAllocator;
33class PipelineHandler;
34class Request;
35
36 class SensorConfiguration
37{
38public:
39 unsigned int bitDepth = 0;
40
41 Rectangle analogCrop;
42
43 struct {
44 unsigned int binX = 1;
45 unsigned int binY = 1;
46 } binning;
47
48 struct {
49 unsigned int xOddInc = 1;
50 unsigned int xEvenInc = 1;
51 unsigned int yOddInc = 1;
52 unsigned int yEvenInc = 1;
53 } skipping;
54
55 Size outputSize;
56
57 bool isValid() const;
58};
59
60 class CameraConfiguration
61{
62public:
63 enum Status {
64 Valid,
65 Adjusted,
66 Invalid,
67 };
68
69 using iterator = std::vector<StreamConfiguration>::iterator;
70 using const_iterator = std::vector<StreamConfiguration>::const_iterator;
71
72 virtual ~CameraConfiguration();
73
74 void addConfiguration(const StreamConfiguration &cfg);
75 virtual Status validate() = 0;
76
77 StreamConfiguration &at(unsigned int index);
78 const StreamConfiguration &at(unsigned int index) const;
79 StreamConfiguration &operator[](unsigned int index)
80 {
81 return at(index);
82 }
83 const StreamConfiguration &operator[](unsigned int index) const
84 {
85 return at(index);
86 }
87
88 iterator begin();
89 const_iterator begin() const;
90 iterator end();
91 const_iterator end() const;
92
93 bool empty() const;
94 std::size_t size() const;
95
96 std::optional<SensorConfiguration> sensorConfig;
97 Orientation orientation;
98
99protected:
100 CameraConfiguration();
101
102 enum class ColorSpaceFlag {
103 None,
104 StreamsShareColorSpace,
105 };
106
107 using ColorSpaceFlags = Flags<ColorSpaceFlag>;
108
109 Status validateColorSpaces(ColorSpaceFlags flags = ColorSpaceFlag::None);
110
111 std::vector<StreamConfiguration> config_;
112};
113
114 class Camera final : public Object, public std::enable_shared_from_this<Camera>,
115 public Extensible
116{
117 LIBCAMERA_DECLARE_PRIVATE()
118
119public:
120 static std::shared_ptr<Camera> create(std::unique_ptr<Private> d,
121 const std::string &id,
122 const std::set<Stream *> &streams);
123
124 const std::string &id() const;
125
126 Signal<Request *, FrameBuffer *> bufferCompleted;
127 Signal<Request *> requestCompleted;
128 Signal<> disconnected;
129
130 int acquire();
131 int release();
132
133 const ControlInfoMap &controls() const;
134 const ControlList &properties() const;
135
136 const std::set<Stream *> &streams() const;
137
138 std::unique_ptr<CameraConfiguration>
139 generateConfiguration(Span<const StreamRole> roles = {});
140
141 std::unique_ptr<CameraConfiguration>
142 generateConfiguration(std::initializer_list<StreamRole> roles)
143 {
144 return generateConfiguration(Span(roles.begin(), roles.end()));
145 }
146
147 int configure(CameraConfiguration *config);
148
149 std::unique_ptr<Request> createRequest(uint64_t cookie = 0);
150 int queueRequest(Request *request);
151
152 int start(const ControlList *controls = nullptr);
153 int stop();
154
155private:
156 LIBCAMERA_DISABLE_COPY(Camera)
157
158 Camera(std::unique_ptr<Private> d, const std::string &id,
159 const std::set<Stream *> &streams);
160 ~Camera();
161
162 friend class PipelineHandler;
163 void disconnect();
164 void requestComplete(Request *request);
165
166 friend class FrameBufferAllocator;
167 int exportFrameBuffers(Stream *stream,
168 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
169
170 void patchControlList(ControlList &controls);
171};
172
173} /* namespace libcamera */
libcamera::CameraConfiguration
Hold configuration for streams of the camera.
Definition camera.h:61
libcamera::CameraConfiguration::config_
std::vector< StreamConfiguration > config_
The vector of stream configurations.
Definition camera.h:111
libcamera::CameraConfiguration::validateColorSpaces
Status validateColorSpaces(ColorSpaceFlags flags=ColorSpaceFlag::None)
Check the color spaces requested for each stream.
Definition camera.cpp:497
libcamera::CameraConfiguration::ColorSpaceFlag
ColorSpaceFlag
Specify the behaviour of validateColorSpaces.
Definition camera.h:102
libcamera::CameraConfiguration::ColorSpaceFlag::None
@ None
No extra validation of color spaces is required.
Definition camera.h:103
libcamera::CameraConfiguration::ColorSpaceFlag::StreamsShareColorSpace
@ StreamsShareColorSpace
Non-raw output streams must share the same color space.
Definition camera.h:104
libcamera::CameraConfiguration::ColorSpaceFlags
Flags< ColorSpaceFlag > ColorSpaceFlags
A bitwise combination of ColorSpaceFlag values.
Definition camera.h:107
libcamera::CameraConfiguration::at
StreamConfiguration & at(unsigned int index)
Retrieve a reference to a stream configuration.
Definition camera.cpp:359
libcamera::CameraConfiguration::Status
Status
Validity of a camera configuration.
Definition camera.h:63
libcamera::CameraConfiguration::Invalid
@ Invalid
Definition camera.h:66
libcamera::CameraConfiguration::Adjusted
@ Adjusted
Definition camera.h:65
libcamera::CameraConfiguration::Valid
@ Valid
Definition camera.h:64
libcamera::CameraConfiguration::operator[]
const StreamConfiguration & operator[](unsigned int index) const
Retrieve a const reference to a stream configuration.
Definition camera.h:83
libcamera::CameraConfiguration::empty
bool empty() const
Check if the camera configuration is empty.
Definition camera.cpp:448
libcamera::CameraConfiguration::CameraConfiguration
CameraConfiguration()
Create an empty camera configuration.
Definition camera.cpp:304
libcamera::CameraConfiguration::size
std::size_t size() const
Retrieve the number of stream configurations.
Definition camera.cpp:457
libcamera::CameraConfiguration::orientation
Orientation orientation
The desired orientation of the images produced by the camera.
Definition camera.h:97
libcamera::CameraConfiguration::iterator
std::vector< StreamConfiguration >::iterator iterator
Iterator for the stream configurations in the camera configuration.
Definition camera.h:69
libcamera::CameraConfiguration::addConfiguration
void addConfiguration(const StreamConfiguration &cfg)
Add a stream configuration to the camera configuration.
Definition camera.cpp:317
libcamera::CameraConfiguration::begin
iterator begin()
Retrieve an iterator to the first stream configuration in the sequence.
Definition camera.cpp:408
libcamera::CameraConfiguration::end
iterator end()
Retrieve an iterator pointing to the past-the-end stream configuration in the sequence.
Definition camera.cpp:428
libcamera::CameraConfiguration::validate
virtual Status validate()=0
Validate and possibly adjust the camera configuration.
libcamera::CameraConfiguration::operator[]
StreamConfiguration & operator[](unsigned int index)
Retrieve a reference to a stream configuration.
Definition camera.h:79
libcamera::CameraConfiguration::sensorConfig
std::optional< SensorConfiguration > sensorConfig
The camera sensor configuration.
Definition camera.h:96
libcamera::CameraConfiguration::const_iterator
std::vector< StreamConfiguration >::const_iterator const_iterator
Const iterator for the stream configuration in the camera configuration.
Definition camera.h:70
libcamera::Camera
Camera device.
Definition camera.h:116
libcamera::Camera::streams
const std::set< Stream * > & streams() const
Retrieve all the camera's stream information.
Definition camera.cpp:1102
libcamera::Camera::controls
const ControlInfoMap & controls() const
Retrieve the list of controls supported by the camera.
Definition camera.cpp:1073
libcamera::Camera::id
const std::string & id() const
Retrieve the ID of the camera.
Definition camera.cpp:901
libcamera::Camera::generateConfiguration
std::unique_ptr< CameraConfiguration > generateConfiguration(Span< const StreamRole > roles={})
Generate a default camera configuration according to stream roles.
Definition camera.cpp:1122
libcamera::Camera::configure
int configure(CameraConfiguration *config)
Configure the camera prior to capture.
Definition camera.cpp:1191
libcamera::Camera::stop
int stop()
Stop capture from camera.
Definition camera.cpp:1445
libcamera::Camera::acquire
int acquire()
Acquire the camera device for exclusive access.
Definition camera.cpp:1007
libcamera::Camera::release
int release()
Release exclusive access to the camera device.
Definition camera.cpp:1045
libcamera::Camera::start
int start(const ControlList *controls=nullptr)
Start capture from camera.
Definition camera.cpp:1400
libcamera::Camera::createRequest
std::unique_ptr< Request > createRequest(uint64_t cookie=0)
Create a request object for the camera.
Definition camera.cpp:1263
libcamera::Camera::bufferCompleted
Signal< Request *, FrameBuffer * > bufferCompleted
Signal emitted when a buffer for a request queued to the camera has completed.
Definition camera.h:126
libcamera::Camera::generateConfiguration
std::unique_ptr< CameraConfiguration > generateConfiguration(std::initializer_list< StreamRole > roles)
Definition camera.h:142
libcamera::Camera::queueRequest
int queueRequest(Request *request)
Queue a request to the camera.
Definition camera.cpp:1330
libcamera::Camera::disconnected
Signal disconnected
Signal emitted when the camera is disconnected from the system.
Definition camera.h:128
libcamera::Camera::properties
const ControlList & properties() const
Retrieve the list of properties of the camera.
Definition camera.cpp:1086
libcamera::Camera::requestCompleted
Signal< Request * > requestCompleted
Signal emitted when a request queued to the camera has completed.
Definition camera.h:127
libcamera::ControlInfoMap
A map of ControlId to ControlInfo.
Definition controls.h:365
libcamera::ControlList
Associate a list of ControlId with their values for an object.
Definition controls.h:409
libcamera::Flags
Type-safe container for enum-based bitfields.
Definition flags.h:16
libcamera::FrameBufferAllocator
FrameBuffer allocator for applications.
Definition framebuffer_allocator.h:23
libcamera::FrameBuffer
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:50
libcamera::Rectangle
Describe a rectangle's position and dimensions.
Definition geometry.h:247
libcamera::Request
A frame capture request.
Definition request.h:30
libcamera::SensorConfiguration
Camera sensor configuration.
Definition camera.h:37
libcamera::SensorConfiguration::bitDepth
unsigned int bitDepth
The sensor image format bit depth.
Definition camera.h:39
libcamera::SensorConfiguration::skipping
struct libcamera::SensorConfiguration::@345224272135250135276377350006277362174110056061 skipping
The sensor skipping configuration.
libcamera::SensorConfiguration::yEvenInc
unsigned int yEvenInc
Vertical increment for even columns. Default to 1.
Definition camera.h:52
libcamera::SensorConfiguration::binning
struct libcamera::SensorConfiguration::@246152371134173154271257342001112340175006073137 binning
Sensor binning configuration.
libcamera::SensorConfiguration::isValid
bool isValid() const
Check if the sensor configuration is valid.
Definition camera.cpp:245
libcamera::SensorConfiguration::binX
unsigned int binX
Horizontal binning factor.
Definition camera.h:44
libcamera::SensorConfiguration::analogCrop
Rectangle analogCrop
The analog crop rectangle.
Definition camera.h:41
libcamera::SensorConfiguration::binY
unsigned int binY
Vertical binning factor.
Definition camera.h:45
libcamera::SensorConfiguration::yOddInc
unsigned int yOddInc
Vertical increment for odd columns. Default to 1.
Definition camera.h:51
libcamera::SensorConfiguration::xEvenInc
unsigned int xEvenInc
Horizontal increment for even rows. Default to 1.
Definition camera.h:50
libcamera::SensorConfiguration::xOddInc
unsigned int xOddInc
Horizontal increment for odd rows. Default to 1.
Definition camera.h:49
libcamera::SensorConfiguration::outputSize
Size outputSize
The frame output (visible) size.
Definition camera.h:55
libcamera::Signal
Generic signal and slot communication mechanism.
Definition signal.h:39
libcamera::Size
Describe a two-dimensional size.
Definition geometry.h:51
libcamera::Stream
Video stream for a camera.
Definition stream.h:76
controls.h
Framework to manage controls related to an object.
flags.h
Enum-based bit fields.
geometry.h
Data structures related to geometric objects.
libcamera::controls
Namespace for libcamera controls.
Definition control_ids.h:22
libcamera::properties::PipelineHandler
const Control< std::string_view > PipelineHandler
The name of the pipeline handler that manages this camera device.o.
Definition camera.h:162
libcamera
Top-level libcamera namespace.
Definition bound_method.h:15
libcamera::Orientation
Orientation
The image orientation in a memory buffer.
Definition orientation.h:14
orientation.h
Image orientation definition.
request.h
Describes a frame capture request to be processed by a camera.
signal.h
Signal & slot implementation.
stream.h
Video stream for a Camera.
libcamera::StreamConfiguration
Configuration parameters for a stream.
Definition stream.h:40