From patchwork Wed May 29 07:02:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20116 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8A69CBD87C for ; Wed, 29 May 2024 07:03:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2A0E2634B0; Wed, 29 May 2024 09:03:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uhBQS2VT"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 539C1634BC for ; Wed, 29 May 2024 09:03:07 +0200 (CEST) Received: from fedora.local (unknown [IPv6:2409:4055:4e99:4251:f523:b915:4362:f847]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1083E2D60; Wed, 29 May 2024 09:03:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1716966184; bh=6LKurF2mZkY/gARw692VbVg3T+pnV7uNVeSUEMZeG3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uhBQS2VTztq1p+uj5EaRlehOsMfEmEjNnF9+HqlhynRdTrc/XoAliAlLs4edcwKUI JSgX/L30jz9/0LeuA97iZ5vl5/d2OJGnB/4/pQKsxhNLUUfBvp3ZtHElwhsGiEnFVL SxyXLlK93aNe87Hd79bnOHPYi3VZLJkR2x34XjXk= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Andrey Konovalov , Umang Jain Subject: [PATCH v2 4/4] libcamera: converter: Replace usage of stream index by Stream pointer Date: Wed, 29 May 2024 12:32:48 +0530 Message-ID: <20240529070248.12186-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240529070248.12186-1-umang.jain@ideasonboard.com> References: <20240529070248.12186-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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_. Signed-off-by: Umang Jain --- include/libcamera/internal/converter.h | 5 ++- .../internal/converter/converter_v4l2_m2m.h | 11 ++--- .../internal/software_isp/software_isp.h | 5 ++- .../converter/converter_v4l2_m2m.cpp | 40 ++++++++++--------- src/libcamera/pipeline/simple/simple.cpp | 14 +++---- src/libcamera/software_isp/software_isp.cpp | 13 +++--- 6 files changed, 46 insertions(+), 42 deletions(-) diff --git a/include/libcamera/internal/converter.h b/include/libcamera/internal/converter.h index 5d74db6b..b51563d7 100644 --- a/include/libcamera/internal/converter.h +++ b/include/libcamera/internal/converter.h @@ -26,6 +26,7 @@ namespace libcamera { class FrameBuffer; class MediaDevice; class PixelFormat; +class Stream; struct StreamConfiguration; class Converter @@ -46,14 +47,14 @@ public: virtual int configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfgs) = 0; - virtual int exportBuffers(unsigned int output, unsigned int count, + virtual int exportBuffers(const Stream *stream, unsigned int count, std::vector> *buffers) = 0; virtual int start() = 0; virtual void stop() = 0; virtual int queueBuffers(FrameBuffer *input, - const std::map &outputs) = 0; + const std::map &outputs) = 0; Signal inputBufferReady; Signal outputBufferReady; diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h index 0da62290..58fd19db 100644 --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h @@ -28,6 +28,7 @@ class FrameBuffer; class MediaDevice; class Size; class SizeRange; +class Stream; struct StreamConfiguration; class V4L2M2MDevice; @@ -47,20 +48,20 @@ public: int configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfg); - int exportBuffers(unsigned int output, unsigned int count, + int exportBuffers(const Stream *stream, unsigned int count, std::vector> *buffers); int start(); void stop(); int queueBuffers(FrameBuffer *input, - const std::map &outputs); + const std::map &outputs); private: class V4L2M2MStream : protected Loggable { public: - V4L2M2MStream(V4L2M2MConverter *converter, unsigned int index); + V4L2M2MStream(V4L2M2MConverter *converter, const Stream *stream); bool isValid() const { return m2m_ != nullptr; } @@ -82,7 +83,7 @@ private: void outputBufferReady(FrameBuffer *buffer); V4L2M2MConverter *converter_; - unsigned int index_; + const Stream *stream_; std::unique_ptr m2m_; unsigned int inputBufferCount_; @@ -91,7 +92,7 @@ private: std::unique_ptr m2m_; - std::vector streams_; + std::map streams_; std::map queue_; }; diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index 7e9fae6a..09cc0f6f 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -37,6 +37,7 @@ namespace libcamera { class DebayerCpu; class FrameBuffer; class PixelFormat; +class Stream; struct StreamConfiguration; LOG_DECLARE_CATEGORY(SoftwareIsp) @@ -62,7 +63,7 @@ public: const std::vector> &outputCfgs, const ControlInfoMap &sensorControls); - int exportBuffers(unsigned int output, unsigned int count, + int exportBuffers(const Stream *stream, unsigned int count, std::vector> *buffers); void processStats(const ControlList &sensorControls); @@ -71,7 +72,7 @@ public: void stop(); int queueBuffers(FrameBuffer *input, - const std::map &outputs); + const std::map &outputs); void process(FrameBuffer *input, FrameBuffer *output); diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp index 6309a0c0..a48b2a87 100644 --- a/src/libcamera/converter/converter_v4l2_m2m.cpp +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp @@ -35,8 +35,8 @@ LOG_DECLARE_CATEGORY(Converter) * V4L2M2MConverter::V4L2M2MStream */ -V4L2M2MConverter::V4L2M2MStream::V4L2M2MStream(V4L2M2MConverter *converter, unsigned int index) - : converter_(converter), index_(index) +V4L2M2MConverter::V4L2M2MStream::V4L2M2MStream(V4L2M2MConverter *converter, const Stream *stream) + : converter_(converter), stream_(stream) { m2m_ = std::make_unique(converter->deviceNode()); @@ -157,7 +157,7 @@ int V4L2M2MConverter::V4L2M2MStream::queueBuffers(FrameBuffer *input, FrameBuffe std::string V4L2M2MConverter::V4L2M2MStream::logPrefix() const { - return "stream" + std::to_string(index_); + return stream_->configuration().toString(); } void V4L2M2MConverter::V4L2M2MStream::outputBufferReady(FrameBuffer *buffer) @@ -333,10 +333,13 @@ int V4L2M2MConverter::configure(const StreamConfiguration &inputCfg, int ret = 0; streams_.clear(); - streams_.reserve(outputCfgs.size()); for (unsigned int i = 0; i < outputCfgs.size(); ++i) { - V4L2M2MStream &stream = streams_.emplace_back(this, i); + const StreamConfiguration &cfg = outputCfgs[i]; + streams_.emplace(cfg.stream(), + V4L2M2MStream(this, cfg.stream())); + + V4L2M2MStream &stream = streams_.at(cfg.stream()); if (!stream.isValid()) { LOG(Converter, Error) @@ -345,7 +348,7 @@ int V4L2M2MConverter::configure(const StreamConfiguration &inputCfg, break; } - ret = stream.configure(inputCfg, outputCfgs[i]); + ret = stream.configure(inputCfg, cfg); if (ret < 0) break; } @@ -361,13 +364,14 @@ int V4L2M2MConverter::configure(const StreamConfiguration &inputCfg, /** * \copydoc libcamera::Converter::exportBuffers */ -int V4L2M2MConverter::exportBuffers(unsigned int output, unsigned int count, +int V4L2M2MConverter::exportBuffers(const Stream *stream, unsigned int count, std::vector> *buffers) { - if (output >= streams_.size()) + auto iter = streams_.find(stream); + if (iter == streams_.end()) return -EINVAL; - return streams_[output].exportBuffers(count, buffers); + return iter->second.exportBuffers(count, buffers); } /** @@ -377,8 +381,8 @@ int V4L2M2MConverter::start() { int ret; - for (V4L2M2MStream &stream : streams_) { - ret = stream.start(); + for (auto &iter : streams_) { + ret = iter.second.start(); if (ret < 0) { stop(); return ret; @@ -393,15 +397,15 @@ int V4L2M2MConverter::start() */ void V4L2M2MConverter::stop() { - for (V4L2M2MStream &stream : utils::reverse(streams_)) - stream.stop(); + for (auto &iter : streams_) + iter.second.stop(); } /** * \copydoc libcamera::Converter::queueBuffers */ int V4L2M2MConverter::queueBuffers(FrameBuffer *input, - const std::map &outputs) + const std::map &outputs) { std::set outputBufs; int ret; @@ -414,11 +418,9 @@ int V4L2M2MConverter::queueBuffers(FrameBuffer *input, if (outputs.empty()) return -EINVAL; - for (auto [index, buffer] : outputs) { + for (auto [stream, buffer] : outputs) { if (!buffer) return -EINVAL; - if (index >= streams_.size()) - return -EINVAL; outputBufs.insert(buffer); } @@ -427,8 +429,8 @@ int V4L2M2MConverter::queueBuffers(FrameBuffer *input, return -EINVAL; /* Queue the input and output buffers to all the streams. */ - for (auto [index, buffer] : outputs) { - ret = streams_[index].queueBuffers(input, buffer); + for (auto [stream, buffer] : outputs) { + ret = streams_.at(stream).queueBuffers(input, buffer); if (ret < 0) return ret; } diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index db3575c3..01ad91a7 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -278,7 +278,7 @@ public: std::map> formats_; std::vector> conversionBuffers_; - std::queue> conversionQueue_; + std::queue> conversionQueue_; bool useConversion_; std::unique_ptr converter_; @@ -837,7 +837,7 @@ void SimpleCameraData::bufferReady(FrameBuffer *buffer) Request *request = buffer->request(); if (useConversion_ && !conversionQueue_.empty()) { - const std::map &outputs = + const std::map &outputs = conversionQueue_.front(); if (!outputs.empty()) { FrameBuffer *outputBuffer = outputs.begin()->second; @@ -1304,10 +1304,8 @@ int SimplePipelineHandler::exportFrameBuffers(Camera *camera, Stream *stream, */ if (data->useConversion_) return data->converter_ - ? data->converter_->exportBuffers(data->streamIndex(stream), - count, buffers) - : data->swIsp_->exportBuffers(data->streamIndex(stream), - count, buffers); + ? data->converter_->exportBuffers(stream, count, buffers) + : data->swIsp_->exportBuffers(stream, count, buffers); else return data->video_->exportBuffers(count, buffers); } @@ -1399,7 +1397,7 @@ int SimplePipelineHandler::queueRequestDevice(Camera *camera, Request *request) SimpleCameraData *data = cameraData(camera); int ret; - std::map buffers; + std::map buffers; for (auto &[stream, buffer] : request->buffers()) { /* @@ -1408,7 +1406,7 @@ int SimplePipelineHandler::queueRequestDevice(Camera *camera, Request *request) * completion handler. */ if (data->useConversion_) { - buffers.emplace(data->streamIndex(stream), buffer); + buffers.emplace(stream, buffer); } else { ret = data->video_->queueBuffer(buffer); if (ret < 0) diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index ac10d82d..7cadd585 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -227,13 +227,13 @@ int SoftwareIsp::configure(const StreamConfiguration &inputCfg, * \return The number of allocated buffers on success or a negative error code * otherwise */ -int SoftwareIsp::exportBuffers(unsigned int output, unsigned int count, +int SoftwareIsp::exportBuffers(const Stream *stream, unsigned int count, std::vector> *buffers) { ASSERT(debayer_ != nullptr); /* single output for now */ - if (output >= 1) + if (stream == nullptr) return -EINVAL; for (unsigned int i = 0; i < count; i++) { @@ -265,7 +265,7 @@ int SoftwareIsp::exportBuffers(unsigned int output, unsigned int count, * \return 0 on success, a negative errno on failure */ int SoftwareIsp::queueBuffers(FrameBuffer *input, - const std::map &outputs) + const std::map &outputs) { /* * Validate the outputs as a sanity check: at least one output is @@ -274,14 +274,15 @@ int SoftwareIsp::queueBuffers(FrameBuffer *input, if (outputs.empty()) return -EINVAL; - for (auto [index, buffer] : outputs) { + for (auto [stream, buffer] : outputs) { if (!buffer) return -EINVAL; - if (index >= 1) /* only single stream atm */ + if (outputs.size() >= 1) /* only single stream atm */ return -EINVAL; } - process(input, outputs.at(0)); + for (auto iter = outputs.begin(); iter != outputs.end(); iter++) + process(input, iter->second); return 0; }