From 973c12488c772e02ee9f027a49f25052cd991c20 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 26 Dec 2020 23:45:04 +0200 Subject: libcamera: pipeline: simple: converter: Add multi-stream support While the M2M device backing the converter doesn't support multiple streams natively, it can be run once per stream to produce multiple outputs from the same input, with different output formats and sizes. To support this, create a class to model a stream and move control of the M2M device to the Stream class. The SimpleConverter class then creates stream instances and iterates over them. Each stream needs its own instance of the V4L2M2MDevice, to support different output configurations. The SimpleConverter class retains a device instance to support the query operations. Signed-off-by: Laurent Pinchart Tested-by: Phi-Bang Nguyen Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/libcamera/pipeline/simple/converter.h | 50 ++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'src/libcamera/pipeline/simple/converter.h') diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h index be6844ca..480e528d 100644 --- a/src/libcamera/pipeline/simple/converter.h +++ b/src/libcamera/pipeline/simple/converter.h @@ -8,13 +8,18 @@ #ifndef __LIBCAMERA_PIPELINE_SIMPLE_CONVERTER_H__ #define __LIBCAMERA_PIPELINE_SIMPLE_CONVERTER_H__ +#include +#include #include +#include #include #include #include #include +#include "libcamera/internal/log.h" + namespace libcamera { class FrameBuffer; @@ -38,26 +43,57 @@ public: strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size); int configure(const StreamConfiguration &inputCfg, - const StreamConfiguration &outputCfg); - int exportBuffers(unsigned int count, + const std::vector> &outputCfg); + int exportBuffers(unsigned int ouput, unsigned int count, std::vector> *buffers); int start(); void stop(); - int queueBuffers(FrameBuffer *input, FrameBuffer *output); + int queueBuffers(FrameBuffer *input, + const std::map &outputs); Signal inputBufferReady; Signal outputBufferReady; private: - void m2mInputBufferReady(FrameBuffer *buffer); - void m2mOutputBufferReady(FrameBuffer *buffer); + class Stream : protected Loggable + { + public: + Stream(SimpleConverter *converter, unsigned int index); + + bool isValid() const { return m2m_ != nullptr; } + + int configure(const StreamConfiguration &inputCfg, + const StreamConfiguration &outputCfg); + int exportBuffers(unsigned int count, + std::vector> *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); + + SimpleConverter *converter_; + unsigned int index_; + std::unique_ptr m2m_; + + unsigned int inputBufferCount_; + unsigned int outputBufferCount_; + }; + std::string deviceNode_; std::unique_ptr m2m_; - unsigned int inputBufferCount_; - unsigned int outputBufferCount_; + std::vector streams_; + std::map queue_; }; } /* namespace libcamera */ -- cgit v1.2.1