From e18441c81eb39095e895cba6a89989f6afcf3b40 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 23 Feb 2024 14:03:32 +0200 Subject: libcamera: camera_sensor: Sort factories by priority In order to support a default implementation for camera sensors when no better implementation matches, libcamera needs to try "specialized" implementations first and pick the default last. Make this possible by adding a priority value for factories. Newly registered factories are inserted in the factories list sorted by descending priority, and the default factory uses a negative priority to be inserted as the last element. This mechanism may be a bit overkill in the sense that there is no expected use cases for priorities other than trying the default last, but the implementation is simple and easy to understand. Signed-off-by: Laurent Pinchart Reviewed-by: Stefan Klug --- Changes since combined RFC: - Make the factory priority mandatory --- include/libcamera/internal/camera_sensor.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index d18115bb..ccdb3a9b 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -78,11 +78,13 @@ public: class CameraSensorFactoryBase { public: - CameraSensorFactoryBase(); + CameraSensorFactoryBase(int priority); virtual ~CameraSensorFactoryBase() = default; static std::unique_ptr create(MediaEntity *entity); + int priority() const { return priority_; } + private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorFactoryBase) @@ -92,14 +94,16 @@ private: virtual std::variant, int> match(MediaEntity *entity) const = 0; + + int priority_; }; template class CameraSensorFactory final : public CameraSensorFactoryBase { public: - CameraSensorFactory() - : CameraSensorFactoryBase() + CameraSensorFactory(int priority) + : CameraSensorFactoryBase(priority) { } @@ -111,7 +115,7 @@ private: } }; -#define REGISTER_CAMERA_SENSOR(sensor) \ -static CameraSensorFactory global_##sensor##Factory{}; +#define REGISTER_CAMERA_SENSOR(sensor, priority) \ +static CameraSensorFactory global_##sensor##Factory{ priority }; } /* namespace libcamera */ -- cgit v1.2.1