summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorXavier Roumegue <xavier.roumegue@oss.nxp.com>2022-12-14 16:52:17 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2022-12-14 16:19:52 +0000
commitf73f4dfad89698bc6f5d892564beaedb2a6a69ff (patch)
tree5b545263d20946ee33cec56915af20cc677d4719 /include
parente653f4c13e32225c2d1c304f3e6c44ff4efbdfe9 (diff)
libcamera: Declare generic converter interface
Declare a converter Abstract Base Class intended to provide generic interfaces to hardware offering size and format conversion services on streams. This is mainly based on the public interfaces of the current converter class implementation found in the simple pipeline handler. The main change is the introduction of loadConfiguration() function which can be used by the concrete implementation to load hardware specific runtime parameters defined by the application. Signed-off-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/internal/converter.h108
-rw-r--r--include/libcamera/internal/meson.build1
2 files changed, 109 insertions, 0 deletions
diff --git a/include/libcamera/internal/converter.h b/include/libcamera/internal/converter.h
new file mode 100644
index 00000000..834ec5ab
--- /dev/null
+++ b/include/libcamera/internal/converter.h
@@ -0,0 +1,108 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2020, Laurent Pinchart
+ * Copyright 2022 NXP
+ *
+ * converter.h - Generic format converter interface
+ */
+
+#pragma once
+
+#include <functional>
+#include <initializer_list>
+#include <map>
+#include <memory>
+#include <string>
+#include <tuple>
+#include <vector>
+
+#include <libcamera/base/class.h>
+#include <libcamera/base/signal.h>
+
+#include <libcamera/geometry.h>
+
+namespace libcamera {
+
+class FrameBuffer;
+class MediaDevice;
+class PixelFormat;
+struct StreamConfiguration;
+
+class Converter
+{
+public:
+ Converter(MediaDevice *media);
+ virtual ~Converter();
+
+ virtual int loadConfiguration(const std::string &filename) = 0;
+
+ virtual bool isValid() const = 0;
+
+ virtual std::vector<PixelFormat> formats(PixelFormat input) = 0;
+ virtual SizeRange sizes(const Size &input) = 0;
+
+ virtual std::tuple<unsigned int, unsigned int>
+ strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size) = 0;
+
+ virtual int configure(const StreamConfiguration &inputCfg,
+ const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs) = 0;
+ virtual int exportBuffers(unsigned int output, unsigned int count,
+ std::vector<std::unique_ptr<FrameBuffer>> *buffers) = 0;
+
+ virtual int start() = 0;
+ virtual void stop() = 0;
+
+ virtual int queueBuffers(FrameBuffer *input,
+ const std::map<unsigned int, FrameBuffer *> &outputs) = 0;
+
+ Signal<FrameBuffer *> inputBufferReady;
+ Signal<FrameBuffer *> outputBufferReady;
+
+ const std::string &deviceNode() const { return deviceNode_; }
+
+private:
+ std::string deviceNode_;
+};
+
+class ConverterFactoryBase
+{
+public:
+ ConverterFactoryBase(const std::string name, std::initializer_list<std::string> compatibles);
+ virtual ~ConverterFactoryBase() = default;
+
+ const std::vector<std::string> &compatibles() const { return compatibles_; }
+
+ static std::unique_ptr<Converter> create(MediaDevice *media);
+ static std::vector<ConverterFactoryBase *> &factories();
+ static std::vector<std::string> names();
+
+private:
+ LIBCAMERA_DISABLE_COPY_AND_MOVE(ConverterFactoryBase)
+
+ static void registerType(ConverterFactoryBase *factory);
+
+ virtual std::unique_ptr<Converter> createInstance(MediaDevice *media) const = 0;
+
+ std::string name_;
+ std::vector<std::string> compatibles_;
+};
+
+template<typename _Converter>
+class ConverterFactory : public ConverterFactoryBase
+{
+public:
+ ConverterFactory(const char *name, std::initializer_list<std::string> compatibles)
+ : ConverterFactoryBase(name, compatibles)
+ {
+ }
+
+ std::unique_ptr<Converter> createInstance(MediaDevice *media) const override
+ {
+ return std::make_unique<_Converter>(media);
+ }
+};
+
+#define REGISTER_CONVERTER(name, converter, compatibles) \
+ static ConverterFactory<converter> global_##converter##Factory(name, compatibles);
+
+} /* namespace libcamera */
diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
index f8be86e0..341af8a2 100644
--- a/include/libcamera/internal/meson.build
+++ b/include/libcamera/internal/meson.build
@@ -19,6 +19,7 @@ libcamera_internal_headers = files([
'camera_sensor_properties.h',
'control_serializer.h',
'control_validator.h',
+ 'converter.h',
'delayed_controls.h',
'device_enumerator.h',
'device_enumerator_sysfs.h',