summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-02-23 14:03:32 +0200
committerJacopo Mondi <jacopo.mondi@ideasonboard.com>2024-11-05 18:07:42 +0100
commit5cb45181d7a6379d7eb3717f2ca8f0ab799baa1f (patch)
tree80aa7341855ba2fd6f385e4a3017c5e47fdffb2f /include
parentaee7f8207e1eea9559e0adcc3c66b04882f1f3dc (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> 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.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index 7713aea0..8aafd82e 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -78,12 +78,13 @@ public:
class CameraSensorFactoryBase
{
public:
- CameraSensorFactoryBase(const char *name);
+ CameraSensorFactoryBase(const char *name, int priority);
virtual ~CameraSensorFactoryBase() = default;
static std::unique_ptr<CameraSensor> create(MediaEntity *entity);
const std::string &name() const { return name_; }
+ int priority() const { return priority_; }
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorFactoryBase)
@@ -96,14 +97,15 @@ private:
match(MediaEntity *entity) const = 0;
std::string name_;
+ int priority_;
};
template<typename _CameraSensor>
class CameraSensorFactory final : public CameraSensorFactoryBase
{
public:
- CameraSensorFactory(const char *name)
- : CameraSensorFactoryBase(name)
+ CameraSensorFactory(const char *name, int priority)
+ : CameraSensorFactoryBase(name, priority)
{
}
@@ -115,7 +117,7 @@ private:
}
};
-#define REGISTER_CAMERA_SENSOR(sensor) \
-static CameraSensorFactory<sensor> global_##sensor##Factory{ #sensor };
+#define REGISTER_CAMERA_SENSOR(sensor, priority) \
+static CameraSensorFactory<sensor> global_##sensor##Factory{ #sensor, priority };
} /* namespace libcamera */