camera_sensor.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* camera_sensor.h - A camera sensor
*/
#ifndef __LIBCAMERA_INTERNAL_CAMERA_SENSOR_H__
#define __LIBCAMERA_INTERNAL_CAMERA_SENSOR_H__
#include <memory>
#include <string>
#include <vector>
#include <libcamera/controls.h>
#include <libcamera/geometry.h>
#include "libcamera/internal/formats.h"
#include "libcamera/internal/log.h"
namespace libcamera {
class MediaEntity;
class V4L2Subdevice;
struct V4L2SubdeviceFormat;
struct CameraSensorInfo {
std::string model;
uint32_t bitsPerPixel;
Size activeAreaSize;
Rectangle analogCrop;
Size outputSize;
uint64_t pixelRate;
uint32_t lineLength;
};
class CameraSensor : protected Loggable
{
public:
explicit CameraSensor(const MediaEntity *entity);
~CameraSensor();
CameraSensor(const CameraSensor &) = delete;
CameraSensor &operator=(const CameraSensor &) = delete;
int init();
const std::string &model() const { return model_; }
const MediaEntity *entity() const { return entity_; }
const std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }
const std::vector<Size> &sizes() const { return sizes_; }
const Size &resolution() const { return resolution_; }
V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
const Size &size) const;
int setFormat(V4L2SubdeviceFormat *format);
const ControlInfoMap &controls() const;
ControlList getControls(const std::vector<uint32_t> &ids);
int setControls(ControlList *ctrls);
const ControlList &properties() const { return properties_; }
int sensorInfo(CameraSensorInfo *info) const;
protected:
std::string logPrefix() const override;
private:
const MediaEntity *entity_;
std::unique_ptr<V4L2Subdevice> subdev_;
unsigned int pad_;
std::string model_;
ImageFormats formats_;
Size resolution_;
std::vector<unsigned int> mbusCodes_;
std::vector<Size> sizes_;
ControlList properties_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_INTERNAL_CAMERA_SENSOR_H__ */
libcamera::CameraSensor
A camera sensor based on V4L2 subdevices.
Definition: camera_sensor.h:41
libcamera::CameraSensor::properties
const ControlList & properties() const
Retrieve the camera sensor properties.
Definition: camera_sensor.h:65
libcamera::CameraSensor::entity
const MediaEntity * entity() const
Retrieve the sensor media entity.
Definition: camera_sensor.h:52
libcamera::CameraSensor::setControls
int setControls(ControlList *ctrls)
Write controls to the sensor.
Definition: camera_sensor.cpp:471
libcamera::CameraSensor::sizes
const std::vector< Size > & sizes() const
Retrieve the frame sizes supported by the camera sensor.
Definition: camera_sensor.h:54
libcamera::CameraSensor::setFormat
int setFormat(V4L2SubdeviceFormat *format)
Set the sensor output format.
Definition: camera_sensor.cpp:405
libcamera::CameraSensor::CameraSensor
CameraSensor(const MediaEntity *entity)
Construct a CameraSensor.
Definition: camera_sensor.cpp:132
libcamera::CameraSensor::controls
const ControlInfoMap & controls() const
Retrieve the supported V4L2 controls and their information.
Definition: camera_sensor.cpp:414
libcamera::CameraSensor::logPrefix
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: camera_sensor.cpp:538
libcamera::CameraSensor::~CameraSensor
~CameraSensor()
Destroy a CameraSensor.
Definition: camera_sensor.cpp:140
libcamera::CameraSensor::model
const std::string & model() const
Retrieve the sensor model name.
Definition: camera_sensor.h:51
libcamera::CameraSensor::init
int init()
Initialize the camera sensor instance.
Definition: camera_sensor.cpp:152
libcamera::CameraSensor::sensorInfo
int sensorInfo(CameraSensorInfo *info) const
Assemble and return the camera sensor info.
Definition: camera_sensor.cpp:485
libcamera::CameraSensor::resolution
const Size & resolution() const
Retrieve the camera sensor resolution.
Definition: camera_sensor.h:55
libcamera::CameraSensor::getFormat
V4L2SubdeviceFormat getFormat(const std::vector< unsigned int > &mbusCodes, const Size &size) const
Retrieve the best sensor format for a desired output.
Definition: camera_sensor.cpp:351
libcamera::CameraSensor::mbusCodes
const std::vector< unsigned int > & mbusCodes() const
Retrieve the media bus codes supported by the camera sensor.
Definition: camera_sensor.h:53
libcamera::CameraSensor::getControls
ControlList getControls(const std::vector< uint32_t > &ids)
Read controls from the sensor.
Definition: camera_sensor.cpp:436
libcamera::ControlInfoMap
A map of ControlId to ControlInfo.
Definition: controls.h:297
libcamera::ControlList
Associate a list of ControlId with their values for an object.
Definition: controls.h:342
libcamera::ImageFormats
Describe V4L2Device and V4L2SubDevice image formats.
Definition: formats.h:22
libcamera::Loggable
Base class to support log message extensions.
Definition: log.h:83
libcamera::MediaEntity
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:86
controls.h
Framework to manage controls related to an object.
geometry.h
Data structures related to geometric objects.
formats.h
Types and helper methods to handle libcamera image formats.
log.h
Logging infrastructure.
libcamera::CameraSensorInfo
Report the image sensor characteristics.
Definition: camera_sensor.h:27
libcamera::CameraSensorInfo::bitsPerPixel
uint32_t bitsPerPixel
The number of bits per pixel of the image format produced by the image sensor.
Definition: camera_sensor.h:30
libcamera::CameraSensorInfo::pixelRate
uint64_t pixelRate
The number of pixels produced in a second.
Definition: camera_sensor.h:36
libcamera::CameraSensorInfo::model
std::string model
The image sensor model name.
Definition: camera_sensor.h:28
libcamera::CameraSensorInfo::outputSize
Size outputSize
The size of the images produced by the camera sensor.
Definition: camera_sensor.h:34
libcamera::CameraSensorInfo::analogCrop
Rectangle analogCrop
The portion of the pixel array active area which is read-out and processed.
Definition: camera_sensor.h:33
libcamera::CameraSensorInfo::activeAreaSize
Size activeAreaSize
The size of the pixel array active area of the sensor.
Definition: camera_sensor.h:32
libcamera::CameraSensorInfo::lineLength
uint32_t lineLength
Total line length in pixels.
Definition: camera_sensor.h:37
libcamera::Rectangle
Describe a rectangle's position and dimensions.
Definition: geometry.h:15
libcamera::Size
Describe a two-dimensional size.
Definition: geometry.h:30
libcamera::V4L2SubdeviceFormat
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:24