diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-02-04 17:55:31 +0200 |
---|---|---|
committer | Jacopo Mondi <jacopo.mondi@ideasonboard.com> | 2024-11-05 18:07:42 +0100 |
commit | aee7f8207e1eea9559e0adcc3c66b04882f1f3dc (patch) | |
tree | e25eca35c30a812c54d816b3ba7e064c0fa1a534 /include | |
parent | 6ba23735b973bb4922efd407cb2ce7c2503eadd0 (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>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/internal/camera_sensor.h | 136 |
1 files changed, 43 insertions, 93 deletions
diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 2d6cb697..7713aea0 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,105 +29,62 @@ 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 { public: - CameraSensorFactoryBase(); + CameraSensorFactoryBase(const char *name); virtual ~CameraSensorFactoryBase() = default; static std::unique_ptr<CameraSensor> create(MediaEntity *entity); + const std::string &name() const { return name_; } + private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorFactoryBase) @@ -137,35 +92,30 @@ private: static void registerFactory(CameraSensorFactoryBase *factory); - virtual bool match(const MediaEntity *entity) const = 0; + virtual std::variant<std::unique_ptr<CameraSensor>, int> + match(MediaEntity *entity) const = 0; - virtual std::unique_ptr<CameraSensor> - createInstance(MediaEntity *entity) const = 0; + std::string name_; }; template<typename _CameraSensor> class CameraSensorFactory final : public CameraSensorFactoryBase { public: - CameraSensorFactory() - : CameraSensorFactoryBase() + CameraSensorFactory(const char *name) + : CameraSensorFactoryBase(name) { } 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) \ -static CameraSensorFactory<sensor> global_##sensor##Factory{}; +static CameraSensorFactory<sensor> global_##sensor##Factory{ #sensor }; } /* namespace libcamera */ |