From 616738943dbc26834479d1250f97fdfddac49bb3 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 4 Feb 2024 17:55:31 +0200 Subject: 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 Reviewed-by: Stefan Klug --- include/libcamera/internal/camera_sensor.h | 126 +++++++++-------------------- 1 file changed, 36 insertions(+), 90 deletions(-) (limited to 'include') 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 #include +#include #include #include -#include #include #include @@ -20,8 +20,6 @@ #include #include -#include - #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 &mbusCodes() const { return mbusCodes_; } - std::vector sizes(unsigned int mbusCode) const; - Size resolution() const; + virtual const std::vector &mbusCodes() const = 0; + virtual std::vector sizes(unsigned int mbusCode) const = 0; + virtual Size resolution() const = 0; - V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, - const Size &size) const; - int setFormat(V4L2SubdeviceFormat *format, - Transform transform = Transform::Identity); - int tryFormat(V4L2SubdeviceFormat *format) const; + virtual V4L2SubdeviceFormat + getFormat(const std::vector &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 &ids); - int setControls(ControlList *ctrls); - - const std::vector &testPatternModes() const - { - return testPatternModes_; - } - int setTestPatternMode(controls::draft::TestPatternModeEnum mode); + virtual const ControlInfoMap &controls() const = 0; + virtual ControlList getControls(const std::vector &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 subdev_; - unsigned int pad_; - - const CameraSensorProperties *staticProps_; - - std::string model_; - std::string id_; - - V4L2Subdevice::Formats formats_; - std::vector mbusCodes_; - std::vector sizes_; - std::vector testPatternModes_; - controls::draft::TestPatternModeEnum testPatternMode_; - - Size pixelArraySize_; - Rectangle activeArea_; - const BayerFormat *bayerFormat_; - bool supportFlips_; - bool flipsAlterBayerOrder_; - Orientation mountingOrientation_; - - ControlList properties_; - - std::unique_ptr focusLens_; + virtual const std::vector & + 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 - createInstance(MediaEntity *entity) const = 0; + virtual std::variant, int> + match(MediaEntity *entity) const = 0; }; template @@ -153,16 +104,11 @@ public: } private: - bool match(const MediaEntity *entity) const override + std::variant, int> + match(MediaEntity *entity) const override { return _CameraSensor::match(entity); } - - std::unique_ptr - createInstance(MediaEntity *entity) const override - { - return _CameraSensor::create(entity); - } }; #define REGISTER_CAMERA_SENSOR(sensor) \ -- cgit v1.2.1