Files
external_libcamera/include/libcamera/internal/converter.h
Umang Jain 1b0b90a332 libcamera: converter: Add interface to support cropping capability
If the converter has cropping capability on its input, the interface
should support it by providing appropriate virtual functions. Provide
Feature::InputCrop in Feature enumeration for the same.

Provide virtual setInputCrop() and inputCropBounds() interfaces so that
the converter can implement its own cropping functionality.

The V4L2M2MConverter implements these interfaces of the Converter
interface. Not all V4L2M2M converters will have cropping ability
on its input, hence it needs to be discovered at construction time.
If the capability to crop is identified successfully, the cropping
bounds are determined during configure() time.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
2024-10-24 14:04:31 +05:30

127 lines
3.2 KiB
C++

/* 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>
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>;
Converter(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 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(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) = 0;
virtual int setInputCrop(const Stream *stream, Rectangle *rect) = 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(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 */