libcamera: include/libcamera/camera.h Source File

libcamera v0.0.4 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 <memory>
11#include <set>
12#include <stdint.h>
13#include <string>
14
15#include <libcamera/base/class.h>
16#include <libcamera/base/flags.h>
17#include <libcamera/base/object.h>
18#include <libcamera/base/signal.h>
19
20#include <libcamera/controls.h>
21#include <libcamera/request.h>
22#include <libcamera/stream.h>
23#include <libcamera/transform.h>
24
25namespace libcamera {
26
27class FrameBuffer;
28class FrameBufferAllocator;
29class PipelineHandler;
30class Request;
31
32 class CameraConfiguration
33{
34public:
35 enum Status {
36 Valid,
37 Adjusted,
38 Invalid,
39 };
40
41 using iterator = std::vector<StreamConfiguration>::iterator;
42 using const_iterator = std::vector<StreamConfiguration>::const_iterator;
43
44 virtual ~CameraConfiguration();
45
46 void addConfiguration(const StreamConfiguration &cfg);
47 virtual Status validate() = 0;
48
49 StreamConfiguration &at(unsigned int index);
50 const StreamConfiguration &at(unsigned int index) const;
51 StreamConfiguration &operator[](unsigned int index)
52 {
53 return at(index);
54 }
55 const StreamConfiguration &operator[](unsigned int index) const
56 {
57 return at(index);
58 }
59
60 iterator begin();
61 const_iterator begin() const;
62 iterator end();
63 const_iterator end() const;
64
65 bool empty() const;
66 std::size_t size() const;
67
68 Transform transform;
69
70protected:
71 CameraConfiguration();
72
73 enum class ColorSpaceFlag {
74 None,
75 StreamsShareColorSpace,
76 };
77
78 using ColorSpaceFlags = Flags<ColorSpaceFlag>;
79
80 Status validateColorSpaces(ColorSpaceFlags flags = ColorSpaceFlag::None);
81
82 std::vector<StreamConfiguration> config_;
83};
84
85 class Camera final : public Object, public std::enable_shared_from_this<Camera>,
86 public Extensible
87{
88 LIBCAMERA_DECLARE_PRIVATE()
89
90public:
91 static std::shared_ptr<Camera> create(std::unique_ptr<Private> d,
92 const std::string &id,
93 const std::set<Stream *> &streams);
94
95 const std::string &id() const;
96
97 Signal<Request *, FrameBuffer *> bufferCompleted;
98 Signal<Request *> requestCompleted;
99 Signal<> disconnected;
100
101 int acquire();
102 int release();
103
104 const ControlInfoMap &controls() const;
105 const ControlList &properties() const;
106
107 const std::set<Stream *> &streams() const;
108 std::unique_ptr<CameraConfiguration> generateConfiguration(const StreamRoles &roles = {});
109 int configure(CameraConfiguration *config);
110
111 std::unique_ptr<Request> createRequest(uint64_t cookie = 0);
112 int queueRequest(Request *request);
113
114 int start(const ControlList *controls = nullptr);
115 int stop();
116
117private:
118 LIBCAMERA_DISABLE_COPY(Camera)
119
120 Camera(std::unique_ptr<Private> d, const std::string &id,
121 const std::set<Stream *> &streams);
122 ~Camera();
123
124 friend class PipelineHandler;
125 void disconnect();
126 void requestComplete(Request *request);
127
128 friend class FrameBufferAllocator;
129 int exportFrameBuffers(Stream *stream,
130 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
131};
132
133} /* namespace libcamera */
class.h
Utilities to help constructing class interfaces.
LIBCAMERA_DECLARE_PRIVATE
#define LIBCAMERA_DECLARE_PRIVATE()
Declare private data for a public class.
LIBCAMERA_DISABLE_COPY
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
libcamera::CameraConfiguration
Hold configuration for streams of the camera.
Definition: camera.h:33
libcamera::CameraConfiguration::iterator
std::vector< StreamConfiguration >::iterator iterator
Iterator for the stream configurations in the camera configuration.
Definition: camera.h:41
libcamera::CameraConfiguration::config_
std::vector< StreamConfiguration > config_
The vector of stream configurations.
Definition: camera.h:82
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:73
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:35
libcamera::CameraConfiguration::Valid
@ Valid
Definition: camera.h:36
libcamera::CameraConfiguration::Adjusted
@ Adjusted
Definition: camera.h:37
libcamera::CameraConfiguration::Invalid
@ Invalid
Definition: camera.h:38
libcamera::CameraConfiguration::operator[]
const StreamConfiguration & operator[](unsigned int index) const
Retrieve a const reference to a stream configuration.
Definition: camera.h:55
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:42
libcamera::CameraConfiguration::operator[]
StreamConfiguration & operator[](unsigned int index)
Retrieve a reference to a stream configuration.
Definition: camera.h:51
libcamera::CameraConfiguration::transform
Transform transform
User-specified transform to be applied to the image.
Definition: camera.h:68
libcamera::Camera
Camera device.
Definition: camera.h:87
libcamera::Camera::streams
const std::set< Stream * > & streams() const
Retrieve all the camera's stream information.
Definition: camera.cpp:921
libcamera::Camera::controls
const ControlInfoMap & controls() const
Retrieve the list of controls supported by the camera.
Definition: camera.cpp:892
libcamera::Camera::id
const std::string & id() const
Retrieve the ID of the camera.
Definition: camera.cpp:723
libcamera::Camera::generateConfiguration
std::unique_ptr< CameraConfiguration > generateConfiguration(const StreamRoles &roles={})
Generate a default camera configuration according to stream roles.
Definition: camera.cpp:941
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:682
libcamera::Camera::configure
int configure(CameraConfiguration *config)
Configure the camera prior to capture.
Definition: camera.cpp:1003
libcamera::Camera::stop
int stop()
Stop capture from camera.
Definition: camera.cpp:1210
libcamera::Camera::acquire
int acquire()
Acquire the camera device for exclusive access.
Definition: camera.cpp:828
libcamera::Camera::release
int release()
Release exclusive access to the camera device.
Definition: camera.cpp:865
libcamera::Camera::start
int start(const ControlList *controls=nullptr)
Start capture from camera.
Definition: camera.cpp:1173
libcamera::Camera::createRequest
std::unique_ptr< Request > createRequest(uint64_t cookie=0)
Create a request object for the camera.
Definition: camera.cpp:1075
libcamera::Camera::requestCompleted
Signal< Request * > requestCompleted
Signal emitted when a request queued to the camera has completed.
Definition: camera.h:98
libcamera::Camera::queueRequest
int queueRequest(Request *request)
Queue a request to the camera.
Definition: camera.cpp:1115
libcamera::Camera::properties
const ControlList & properties() const
Retrieve the list of properties of the camera.
Definition: camera.cpp:905
libcamera::Camera::disconnected
Signal disconnected
Signal emitted when the camera is disconnected from the system.
Definition: camera.h:99
libcamera::Camera::bufferCompleted
Signal< Request *, FrameBuffer * > bufferCompleted
Signal emitted when a buffer for a request queued to the camera has completed.
Definition: camera.h:97
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:77
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
libcamera::StreamRoles
std::vector< StreamRole > StreamRoles
A vector of StreamRole.
Definition: stream.h:72
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.