From patchwork Tue Jan 5 12:31:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10807 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 72025C0F1C for ; Tue, 5 Jan 2021 12:31:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 429EC62D3E; Tue, 5 Jan 2021 13:31:23 +0100 (CET) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4CE326010F for ; Tue, 5 Jan 2021 13:31:20 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 0AACBE000E for ; Tue, 5 Jan 2021 12:31:19 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 5 Jan 2021 13:31:22 +0100 Message-Id: <20210105123128.617543-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210105123128.617543-1-jacopo@jmondi.org> References: <20210105123128.617543-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 04/10] libcamera: camera_sensor: Default analogue crop rectangle 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" As support for the V4L2_SEL_TGT_CROP selection target, used to read the sensor analogue crop rectangle is schedule to become mandatory but is still optional, cache a default value equal to the sensor's active area size at sensor validation time to allow the creation of the CameraSensorInfo in the case the driver does not support it. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 27 ++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 86902b85ada8..de6a0202d19a 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -86,6 +86,7 @@ private: Size pixelArraySize_; Rectangle activeArea_; + Rectangle analogueCrop_; ControlList properties_; }; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 92c90862215d..eda41980aa22 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -289,8 +289,10 @@ int CameraSensor::validateSensorDriver() ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP, &rect); if (ret) { + analogueCrop_ = activeArea_; LOG(CameraSensor, Warning) - << "Failed to retrieve the sensor crop rectangle"; + << "The analogue crop rectangle has been defaulted to: " + << analogueCrop_.toString(); err = -EINVAL; } @@ -643,13 +645,20 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const */ info->activeAreaSize = { activeArea_.width, activeArea_.height }; - /* It's mandatory for the subdevice to report its crop rectangle. */ - int ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP, &info->analogCrop); - if (ret) { - LOG(CameraSensor, Error) - << "Failed to construct camera sensor info: " - << "the camera sensor does not report the crop rectangle"; - return ret; + /* + * \todo Support for retreiving the crop rectangle is scheduled to + * become mandatory. For the time being use the default value if it has + * been initialized at sensor driver validation time. + */ + if (!analogueCrop_.isNull()) { + info->analogCrop = analogueCrop_; + } else { + int ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP, &info->analogCrop); + if (ret) { + LOG(CameraSensor, Error) + << "Failed to retrieve the sensor crop rectangle."; + return -EINVAL; + } } /* @@ -664,7 +673,7 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const /* The bit depth and image size depend on the currently applied format. */ V4L2SubdeviceFormat format{}; - ret = subdev_->getFormat(pad_, &format); + int ret = subdev_->getFormat(pad_, &format); if (ret) return ret; info->bitsPerPixel = format.bitsPerPixel();