From patchwork Tue Aug 10 07:58:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13273 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 39019BD87D for ; Tue, 10 Aug 2021 07:59:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E51AE687FA; Tue, 10 Aug 2021 09:59:05 +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="F0B6Ut1+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D793D687DE for ; Tue, 10 Aug 2021 09:59:04 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.238.109.8]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A734DEE; Tue, 10 Aug 2021 09:59:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1628582344; bh=1XEI1fJ8n+4eb+I77B9m/UzjzNxJl5yljDMjF//fpsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F0B6Ut1+Zg20uFHAh51Brd1eG+5pSrp+wvegmdrS7nmoZhMCSz9FANxZ3k31MABot ZVtmKkctQ1U8UAwBq76p6tTpc2jxrNqLaUWC/17ZzY6iTpynJYBsQM1V644ISGYkrb XBrcUNJ+QHHobEKp6iSaEgr8F7s3WC985QCxUGKE= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 10 Aug 2021 13:28:51 +0530 Message-Id: <20210810075854.86191-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810075854.86191-1-umang.jain@ideasonboard.com> References: <20210810075854.86191-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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. The patch also transforms existing CIO2Device::sizes() in IPU3 pipeline handler to CIO2Device::sizes(PixelFormat) on a similar principle. The function is then plumbed to CameraSensor::sizes(mbusCode) to enumerate the per-format sizes as required in PipelineHandlerIPU3::generateConfiguration(). Signed-off-by: Umang Jain Tested-by: Umang Jain Tested-by: Jacopo Mondi Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- include/libcamera/internal/camera_sensor.h | 2 +- src/libcamera/camera_sensor.cpp | 25 ++++++++++++++++------ src/libcamera/pipeline/ipu3/cio2.cpp | 20 ++++++++++++----- src/libcamera/pipeline/ipu3/cio2.h | 2 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 2 +- test/camera-sensor.cpp | 2 +- 6 files changed, 38 insertions(+), 15 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 7a386415..87668509 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -472,14 +472,27 @@ int CameraSensor::initProperties() */ /** - * \fn CameraSensor::sizes() - * \brief Retrieve the frame sizes supported by the camera sensor + * \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 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 + * \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 Retrieve the camera sensor resolution diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 1bcd580e..8a40e955 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -64,16 +64,26 @@ std::vector CIO2Device::formats() const * \brief Retrieve the list of supported size ranges * \return The list of supported SizeRange */ -std::vector CIO2Device::sizes() const +std::vector CIO2Device::sizes(const PixelFormat &format) const { + std::vector szRange; + int mbusCode = -1; + if (!sensor_) return {}; - std::vector sizes; - for (const Size &size : sensor_->sizes()) - sizes.emplace_back(size, size); + for (const auto &iter : mbusCodesToPixelFormat) { + if (iter.second == format) + mbusCode = iter.first; + } + + if (!mbusCode) + return {}; + + for (const Size &sz: sensor_->sizes(mbusCode)) + szRange.emplace_back(sz); - return sizes; + return szRange; } /** diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h index f28e9f1d..24272dc5 100644 --- a/src/libcamera/pipeline/ipu3/cio2.h +++ b/src/libcamera/pipeline/ipu3/cio2.h @@ -35,7 +35,7 @@ public: CIO2Device(); std::vector formats() const; - std::vector sizes() const; + std::vector sizes(const PixelFormat &format) const; int init(const MediaDevice *media, unsigned int index); int configure(const Size &size, V4L2DeviceFormat *outputFormat); diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 19cb5c4e..c73540fb 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -455,7 +455,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, bufferCount = cio2Config.bufferCount; for (const PixelFormat &format : data->cio2_.formats()) - streamFormats[format] = data->cio2_.sizes(); + streamFormats[format] = data->cio2_.sizes(format); break; } 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 10 07:58:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13274 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 81EE5BD87D for ; Tue, 10 Aug 2021 07:59:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4989E68822; Tue, 10 Aug 2021 09:59:09 +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="R5c4VApl"; 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 1A395687DE for ; Tue, 10 Aug 2021 09:59:07 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.238.109.8]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D23D4EE; Tue, 10 Aug 2021 09:59:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1628582346; bh=JmKqQFUP+jhaRkbJNN+NpVbgtrQsjCj+1dAJGHvyw1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R5c4VAplWpRZCetW78wuktmImNnQwahQhHO7trsBnZcZBw8AsGHNzzc5ee82/oHPb J6sYrpqFEA2IctCvjTJJR+MOGEvuA5U/Tx4KLHkm7qdrDaOFjcw/+ae3LKaV6G9SQ4 pi+jdFXZAgtvuqL8drJY620UQFz2xiNozZe4o/2s= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 10 Aug 2021 13:28:52 +0530 Message-Id: <20210810075854.86191-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810075854.86191-1-umang.jain@ideasonboard.com> References: <20210810075854.86191-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 function is copied from CameraSensor::getFormat() in the IPU3 pipeline handler code to be later changed on top. The copy is not verbatim and has a minor change as follows: CameraSensor::getFormats() has access to a V4L2Subdevice::Formats interally and use it directly to iterate over supported camera sensor frame sizes. The copy is adapted to use the CameraSensor::sizes(mbusCode) instead, to enumerate over the supported frame sizes as per mbusCodesToPixelFormat map. No functional changes in this patch. Signed-off-by: Umang Jain Tested-by: Umang Jain Reviewed-by: Jacopo Mondi Tested-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/ipu3/cio2.cpp | 92 +++++++++++++++++++++++++++- src/libcamera/pipeline/ipu3/cio2.h | 3 + 2 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 8a40e955..88dd364b 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -7,6 +7,9 @@ #include "cio2.h" +#include +#include + #include #include @@ -178,7 +181,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; @@ -216,7 +219,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 {}; @@ -229,6 +232,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 = std::numeric_limits::max(); + float desiredRatio = static_cast(size.width) / size.height; + float bestRatio = std::numeric_limits::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 24272dc5..5fffe921 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 10 07:58:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13275 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 D032ABD87D for ; Tue, 10 Aug 2021 07:59:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9A4D36884F; Tue, 10 Aug 2021 09:59:10 +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="vVuW6CPZ"; 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 1285B687DE for ; Tue, 10 Aug 2021 09:59:09 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.238.109.8]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EB87DEE; Tue, 10 Aug 2021 09:59:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1628582348; bh=ztSBoGxIHRY6RabL/Z0ZrRT+YLswlAD2ozhrlQveljo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vVuW6CPZdewgzQWhkPUJJTe/FXvXpBnoH/bzE7jfB3kZvL7UDIShYvxvboN2vRXpj KpV8Ks6xaa2oyvmf0LEWnAjxqGVqKe6XEeC6m+3Hq3YSlsMB5UdLaW0TIM4XdEPcQM f45W9cCh2HzCQA/7Sw3+anw41XIvYbP/Yy5unWo4= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 10 Aug 2021 13:28:53 +0530 Message-Id: <20210810075854.86191-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810075854.86191-1-umang.jain@ideasonboard.com> References: <20210810075854.86191-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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" 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. For example: - 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. Suggested-by:: Jacopo Mondi Signed-off-by: Umang Jain Tested-by: Umang Jain Reviewed-by: Jacopo Mondi Tested-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- 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 88dd364b..3c9331e3 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -248,8 +248,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 @@ -273,7 +273,9 @@ V4L2SubdeviceFormat CIO2Device::getSensorFormat(const std::vector { unsigned int desiredArea = size.width * size.height; unsigned int bestArea = std::numeric_limits::max(); - float desiredRatio = static_cast(size.width) / size.height; + const Size &resolution = sensor_->resolution(); + float desiredRatio = static_cast(resolution.width) / + resolution.height; float bestRatio = std::numeric_limits::max(); Size bestSize; uint32_t bestCode = 0; From patchwork Tue Aug 10 07:58:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13276 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 4663FBD87D for ; Tue, 10 Aug 2021 07:59:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0995A68886; Tue, 10 Aug 2021 09:59:13 +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="W/YH3nnk"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E1F168826 for ; Tue, 10 Aug 2021 09:59:11 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.238.109.8]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D13A4466; Tue, 10 Aug 2021 09:59:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1628582350; bh=uQXQGCNIbtRwW/wywRTu1eBmJWomvFWYMe38wBqLDy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W/YH3nnkSJlYfrcUea6rK4BtC5JiUXXRgI7L+9fA4ruzEW2Xb+UGK066bsjerYjUJ Zo+h94R7Ap9JQXYk10ueNgZ1wxjtDU1ZA+PkWm2MNXTZEp1a5jrAFOuU8hNtKOiYMN iIZ617VyDdQp02S4vy1tv0B7A0olzNwXxYVf99bw= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 10 Aug 2021 13:28:54 +0530 Message-Id: <20210810075854.86191-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810075854.86191-1-umang.jain@ideasonboard.com> References: <20210810075854.86191-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 Tested-by: Umang Jain Tested-by: Jacopo Mondi Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/ipu3/cio2.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 3c9331e3..6ccef301 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -290,6 +290,11 @@ V4L2SubdeviceFormat CIO2Device::getSensorFormat(const std::vector continue; float ratio = static_cast(sz.width) / sz.height; + /* + * Comparing ratios with a single precision digit + * is enough. + */ + ratio = static_cast(ratio * 10) / 10.0; float ratioDiff = fabsf(ratio - desiredRatio); unsigned int area = sz.width * sz.height; unsigned int areaDiff = area - desiredArea;