libcamera v0.3.2 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 * 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
24 namespace libcamera {
25
26 class FrameBuffer;
27 class MediaDevice;
28 class PixelFormat;
29 class Stream;
30 struct StreamConfiguration;
31
32 class Converter
33{
34 public:
35 Converter(MediaDevice *media);
36 virtual ~Converter();
37
38 virtual int loadConfiguration(const std::string &filename) = 0;
39
40 virtual bool isValid() const = 0;
41
42 virtual std::vector<PixelFormat> formats(PixelFormat input) = 0;
43 virtual SizeRange sizes(const Size &input) = 0;
44
45 virtual std::tuple<unsigned int, unsigned int>
46 strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size) = 0;
47
48 virtual int configure(const StreamConfiguration &inputCfg,
49 const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs) = 0;
50 virtual int exportBuffers(const Stream *stream, unsigned int count,
51 std::vector<std::unique_ptr<FrameBuffer>> *buffers) = 0;
52
53 virtual int start() = 0;
54 virtual void stop() = 0;
55
56 virtual int queueBuffers(FrameBuffer *input,
57 const std::map<const Stream *, FrameBuffer *> &outputs) = 0;
58
59 Signal<FrameBuffer *> inputBufferReady;
60 Signal<FrameBuffer *> outputBufferReady;
61
62 const std::string &deviceNode() const { return deviceNode_; }
63
64 private:
65 std::string deviceNode_;
66};
67
68 class ConverterFactoryBase
69{
70 public:
71 ConverterFactoryBase(const std::string name, std::initializer_list<std::string> compatibles);
72 virtual ~ConverterFactoryBase() = default;
73
74 const std::vector<std::string> &compatibles() const { return compatibles_; }
75
76 static std::unique_ptr<Converter> create(MediaDevice *media);
77 static std::vector<ConverterFactoryBase *> &factories();
78 static std::vector<std::string> names();
79
80 private:
81 LIBCAMERA_DISABLE_COPY_AND_MOVE(ConverterFactoryBase)
82
83 static void registerType(ConverterFactoryBase *factory);
84
85 virtual std::unique_ptr<Converter> createInstance(MediaDevice *media) const = 0;
86
87 std::string name_;
88 std::vector<std::string> compatibles_;
89};
90
91 template<typename _Converter>
92 class ConverterFactory : public ConverterFactoryBase
93{
94 public:
95 ConverterFactory(const char *name, std::initializer_list<std::string> compatibles)
96 : ConverterFactoryBase(name, compatibles)
97 {
98 }
99
100 std::unique_ptr<Converter> createInstance(MediaDevice *media) const override
101 {
102 return std::make_unique<_Converter>(media);
103 }
104};
105
106#define REGISTER_CONVERTER(name, converter, compatibles) \
107 static ConverterFactory<converter> global_##converter##Factory(name, compatibles);
108
109} /* 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.
Definition class.h:29
libcamera::ConverterFactoryBase
Base class for converter factories.
Definition converter.h:69
libcamera::ConverterFactoryBase::compatibles
const std::vector< std::string > & compatibles() const
Definition converter.h:74
libcamera::ConverterFactoryBase::factories
static std::vector< ConverterFactoryBase * > & factories()
Retrieve the list of all converter factories.
Definition converter.cpp:277
libcamera::ConverterFactoryBase::ConverterFactoryBase
ConverterFactoryBase(const std::string name, std::initializer_list< std::string > compatibles)
Construct a converter factory base.
Definition converter.cpp:192
libcamera::ConverterFactoryBase::create
static std::unique_ptr< Converter > create(MediaDevice *media)
Create an instance of the converter corresponding to the media device.
Definition converter.cpp:213
libcamera::ConverterFactoryBase::names
static std::vector< std::string > names()
Retrieve the list of all converter factory names.
Definition converter.cpp:257
libcamera::ConverterFactory
Registration of ConverterFactory classes and creation of instances.
Definition converter.h:93
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:100
libcamera::ConverterFactory::ConverterFactory
ConverterFactory(const char *name, std::initializer_list< std::string > compatibles)
Construct a converter factory.
Definition converter.h:95
libcamera::Converter
Abstract Base Class for converter.
Definition converter.h:33
libcamera::Converter::queueBuffers
virtual int queueBuffers(FrameBuffer *input, const std::map< const Stream *, FrameBuffer * > &outputs)=0
Queue buffers to converter device.
libcamera::Converter::exportBuffers
virtual int exportBuffers(const Stream *stream, unsigned int count, std::vector< std::unique_ptr< FrameBuffer > > *buffers)=0
Export buffers from the converter device.
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::sizes
virtual SizeRange sizes(const Size &input)=0
Retrieve the range of minimum and maximum output sizes for an input size.
libcamera::Converter::outputBufferReady
Signal< FrameBuffer * > outputBufferReady
A signal emitted on each frame buffer completion of the output queue.
Definition converter.h:60
libcamera::Converter::isValid
virtual bool isValid() const =0
Check if the converter configuration is valid.
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::loadConfiguration
virtual int loadConfiguration(const std::string &filename)=0
Load converter configuration from file.
libcamera::Converter::inputBufferReady
Signal< FrameBuffer * > inputBufferReady
A signal emitted when the input frame buffer completes.
Definition converter.h:59
libcamera::Converter::deviceNode
const std::string & deviceNode() const
The converter device node attribute accessor.
Definition converter.h:62
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::Converter
Converter(MediaDevice *media)
Construct a Converter instance.
Definition converter.cpp:44
libcamera::Converter::stop
virtual void stop()=0
Stop the converter streaming operation.
libcamera::FrameBuffer
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:49
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition media_device.h:25
libcamera::PixelFormat
libcamera image pixel format
Definition pixel_format.h:17
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
libcamera::Stream
Video stream for a camera.
Definition stream.h:74
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:40