Loading...
Searching...
No Matches
converter.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2020, Laurent Pinchart
* Copyright 2022 NXP
*
* Generic format converter interface
*/
#pragma once
#include <functional>
#include <initializer_list>
#include <map>
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <libcamera/base/class.h>
#include <libcamera/base/flags.h>
#include <libcamera/base/signal.h>
#include <libcamera/geometry.h>
#include "libcamera/internal/v4l2_request.h"
namespace libcamera {
class FrameBuffer;
class MediaDevice;
class PixelFormat;
class Stream;
struct StreamConfiguration;
class Converter
{
public:
enum class Feature {
None = 0,
InputCrop = (1 << 0),
};
using Features = Flags<Feature>;
enum class Alignment {
Down = 0,
Up,
};
Converter(std::shared_ptr<MediaDevice> media, Features features = Feature::None);
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 Size adjustInputSize(const PixelFormat &pixFmt,
const Size &size,
Alignment align = Alignment::Down) = 0;
virtual Size adjustOutputSize(const PixelFormat &pixFmt,
const Size &size,
Alignment align = Alignment::Down) = 0;
virtual std::tuple<unsigned int, unsigned int>
strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size) = 0;
virtual int validateOutput(StreamConfiguration *cfg, bool *adjusted,
Alignment align = Alignment::Down) = 0;
virtual int configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs) = 0;
virtual bool isConfigured(const Stream *stream) const = 0;
virtual int exportBuffers(const Stream *stream, 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<const Stream *, FrameBuffer *> &outputs,
const V4L2Request *request = nullptr) = 0;
virtual int setInputCrop(const Stream *stream, Rectangle *rect) = 0;
virtual std::pair<Rectangle, Rectangle> inputCropBounds() = 0;
virtual std::pair<Rectangle, Rectangle> inputCropBounds(const Stream *stream) = 0;
Signal<FrameBuffer *> inputBufferReady;
Signal<FrameBuffer *> outputBufferReady;
const std::string &deviceNode() const { return deviceNode_; }
Features features() const { return features_; }
protected:
Features features_;
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(std::shared_ptr<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(std::shared_ptr<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(std::shared_ptr<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 */
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:105
libcamera::ConverterFactoryBase::compatibles
const std::vector< std::string > & compatibles() const
Definition converter.h:110
libcamera::ConverterFactoryBase::factories
static std::vector< ConverterFactoryBase * > & factories()
Retrieve the list of all converter factories.
Definition converter.cpp:404
libcamera::ConverterFactoryBase::ConverterFactoryBase
ConverterFactoryBase(const std::string name, std::initializer_list< std::string > compatibles)
Construct a converter factory base.
Definition converter.cpp:318
libcamera::ConverterFactoryBase::names
static std::vector< std::string > names()
Retrieve the list of all converter factory names.
Definition converter.cpp:383
libcamera::ConverterFactoryBase::create
static std::unique_ptr< Converter > create(std::shared_ptr< MediaDevice > media)
Create an instance of the converter corresponding to the media device.
Definition converter.cpp:339
libcamera::ConverterFactory::ConverterFactory
ConverterFactory(const char *name, std::initializer_list< std::string > compatibles)
Construct a converter factory.
Definition converter.h:132
libcamera::ConverterFactory::createInstance
std::unique_ptr< Converter > createInstance(std::shared_ptr< MediaDevice > media) const override
Create an instance of the Converter corresponding to the factory.
Definition converter.h:137
libcamera::Converter
Abstract Base Class for converter.
Definition converter.h:36
libcamera::Converter::features_
Features features_
Stores the features supported by the converter.
Definition converter.h:98
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::inputCropBounds
virtual std::pair< Rectangle, Rectangle > inputCropBounds()=0
Retrieve the crop bounds of the converter.
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::adjustInputSize
virtual Size adjustInputSize(const PixelFormat &pixFmt, const Size &size, Alignment align=Alignment::Down)=0
Adjust the converter input size to a valid value.
libcamera::Converter::inputCropBounds
virtual std::pair< Rectangle, Rectangle > inputCropBounds(const Stream *stream)=0
Retrieve the crop bounds for stream.
libcamera::Converter::Features
Flags< Feature > Features
A bitwise combination of features supported by the converter.
Definition converter.h:43
libcamera::Converter::setInputCrop
virtual int setInputCrop(const Stream *stream, Rectangle *rect)=0
Set the crop rectangle rect for stream.
libcamera::Converter::adjustOutputSize
virtual Size adjustOutputSize(const PixelFormat &pixFmt, const Size &size, Alignment align=Alignment::Down)=0
Adjust the converter output size to a valid value.
libcamera::Converter::outputBufferReady
Signal< FrameBuffer * > outputBufferReady
A signal emitted on each frame buffer completion of the output queue.
Definition converter.h:91
libcamera::Converter::isValid
virtual bool isValid() const =0
Check if the converter configuration is valid.
libcamera::Converter::features
Features features() const
Retrieve the features supported by the converter.
Definition converter.h:95
libcamera::Converter::Alignment
Alignment
The alignment mode specified when adjusting the converter input or output sizes.
Definition converter.h:45
libcamera::Converter::Alignment::Down
@ Down
Adjust the Converter sizes to a smaller valid size.
Definition converter.h:46
libcamera::Converter::Alignment::Up
@ Up
Adjust the Converter sizes to a larger valid size.
Definition converter.h:47
libcamera::Converter::queueBuffers
virtual int queueBuffers(FrameBuffer *input, const std::map< const Stream *, FrameBuffer * > &outputs, const V4L2Request *request=nullptr)=0
Queue buffers to converter device.
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::isConfigured
virtual bool isConfigured(const Stream *stream) const =0
Check if a given stream is configured.
libcamera::Converter::Feature
Feature
Specify the features supported by the converter.
Definition converter.h:38
libcamera::Converter::Feature::None
@ None
No extra features supported by the converter.
Definition converter.h:39
libcamera::Converter::Feature::InputCrop
@ InputCrop
Cropping capability at input is supported by the converter.
Definition converter.h:40
libcamera::Converter::inputBufferReady
Signal< FrameBuffer * > inputBufferReady
A signal emitted when the input frame buffer completes.
Definition converter.h:90
libcamera::Converter::deviceNode
const std::string & deviceNode() const
The converter device node attribute accessor.
Definition converter.h:93
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(std::shared_ptr< MediaDevice > media, Features features=Feature::None)
Construct a Converter instance.
Definition converter.cpp:72
libcamera::Converter::stop
virtual void stop()=0
Stop the converter streaming operation.
libcamera::Converter::validateOutput
virtual int validateOutput(StreamConfiguration *cfg, bool *adjusted, Alignment align=Alignment::Down)=0
Validate and possibily adjust cfg to a valid converter output.
libcamera::Flags
Type-safe container for enum-based bitfields.
Definition flags.h:16
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:28
libcamera::PixelFormat
libcamera image pixel format
Definition pixel_format.h:17
libcamera::Rectangle
Describe a rectangle's position and dimensions.
Definition geometry.h:247
libcamera::Signal
Generic signal and slot communication mechanism.
Definition signal.h:39
libcamera::SizeRange
Describe a range of sizes.
Definition geometry.h:205
libcamera::Size
Describe a two-dimensional size.
Definition geometry.h:51
libcamera::Stream
Video stream for a camera.
Definition stream.h:76
libcamera::V4L2Request
V4L2Request object and API.
Definition v4l2_request.h:22
flags.h
Enum-based bit fields.
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
v4l2_request.h
V4L2 Request.