libcamera v0.2.0 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 * converter_v4l2_m2m.h - 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
25 namespace libcamera {
26
27 class FrameBuffer;
28 class MediaDevice;
29 class Size;
30 class SizeRange;
31 struct StreamConfiguration;
32 class V4L2M2MDevice;
33
34 class V4L2M2MConverter : public Converter
35{
36 public:
37 V4L2M2MConverter(MediaDevice *media);
38
39 int loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; }
40 bool isValid() const { return m2m_ != nullptr; }
41
42 std::vector<PixelFormat> formats(PixelFormat input);
43 SizeRange sizes(const Size &input);
44
45 std::tuple<unsigned int, unsigned int>
46 strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size);
47
48 int configure(const StreamConfiguration &inputCfg,
49 const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfg);
50 int exportBuffers(unsigned int ouput, unsigned int count,
51 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
52
53 int start();
54 void stop();
55
56 int queueBuffers(FrameBuffer *input,
57 const std::map<unsigned int, FrameBuffer *> &outputs);
58
59 private:
60 class Stream : protected Loggable
61 {
62 public:
63 Stream(V4L2M2MConverter *converter, unsigned int index);
64
65 bool isValid() const { return m2m_ != nullptr; }
66
67 int configure(const StreamConfiguration &inputCfg,
68 const StreamConfiguration &outputCfg);
69 int exportBuffers(unsigned int count,
70 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
71
72 int start();
73 void stop();
74
75 int queueBuffers(FrameBuffer *input, FrameBuffer *output);
76
77 protected:
78 std::string logPrefix() const override;
79
80 private:
81 void captureBufferReady(FrameBuffer *buffer);
82 void outputBufferReady(FrameBuffer *buffer);
83
84 V4L2M2MConverter *converter_;
85 unsigned int index_;
86 std::unique_ptr<V4L2M2MDevice> m2m_;
87
88 unsigned int inputBufferCount_;
89 unsigned int outputBufferCount_;
90 };
91
92 std::unique_ptr<V4L2M2MDevice> m2m_;
93
94 std::vector<Stream> streams_;
95 std::map<FrameBuffer *, unsigned int> queue_;
96};
97
98} /* namespace libcamera */
libcamera::Converter
Abstract Base Class for converter.
Definition converter.h:32
libcamera::Converter::outputBufferReady
Signal< FrameBuffer * > outputBufferReady
A signal emitted on each frame buffer completion of the output queue.
Definition converter.h:59
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:91
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition media_device.h:26
libcamera::PixelFormat
libcamera image pixel format
Definition pixel_format.h:18
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:75
libcamera::V4L2M2MConverter
The V4L2 M2M converter implements the converter interface based on V4L2 M2M device.
Definition converter_v4l2_m2m.h:35
libcamera::V4L2M2MConverter::V4L2M2MConverter
V4L2M2MConverter(MediaDevice *media)
Construct a V4L2M2MConverter instance.
Definition converter_v4l2_m2m.cpp:196
libcamera::V4L2M2MConverter::loadConfiguration
int loadConfiguration(const std::string &filename)
Definition converter_v4l2_m2m.h:39
libcamera::V4L2M2MConverter::queueBuffers
int queueBuffers(FrameBuffer *input, const std::map< unsigned int, FrameBuffer * > &outputs)
Queue buffers to converter device.
Definition converter_v4l2_m2m.cpp:403
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:313
libcamera::V4L2M2MConverter::stop
void stop()
Stop the converter streaming operation.
Definition converter_v4l2_m2m.cpp:394
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:264
libcamera::V4L2M2MConverter::isValid
bool isValid() const
Definition converter_v4l2_m2m.h:40
libcamera::V4L2M2MConverter::exportBuffers
int exportBuffers(unsigned int ouput, unsigned int count, std::vector< std::unique_ptr< FrameBuffer > > *buffers)
Export buffers from the converter device.
Definition converter_v4l2_m2m.cpp:364
libcamera::V4L2M2MConverter::start
int start()
Start the converter streaming operation.
Definition converter_v4l2_m2m.cpp:376
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:330
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:41