libcamera  v0.3.1+12-19bbca3c
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>
19 #include <libcamera/base/signal.h>
20 
21 #include <libcamera/pixel_format.h>
22 
24 
25 namespace libcamera {
26 
27 class FrameBuffer;
28 class MediaDevice;
29 class Size;
30 class SizeRange;
31 class Stream;
32 struct StreamConfiguration;
33 class V4L2M2MDevice;
34 
36 {
37 public:
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 
60 private:
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 */
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
Video stream for a camera.
Definition: stream.h:74
Base class to support log message extensions.
Definition: log.h:91
Top-level libcamera namespace.
Definition: backtrace.h:17
SizeRange sizes(const Size &input)
Retrieve the range of minimum and maximum output sizes for an input size.
Definition: converter_v4l2_m2m.cpp:264
std::vector< PixelFormat > formats(PixelFormat input)
Definition: converter_v4l2_m2m.cpp:224
Frame buffer data and its associated dynamic metadata.
Definition: framebuffer.h:49
Describe a two-dimensional size.
Definition: geometry.h:52
The V4L2 M2M converter implements the converter interface based on V4L2 M2M device.
Definition: converter_v4l2_m2m.h:35
Signal & slot implementation.
void stop()
Stop the converter streaming operation.
Definition: converter_v4l2_m2m.cpp:398
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
Abstract converter.
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
Signal< FrameBuffer * > outputBufferReady
A signal emitted on each frame buffer completion of the output queue.
Definition: converter.h:60
bool isValid() const
Definition: converter_v4l2_m2m.h:41
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:367
Describe a range of sizes.
Definition: geometry.h:200
int loadConfiguration([[maybe_unused]] const std::string &filename)
Definition: converter_v4l2_m2m.h:40
int start()
Start the converter streaming operation.
Definition: converter_v4l2_m2m.cpp:380
Logging infrastructure.
Configuration parameters for a stream.
Definition: stream.h:41
V4L2M2MConverter(MediaDevice *media)
Construct a V4L2M2MConverter instance.
Definition: converter_v4l2_m2m.cpp:196
libcamera pixel format
int queueBuffers(FrameBuffer *input, const std::map< const Stream *, FrameBuffer *> &outputs)
Queue buffers to converter device.
Definition: converter_v4l2_m2m.cpp:407
Abstract Base Class for converter.
Definition: converter.h:32