summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-02-23 14:03:32 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-06-25 14:38:48 +0300
commitccb50c0a3843df9b5c04e977a7f317359b15a98f (patch)
tree75ce33c3aa0d0d9bf9419d0404b8b9fbf55d2942 /include
parent049b61ca10830610ebdcaa2d13a05e27327ec843 (diff)
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> --- Changes since combined RFC: - Make the factory priority mandatory
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/internal/camera_sensor.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index 13d9d9e4..b75cde8d 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -79,11 +79,13 @@ public:
class CameraSensorFactoryBase
{
public:
- CameraSensorFactoryBase();
+ CameraSensorFactoryBase(int priority);
virtual ~CameraSensorFactoryBase() = default;
static std::unique_ptr<CameraSensor> create(MediaEntity *entity);
+ int priority() const { return priority_; }
+
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorFactoryBase)
@@ -93,14 +95,16 @@ private:
virtual std::variant<std::unique_ptr<CameraSensor>, int>
match(MediaEntity *entity) const = 0;
+
+ int priority_;
};
template<typename _CameraSensor>
class CameraSensorFactory final : public CameraSensorFactoryBase
{
public:
- CameraSensorFactory()
- : CameraSensorFactoryBase()
+ CameraSensorFactory(int priority)
+ : CameraSensorFactoryBase(priority)
{
}
@@ -112,7 +116,7 @@ private:
}
};
-#define REGISTER_CAMERA_SENSOR(sensor) \
-static CameraSensorFactory<sensor> global_##sensor##Factory{};
+#define REGISTER_CAMERA_SENSOR(sensor, priority) \
+static CameraSensorFactory<sensor> global_##sensor##Factory{ priority };
} /* namespace libcamera */