libcamera: include/libcamera/camera.h Source File

libcamera v0.3.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
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
28namespace libcamera {
29
30class FrameBuffer;
31class FrameBufferAllocator;
32class PipelineHandler;
33class Request;
34
35 class SensorConfiguration
36{
37public:
38 unsigned int bitDepth = 0;
39
40 Rectangle analogCrop;
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
54 Size outputSize;
55
56 bool isValid() const;
57};
58
59 class CameraConfiguration
60{
61public:
62 enum Status {
63 Valid,
64 Adjusted,
65 Invalid,
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;
96 Orientation orientation;
97
98protected:
99 CameraConfiguration();
100
101 enum class ColorSpaceFlag {
102 None,
103 StreamsShareColorSpace,
104 };
105
106 using ColorSpaceFlags = Flags<ColorSpaceFlag>;
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{
116 LIBCAMERA_DECLARE_PRIVATE()
117
118public:
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
125 Signal<Request *, FrameBuffer *> bufferCompleted;
126 Signal<Request *> requestCompleted;
127 Signal<> disconnected;
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
154private:
155 LIBCAMERA_DISABLE_COPY(Camera)
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 */
libcamera::CameraConfiguration
Hold configuration for streams of the camera.
Definition camera.h:60
libcamera::CameraConfiguration::config_
std::vector< StreamConfiguration > config_
The vector of stream configurations.
Definition camera.h:110
libcamera::CameraConfiguration::validateColorSpaces
Status validateColorSpaces(ColorSpaceFlags flags=ColorSpaceFlag::None)
Check the color spaces requested for each stream.
Definition camera.cpp:495
libcamera::CameraConfiguration::ColorSpaceFlag
ColorSpaceFlag
Specify the behaviour of validateColorSpaces.
Definition camera.h:101
libcamera::CameraConfiguration::ColorSpaceFlag::None
@ None
No extra validation of color spaces is required.
libcamera::CameraConfiguration::ColorSpaceFlag::StreamsShareColorSpace
@ StreamsShareColorSpace
Non-raw output streams must share the same color space.
libcamera::CameraConfiguration::at
StreamConfiguration & at(unsigned int index)
Retrieve a reference to a stream configuration.
Definition camera.cpp:357
libcamera::CameraConfiguration::Status
Status
Validity of a camera configuration.
Definition camera.h:62
libcamera::CameraConfiguration::Invalid
@ Invalid
Definition camera.h:65
libcamera::CameraConfiguration::Adjusted
@ Adjusted
Definition camera.h:64
libcamera::CameraConfiguration::Valid
@ Valid
Definition camera.h:63
libcamera::CameraConfiguration::operator[]
const StreamConfiguration & operator[](unsigned int index) const
Retrieve a const reference to a stream configuration.
Definition camera.h:82
libcamera::CameraConfiguration::empty
bool empty() const
Check if the camera configuration is empty.
Definition camera.cpp:446
libcamera::CameraConfiguration::CameraConfiguration
CameraConfiguration()
Create an empty camera configuration.
Definition camera.cpp:302
libcamera::CameraConfiguration::size
std::size_t size() const
Retrieve the number of stream configurations.
Definition camera.cpp:455
libcamera::CameraConfiguration::orientation
Orientation orientation
The desired orientation of the images produced by the camera.
Definition camera.h:96
libcamera::CameraConfiguration::iterator
std::vector< StreamConfiguration >::iterator iterator
Iterator for the stream configurations in the camera configuration.
Definition camera.h:68
libcamera::CameraConfiguration::addConfiguration
void addConfiguration(const StreamConfiguration &cfg)
Add a stream configuration to the camera configuration.
Definition camera.cpp:315
libcamera::CameraConfiguration::begin
iterator begin()
Retrieve an iterator to the first stream configuration in the sequence.
Definition camera.cpp:406
libcamera::CameraConfiguration::end
iterator end()
Retrieve an iterator pointing to the past-the-end stream configuration in the sequence.
Definition camera.cpp:426
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:78
libcamera::CameraConfiguration::sensorConfig
std::optional< SensorConfiguration > sensorConfig
The camera sensor configuration.
Definition camera.h:95
libcamera::CameraConfiguration::const_iterator
std::vector< StreamConfiguration >::const_iterator const_iterator
Const iterator for the stream configuration in the camera configuration.
Definition camera.h:69
libcamera::Camera
Camera device.
Definition camera.h:115
libcamera::Camera::streams
const std::set< Stream * > & streams() const
Retrieve all the camera's stream information.
Definition camera.cpp:1084
libcamera::Camera::controls
const ControlInfoMap & controls() const
Retrieve the list of controls supported by the camera.
Definition camera.cpp:1055
libcamera::Camera::id
const std::string & id() const
Retrieve the ID of the camera.
Definition camera.cpp:884
libcamera::Camera::generateConfiguration
std::unique_ptr< CameraConfiguration > generateConfiguration(Span< const StreamRole > roles={})
Generate a default camera configuration according to stream roles.
Definition camera.cpp:1104
libcamera::Camera::configure
int configure(CameraConfiguration *config)
Configure the camera prior to capture.
Definition camera.cpp:1172
libcamera::Camera::stop
int stop()
Stop capture from camera.
Definition camera.cpp:1384
libcamera::Camera::acquire
int acquire()
Acquire the camera device for exclusive access.
Definition camera.cpp:989
libcamera::Camera::release
int release()
Release exclusive access to the camera device.
Definition camera.cpp:1027
libcamera::Camera::start
int start(const ControlList *controls=nullptr)
Start capture from camera.
Definition camera.cpp:1347
libcamera::Camera::createRequest
std::unique_ptr< Request > createRequest(uint64_t cookie=0)
Create a request object for the camera.
Definition camera.cpp:1244
libcamera::Camera::bufferCompleted
Signal< Request *, FrameBuffer * > bufferCompleted
Signal emitted when a buffer for a request queued to the camera has completed.
Definition camera.h:125
libcamera::Camera::generateConfiguration
std::unique_ptr< CameraConfiguration > generateConfiguration(std::initializer_list< StreamRole > roles)
Definition camera.h:141
libcamera::Camera::queueRequest
int queueRequest(Request *request)
Queue a request to the camera.
Definition camera.cpp:1284
libcamera::Camera::disconnected
Signal disconnected
Signal emitted when the camera is disconnected from the system.
Definition camera.h:127
libcamera::Camera::properties
const ControlList & properties() const
Retrieve the list of properties of the camera.
Definition camera.cpp:1068
libcamera::Camera::requestCompleted
Signal< Request * > requestCompleted
Signal emitted when a request queued to the camera has completed.
Definition camera.h:126
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::Flags
Type-safe container for enum-based bitfields.
Definition flags.h:16
libcamera::FrameBufferAllocator
FrameBuffer allocator for applications.
Definition framebuffer_allocator.h:23
libcamera::Rectangle
Describe a rectangle's position and dimensions.
Definition geometry.h:243
libcamera::Request
A frame capture request.
Definition request.h:30
libcamera::SensorConfiguration
Camera sensor configuration.
Definition camera.h:36
libcamera::SensorConfiguration::bitDepth
unsigned int bitDepth
The sensor image format bit depth.
Definition camera.h:38
libcamera::SensorConfiguration::yEvenInc
unsigned int yEvenInc
Vertical increment for even columns. Default to 1.
Definition camera.h:51
libcamera::SensorConfiguration::isValid
bool isValid() const
Check if the sensor configuration is valid.
Definition camera.cpp:243
libcamera::SensorConfiguration::binX
unsigned int binX
Horizontal binning factor.
Definition camera.h:43
libcamera::SensorConfiguration::analogCrop
Rectangle analogCrop
The analog crop rectangle.
Definition camera.h:40
libcamera::SensorConfiguration::binning
struct libcamera::SensorConfiguration::@0 binning
Sensor binning configuration.
libcamera::SensorConfiguration::binY
unsigned int binY
Vertical binning factor.
Definition camera.h:44
libcamera::SensorConfiguration::yOddInc
unsigned int yOddInc
Vertical increment for odd columns. Default to 1.
Definition camera.h:50
libcamera::SensorConfiguration::xEvenInc
unsigned int xEvenInc
Horizontal increment for even rows. Default to 1.
Definition camera.h:49
libcamera::SensorConfiguration::xOddInc
unsigned int xOddInc
Horizontal increment for odd rows. Default to 1.
Definition camera.h:48
libcamera::SensorConfiguration::outputSize
Size outputSize
The frame output (visible) size.
Definition camera.h:54
libcamera::SensorConfiguration::skipping
struct libcamera::SensorConfiguration::@1 skipping
The sensor skipping configuration.
libcamera::Signal
Generic signal and slot communication mechanism.
Definition signal.h:39
libcamera::Size
Describe a two-dimensional size.
Definition geometry.h:53
libcamera::Stream
Video stream for a camera.
Definition stream.h:74
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
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