libcamera: include/libcamera/internal/converter.h Source File

libcamera v0.0.4 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
converter.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2020, Laurent Pinchart
4 * Copyright 2022 NXP
5 *
6 * converter.h - Generic format converter interface
7 */
8
9#pragma once
10
11#include <functional>
12#include <initializer_list>
13#include <map>
14#include <memory>
15#include <string>
16#include <tuple>
17#include <vector>
18
19#include <libcamera/base/class.h>
20#include <libcamera/base/signal.h>
21
22#include <libcamera/geometry.h>
23
24namespace libcamera {
25
26class FrameBuffer;
27class MediaDevice;
28class PixelFormat;
29struct StreamConfiguration;
30
31 class Converter
32{
33public:
34 Converter(MediaDevice *media);
35 virtual ~Converter();
36
37 virtual int loadConfiguration(const std::string &filename) = 0;
38
39 virtual bool isValid() const = 0;
40
41 virtual std::vector<PixelFormat> formats(PixelFormat input) = 0;
42 virtual SizeRange sizes(const Size &input) = 0;
43
44 virtual std::tuple<unsigned int, unsigned int>
45 strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size) = 0;
46
47 virtual int configure(const StreamConfiguration &inputCfg,
48 const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs) = 0;
49 virtual int exportBuffers(unsigned int output, unsigned int count,
50 std::vector<std::unique_ptr<FrameBuffer>> *buffers) = 0;
51
52 virtual int start() = 0;
53 virtual void stop() = 0;
54
55 virtual int queueBuffers(FrameBuffer *input,
56 const std::map<unsigned int, FrameBuffer *> &outputs) = 0;
57
58 Signal<FrameBuffer *> inputBufferReady;
59 Signal<FrameBuffer *> outputBufferReady;
60
61 const std::string &deviceNode() const { return deviceNode_; }
62
63private:
64 std::string deviceNode_;
65};
66
67 class ConverterFactoryBase
68{
69public:
70 ConverterFactoryBase(const std::string name, std::initializer_list<std::string> compatibles);
71 virtual ~ConverterFactoryBase() = default;
72
73 const std::vector<std::string> &compatibles() const { return compatibles_; }
74
75 static std::unique_ptr<Converter> create(MediaDevice *media);
76 static std::vector<ConverterFactoryBase *> &factories();
77 static std::vector<std::string> names();
78
79private:
80 LIBCAMERA_DISABLE_COPY_AND_MOVE(ConverterFactoryBase)
81
82 static void registerType(ConverterFactoryBase *factory);
83
84 virtual std::unique_ptr<Converter> createInstance(MediaDevice *media) const = 0;
85
86 std::string name_;
87 std::vector<std::string> compatibles_;
88};
89
90template<typename _Converter>
91 class ConverterFactory : public ConverterFactoryBase
92{
93public:
94 ConverterFactory(const char *name, std::initializer_list<std::string> compatibles)
95 : ConverterFactoryBase(name, compatibles)
96 {
97 }
98
99 std::unique_ptr<Converter> createInstance(MediaDevice *media) const override
100 {
101 return std::make_unique<_Converter>(media);
102 }
103};
104
105#define REGISTER_CONVERTER(name, converter, compatibles) \
106 static ConverterFactory<converter> global_##converter##Factory(name, compatibles);
107
108} /* namespace libcamera */
class.h
Utilities to help constructing class interfaces.
LIBCAMERA_DISABLE_COPY_AND_MOVE
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
libcamera::ConverterFactoryBase
Base class for converter factories.
Definition: converter.h:68
libcamera::ConverterFactoryBase::factories
static std::vector< ConverterFactoryBase * > & factories()
Retrieve the list of all converter factories.
Definition: converter.cpp:274
libcamera::ConverterFactoryBase::create
static std::unique_ptr< Converter > create(MediaDevice *media)
Create an instance of the converter corresponding to a named factory.
Definition: converter.cpp:213
libcamera::ConverterFactoryBase::compatibles
const std::vector< std::string > & compatibles() const
Definition: converter.h:73
libcamera::ConverterFactoryBase::names
static std::vector< std::string > names()
Retrieve the list of all converter factory names.
Definition: converter.cpp:254
libcamera::ConverterFactory
Registration of ConverterFactory classes and creation of instances.
Definition: converter.h:92
libcamera::ConverterFactory::createInstance
std::unique_ptr< Converter > createInstance(MediaDevice *media) const override
Create an instance of the Converter corresponding to the factory.
Definition: converter.h:99
libcamera::ConverterFactory::ConverterFactory
ConverterFactory(const char *name, std::initializer_list< std::string > compatibles)
Construct a converter factory.
Definition: converter.h:94
libcamera::Converter
Abstract Base Class for converter.
Definition: converter.h:32
libcamera::Converter::deviceNode
const std::string & deviceNode() const
The converter device node attribute accessor.
Definition: converter.h:61
libcamera::Converter::outputBufferReady
Signal< FrameBuffer * > outputBufferReady
A signal emitted on each frame buffer completion of the output queue.
Definition: converter.h:59
libcamera::Converter::stop
virtual void stop()=0
Stop the converter streaming operation.
libcamera::Converter::isValid
virtual bool isValid() const =0
Check if the converter configuration is valid.
libcamera::Converter::strideAndFrameSize
virtual std::tuple< unsigned int, unsigned int > strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size)=0
Retrieve the output stride and frame size for an input configutation.
libcamera::Converter::queueBuffers
virtual int queueBuffers(FrameBuffer *input, const std::map< unsigned int, FrameBuffer * > &outputs)=0
Queue buffers to converter device.
libcamera::Converter::loadConfiguration
virtual int loadConfiguration(const std::string &filename)=0
Load converter configuration from file.
libcamera::Converter::formats
virtual std::vector< PixelFormat > formats(PixelFormat input)=0
Retrieve the list of supported pixel formats for an input pixel format.
libcamera::Converter::start
virtual int start()=0
Start the converter streaming operation.
libcamera::Converter::exportBuffers
virtual int exportBuffers(unsigned int output, unsigned int count, std::vector< std::unique_ptr< FrameBuffer > > *buffers)=0
Export buffers from the converter device.
libcamera::Converter::inputBufferReady
Signal< FrameBuffer * > inputBufferReady
A signal emitted when the input frame buffer completes.
Definition: converter.h:58
libcamera::Converter::configure
virtual int configure(const StreamConfiguration &inputCfg, const std::vector< std::reference_wrapper< StreamConfiguration > > &outputCfgs)=0
Configure a set of output stream conversion from an input stream.
libcamera::Converter::sizes
virtual SizeRange sizes(const Size &input)=0
Retrieve the range of minimum and maximum output sizes for an input size.
libcamera::FrameBuffer
Frame buffer data and its associated dynamic metadata.
Definition: framebuffer.h:50
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition: media_device.h:26
libcamera::PixelFormat
libcamera image pixel format
Definition: pixel_format.h:18
libcamera::Signal
Generic signal and slot communication mechanism.
Definition: signal.h:39
libcamera::SizeRange
Describe a range of sizes.
Definition: geometry.h:201
libcamera::Size
Describe a two-dimensional size.
Definition: geometry.h:53
geometry.h
Data structures related to geometric objects.
libcamera
Top-level libcamera namespace.
Definition: backtrace.h:17
signal.h
Signal & slot implementation.
libcamera::StreamConfiguration
Configuration parameters for a stream.
Definition: stream.h:41