Loading...
Searching...
No Matches
camera.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* Camera object interface
*/
#pragma once
#include <initializer_list>
#include <memory>
#include <optional>
#include <set>
#include <stdint.h>
#include <string>
#include <libcamera/base/class.h>
#include <libcamera/base/flags.h>
#include <libcamera/base/object.h>
#include <libcamera/base/signal.h>
#include <libcamera/controls.h>
#include <libcamera/geometry.h>
#include <libcamera/orientation.h>
#include <libcamera/request.h>
#include <libcamera/stream.h>
namespace libcamera {
class FrameBuffer;
class FrameBufferAllocator;
class PipelineHandler;
class Request;
class SensorConfiguration
{
public:
unsigned int bitDepth = 0;
Rectangle analogCrop;
struct {
unsigned int binX = 1;
unsigned int binY = 1;
} binning;
struct {
unsigned int xOddInc = 1;
unsigned int xEvenInc = 1;
unsigned int yOddInc = 1;
unsigned int yEvenInc = 1;
} skipping;
Size outputSize;
bool isValid() const;
};
class CameraConfiguration
{
public:
enum Status {
Valid,
Adjusted,
Invalid,
};
using iterator = std::vector<StreamConfiguration>::iterator;
using const_iterator = std::vector<StreamConfiguration>::const_iterator;
virtual ~CameraConfiguration();
void addConfiguration(const StreamConfiguration &cfg);
virtual Status validate() = 0;
StreamConfiguration &at(unsigned int index);
const StreamConfiguration &at(unsigned int index) const;
StreamConfiguration &operator[](unsigned int index)
{
return at(index);
}
const StreamConfiguration &operator[](unsigned int index) const
{
return at(index);
}
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
bool empty() const;
std::size_t size() const;
std::optional<SensorConfiguration> sensorConfig;
Orientation orientation;
protected:
CameraConfiguration();
enum class ColorSpaceFlag {
None,
StreamsShareColorSpace,
};
using ColorSpaceFlags = Flags<ColorSpaceFlag>;
Status validateColorSpaces(ColorSpaceFlags flags = ColorSpaceFlag::None);
std::vector<StreamConfiguration> config_;
};
class Camera final : public Object, public std::enable_shared_from_this<Camera>,
public Extensible
{
LIBCAMERA_DECLARE_PRIVATE()
public:
static std::shared_ptr<Camera> create(std::unique_ptr<Private> d,
const std::string &id,
const std::set<Stream *> &streams);
const std::string &id() const;
Signal<Request *, FrameBuffer *> bufferCompleted;
Signal<Request *> requestCompleted;
Signal<> disconnected;
int acquire();
int release();
const ControlInfoMap &controls() const;
const ControlList &properties() const;
const std::set<Stream *> &streams() const;
std::unique_ptr<CameraConfiguration>
generateConfiguration(Span<const StreamRole> roles = {});
std::unique_ptr<CameraConfiguration>
generateConfiguration(std::initializer_list<StreamRole> roles)
{
return generateConfiguration(Span(roles.begin(), roles.end()));
}
int configure(CameraConfiguration *config);
std::unique_ptr<Request> createRequest(uint64_t cookie = 0);
int queueRequest(Request *request);
int start(const ControlList *controls = nullptr);
int stop();
private:
LIBCAMERA_DISABLE_COPY(Camera)
Camera(std::unique_ptr<Private> d, const std::string &id,
const std::set<Stream *> &streams);
~Camera();
friend class PipelineHandler;
void disconnect();
void requestComplete(Request *request);
friend class FrameBufferAllocator;
int exportFrameBuffers(Stream *stream,
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
void patchControlList(ControlList &controls);
};
} /* 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:497
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.
Definition camera.h:102
libcamera::CameraConfiguration::ColorSpaceFlag::StreamsShareColorSpace
@ StreamsShareColorSpace
Non-raw output streams must share the same color space.
Definition camera.h:103
libcamera::CameraConfiguration::ColorSpaceFlags
Flags< ColorSpaceFlag > ColorSpaceFlags
A bitwise combination of ColorSpaceFlag values.
Definition camera.h:106
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: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: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: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: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: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:1101
libcamera::Camera::controls
const ControlInfoMap & controls() const
Retrieve the list of controls supported by the camera.
Definition camera.cpp:1072
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:1121
libcamera::Camera::configure
int configure(CameraConfiguration *config)
Configure the camera prior to capture.
Definition camera.cpp:1190
libcamera::Camera::stop
int stop()
Stop capture from camera.
Definition camera.cpp:1446
libcamera::Camera::acquire
int acquire()
Acquire the camera device for exclusive access.
Definition camera.cpp:1006
libcamera::Camera::release
int release()
Release exclusive access to the camera device.
Definition camera.cpp:1044
libcamera::Camera::start
int start(const ControlList *controls=nullptr)
Start capture from camera.
Definition camera.cpp:1401
libcamera::Camera::createRequest
std::unique_ptr< Request > createRequest(uint64_t cookie=0)
Create a request object for the camera.
Definition camera.cpp:1262
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:1329
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:1085
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: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:36
libcamera::SensorConfiguration::bitDepth
unsigned int bitDepth
The sensor image format bit depth.
Definition camera.h:38
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:51
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:43
libcamera::SensorConfiguration::analogCrop
Rectangle analogCrop
The analog crop rectangle.
Definition camera.h:40
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::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
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