From patchwork Fri Jul 14 14:26:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18835 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 B1057BEFBE for ; Fri, 14 Jul 2023 14:26:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4F9AB628C3; Fri, 14 Jul 2023 16:26:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1689344819; bh=VeKYMrG+d3Q4GJWIsBL12kCdRK0bPMgt5MG/x1w5cfE=; 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=Gi/rYVyrN4e+K+vxSYl33evNl0AO2uC4GpcKmnfaLR46skSKv3izhPf4WEdXMX42k Ng34B3nlmMMzspnqzVfTTd5D37CuXVxe29QmqgCFTpp9aOEQpsdBO58Tx1v045iv2b UxUNFz2OmIGT9ibIT1NUSUxkmlW4dYacL+uavr6UP8ZAidaVtPnqK1Zo7UyAz/G48z kcwVhLXANzvyQcHoI0kubFoaD/TnSxI6+4Jxk0v/Cq31TtK4e/JNKjhm0FuZZVKmWR NAAqD7RgzYzN8ppOA8I4Eq8j+q0G1+tNS0TM4nMmq5I957PE0BMkr8kVUBwaXSCJJe Vq+byHhegDD2g== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1EE9660382 for ; Fri, 14 Jul 2023 16:26:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="H6e98CX9"; dkim-atps=neutral Received: from uno.localdomain (mob-5-90-9-92.net.vodafone.it [5.90.9.92]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0967A814; Fri, 14 Jul 2023 16:26:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1689344765; bh=VeKYMrG+d3Q4GJWIsBL12kCdRK0bPMgt5MG/x1w5cfE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H6e98CX9O+qWaRbQh9Nghm2WyxZ4M5aVUzyS2yvscFNrFJvxMUwbaLA6beSBayn5w T5uH6EuslBB+Ze6+/RV5dmSipn1G4x4+KtXzFUfOFsd+AeXfX8m3i53cqWUxZu0yJS 6eOiCcSyTg4/aXJ/at0lhSkt8HB2vp5jKw2/e43M= To: libcamera-devel@lists.libcamera.org Date: Fri, 14 Jul 2023 16:26:34 +0200 Message-Id: <20230714142634.13134-4-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230714142634.13134-1-jacopo.mondi@ideasonboard.com> References: <20230714142634.13134-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] libcamera: rpi: pipeline_base: Cache sensor format 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: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The format to be applied on the sensor is selected by two criteria: the desired output size and the bit depth. As the selection depends on the presence of a RAW stream and the streams configuration is handled in validate() there is no need to re-compute the format in configure(). Centralize the computation of the sensor format in validate() and remove it from configure(). Signed-off-by: Jacopo Mondi Reviewed-by: Naushir Patuck --- .../pipeline/rpi/common/pipeline_base.cpp | 44 +++++++------------ .../pipeline/rpi/common/pipeline_base.h | 2 + 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index a71715a6aff0..26d869265418 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -214,10 +214,9 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() bitDepth = bayerFormat.bitDepth; } - V4L2SubdeviceFormat sensorFormat = - data_->findBestFormat(rawStreams.empty() ? outStreams[0].cfg->size - : rawStreams[0].cfg->size, - bitDepth); + sensorFormat_ = data_->findBestFormat(rawStreams.empty() ? outStreams[0].cfg->size + : rawStreams[0].cfg->size, + bitDepth); status = data_->platformValidate(rawStreams, outStreams); if (status == Invalid) @@ -232,7 +231,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() bitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth; BayerFormat::Packing packing = BayerFormat::fromPixelFormat(cfg.pixelFormat).packing; - rawFormat = PipelineHandlerBase::toV4L2DeviceFormat(raw.dev, sensorFormat, packing); + rawFormat = PipelineHandlerBase::toV4L2DeviceFormat(raw.dev, sensorFormat_, packing); int ret = raw.dev->tryFormat(&rawFormat); if (ret) @@ -452,8 +451,6 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) stream->clearFlags(StreamFlag::External); std::vector rawStreams, ispStreams; - std::optional packing; - unsigned int bitDepth = defaultRawBitDepth; for (unsigned i = 0; i < config->size(); i++) { StreamConfiguration *cfg = &config->at(i); @@ -471,32 +468,23 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) std::sort(ispStreams.begin(), ispStreams.end(), [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; }); - /* - * Calculate the best sensor mode we can use based on the user's request, - * and apply it to the sensor with the cached tranform, if any. - * - * If we have been given a RAW stream, use that size for setting up the sensor. - */ - if (!rawStreams.empty()) { - BayerFormat bayerFormat = BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat); - /* Replace the user requested packing/bit-depth. */ - packing = bayerFormat.packing; - bitDepth = bayerFormat.bitDepth; - } - - V4L2SubdeviceFormat sensorFormat = - data->findBestFormat(rawStreams.empty() ? ispStreams[0].cfg->size - : rawStreams[0].cfg->size, - bitDepth); + /* Apply the format on the sensor with any cached transform. */ + const RPiCameraConfiguration *rpiConfig = + static_cast(config); + V4L2SubdeviceFormat sensorFormat = rpiConfig->sensorFormat_; - /* Apply any cached transform. */ - const RPiCameraConfiguration *rpiConfig = static_cast(config); - - /* Then apply the format on the sensor. */ ret = data->sensor_->setFormat(&sensorFormat, rpiConfig->combinedTransform_); if (ret) return ret; + /* Use the user requested packing/bit-depth. */ + std::optional packing; + if (!rawStreams.empty()) { + BayerFormat bayerFormat = + BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat); + packing = bayerFormat.packing; + } + /* * Platform specific internal stream configuration. This also assigns * external streams which get configured below. diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 2eda3cd89812..a139c98a5a2b 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -262,6 +262,8 @@ public: /* Cache the combinedTransform_ that will be applied to the sensor */ Transform combinedTransform_; + /* The sensor format computed in validate() */ + V4L2SubdeviceFormat sensorFormat_; private: const CameraData *data_;