The converter interface uses the unsigned int output stream index to map to the output frame buffers. This is cumbersome to implement new converters because one has to keep around additional book keeping to track the streams with their correct indexes. The v4l2_converter_m2m and simple pipeline handler are adapted to use the new interface. This work roped in software ISP as well, which also seems to use indexes (although it doesn't implement converter interface) because of a common conversionQueue_ queue used for converter_ and swIsp_. The logPrefix is no longer able to generate an index from a stream, and is updated to be more expressive by reporting the stream configuration instead, for example, reporting "1920x1080-MJPEG" in place of "stream0". Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Tested-by: Andrei Konovalov <andrey.konovalov.ynk@gmail.com> # sm8250 RB5
100 lines
2.3 KiB
C++
100 lines
2.3 KiB
C++
/* 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 FrameBuffer;
|
|
class MediaDevice;
|
|
class Size;
|
|
class SizeRange;
|
|
class Stream;
|
|
struct StreamConfiguration;
|
|
class V4L2M2MDevice;
|
|
|
|
class V4L2M2MConverter : public Converter
|
|
{
|
|
public:
|
|
V4L2M2MConverter(MediaDevice *media);
|
|
|
|
int loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; }
|
|
bool isValid() const { return m2m_ != nullptr; }
|
|
|
|
std::vector<PixelFormat> formats(PixelFormat input);
|
|
SizeRange sizes(const Size &input);
|
|
|
|
std::tuple<unsigned int, unsigned int>
|
|
strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size);
|
|
|
|
int configure(const StreamConfiguration &inputCfg,
|
|
const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfg);
|
|
int exportBuffers(const Stream *stream, unsigned int count,
|
|
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
|
|
|
|
int start();
|
|
void stop();
|
|
|
|
int queueBuffers(FrameBuffer *input,
|
|
const std::map<const Stream *, FrameBuffer *> &outputs);
|
|
|
|
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 queueBuffers(FrameBuffer *input, FrameBuffer *output);
|
|
|
|
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::unique_ptr<V4L2M2MDevice> m2m_;
|
|
|
|
std::map<const Stream *, std::unique_ptr<V4L2M2MStream>> streams_;
|
|
std::map<FrameBuffer *, unsigned int> queue_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|