Loading...
Searching...
No Matches
converter_v4l2_m2m.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2020, Laurent Pinchart
* Copyright 2022 NXP
*
* V4l2 M2M Format converter interface
*/
#pragma once
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include <libcamera/base/log.h>
#include <libcamera/base/signal.h>
#include <libcamera/pixel_format.h>
#include "libcamera/internal/converter.h"
namespace libcamera {
class ControlList;
class FrameBuffer;
class MediaDevice;
class Size;
class SizeRange;
class Stream;
struct StreamConfiguration;
class Rectangle;
class V4L2M2MDevice;
class V4L2M2MConverter : public Converter
{
public:
V4L2M2MConverter(std::shared_ptr<MediaDevice> media);
int loadConfiguration([[maybe_unused]] const std::string &filename) override { return 0; }
bool isValid() const override { return m2m_ != nullptr; }
std::vector<PixelFormat> formats(PixelFormat input) override;
SizeRange sizes(const Size &input) override;
std::tuple<unsigned int, unsigned int>
strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size) override;
Size adjustInputSize(const PixelFormat &pixFmt,
const Size &size, Alignment align = Alignment::Down) override;
Size adjustOutputSize(const PixelFormat &pixFmt,
const Size &size, Alignment align = Alignment::Down) override;
int configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<StreamConfiguration>>
&outputCfg) override;
bool isConfigured(const Stream *stream) const override;
int exportBuffers(const Stream *stream, unsigned int count,
std::vector<std::unique_ptr<FrameBuffer>> *buffers) override;
int start() override;
void stop() override;
int validateOutput(StreamConfiguration *cfg, bool *adjusted,
Alignment align = Alignment::Down) override;
int queueBuffers(FrameBuffer *input,
const std::map<const Stream *, FrameBuffer *> &outputs,
const V4L2Request *request = nullptr) override;
int setInputCrop(const Stream *stream, Rectangle *rect) override;
std::pair<Rectangle, Rectangle> inputCropBounds() override { return inputCropBounds_; }
std::pair<Rectangle, Rectangle> inputCropBounds(const Stream *stream) override;
int applyControls(const Stream *stream, ControlList &ctrls, const V4L2Request *request = nullptr);
int allocateRequests(unsigned int count,
std::vector<std::unique_ptr<V4L2Request>> *requests);
bool supportsRequests();
private:
class V4L2M2MStream : protected Loggable
{
public:
V4L2M2MStream(V4L2M2MConverter *converter, const Stream *stream);
bool isValid() const { return m2m_ != nullptr; }
int configure(const StreamConfiguration &inputCfg,
const StreamConfiguration &outputCfg);
int exportBuffers(unsigned int count,
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
int start();
void stop();
int applyControls(ControlList &ctrls, const V4L2Request *request = nullptr);
int queueBuffers(FrameBuffer *input, FrameBuffer *output,
const V4L2Request *request = nullptr);
int setInputSelection(unsigned int target, Rectangle *rect);
int getInputSelection(unsigned int target, Rectangle *rect);
std::pair<Rectangle, Rectangle> inputCropBounds();
protected:
std::string logPrefix() const override;
private:
void captureBufferReady(FrameBuffer *buffer);
void outputBufferReady(FrameBuffer *buffer);
V4L2M2MConverter *converter_;
const Stream *stream_;
std::unique_ptr<V4L2M2MDevice> m2m_;
unsigned int inputBufferCount_;
unsigned int outputBufferCount_;
std::pair<Rectangle, Rectangle> inputCropBounds_;
};
Size adjustSizes(const Size &size, const std::vector<SizeRange> &ranges,
Alignment align);
std::unique_ptr<V4L2M2MDevice> m2m_;
std::map<const Stream *, std::unique_ptr<V4L2M2MStream>> streams_;
std::map<FrameBuffer *, unsigned int> queue_;
std::pair<Rectangle, Rectangle> inputCropBounds_;
std::shared_ptr<MediaDevice> media_;
};
} /* namespace libcamera */
libcamera::ControlList
Associate a list of ControlId with their values for an object.
Definition controls.h:409
libcamera::Converter::outputBufferReady
Signal< FrameBuffer * > outputBufferReady
A signal emitted on each frame buffer completion of the output queue.
Definition converter.h:91
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::Converter
Converter(std::shared_ptr< MediaDevice > media, Features features=Feature::None)
Construct a Converter instance.
Definition converter.cpp:72
libcamera::FrameBuffer
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:50
libcamera::Loggable
Base class to support log message extensions.
Definition log.h:92
libcamera::Loggable::logPrefix
virtual std::string logPrefix() const =0
Retrieve a string to be prefixed to the log message.
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::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::V4L2M2MConverter
The V4L2 M2M converter implements the converter interface based on V4L2 M2M device.
Definition converter_v4l2_m2m.h:38
libcamera::V4L2M2MConverter::adjustOutputSize
Size adjustOutputSize(const PixelFormat &pixFmt, const Size &size, Alignment align=Alignment::Down) override
Adjust the converter output size to a valid value.
Definition converter_v4l2_m2m.cpp:448
libcamera::V4L2M2MConverter::isConfigured
bool isConfigured(const Stream *stream) const override
Check if a given stream is configured.
Definition converter_v4l2_m2m.cpp:587
libcamera::V4L2M2MConverter::setInputCrop
int setInputCrop(const Stream *stream, Rectangle *rect) override
Set the crop rectangle rect for stream.
Definition converter_v4l2_m2m.cpp:608
libcamera::V4L2M2MConverter::start
int start() override
Start the converter streaming operation.
Definition converter_v4l2_m2m.cpp:645
libcamera::V4L2M2MConverter::isValid
bool isValid() const override
Definition converter_v4l2_m2m.h:43
libcamera::V4L2M2MConverter::inputCropBounds
std::pair< Rectangle, Rectangle > inputCropBounds() override
Retrieve the crop bounds of the converter.
Definition converter_v4l2_m2m.h:74
libcamera::V4L2M2MConverter::supportsRequests
bool supportsRequests()
Check if requests are supported.
Definition converter_v4l2_m2m.cpp:802
libcamera::V4L2M2MConverter::exportBuffers
int exportBuffers(const Stream *stream, unsigned int count, std::vector< std::unique_ptr< FrameBuffer > > *buffers) override
Export buffers from the converter device.
Definition converter_v4l2_m2m.cpp:595
libcamera::V4L2M2MConverter::strideAndFrameSize
std::tuple< unsigned int, unsigned int > strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size) override
Retrieve the output stride and frame size for an input configutation.
Definition converter_v4l2_m2m.cpp:412
libcamera::V4L2M2MConverter::configure
int configure(const StreamConfiguration &inputCfg, const std::vector< std::reference_wrapper< StreamConfiguration > > &outputCfg) override
Configure a set of output stream conversion from an input stream.
Definition converter_v4l2_m2m.cpp:550
libcamera::V4L2M2MConverter::V4L2M2MConverter
V4L2M2MConverter(std::shared_ptr< MediaDevice > media)
Construct a V4L2M2MConverter instance.
Definition converter_v4l2_m2m.cpp:286
libcamera::V4L2M2MConverter::allocateRequests
int allocateRequests(unsigned int count, std::vector< std::unique_ptr< V4L2Request > > *requests)
Allocate requests.
Definition converter_v4l2_m2m.cpp:786
libcamera::V4L2M2MConverter::formats
std::vector< PixelFormat > formats(PixelFormat input) override
Definition converter_v4l2_m2m.cpp:323
libcamera::V4L2M2MConverter::adjustInputSize
Size adjustInputSize(const PixelFormat &pixFmt, const Size &size, Alignment align=Alignment::Down) override
Adjust the converter input size to a valid value.
Definition converter_v4l2_m2m.cpp:429
libcamera::V4L2M2MConverter::loadConfiguration
int loadConfiguration(const std::string &filename) override
Definition converter_v4l2_m2m.h:42
libcamera::V4L2M2MConverter::validateOutput
int validateOutput(StreamConfiguration *cfg, bool *adjusted, Alignment align=Alignment::Down) override
Validate and possibily adjust cfg to a valid converter output.
Definition converter_v4l2_m2m.cpp:672
libcamera::V4L2M2MConverter::queueBuffers
int queueBuffers(FrameBuffer *input, const std::map< const Stream *, FrameBuffer * > &outputs, const V4L2Request *request=nullptr) override
Queue buffers to converter device.
Definition converter_v4l2_m2m.cpp:720
libcamera::V4L2M2MConverter::stop
void stop() override
Stop the converter streaming operation.
Definition converter_v4l2_m2m.cpp:663
libcamera::V4L2M2MConverter::applyControls
int applyControls(const Stream *stream, ControlList &ctrls, const V4L2Request *request=nullptr)
Apply controls.
Definition converter_v4l2_m2m.cpp:773
libcamera::V4L2M2MConverter::sizes
SizeRange sizes(const Size &input) override
Retrieve the range of minimum and maximum output sizes for an input size.
Definition converter_v4l2_m2m.cpp:363
libcamera::V4L2M2MDevice
Memory-to-Memory video device.
Definition v4l2_videodevice.h:301
libcamera::V4L2Request
V4L2Request object and API.
Definition v4l2_request.h:22
converter.h
Abstract converter.
log.h
Logging infrastructure.
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
pixel_format.h
libcamera pixel format
signal.h
Signal & slot implementation.
libcamera::StreamConfiguration
Configuration parameters for a stream.
Definition stream.h:40