From patchwork Wed Jul 12 10:55:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18814 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 9496EC32AA for ; Wed, 12 Jul 2023 10:55:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2AFC9628C7; Wed, 12 Jul 2023 12:55:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1689159321; bh=aHk2zTyENpUWBARItTcIPD+G7T6aEl7gR3EykRwUqm4=; 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=txWKwztZthk50DNfSWa6oOVvbSSiIjrDhNi/w75Z3QQDKlMjNeYIYL7vlFS4fu1MQ vYiI3XBW+8lZ2lCo7rq+nKOMuLpLUsuzL/EzpaS//V//WoqDA/nMHAbP9cFzqH3c9e b5sw0VX9mzAMx4EWsOAlnWuNLmGIHOo9FMqx0B6F11CUmj95qUZhfW7Z6IFqr6f/NI nXTLV/B2//t0C8Nnetzw3sf0p/lMEuQMhRe0RWMLLbNfQEKX0kCb9sM6kJtrjQOv+W ce1WCNTuC6gDQgtfjgnWM8ACJ7XK6CzrA+5DR6KCQSuzm1Yas7NCaf0Q8h5+kxNt99 pGMk5iXeNcGkQ== Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 091EE628BF for ; Wed, 12 Jul 2023 12:55:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="gqDv8b4u"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fbef8ad9bbso73637715e9.0 for ; Wed, 12 Jul 2023 03:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1689159317; x=1691751317; 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=LuE01IzKS/jg841yuDMjBnJW/WQ5GKocPMPeElWrjP4=; b=gqDv8b4uLltOJhc1mHF1Qbgi0Bu86j8+WWvWVSA0swbLVY3LQlIsIYlsbdBKtRdcTN Q09d+3oKnVJLDzUCb2h9NHphmcuPak4drABB2LJZ93YJtzQVSn7z8XoCDlFQVcDKTk0l ufoLF9xHwL78yLeTfxa76pJ7kIc2GlYC4gGSlOpYOLTaGlRj/XD2QcHKatMuW5UpL7tV T6LhZ7rEaCO9dMoFlqbJMI2XXTGayhXV/ofkDnWU5dEg+ibYiPEZ7sgnSZKo7cWCffn4 a68x0CiqPBxkIcXcl8KaXliNu4lqK0WgotzQg6uxLNvBnjKgWNpTTCW7gDCS/ITVHIPO nzcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689159317; x=1691751317; 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=LuE01IzKS/jg841yuDMjBnJW/WQ5GKocPMPeElWrjP4=; b=Gxchc5FIPC5+tgJw5cdDuOvxqrqW24K6Y5CH0UEifGhjjxx4TmfqS9U75JhWi4gLqV zwcc+DFHcgdabk/9wY2kbQPSCatGmAxyJn7+vQ8mC7NqAzLu3t5hL4wCqnrkGzyjRHQ3 EekjTQNhYRRNkRpklDjNEISnWPvg11xgvhH5Fb2Fg3Es90Yki8K4SqlBhhuGTwn0SYq7 DdY2BI7BYGsG712PwJLgGdT7BbAMVzIJlh+Zpt7w2shhDOSBBprCIDDkzdnaE+fczccz Rh4abKL8392izmDpX/rR9fgeLuzul/YJwob+06SMsgK0XBAm1QN8UFAtk8S3c8BAFGGm jH4Q== X-Gm-Message-State: ABy/qLZWNhE3HFOuD73oFThe6KC/1FzcAb5yKlUm+jUDpRMhLsMMlYmI +jM34qJyH8rZ0LCoAW3tEJ2efsEn1oqCHqKptg3VjQ== X-Google-Smtp-Source: APBJJlHVmNUlVfq66m5bHfOYA/GcJDdgSCf6QLgThXcxonn9YCvOF3dq+bdojgQzDSqlQvf+7jPCXg== X-Received: by 2002:a5d:4c92:0:b0:314:1494:ea01 with SMTP id z18-20020a5d4c92000000b003141494ea01mr18207220wrs.5.1689159317478; Wed, 12 Jul 2023 03:55:17 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id h14-20020a05600c260e00b003fc05b89e5bsm4729236wma.34.2023.07.12.03.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 03:55:17 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 12 Jul 2023 11:55:10 +0100 Message-Id: <20230712105510.14658-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230712105510.14658-1-naush@raspberrypi.com> References: <20230712105510.14658-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 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: 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" From: Jacopo Mondi 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 | 46 +++++++------------ .../pipeline/rpi/common/pipeline_base.h | 2 + 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 725c1db0d527..d96277a2794e 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) @@ -230,10 +229,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); bitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth; - sensorFormat = data_->findBestFormat(cfg.size, bitDepth); + V4L2SubdeviceFormat subdevFormat = data_->findBestFormat(cfg.size, bitDepth); BayerFormat::Packing packing = BayerFormat::fromPixelFormat(cfg.pixelFormat).packing; - rawFormat = PipelineHandlerBase::toV4L2DeviceFormat(raw.dev, sensorFormat, packing); + rawFormat = PipelineHandlerBase::toV4L2DeviceFormat(raw.dev, subdevFormat, packing); int ret = raw.dev->tryFormat(&rawFormat); if (ret) @@ -453,8 +452,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); @@ -472,32 +469,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_;