diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-02-04 17:55:31 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-09-30 11:15:26 +0300 |
commit | 616738943dbc26834479d1250f97fdfddac49bb3 (patch) | |
tree | d1524ed1262011141cb8669c216e10bc05e78343 /include | |
parent | 674828e35f823433ab5469510359bea21ccd26de (diff) |
libcamera: camera_sensor: Create abstract base class
With a camera sensor factory in place, the next step is to create an
abstract base class that all camera sensors implement, providing a
uniform API to pipeline handler. Turn all public functions of the
CameraSensor class into pure virtual functions, and move the
implementation to the CameraSensorLegacy class.
Part of the code is likely worth keeping as common helpers in a base
class. However, to follow the principle of not designing helpers with a
single user, this commit moves the whole implementation. Common helpers
will be introduced later, along with other CameraSensor subclasses.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/internal/camera_sensor.h | 126 |
1 files changed, 36 insertions, 90 deletions
diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 2d6cb697..d18115bb 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -9,10 +9,10 @@ #include <memory> #include <string> +#include <variant> #include <vector> #include <libcamera/base/class.h> -#include <libcamera/base/log.h> #include <libcamera/control_ids.h> #include <libcamera/controls.h> @@ -20,8 +20,6 @@ #include <libcamera/orientation.h> #include <libcamera/transform.h> -#include <libcamera/ipa/core_ipa_interface.h> - #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/v4l2_subdevice.h" @@ -31,95 +29,50 @@ class CameraLens; class MediaEntity; class SensorConfiguration; -struct CameraSensorProperties; - enum class Orientation; -class CameraSensor : protected Loggable +struct IPACameraSensorInfo; + +class CameraSensor { public: - ~CameraSensor(); - - int init(); + virtual ~CameraSensor(); - const std::string &model() const { return model_; } - const std::string &id() const { return id_; } + virtual const std::string &model() const = 0; + virtual const std::string &id() const = 0; - const MediaEntity *entity() const { return entity_; } - V4L2Subdevice *device() { return subdev_.get(); } + virtual const MediaEntity *entity() const = 0; + virtual V4L2Subdevice *device() = 0; - CameraLens *focusLens() { return focusLens_.get(); } + virtual CameraLens *focusLens() = 0; - const std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; } - std::vector<Size> sizes(unsigned int mbusCode) const; - Size resolution() const; + virtual const std::vector<unsigned int> &mbusCodes() const = 0; + virtual std::vector<Size> sizes(unsigned int mbusCode) const = 0; + virtual Size resolution() const = 0; - V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes, - const Size &size) const; - int setFormat(V4L2SubdeviceFormat *format, - Transform transform = Transform::Identity); - int tryFormat(V4L2SubdeviceFormat *format) const; + virtual V4L2SubdeviceFormat + getFormat(const std::vector<unsigned int> &mbusCodes, + const Size &size) const = 0; + virtual int setFormat(V4L2SubdeviceFormat *format, + Transform transform = Transform::Identity) = 0; + virtual int tryFormat(V4L2SubdeviceFormat *format) const = 0; - int applyConfiguration(const SensorConfiguration &config, - Transform transform = Transform::Identity, - V4L2SubdeviceFormat *sensorFormat = nullptr); + virtual int applyConfiguration(const SensorConfiguration &config, + Transform transform = Transform::Identity, + V4L2SubdeviceFormat *sensorFormat = nullptr) = 0; - const ControlList &properties() const { return properties_; } - int sensorInfo(IPACameraSensorInfo *info) const; - Transform computeTransform(Orientation *orientation) const; - BayerFormat::Order bayerOrder(Transform t) const; + 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; - const ControlInfoMap &controls() const; - ControlList getControls(const std::vector<uint32_t> &ids); - int setControls(ControlList *ctrls); - - const std::vector<controls::draft::TestPatternModeEnum> &testPatternModes() const - { - return testPatternModes_; - } - int setTestPatternMode(controls::draft::TestPatternModeEnum mode); + virtual const ControlInfoMap &controls() const = 0; + virtual ControlList getControls(const std::vector<uint32_t> &ids) = 0; + virtual int setControls(ControlList *ctrls) = 0; -protected: - explicit CameraSensor(const MediaEntity *entity); - std::string logPrefix() const override; - -private: - LIBCAMERA_DISABLE_COPY(CameraSensor) - - int generateId(); - int validateSensorDriver(); - void initVimcDefaultProperties(); - void initStaticProperties(); - void initTestPatternModes(); - int initProperties(); - int discoverAncillaryDevices(); - int applyTestPatternMode(controls::draft::TestPatternModeEnum mode); - - const MediaEntity *entity_; - std::unique_ptr<V4L2Subdevice> subdev_; - unsigned int pad_; - - const CameraSensorProperties *staticProps_; - - std::string model_; - std::string id_; - - V4L2Subdevice::Formats formats_; - std::vector<unsigned int> mbusCodes_; - std::vector<Size> sizes_; - std::vector<controls::draft::TestPatternModeEnum> testPatternModes_; - controls::draft::TestPatternModeEnum testPatternMode_; - - Size pixelArraySize_; - Rectangle activeArea_; - const BayerFormat *bayerFormat_; - bool supportFlips_; - bool flipsAlterBayerOrder_; - Orientation mountingOrientation_; - - ControlList properties_; - - std::unique_ptr<CameraLens> focusLens_; + virtual const std::vector<controls::draft::TestPatternModeEnum> & + testPatternModes() const = 0; + virtual int setTestPatternMode(controls::draft::TestPatternModeEnum mode) = 0; }; class CameraSensorFactoryBase @@ -137,10 +90,8 @@ private: static void registerFactory(CameraSensorFactoryBase *factory); - virtual bool match(const MediaEntity *entity) const = 0; - - virtual std::unique_ptr<CameraSensor> - createInstance(MediaEntity *entity) const = 0; + virtual std::variant<std::unique_ptr<CameraSensor>, int> + match(MediaEntity *entity) const = 0; }; template<typename _CameraSensor> @@ -153,16 +104,11 @@ public: } private: - bool match(const MediaEntity *entity) const override + std::variant<std::unique_ptr<CameraSensor>, int> + match(MediaEntity *entity) const override { return _CameraSensor::match(entity); } - - std::unique_ptr<CameraSensor> - createInstance(MediaEntity *entity) const override - { - return _CameraSensor::create(entity); - } }; #define REGISTER_CAMERA_SENSOR(sensor) \ |