libcamera v0.3.2+99-1230f78d
Supporting cameras in Linux since 2019
converter_v4l2_m2m.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 * V4l2 M2M Format converter interface
7 */
8
9#pragma once
10
11#include <functional>
12#include <map>
13#include <memory>
14#include <string>
15#include <tuple>
16#include <vector>
17
18#include <libcamera/base/log.h>
20
22
24
25namespace libcamera {
26
27class FrameBuffer;
28class MediaDevice;
29class Size;
30class SizeRange;
31class Stream;
32struct StreamConfiguration;
33class Rectangle;
34class V4L2M2MDevice;
35
37{
38public:
40
41 int loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; }
42 bool isValid() const { return m2m_ != nullptr; }
43
44 std::vector<PixelFormat> formats(PixelFormat input);
45 SizeRange sizes(const Size &input);
46
47 std::tuple<unsigned int, unsigned int>
48 strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size);
49
50 int configure(const StreamConfiguration &inputCfg,
51 const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfg);
52 int exportBuffers(const Stream *stream, unsigned int count,
53 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
54
55 int start();
56 void stop();
57
58 int queueBuffers(FrameBuffer *input,
59 const std::map<const Stream *, FrameBuffer *> &outputs);
60
61 int setInputCrop(const Stream *stream, Rectangle *rect);
62 std::pair<Rectangle, Rectangle> inputCropBounds(const Stream *stream);
63
64private:
65 class V4L2M2MStream : protected Loggable
66 {
67 public:
68 V4L2M2MStream(V4L2M2MConverter *converter, const Stream *stream);
69
70 bool isValid() const { return m2m_ != nullptr; }
71
72 int configure(const StreamConfiguration &inputCfg,
73 const StreamConfiguration &outputCfg);
74 int exportBuffers(unsigned int count,
75 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
76
77 int start();
78 void stop();
79
80 int queueBuffers(FrameBuffer *input, FrameBuffer *output);
81
82 int setInputSelection(unsigned int target, Rectangle *rect);
83 int getInputSelection(unsigned int target, Rectangle *rect);
84
85 std::pair<Rectangle, Rectangle> inputCropBounds();
86
87 protected:
88 std::string logPrefix() const override;
89
90 private:
91 void captureBufferReady(FrameBuffer *buffer);
92 void outputBufferReady(FrameBuffer *buffer);
93
94 V4L2M2MConverter *converter_;
95 const Stream *stream_;
96 std::unique_ptr<V4L2M2MDevice> m2m_;
97
98 unsigned int inputBufferCount_;
99 unsigned int outputBufferCount_;
100
101 std::pair<Rectangle, Rectangle> inputCropBounds_;
102 };
103
104 std::unique_ptr<V4L2M2MDevice> m2m_;
105
106 std::map<const Stream *, std::unique_ptr<V4L2M2MStream>> streams_;
107 std::map<FrameBuffer *, unsigned int> queue_;
108};
109
110} /* namespace libcamera */
Abstract Base Class for converter.
Definition: converter.h:35
Signal< FrameBuffer * > outputBufferReady
A signal emitted on each frame buffer completion of the output queue.
Definition: converter.h:72
Frame buffer data and its associated dynamic metadata.
Definition: framebuffer.h:49
Base class to support log message extensions.
Definition: log.h:91
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition: media_device.h:25
libcamera image pixel format
Definition: pixel_format.h:17
Describe a rectangle's position and dimensions.
Definition: geometry.h:243
Describe a range of sizes.
Definition: geometry.h:201
Describe a two-dimensional size.
Definition: geometry.h:53
Video stream for a camera.
Definition: stream.h:74
The V4L2 M2M converter implements the converter interface based on V4L2 M2M device.
Definition: converter_v4l2_m2m.h:37
int setInputCrop(const Stream *stream, Rectangle *rect)
Set the crop rectangle rect for stream.
Definition: converter_v4l2_m2m.cpp:459
V4L2M2MConverter(MediaDevice *media)
Construct a V4L2M2MConverter instance.
Definition: converter_v4l2_m2m.cpp:248
int loadConfiguration(const std::string &filename)
Definition: converter_v4l2_m2m.h:41
std::pair< Rectangle, Rectangle > inputCropBounds(const Stream *stream)
Retrieve the crop bounds for stream.
Definition: converter_v4l2_m2m.cpp:477
std::tuple< unsigned int, unsigned int > strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size)
Retrieve the output stride and frame size for an input configutation.
Definition: converter_v4l2_m2m.cpp:392
void stop()
Stop the converter streaming operation.
Definition: converter_v4l2_m2m.cpp:507
SizeRange sizes(const Size &input)
Retrieve the range of minimum and maximum output sizes for an input size.
Definition: converter_v4l2_m2m.cpp:343
std::vector< PixelFormat > formats(PixelFormat input)
Definition: converter_v4l2_m2m.cpp:303
bool isValid() const
Definition: converter_v4l2_m2m.h:42
int exportBuffers(const Stream *stream, unsigned int count, std::vector< std::unique_ptr< FrameBuffer > > *buffers)
Export buffers from the converter device.
Definition: converter_v4l2_m2m.cpp:446
int start()
Start the converter streaming operation.
Definition: converter_v4l2_m2m.cpp:489
int configure(const StreamConfiguration &inputCfg, const std::vector< std::reference_wrapper< StreamConfiguration > > &outputCfg)
Configure a set of output stream conversion from an input stream.
Definition: converter_v4l2_m2m.cpp:409
int queueBuffers(FrameBuffer *input, const std::map< const Stream *, FrameBuffer * > &outputs)
Queue buffers to converter device.
Definition: converter_v4l2_m2m.cpp:516
Abstract converter.
Logging infrastructure.
Top-level libcamera namespace.
Definition: backtrace.h:17
libcamera pixel format
Signal & slot implementation.
Configuration parameters for a stream.
Definition: stream.h:40