libcamera: include/libcamera/internal/converter/converter_v4l2_m2m.h Source File

libcamera v0.3.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
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>
19#include <libcamera/base/signal.h>
20
21#include <libcamera/pixel_format.h>
22
23#include "libcamera/internal/converter.h"
24
25namespace libcamera {
26
27class FrameBuffer;
28class MediaDevice;
29class Size;
30class SizeRange;
31class Stream;
32struct StreamConfiguration;
33class V4L2M2MDevice;
34
35class V4L2M2MConverter : public Converter
36{
37public:
38 V4L2M2MConverter(MediaDevice *media);
39
40 int loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; }
41 bool isValid() const { return m2m_ != nullptr; }
42
43 std::vector<PixelFormat> formats(PixelFormat input);
44 SizeRange sizes(const Size &input);
45
46 std::tuple<unsigned int, unsigned int>
47 strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size);
48
49 int configure(const StreamConfiguration &inputCfg,
50 const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfg);
51 int exportBuffers(const Stream *stream, unsigned int count,
52 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
53
54 int start();
55 void stop();
56
57 int queueBuffers(FrameBuffer *input,
58 const std::map<const Stream *, FrameBuffer *> &outputs);
59
60private:
61 class V4L2M2MStream : protected Loggable
62 {
63 public:
64 V4L2M2MStream(V4L2M2MConverter *converter, const Stream *stream);
65
66 bool isValid() const { return m2m_ != nullptr; }
67
68 int configure(const StreamConfiguration &inputCfg,
69 const StreamConfiguration &outputCfg);
70 int exportBuffers(unsigned int count,
71 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
72
73 int start();
74 void stop();
75
76 int queueBuffers(FrameBuffer *input, FrameBuffer *output);
77
78 protected:
79 std::string logPrefix() const override;
80
81 private:
82 void captureBufferReady(FrameBuffer *buffer);
83 void outputBufferReady(FrameBuffer *buffer);
84
85 V4L2M2MConverter *converter_;
86 const Stream *stream_;
87 std::unique_ptr<V4L2M2MDevice> m2m_;
88
89 unsigned int inputBufferCount_;
90 unsigned int outputBufferCount_;
91 };
92
93 std::unique_ptr<V4L2M2MDevice> m2m_;
94
95 std::map<const Stream *, std::unique_ptr<V4L2M2MStream>> streams_;
96 std::map<FrameBuffer *, unsigned int> queue_;
97};
98
99} /* namespace libcamera */
libcamera::Converter::outputBufferReady
Signal< FrameBuffer * > outputBufferReady
A signal emitted on each frame buffer completion of the output queue.
Definition converter.h:60
libcamera::FrameBuffer
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:49
libcamera::Loggable
Base class to support log message extensions.
Definition log.h:91
libcamera::PixelFormat
libcamera image pixel format
Definition pixel_format.h:17
libcamera::SizeRange
Describe a range of sizes.
Definition geometry.h:201
libcamera::Size
Describe a two-dimensional size.
Definition geometry.h:53
libcamera::Stream
Video stream for a camera.
Definition stream.h:74
libcamera::V4L2M2MConverter
The V4L2 M2M converter implements the converter interface based on V4L2 M2M device.
libcamera::V4L2M2MConverter::V4L2M2MConverter
V4L2M2MConverter(MediaDevice *media)
Construct a V4L2M2MConverter instance.
Definition converter_v4l2_m2m.cpp:195
libcamera::V4L2M2MConverter::loadConfiguration
int loadConfiguration(const std::string &filename)
Definition converter_v4l2_m2m.h:40
libcamera::V4L2M2MConverter::isValid
bool isValid() const
Definition converter_v4l2_m2m.h:41
libcamera::V4L2M2MConverter::strideAndFrameSize
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:312
libcamera::V4L2M2MConverter::stop
void stop()
Stop the converter streaming operation.
Definition converter_v4l2_m2m.cpp:397
libcamera::V4L2M2MConverter::sizes
SizeRange sizes(const Size &input)
Retrieve the range of minimum and maximum output sizes for an input size.
Definition converter_v4l2_m2m.cpp:263
libcamera::V4L2M2MConverter::exportBuffers
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:366
libcamera::V4L2M2MConverter::start
int start()
Start the converter streaming operation.
Definition converter_v4l2_m2m.cpp:379
libcamera::V4L2M2MConverter::configure
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:329
libcamera::V4L2M2MConverter::queueBuffers
int queueBuffers(FrameBuffer *input, const std::map< const Stream *, FrameBuffer * > &outputs)
Queue buffers to converter device.
Definition converter_v4l2_m2m.cpp:406
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