libcamera/include/libcamera/internal/converter.h
Laurent Pinchart 626172a16b libcamera: Drop file name from header comment blocks
Source files in libcamera start by a comment block header, which
includes the file name and a one-line description of the file contents.
While the latter is useful to get a quick overview of the file contents
at a glance, the former is mostly a source of inconvenience. The name in
the comments can easily get out of sync with the file name when files
are renamed, and copy & paste during development have often lead to
incorrect names being used to start with.

Readers of the source code are expected to know which file they're
looking it. Drop the file name from the header comment block.

The change was generated with the following script:

----------------------------------------

dirs="include/libcamera src test utils"

declare -rA patterns=(
	['c']=' \* '
	['cpp']=' \* '
	['h']=' \* '
	['py']='# '
	['sh']='# '
)

for ext in ${!patterns[@]} ; do
	files=$(for dir in $dirs ; do find $dir -name "*.${ext}" ; done)
	pattern=${patterns[${ext}]}

	for file in $files ; do
		name=$(basename ${file})
		sed -i "s/^\(${pattern}\)${name} - /\1/" "$file"
	done
done
----------------------------------------

This misses several files that are out of sync with the comment block
header. Those will be addressed separately and manually.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
2024-05-08 22:39:50 +03:00

108 lines
2.7 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 <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 */