From patchwork Tue Aug 3 13:32:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13178 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 C85ADC3235 for ; Tue, 3 Aug 2021 13:32:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 82BAE687CE; Tue, 3 Aug 2021 15:32:27 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VTpiDiw4"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EB50E6026A for ; Tue, 3 Aug 2021 15:32:25 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.238.109.12]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D85DC3F0; Tue, 3 Aug 2021 15:32:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1627997545; bh=awfRVeK4EkuD9Hy2AouVGj9dsPxvxRCmHcnme0lmKRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VTpiDiw49U+HT45GaiXpB8C121aCymzff60e86zo08QXGJMJM5TOQnb/5S0/M8LHg itolYXeqohayGUDn/k1+3PBEABbxp9GPpExayVbv+Z7xlJwSpJhTPZFi44J/WmMy7x EGrW1LEa/3poSWfSb6Xx/s3UF9W1FgZhCcIjr2GU= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 3 Aug 2021 19:02:02 +0530 Message-Id: <20210803133205.6599-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210803133205.6599-1-umang.jain@ideasonboard.com> References: <20210803133205.6599-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] libcamera: camera_sensor: Transform CameraSensor::sizes() 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" In CameraSensor, the mbusCodes() and sizes() accessor functions retrieves all the supported media bus codes and the supported sizes respectively. However, this is quite limiting since the caller probably isn't in a position to match which range of sizes are supported for a particular mbusCode. Hence, the caller is most likely interested to know about the sizes supported for a particular media bus code. This patch transforms the existing CameraSensor::sizes() to CameraSensor::sizes(mbuscode) to achieve that goal. To know all the frame sizes of the CameraSensor as required in IPU3 case Cio2Device::sizes(), one would now require to enumerate all the media bus codes (can be retrieved by CameraSensor::mbusCodes()) with CameraSensor::size(mbusCode). The result can be inserted in a std::set<> to avoid duplicates. Signed-off-by: Umang Jain --- include/libcamera/internal/camera_sensor.h | 2 +- src/libcamera/camera_sensor.cpp | 36 ++++++++++++++++------ src/libcamera/pipeline/ipu3/cio2.cpp | 10 +++--- test/camera-sensor.cpp | 2 +- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index db12b07e..d25a1165 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -38,7 +38,7 @@ public: const std::string &id() const { return id_; } const MediaEntity *entity() const { return entity_; } const std::vector &mbusCodes() const { return mbusCodes_; } - const std::vector &sizes() const { return sizes_; } + const std::vector sizes(unsigned int mbusCode) const; Size resolution() const; const std::vector &testPatternModes() const { diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index cde431cc..3c3ceff3 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -471,16 +471,6 @@ int CameraSensor::initProperties() * \return The supported media bus codes sorted in increasing order */ -/** - * \fn CameraSensor::sizes() - * \brief Retrieve the frame sizes supported by the camera sensor - * - * The reported sizes span all media bus codes supported by the camera sensor. - * Not all sizes may be supported by all media bus codes. - * - * \return The supported frame sizes sorted in increasing order - */ - /** * \brief Retrieve the camera sensor resolution * @@ -594,6 +584,32 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector &mbu return format; } +/** + * \brief Retrieve the supported frame sizes for a media bus code + * \param[in] mbusCode The media bus code for which sizes are requested + * + * The reported sizes for a particular \a mbusCode are supported by the camera + * sensor. + * + * \return The supported frame sizes for \a mbusCode sorted in increasing order + */ +const std::vector CameraSensor::sizes(unsigned int mbusCode) const +{ + std::vector sizes; + + const auto format = formats_.find(mbusCode); + if (format == formats_.end()) + return sizes; + + const std::vector &ranges = format->second; + std::transform(ranges.begin(), ranges.end(), std::back_inserter(sizes), + [](const SizeRange &range) { return range.max; }); + + std::sort(sizes.begin(), sizes.end()); + + return sizes; +} + /** * \brief Set the sensor output format * \param[in] format The desired sensor output format diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 1bcd580e..6f2ef321 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -69,11 +69,13 @@ std::vector CIO2Device::sizes() const if (!sensor_) return {}; - std::vector sizes; - for (const Size &size : sensor_->sizes()) - sizes.emplace_back(size, size); + std::set allSizes; + for (unsigned int code : sensor_->mbusCodes()) { + for (Size sz : sensor_->sizes(code)) + allSizes.insert(sz); + } - return sizes; + return std::vector(allSizes.begin(), allSizes.end()); } /** diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp index a8dcad82..372ee4af 100644 --- a/test/camera-sensor.cpp +++ b/test/camera-sensor.cpp @@ -76,7 +76,7 @@ protected: return TestFail; } - const std::vector &sizes = sensor_->sizes(); + const std::vector &sizes = sensor_->sizes(*iter); auto iter2 = std::find(sizes.begin(), sizes.end(), Size(4096, 2160)); if (iter2 == sizes.end()) { From patchwork Tue Aug 3 13:32:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13179 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 709CBC3235 for ; Tue, 3 Aug 2021 13:32:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 287C1687BC; Tue, 3 Aug 2021 15:32:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cS0Pgq0/"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CFF056026A for ; Tue, 3 Aug 2021 15:32:29 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.238.109.12]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7281E3F0; Tue, 3 Aug 2021 15:32:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1627997549; bh=XI2fwNT/vRzreI/MHOIyCO6zOrg+qzwqMxOr0NiIQ70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cS0Pgq0/3VT4lktHkcXNSJKonKsHJ+pVuUIlPoRTVc5UO1LVypDlpKDYxySkyjVdn afsIkocJKTJVD8WEPDozoyyGNFOwP+SZt8toGL5ryJgXrCKyEIWX4+/fYJB2/NLbmc RyqBOh+3njgcIDFf32DNzsu5AV6I+CyjOTG9x9kg= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 3 Aug 2021 19:02:03 +0530 Message-Id: <20210803133205.6599-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210803133205.6599-1-umang.jain@ideasonboard.com> References: <20210803133205.6599-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] ipu3: cio2: Replicate CameraSensor::getFormats() to a member function 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" This prepares a base to introduce custom selection of sensor format based on platform(soraka or nautilus) constraints. The changes in selection policy will be introduced in a subsequent patch. The replication of the function is not verbatim and has small changes. CameraSensor::getFormats() has accesss to all the supported sensor formats via a V4L2Subdevice::Formats internally and use it directly. We do not want to expose V4L2Subdevice::Formats directly to the pipeline-handler hence, the patch is adapted to use the CameraSensor::sizes(mbusCode) instead, to get the range of sensor sizes supported for desired media bus codes. No functional changes in this patch. Signed-off-by: Umang Jain Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/cio2.cpp | 91 +++++++++++++++++++++++++++- src/libcamera/pipeline/ipu3/cio2.h | 3 + 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 6f2ef321..be063613 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -7,6 +7,8 @@ #include "cio2.h" +#include + #include #include @@ -170,7 +172,7 @@ int CIO2Device::configure(const Size &size, V4L2DeviceFormat *outputFormat) * the CIO2 output device. */ std::vector mbusCodes = utils::map_keys(mbusCodesToPixelFormat); - sensorFormat = sensor_->getFormat(mbusCodes, size); + sensorFormat = getSensorFormat(mbusCodes, size); ret = sensor_->setFormat(&sensorFormat); if (ret) return ret; @@ -208,7 +210,7 @@ StreamConfiguration CIO2Device::generateConfiguration(Size size) const /* Query the sensor static information for closest match. */ std::vector mbusCodes = utils::map_keys(mbusCodesToPixelFormat); - V4L2SubdeviceFormat sensorFormat = sensor_->getFormat(mbusCodes, size); + V4L2SubdeviceFormat sensorFormat = getSensorFormat(mbusCodes, size); if (!sensorFormat.mbus_code) { LOG(IPU3, Error) << "Sensor does not support mbus code"; return {}; @@ -221,6 +223,91 @@ StreamConfiguration CIO2Device::generateConfiguration(Size size) const return cfg; } +/** + * \brief Retrieve the best sensor format for a desired output + * \param[in] mbusCodes The list of acceptable media bus codes + * \param[in] size The desired size + * + * Media bus codes are selected from \a mbusCodes, which lists all acceptable + * codes in decreasing order of preference. Media bus codes supported by the + * sensor but not listed in \a mbusCodes are ignored. If none of the desired + * codes is supported, it returns an error. + * + * \a size indicates the desired size at the output of the sensor. This method + * selects the best media bus code and size supported by the sensor according + * to the following criteria. + * + * - The desired \a size shall fit in the sensor output size to avoid the need + * to up-scale. + * - The sensor output size shall match the desired aspect ratio to avoid the + * need to crop the field of view. + * - The sensor output size shall be as small as possible to lower the required + * bandwidth. + * - The desired \a size shall be supported by one of the media bus code listed + * in \a mbusCodes. + * + * When multiple media bus codes can produce the same size, the code at the + * lowest position in \a mbusCodes is selected. + * + * The use of this method is optional, as the above criteria may not match the + * needs of all pipeline handlers. Pipeline handlers may implement custom + * sensor format selection when needed. + * + * The returned sensor output format is guaranteed to be acceptable by the + * setFormat() method without any modification. + * + * \return The best sensor output format matching the desired media bus codes + * and size on success, or an empty format otherwise. + */ +V4L2SubdeviceFormat CIO2Device::getSensorFormat(const std::vector &mbusCodes, + const Size &size) const +{ + unsigned int desiredArea = size.width * size.height; + unsigned int bestArea = UINT_MAX; + float desiredRatio = static_cast(size.width) / size.height; + float bestRatio = FLT_MAX; + Size bestSize; + uint32_t bestCode = 0; + + for (unsigned int code : mbusCodes) { + const auto sizes = sensor_->sizes(code); + if (!sizes.size()) + continue; + + for (const Size &sz : sizes) { + if (sz.width < size.width || sz.height < size.height) + continue; + + float ratio = static_cast(sz.width) / sz.height; + float ratioDiff = fabsf(ratio - desiredRatio); + unsigned int area = sz.width * sz.height; + unsigned int areaDiff = area - desiredArea; + + if (ratioDiff > bestRatio) + continue; + + if (ratioDiff < bestRatio || areaDiff < bestArea) { + bestRatio = ratioDiff; + bestArea = areaDiff; + bestSize = sz; + bestCode = code; + } + } + } + + if (bestSize.isNull()) { + LOG(IPU3, Debug) << "No supported format or size found"; + return {}; + } + + V4L2SubdeviceFormat format{ + .mbus_code = bestCode, + .size = bestSize, + }; + + return format; +} + int CIO2Device::exportBuffers(unsigned int count, std::vector> *buffers) { diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h index f28e9f1d..da024d45 100644 --- a/src/libcamera/pipeline/ipu3/cio2.h +++ b/src/libcamera/pipeline/ipu3/cio2.h @@ -45,6 +45,9 @@ public: int exportBuffers(unsigned int count, std::vector> *buffers); + V4L2SubdeviceFormat getSensorFormat(const std::vector &mbusCodes, + const Size &size) const; + int start(); int stop(); From patchwork Tue Aug 3 13:32:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13180 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 BCD2BC3235 for ; Tue, 3 Aug 2021 13:32:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7BA7D687EB; Tue, 3 Aug 2021 15:32:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="wbgFbsiY"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E2DBF687CE for ; Tue, 3 Aug 2021 15:32:31 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.238.109.12]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B8C1B3F0; Tue, 3 Aug 2021 15:32:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1627997551; bh=rlDFcRXJQC8DrRziJUYhUuPYmCzT2LxvxNcrBDMTuQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wbgFbsiYo0+H94MmJ0SsSbV0NADbiEtTCu8Sw/urRgECOcg1SnYnUJEFRlNpCr97e fjD3h3NFY4aqVyFGFSG6tP5bF1bfA7zs/bfzoOnu47Up7PVkn1eLuPOF9h5EBTuLlK O3zOOy3ms7QN+gSvngNReZjTxjPA12L+6IPT3kH8= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 3 Aug 2021 19:02:04 +0530 Message-Id: <20210803133205.6599-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210803133205.6599-1-umang.jain@ideasonboard.com> References: <20210803133205.6599-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] ipu3: cio2: Change sensor size selection policy 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" From: Jacopo Mondi The current implementation of getSensorFormat() prioritizes sensor sizes that match the output size FOV ratio. Modify the frame size selection procedure to prioritize resolutions with the same FOV as the sensor's native one, to avoid cropping in the sensor pixel array. In example, with the current implementation : - on a Soraka device equipped with ov13858 as back sensor, with a native resolution of 4224x3136 (4:3), when requested to select the sensor output size to produce 1080p (16:9) a frame size of 2112x1188 (16:9) is selected causing the ImgU configuration procedure to fail. If a resolution with the same FOV as the sensor's native size, such as 2112x1568 (4:3), is selected the pipeline works correctly. Signed-off-by: Jacopo Mondi Signed-off-by: Umang Jain Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/cio2.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index be063613..9980b8bd 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -239,8 +239,8 @@ StreamConfiguration CIO2Device::generateConfiguration(Size size) const * * - The desired \a size shall fit in the sensor output size to avoid the need * to up-scale. - * - The sensor output size shall match the desired aspect ratio to avoid the - * need to crop the field of view. + * - The aspect ratio of sensor output size shall be as close as possible to + * the sensor's native resolution field of view. * - The sensor output size shall be as small as possible to lower the required * bandwidth. * - The desired \a size shall be supported by one of the media bus code listed @@ -264,7 +264,9 @@ V4L2SubdeviceFormat CIO2Device::getSensorFormat(const std::vector { unsigned int desiredArea = size.width * size.height; unsigned int bestArea = UINT_MAX; - float desiredRatio = static_cast(size.width) / size.height; + const Size &resolution = sensor_->resolution(); + float desiredRatio = static_cast(resolution.width) / + resolution.height; float bestRatio = FLT_MAX; Size bestSize; uint32_t bestCode = 0; From patchwork Tue Aug 3 13:32:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13181 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 38AEBC3235 for ; Tue, 3 Aug 2021 13:32:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C9BBF687DE; Tue, 3 Aug 2021 15:32:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Qk62e1az"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BB5E2687CE for ; Tue, 3 Aug 2021 15:32:33 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.238.109.12]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B492D3F0; Tue, 3 Aug 2021 15:32:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1627997553; bh=8RpSljUB7bb7AR22UrEoMo0xiz6QWPZswzKxRCnSPjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qk62e1azlA70n32aO4ElGiTo/dyaH1eQLArMK1fRR90SC/s8Ylb2y5vqA9jD0+900 SlgAXmx0PrDTyJWlNqgXyN4RvvTk/F2FgmwvChgEhd4atFyluC+BL9BQKfQf+o0w/P Tmg7wyM7/JhzikV+0U0+jZEMSTa4dAOCPy27AJHs= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 3 Aug 2021 19:02:05 +0530 Message-Id: <20210803133205.6599-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210803133205.6599-1-umang.jain@ideasonboard.com> References: <20210803133205.6599-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] ipu3: cio2: Tweak sensor size selection policy 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" Do not compare higher precision of the ratios, as it might lead to absurd selection of sensor size for a relatively low requested resolution size. For example: The imx258 driver supports the following sensor resolutions: - 4208x3118 = 1.349583066 - 2104x1560 = 1.348717949 - 1048x780 = 1.343589744 It can be inferred that, that the aspect ratio only differs by a small factor with each other. It does not makes sense to select a 4208x3118 for a requested size of say 640x480 or 1280x720, which is what is happening currently. ($) cam -c1 -swidth=640,height=480,role=raw - CIO2 configuration: 4208x3118-SGRBG10_IPU3 In order to address this constraint, only compare the ratio with single precision to make a better decision on the sensor resolution policy selection. ($) cam -c1 -srole=raw,width=640,height=480 - CIO2 configuration: 1048x780-SGRBG10_IPU3 Signed-off-by: Umang Jain --- src/libcamera/pipeline/ipu3/cio2.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 9980b8bd..887b850d 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -281,6 +281,13 @@ V4L2SubdeviceFormat CIO2Device::getSensorFormat(const std::vector continue; float ratio = static_cast(sz.width) / sz.height; + /* + * Comparing ratios with a single precision is enough. + * This avoids the selection of a frame size which is + * 2x or 3x than the requested size, having a slightly + * better ratio w.r.t native resolution ratio. + */ + ratio = static_cast(ratio * 10) / 10.0; float ratioDiff = fabsf(ratio - desiredRatio); unsigned int area = sz.width * sz.height; unsigned int areaDiff = area - desiredArea;