From patchwork Wed May 3 12:20:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18597 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 41FC3C0DA4 for ; Wed, 3 May 2023 12:21:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0412B633C3; Wed, 3 May 2023 14:21:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1683116465; bh=KwBE0uPVA2vSMqX4i4juvfO9whsaBV4+pfIEQIzQDFs=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=CSWCeaKPapLezDSCPY9lb9N0gbwmoswib6bDpdIxrzctwgCDFD+qOohmXC6U7mIXq JIFbuN9Di/3xrOOXq8AlJCd5riA71W/ga6foblo2Eks6N2Q/983Hrvj6hhK/wugDVc X6jvljPOIITWKit2Q+RDDzBFQQfYq233T3qdu/81cqcLXh5JskcpmTOVEojuWYILjz ftRl++YZabmXVJ/uZe6vmFvs9sqryUMmBGG/vUivCwkQDK6rjESSjVTTMSjzk6DEE5 Ry4c1KqJpiO0cnqaofp+TwvIKvGnkOqbKsdv8NT3R9BGWwAwOwLpq3tk4UxY/3cDdn 2lypXZfBV8tsA== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B0C96633B4 for ; Wed, 3 May 2023 14:21:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="LVlS7sMo"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f19afc4fbfso50885245e9.2 for ; Wed, 03 May 2023 05:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1683116463; x=1685708463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zo95N/QeZOpCPpe+CBOXO5Itz+bJlZWdBtIRXvOcgIw=; b=LVlS7sMouP2iODT3/zH36ewYg1AQAiu7lSw3GYN16FLY3LJqhE6aXDIc6uwl2QhtfP lT/kLOCMNORkym8jW7iwcRy5O9Xs8ckHgtDbidJyQ2YOSj8pYcY/aoG9/xnoSJJqiYiX HzN7bnLjD7tK29yC8rDjpfOQyuoDpYEQmYWh8+P/Juc59oRtGz6nuy6AL8yAp0O35Qkk fnb/8fEVbuU9b3kf09O8WPZft6EPvvMGh8ZpO2vNQadIlpKeCEc8bKTd67ykVuEwXHZ4 kthyCxDR2Iirby/RPEU7zGc78FNXH/7zBtxHP6kUZD72sKYQD0GkXVr8ARro9Mxev2NJ VOvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683116463; x=1685708463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zo95N/QeZOpCPpe+CBOXO5Itz+bJlZWdBtIRXvOcgIw=; b=bVauv1TuzRFOnIjPBUBy2XN5OQLtqPxEBB2FPhz8Qz/8FzI0mCdPQLkKJY1v9wdSal Swzj1oXIMf5SF1mukE/ya8IPBvWFg8D1wWI8+NuhUAyxfHYO2dS9RdiA4Tr2L/YYPRkc 4n1Om1h8tEuZbVnAAzSOQIbQ2zBNohtMxt7wTczBFIglTmynNkS4kguIIZOlGoD5v3fw xrFxlxcXVt+CLsEquu8CicedSd2KOD5CLSAALkmyKvUR4mk8RZrTrE6N/hpavJrU+u7u S50PMYmVztTkY0og+MXJW9HtDdD+6Th5pgsCApNvwmT4JIa2VLr77oEUTIVPNGUmz9PP eeOA== X-Gm-Message-State: AC+VfDxbCyaSprTi+bkJpa+YmXuDAouxHA3E4MQlc5g1LNazXyk11i8G 0k+fHpStTCQKxQw7Z3sZ55lHxTDd261KQX2R4SjgJw== X-Google-Smtp-Source: ACHHUZ6Dfm6U+LFhv1+ERowBjE23UAz4ajoZhVH2xsjO69FugU0KqydRRFPajCsNfrGF4k7w4Rhxmg== X-Received: by 2002:a05:600c:299:b0:3f2:50ab:1bba with SMTP id 25-20020a05600c029900b003f250ab1bbamr14908162wmk.19.1683116462874; Wed, 03 May 2023 05:21:02 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id f23-20020a7bcd17000000b003ee443bf0c7sm1736785wmj.16.2023.05.03.05.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 May 2023 05:21:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 3 May 2023 13:20:35 +0100 Message-Id: <20230503122035.32026-14-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230503122035.32026-1-naush@raspberrypi.com> References: <20230503122035.32026-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 13/13] pipeline: raspberrypi: Add stream flags to RPi::Stream 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: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a flags_ field to indicate stream state information in RPi::Stream. This replaces the existing external_ and importOnly_ boolean flags. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- .../pipeline/rpi/common/pipeline_base.cpp | 8 ++-- .../pipeline/rpi/common/rpi_stream.cpp | 40 ++++++++++-------- .../pipeline/rpi/common/rpi_stream.h | 42 ++++++++++++------- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 8 ++-- 4 files changed, 60 insertions(+), 38 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 69c67acd7d45..ba1797bcfef0 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -31,6 +31,8 @@ using namespace RPi; LOG_DEFINE_CATEGORY(RPI) +using StreamFlag = RPi::Stream::StreamFlag; + namespace { constexpr unsigned int defaultRawBitDepth = 12; @@ -504,7 +506,7 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) /* Start by freeing all buffers and reset the stream states. */ data->freeBuffers(); for (auto const stream : data->streams_) - stream->setExternal(false); + stream->clearFlags(StreamFlag::External); std::vector rawStreams, ispStreams; std::optional packing; @@ -752,7 +754,7 @@ int PipelineHandlerBase::queueRequestDevice(Camera *camera, Request *request) /* Push all buffers supplied in the Request to the respective streams. */ for (auto stream : data->streams_) { - if (!stream->isExternal()) + if (!(stream->getFlags() & StreamFlag::External)) continue; FrameBuffer *buffer = request->findBuffer(stream); @@ -932,7 +934,7 @@ int PipelineHandlerBase::queueAllBuffers(Camera *camera) int ret; for (auto const stream : data->streams_) { - if (!stream->isExternal()) { + if (!(stream->getFlags() & StreamFlag::External)) { ret = stream->queueAllBuffers(); if (ret < 0) return ret; diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp index b7e4130f5e56..c158843cb0ed 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp @@ -14,6 +14,24 @@ LOG_DEFINE_CATEGORY(RPISTREAM) namespace RPi { +void Stream::setFlags(StreamFlags flags) +{ + flags_ |= flags; + + /* Import streams cannot be external. */ + ASSERT(!(flags_ & StreamFlag::External) || !(flags_ & StreamFlag::ImportOnly)); +} + +void Stream::clearFlags(StreamFlags flags) +{ + flags_ &= ~flags; +} + +RPi::Stream::StreamFlags Stream::getFlags() const +{ + return flags_; +} + V4L2VideoDevice *Stream::dev() const { return dev_.get(); @@ -32,18 +50,6 @@ void Stream::resetBuffers() availableBuffers_.push(buffer.get()); } -void Stream::setExternal(bool external) -{ - /* Import streams cannot be external. */ - ASSERT(!external || !importOnly_); - external_ = external; -} - -bool Stream::isExternal() const -{ - return external_; -} - void Stream::setExportedBuffers(std::vector> *buffers) { for (auto const &buffer : *buffers) @@ -57,7 +63,7 @@ const BufferMap &Stream::getBuffers() const unsigned int Stream::getBufferId(FrameBuffer *buffer) const { - if (importOnly_) + if (flags_ & StreamFlag::ImportOnly) return 0; /* Find the buffer in the map, and return the buffer id. */ @@ -88,7 +94,7 @@ int Stream::prepareBuffers(unsigned int count) { int ret; - if (!importOnly_) { + if (!(flags_ & StreamFlag::ImportOnly)) { if (count) { /* Export some frame buffers for internal use. */ ret = dev_->exportBuffers(count, &internalBuffers_); @@ -113,7 +119,7 @@ int Stream::prepareBuffers(unsigned int count) * \todo Find a better heuristic, or, even better, an exact solution to * this issue. */ - if (isExternal() || importOnly_) + if ((flags_ & StreamFlag::External) || (flags_ & StreamFlag::ImportOnly)) count = count * 2; return dev_->importBuffers(count); @@ -160,7 +166,7 @@ int Stream::queueBuffer(FrameBuffer *buffer) void Stream::returnBuffer(FrameBuffer *buffer) { - if (!external_) { + if (!(flags_ & StreamFlag::External)) { /* For internal buffers, simply requeue back to the device. */ queueToDevice(buffer); return; @@ -204,7 +210,7 @@ int Stream::queueAllBuffers() { int ret; - if (external_) + if (flags_ & StreamFlag::External) return 0; while (!availableBuffers_.empty()) { diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h index b8c74de35863..6edd304bdfe2 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h @@ -12,6 +12,7 @@ #include #include +#include #include #include "libcamera/internal/v4l2_videodevice.h" @@ -37,25 +38,41 @@ enum BufferMask { class Stream : public libcamera::Stream { public: + enum class StreamFlag { + None = 0, + /* + * Indicates that this stream only imports buffers, e.g. the ISP + * input stream. + */ + ImportOnly = (1 << 0), + /* + * Indicates that this stream is active externally, i.e. the + * buffers might be provided by (and returned to) the application. + */ + External = (1 << 1), + }; + + using StreamFlags = Flags; + Stream() - : id_(BufferMask::MaskID) + : flags_(StreamFlag::None), id_(BufferMask::MaskID) { } - Stream(const char *name, MediaEntity *dev, bool importOnly = false) - : external_(false), importOnly_(importOnly), name_(name), + Stream(const char *name, MediaEntity *dev, StreamFlags flags = StreamFlag::None) + : flags_(flags), name_(name), dev_(std::make_unique(dev)), id_(BufferMask::MaskID) { } + void setFlags(StreamFlags flags); + void clearFlags(StreamFlags flags); + StreamFlags getFlags() const; + V4L2VideoDevice *dev() const; const std::string &name() const; - bool isImporter() const; void resetBuffers(); - void setExternal(bool external); - bool isExternal() const; - void setExportedBuffers(std::vector> *buffers); const BufferMap &getBuffers() const; unsigned int getBufferId(FrameBuffer *buffer) const; @@ -112,14 +129,7 @@ private: void clearBuffers(); int queueToDevice(FrameBuffer *buffer); - /* - * Indicates that this stream is active externally, i.e. the buffers - * might be provided by (and returned to) the application. - */ - bool external_; - - /* Indicates that this stream only imports buffers, e.g. ISP input. */ - bool importOnly_; + StreamFlags flags_; /* Stream name identifier. */ std::string name_; @@ -182,4 +192,6 @@ public: } /* namespace RPi */ +LIBCAMERA_FLAGS_ENABLE_OPERATORS(RPi::Stream::StreamFlag) + } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index c3a40326b228..018cf4881d0e 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -24,6 +24,8 @@ namespace libcamera { LOG_DECLARE_CATEGORY(RPI) +using StreamFlag = RPi::Stream::StreamFlag; + namespace { enum class Unicam : unsigned int { Image, Embedded }; @@ -318,7 +320,7 @@ int PipelineHandlerVc4::platformRegister(std::unique_ptr &camer } /* Tag the ISP input stream as an import stream. */ - data->isp_[Isp::Input] = RPi::Stream("ISP Input", ispOutput0, true); + data->isp_[Isp::Input] = RPi::Stream("ISP Input", ispOutput0, StreamFlag::ImportOnly); data->isp_[Isp::Output0] = RPi::Stream("ISP Output0", ispCapture1); data->isp_[Isp::Output1] = RPi::Stream("ISP Output1", ispCapture2); data->isp_[Isp::Stats] = RPi::Stream("ISP Stats", ispCapture3); @@ -500,7 +502,7 @@ int Vc4CameraData::platformConfigure(const V4L2SubdeviceFormat &sensorFormat, */ if (!rawStreams.empty()) { rawStreams[0].cfg->setStream(&unicam_[Unicam::Image]); - unicam_[Unicam::Image].setExternal(true); + unicam_[Unicam::Image].setFlags(StreamFlag::External); } ret = isp_[Isp::Input].dev()->setFormat(&unicamFormat); @@ -545,7 +547,7 @@ int Vc4CameraData::platformConfigure(const V4L2SubdeviceFormat &sensorFormat, << ColorSpace::toString(cfg->colorSpace); cfg->setStream(stream); - stream->setExternal(true); + stream->setFlags(StreamFlag::External); } ispOutputTotal_ = outStreams.size();