libcamera: include/libcamera/camera.h Source File

libcamera v0.1.0 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.h - Camera object interface
6 */
7
8#pragma once
9
10#include <initializer_list>
11#include <memory>
12#include <set>
13#include <stdint.h>
14#include <string>
15
16#include <libcamera/base/class.h>
17#include <libcamera/base/flags.h>
18#include <libcamera/base/object.h>
19#include <libcamera/base/signal.h>
20
21#include <libcamera/controls.h>
22#include <libcamera/request.h>
23#include <libcamera/stream.h>
24#include <libcamera/transform.h>
25
26namespace libcamera {
27
28class FrameBuffer;
29class FrameBufferAllocator;
30class PipelineHandler;
31class Request;
32
33 class CameraConfiguration
34{
35public:
36 enum Status {
37 Valid,
38 Adjusted,
39 Invalid,
40 };
41
42 using iterator = std::vector<StreamConfiguration>::iterator;
43 using const_iterator = std::vector<StreamConfiguration>::const_iterator;
44
45 virtual ~CameraConfiguration();
46
47 void addConfiguration(const StreamConfiguration &cfg);
48 virtual Status validate() = 0;
49
50 StreamConfiguration &at(unsigned int index);
51 const StreamConfiguration &at(unsigned int index) const;
52 StreamConfiguration &operator[](unsigned int index)
53 {
54 return at(index);
55 }
56 const StreamConfiguration &operator[](unsigned int index) const
57 {
58 return at(index);
59 }
60
61 iterator begin();
62 const_iterator begin() const;
63 iterator end();
64 const_iterator end() const;
65
66 bool empty() const;
67 std::size_t size() const;
68
69 Transform transform;
70
71protected:
72 CameraConfiguration();
73
74 enum class ColorSpaceFlag {
75 None,
76 StreamsShareColorSpace,
77 };
78
79 using ColorSpaceFlags = Flags<ColorSpaceFlag>;
80
81 Status validateColorSpaces(ColorSpaceFlags flags = ColorSpaceFlag::None);
82
83 std::vector<StreamConfiguration> config_;
84};
85
86 class Camera final : public Object, public std::enable_shared_from_this<Camera>,
87 public Extensible
88{
89 LIBCAMERA_DECLARE_PRIVATE()
90
91public:
92 static std::shared_ptr<Camera> create(std::unique_ptr<Private> d,
93 const std::string &id,
94 const std::set<Stream *> &streams);
95
96 const std::string &id() const;
97
98 Signal<Request *, FrameBuffer *> bufferCompleted;
99 Signal<Request *> requestCompleted;
100 Signal<> disconnected;
101
102 int acquire();
103 int release();
104
105 const ControlInfoMap &controls() const;
106 const ControlList &properties() const;
107
108 const std::set<Stream *> &streams() const;
109
110 std::unique_ptr<CameraConfiguration>
111 generateConfiguration(Span<const StreamRole> roles = {});
112
113 std::unique_ptr<CameraConfiguration>
114 generateConfiguration(std::initializer_list<StreamRole> roles)
115 {
116 return generateConfiguration(Span(roles.begin(), roles.end()));
117 }
118
119 int configure(CameraConfiguration *config);
120
121 std::unique_ptr<Request> createRequest(uint64_t cookie = 0);
122 int queueRequest(Request *request);
123
124 int start(const ControlList *controls = nullptr);
125 int stop();
126
127private:
128 LIBCAMERA_DISABLE_COPY(Camera)
129
130 Camera(std::unique_ptr<Private> d, const std::string &id,
131 const std::set<Stream *> &streams);
132 ~Camera();
133
134 friend class PipelineHandler;
135 void disconnect();
136 void requestComplete(Request *request);
137
138 friend class FrameBufferAllocator;
139 int exportFrameBuffers(Stream *stream,
140 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
141};
142
143} /* namespace libcamera */
class.h
Utilities to help constructing class interfaces.
LIBCAMERA_DECLARE_PRIVATE
#define LIBCAMERA_DECLARE_PRIVATE()
Declare private data for a public class.
Definition class.h:56
LIBCAMERA_DISABLE_COPY
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
Definition class.h:27
libcamera::CameraConfiguration
Hold configuration for streams of the camera.
Definition camera.h:34
libcamera::CameraConfiguration::iterator
std::vector< StreamConfiguration >::iterator iterator
Iterator for the stream configurations in the camera configuration.
Definition camera.h:42
libcamera::CameraConfiguration::config_
std::vector< StreamConfiguration > config_
The vector of stream configurations.
Definition camera.h:83
libcamera::CameraConfiguration::validateColorSpaces
Status validateColorSpaces(ColorSpaceFlags flags=ColorSpaceFlag::None)
Check the color spaces requested for each stream.
Definition camera.cpp:355
libcamera::CameraConfiguration::validate
virtual Status validate()=0
Validate and possibly adjust the camera configuration.
libcamera::CameraConfiguration::ColorSpaceFlag
ColorSpaceFlag
Specify the behaviour of validateColorSpaces.
Definition camera.h:74
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:217
libcamera::CameraConfiguration::Status
Status
Validity of a camera configuration.
Definition camera.h:36
libcamera::CameraConfiguration::Valid
@ Valid
Definition camera.h:37
libcamera::CameraConfiguration::Adjusted
@ Adjusted
Definition camera.h:38
libcamera::CameraConfiguration::Invalid
@ Invalid
Definition camera.h:39
libcamera::CameraConfiguration::operator[]
const StreamConfiguration & operator[](unsigned int index) const
Retrieve a const reference to a stream configuration.
Definition camera.h:56
libcamera::CameraConfiguration::empty
bool empty() const
Check if the camera configuration is empty.
Definition camera.cpp:306
libcamera::CameraConfiguration::CameraConfiguration
CameraConfiguration()
Create an empty camera configuration.
Definition camera.cpp:162
libcamera::CameraConfiguration::size
std::size_t size() const
Retrieve the number of stream configurations.
Definition camera.cpp:315
libcamera::CameraConfiguration::addConfiguration
void addConfiguration(const StreamConfiguration &cfg)
Add a stream configuration to the camera configuration.
Definition camera.cpp:175
libcamera::CameraConfiguration::begin
iterator begin()
Retrieve an iterator to the first stream configuration in the sequence.
Definition camera.cpp:266
libcamera::CameraConfiguration::end
iterator end()
Retrieve an iterator pointing to the past-the-end stream configuration in the sequence.
Definition camera.cpp:286
libcamera::CameraConfiguration::const_iterator
std::vector< StreamConfiguration >::const_iterator const_iterator
Const iterator for the stream configuration in the camera configuration.
Definition camera.h:43
libcamera::CameraConfiguration::operator[]
StreamConfiguration & operator[](unsigned int index)
Retrieve a reference to a stream configuration.
Definition camera.h:52
libcamera::CameraConfiguration::transform
Transform transform
User-specified transform to be applied to the image.
Definition camera.h:69
libcamera::Camera
Camera device.
Definition camera.h:88
libcamera::Camera::streams
const std::set< Stream * > & streams() const
Retrieve all the camera's stream information.
Definition camera.cpp:920
libcamera::Camera::controls
const ControlInfoMap & controls() const
Retrieve the list of controls supported by the camera.
Definition camera.cpp:891
libcamera::Camera::id
const std::string & id() const
Retrieve the ID of the camera.
Definition camera.cpp:722
libcamera::Camera::generateConfiguration
std::unique_ptr< CameraConfiguration > generateConfiguration(Span< const StreamRole > roles={})
Generate a default camera configuration according to stream roles.
Definition camera.cpp:940
libcamera::Camera::create
static std::shared_ptr< Camera > create(std::unique_ptr< Private > d, const std::string &id, const std::set< Stream * > &streams)
Create a camera instance.
Definition camera.cpp:681
libcamera::Camera::configure
int configure(CameraConfiguration *config)
Configure the camera prior to capture.
Definition camera.cpp:1008
libcamera::Camera::stop
int stop()
Stop capture from camera.
Definition camera.cpp:1220
libcamera::Camera::acquire
int acquire()
Acquire the camera device for exclusive access.
Definition camera.cpp:827
libcamera::Camera::release
int release()
Release exclusive access to the camera device.
Definition camera.cpp:864
libcamera::Camera::start
int start(const ControlList *controls=nullptr)
Start capture from camera.
Definition camera.cpp:1183
libcamera::Camera::createRequest
std::unique_ptr< Request > createRequest(uint64_t cookie=0)
Create a request object for the camera.
Definition camera.cpp:1080
libcamera::Camera::requestCompleted
Signal< Request * > requestCompleted
Signal emitted when a request queued to the camera has completed.
Definition camera.h:99
libcamera::Camera::generateConfiguration
std::unique_ptr< CameraConfiguration > generateConfiguration(std::initializer_list< StreamRole > roles)
Definition camera.h:114
libcamera::Camera::queueRequest
int queueRequest(Request *request)
Queue a request to the camera.
Definition camera.cpp:1120
libcamera::Camera::properties
const ControlList & properties() const
Retrieve the list of properties of the camera.
Definition camera.cpp:904
libcamera::Camera::disconnected
Signal disconnected
Signal emitted when the camera is disconnected from the system.
Definition camera.h:100
libcamera::Camera::bufferCompleted
Signal< Request *, FrameBuffer * > bufferCompleted
Signal emitted when a buffer for a request queued to the camera has completed.
Definition camera.h:98
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::Extensible
Base class to manage private data through a d-pointer.
Definition class.h:62
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::Object
Base object to support automatic signal disconnection.
Definition object.h:25
libcamera::PipelineHandler
Create and manage cameras based on a set of media devices.
Definition pipeline_handler.h:39
libcamera::Request
A frame capture request.
Definition request.h:31
libcamera::Signal
Generic signal and slot communication mechanism.
Definition signal.h:39
libcamera::Stream
Video stream for a camera.
Definition stream.h:75
controls.h
Framework to manage controls related to an object.
flags.h
Enum-based bit fields.
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::Transform
Transform
Enum to represent a 2D plane transform.
Definition transform.h:14
object.h
Base object to support automatic signal disconnection.
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:41
transform.h
Enum to represent and manipulate 2D plane transforms.