Loading...
Searching...
No Matches
camera_sensor.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* A camera sensor
*/
#pragma once
#include <memory>
#include <stdint.h>
#include <string>
#include <variant>
#include <vector>
#include <libcamera/base/class.h>
#include <libcamera/base/span.h>
#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
#include <libcamera/geometry.h>
#include <libcamera/orientation.h>
#include <libcamera/transform.h>
#include "libcamera/internal/bayer_format.h"
#include "libcamera/internal/camera_sensor_properties.h"
#include "libcamera/internal/v4l2_subdevice.h"
namespace libcamera {
class CameraLens;
class MediaEntity;
class SensorConfiguration;
enum class Orientation;
struct IPACameraSensorInfo;
class CameraSensor
{
public:
virtual ~CameraSensor();
virtual const std::string &model() const = 0;
virtual const std::string &id() const = 0;
virtual const MediaEntity *entity() const = 0;
virtual V4L2Subdevice *device() = 0;
virtual CameraLens *focusLens() = 0;
virtual const std::vector<unsigned int> &mbusCodes() const = 0;
virtual std::vector<Size> sizes(unsigned int mbusCode) const = 0;
virtual Size resolution() const = 0;
virtual V4L2SubdeviceFormat
getFormat(Span<const unsigned int> mbusCodes,
const Size &size, const Size maxSize = Size()) const = 0;
virtual int setFormat(V4L2SubdeviceFormat *format,
Transform transform = Transform::Identity) = 0;
virtual int tryFormat(V4L2SubdeviceFormat *format) const = 0;
virtual int applyConfiguration(const SensorConfiguration &config,
Transform transform = Transform::Identity,
V4L2SubdeviceFormat *sensorFormat = nullptr) = 0;
virtual V4L2Subdevice::Stream imageStream() const;
virtual std::optional<V4L2Subdevice::Stream> embeddedDataStream() const;
virtual V4L2SubdeviceFormat embeddedDataFormat() const;
virtual int setEmbeddedDataEnabled(bool enable);
virtual const ControlList &properties() const = 0;
virtual int sensorInfo(IPACameraSensorInfo *info) const = 0;
virtual Transform computeTransform(Orientation *orientation) const = 0;
virtual BayerFormat::Order bayerOrder(Transform t) const = 0;
virtual Orientation mountingOrientation() const = 0;
virtual const ControlInfoMap &controls() const = 0;
virtual ControlList getControls(Span<const uint32_t> ids) = 0;
virtual int setControls(ControlList *ctrls) = 0;
virtual const std::vector<controls::draft::TestPatternModeEnum> &
testPatternModes() const = 0;
virtual int setTestPatternMode(controls::draft::TestPatternModeEnum mode) = 0;
virtual const CameraSensorProperties::SensorDelays &sensorDelays() = 0;
};
class CameraSensorFactoryBase
{
public:
CameraSensorFactoryBase(const char *name, int priority);
virtual ~CameraSensorFactoryBase() = default;
static std::unique_ptr<CameraSensor> create(MediaEntity *entity);
const std::string &name() const { return name_; }
int priority() const { return priority_; }
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorFactoryBase)
static std::vector<CameraSensorFactoryBase *> &factories();
static void registerFactory(CameraSensorFactoryBase *factory);
virtual std::variant<std::unique_ptr<CameraSensor>, int>
match(MediaEntity *entity) const = 0;
std::string name_;
int priority_;
};
template<typename _CameraSensor>
class CameraSensorFactory final : public CameraSensorFactoryBase
{
public:
CameraSensorFactory(const char *name, int priority)
: CameraSensorFactoryBase(name, priority)
{
}
private:
std::variant<std::unique_ptr<CameraSensor>, int>
match(MediaEntity *entity) const override
{
return _CameraSensor::match(entity);
}
};
#define REGISTER_CAMERA_SENSOR(sensor, priority) \
static CameraSensorFactory<sensor> global_##sensor##Factory{ #sensor, priority };
} /* namespace libcamera */
bayer_format.h
Class to represent Bayer formats and manipulate them.
camera_sensor_properties.h
Database of camera sensor properties.
class.h
Utilities to help constructing class interfaces.
LIBCAMERA_DISABLE_COPY_AND_MOVE
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Definition class.h:29
libcamera::BayerFormat::Order
Order
The order of the colour channels in the Bayer pattern.
Definition bayer_format.h:25
libcamera::CameraLens
A camera lens based on V4L2 subdevices.
Definition camera_lens.h:24
libcamera::CameraSensorFactoryBase
Base class for camera sensor factories.
Definition camera_sensor.h:89
libcamera::CameraSensorFactoryBase::name
const std::string & name() const
Retrieve the camera sensor factory name.
Definition camera_sensor.h:96
libcamera::CameraSensorFactoryBase::priority
int priority() const
Retrieve the priority value for the factory.
Definition camera_sensor.h:97
libcamera::CameraSensorFactoryBase::CameraSensorFactoryBase
CameraSensorFactoryBase(const char *name, int priority)
Construct a camera sensor factory base.
Definition camera_sensor.cpp:447
libcamera::CameraSensorFactoryBase::create
static std::unique_ptr< CameraSensor > create(MediaEntity *entity)
Create an instance of the CameraSensor corresponding to a media entity.
Definition camera_sensor.cpp:466
libcamera::CameraSensorFactory::CameraSensorFactory
CameraSensorFactory(const char *name, int priority)
Construct a camera sensor factory.
Definition camera_sensor.h:117
libcamera::CameraSensor
A abstract camera sensor.
Definition camera_sensor.h:40
libcamera::CameraSensor::setControls
virtual int setControls(ControlList *ctrls)=0
Write V4L2 controls to the sensor.
libcamera::CameraSensor::imageStream
virtual V4L2Subdevice::Stream imageStream() const
Retrieve the image source stream.
Definition camera_sensor.cpp:212
libcamera::CameraSensor::computeTransform
virtual Transform computeTransform(Orientation *orientation) const =0
Compute the Transform that gives the requested orientation.
libcamera::CameraSensor::properties
virtual const ControlList & properties() const =0
Retrieve the camera sensor properties.
libcamera::CameraSensor::model
virtual const std::string & model() const =0
Retrieve the sensor model name.
libcamera::CameraSensor::mountingOrientation
virtual Orientation mountingOrientation() const =0
Fetch the mounting orientation of the sensor.
libcamera::CameraSensor::bayerOrder
virtual BayerFormat::Order bayerOrder(Transform t) const =0
Compute the Bayer order that results from the given Transform.
libcamera::CameraSensor::id
virtual const std::string & id() const =0
Retrieve the sensor ID.
libcamera::CameraSensor::controls
virtual const ControlInfoMap & controls() const =0
Retrieve the supported V4L2 controls and their information.
libcamera::CameraSensor::tryFormat
virtual int tryFormat(V4L2SubdeviceFormat *format) const =0
Try the sensor output format.
libcamera::CameraSensor::~CameraSensor
virtual ~CameraSensor()
Destroy a CameraSensor.
libcamera::CameraSensor::resolution
virtual Size resolution() const =0
Retrieve the camera sensor resolution.
libcamera::CameraSensor::setFormat
virtual int setFormat(V4L2SubdeviceFormat *format, Transform transform=Transform::Identity)=0
Set the sensor output format.
libcamera::CameraSensor::testPatternModes
virtual const std::vector< controls::draft::TestPatternModeEnum > & testPatternModes() const =0
Retrieve all the supported test pattern modes of the camera sensor The test pattern mode values corre...
libcamera::CameraSensor::sensorDelays
virtual const CameraSensorProperties::SensorDelays & sensorDelays()=0
Fetch the sensor delay values.
libcamera::CameraSensor::getFormat
virtual V4L2SubdeviceFormat getFormat(Span< const unsigned int > mbusCodes, const Size &size, const Size maxSize=Size()) const =0
Retrieve the best sensor format for a desired output.
libcamera::CameraSensor::mbusCodes
virtual const std::vector< unsigned int > & mbusCodes() const =0
Retrieve the media bus codes supported by the camera sensor.
libcamera::CameraSensor::embeddedDataStream
virtual std::optional< V4L2Subdevice::Stream > embeddedDataStream() const
Retrieve the embedded data source stream.
Definition camera_sensor.cpp:227
libcamera::CameraSensor::setTestPatternMode
virtual int setTestPatternMode(controls::draft::TestPatternModeEnum mode)=0
Set the test pattern mode for the camera sensor.
libcamera::CameraSensor::applyConfiguration
virtual int applyConfiguration(const SensorConfiguration &config, Transform transform=Transform::Identity, V4L2SubdeviceFormat *sensorFormat=nullptr)=0
Apply a sensor configuration to the camera sensor.
libcamera::CameraSensor::focusLens
virtual CameraLens * focusLens()=0
Retrieve the focus lens controller.
libcamera::CameraSensor::setEmbeddedDataEnabled
virtual int setEmbeddedDataEnabled(bool enable)
Enable or disable the embedded data stream.
Definition camera_sensor.cpp:264
libcamera::CameraSensor::sizes
virtual std::vector< Size > sizes(unsigned int mbusCode) const =0
Retrieve the supported frame sizes for a media bus code.
libcamera::CameraSensor::getControls
virtual ControlList getControls(Span< const uint32_t > ids)=0
Read V4L2 controls from the sensor.
libcamera::CameraSensor::entity
virtual const MediaEntity * entity() const =0
Retrieve the sensor media entity.
libcamera::CameraSensor::sensorInfo
virtual int sensorInfo(IPACameraSensorInfo *info) const =0
Assemble and return the camera sensor info.
libcamera::CameraSensor::device
virtual V4L2Subdevice * device()=0
Retrieve the camera sensor device.
libcamera::CameraSensor::embeddedDataFormat
virtual V4L2SubdeviceFormat embeddedDataFormat() const
Retrieve the format on the embedded data stream.
Definition camera_sensor.cpp:245
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::MediaEntity
The MediaEntity represents an entity in the media graph.
Definition media_object.h:97
libcamera::SensorConfiguration
Camera sensor configuration.
Definition camera.h:36
libcamera::Size
Describe a two-dimensional size.
Definition geometry.h:51
libcamera::V4L2Subdevice
A V4L2 subdevice as exposed by the Linux kernel.
Definition v4l2_subdevice.h:76
control_ids.h
Camera controls identifiers.
controls.h
Framework to manage controls related to an object.
geometry.h
Data structures related to geometric objects.
libcamera::controls::draft::TestPatternModeEnum
TestPatternModeEnum
Supported TestPatternMode values.
Definition control_ids.h:406
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::Transform
Transform
Enum to represent a 2D plane transform.
Definition transform.h:14
libcamera::Transform::Identity
@ Identity
Definition transform.h:15
libcamera::Orientation
Orientation
The image orientation in a memory buffer.
Definition orientation.h:14
orientation.h
Image orientation definition.
libcamera::CameraSensorProperties::SensorDelays
Sensor control application delay values.
Definition camera_sensor_properties.h:20
libcamera::IPACameraSensorInfo
Report the image sensor characteristics.
Definition core_ipa_interface.h:31
libcamera::V4L2SubdeviceFormat
The V4L2 sub-device image format and sizes.
Definition v4l2_subdevice.h:65
libcamera::V4L2Subdevice::Stream
V4L2 subdevice stream.
Definition v4l2_subdevice.h:85
transform.h
Enum to represent and manipulate 2D plane transforms.
v4l2_subdevice.h
V4L2 Subdevice API.