From patchwork Wed Dec 2 13:53:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10548 X-Patchwork-Delegate: jacopo@jmondi.org 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 36CD8BE176 for ; Wed, 2 Dec 2020 13:54:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D03A1635AC; Wed, 2 Dec 2020 14:53:58 +0100 (CET) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 78129634A2 for ; Wed, 2 Dec 2020 14:53:57 +0100 (CET) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 3522420003 for ; Wed, 2 Dec 2020 13:53:57 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Dec 2020 14:53:51 +0100 Message-Id: <20201202135354.264212-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201202135354.264212-1-jacopo@jmondi.org> References: <20201202135354.264212-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/4] libcamera: camera_sensor: Adjust CameraSensorInfo::analogCrop 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 CameraSensorInfo::analogCrop top-left corner is defined relatively to the sensor active area. The analogCrop rectangle is constucted by retrieving the V4L2 selection target V4L2_SEL_TGT_CROP which is instead defined relatively to the whole sensor's pixel array size. Adjust the the analogCrop rectangle subtracting from its top-left corner the active area distance from the full pixel array. Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi --- This patch depends on kernel patch: "media: i2c: imx219: Selection compliance fixes": RPi downstream: https://github.com/raspberrypi/linux/pull/3983 Linux mainline (should land in v5.11) https://patchwork.linuxtv.org/project/linux-media/patch/20200805105721.15445-5-jacopo@jmondi.org/ --- src/libcamera/camera_sensor.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.29.1 diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 935de528c496..c5fa89143ac8 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -527,6 +527,16 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const return ret; } + /* + * CameraSensorInfo::analogCrop::x and CameraSensorInfo::analogCrop::y + * are defined relatively to the active pixel area, while V4L2's + * TGT_CROP target is defined in respect to the full pixel array. + * + * Compensate it by subtracting the active areas offset. + */ + info->analogCrop.x -= rect.x; + info->analogCrop.y -= rect.y; + /* The bit depth and image size depend on the currently applied format. */ V4L2SubdeviceFormat format{}; ret = subdev_->getFormat(pad_, &format); From patchwork Wed Dec 2 13:53:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10549 X-Patchwork-Delegate: jacopo@jmondi.org 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 A8DE3BE178 for ; Wed, 2 Dec 2020 13:54:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 07ED6635AF; Wed, 2 Dec 2020 14:53:59 +0100 (CET) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D0F29634A2 for ; Wed, 2 Dec 2020 14:53:57 +0100 (CET) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 9C2F920003 for ; Wed, 2 Dec 2020 13:53:57 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Dec 2020 14:53:52 +0100 Message-Id: <20201202135354.264212-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201202135354.264212-1-jacopo@jmondi.org> References: <20201202135354.264212-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/4] libcamera: camera_sensor: Break out properties initialization 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" Break out initialization to its own function in preparation to add more properties. Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi --- include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 79 ++++++++++++---------- 2 files changed, 45 insertions(+), 35 deletions(-) -- 2.29.1 diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index b9eba89f00fb..f80d836161a5 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -69,6 +69,7 @@ protected: private: int generateId(); + int initProperties(); const MediaEntity *entity_; std::unique_ptr subdev_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index c5fa89143ac8..7e6995c43010 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -172,6 +172,49 @@ int CameraSensor::init() return -EINVAL; } + /* Create and open the subdev. */ + subdev_ = std::make_unique(entity_); + int ret = subdev_->open(); + if (ret < 0) + return ret; + + ret = initProperties(); + if (ret) + return ret; + + /* Enumerate, sort and cache media bus codes and sizes. */ + formats_ = subdev_->formats(pad_); + if (formats_.empty()) { + LOG(CameraSensor, Error) << "No image format found"; + return -EINVAL; + } + + mbusCodes_ = utils::map_keys(formats_); + std::sort(mbusCodes_.begin(), mbusCodes_.end()); + + for (const auto &format : formats_) { + 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()); + + /* Remove duplicates. */ + auto last = std::unique(sizes_.begin(), sizes_.end()); + sizes_.erase(last, sizes_.end()); + + /* + * The sizes_ vector is sorted in ascending order, the resolution is + * thus the last element of the vector. + */ + resolution_ = sizes_.back(); + + return 0; +} + +int CameraSensor::initProperties() +{ /* * Extract the camera sensor model name from the media entity name. * @@ -202,14 +245,8 @@ int CameraSensor::init() properties_.set(properties::Model, utils::toAscii(model_)); - /* Create and open the subdev. */ - subdev_ = std::make_unique(entity_); - int ret = subdev_->open(); - if (ret < 0) - return ret; - /* Generate a unique ID for the sensor. */ - ret = generateId(); + int ret = generateId(); if (ret) return ret; @@ -251,34 +288,6 @@ int CameraSensor::init() propertyValue = 0; properties_.set(properties::Rotation, propertyValue); - /* Enumerate, sort and cache media bus codes and sizes. */ - formats_ = subdev_->formats(pad_); - if (formats_.empty()) { - LOG(CameraSensor, Error) << "No image format found"; - return -EINVAL; - } - - mbusCodes_ = utils::map_keys(formats_); - std::sort(mbusCodes_.begin(), mbusCodes_.end()); - - for (const auto &format : formats_) { - 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()); - - /* Remove duplicates. */ - auto last = std::unique(sizes_.begin(), sizes_.end()); - sizes_.erase(last, sizes_.end()); - - /* - * The sizes_ vector is sorted in ascending order, the resolution is - * thus the last element of the vector. - */ - resolution_ = sizes_.back(); - return 0; } From patchwork Wed Dec 2 13:53:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10550 X-Patchwork-Delegate: jacopo@jmondi.org 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 9F415BE176 for ; Wed, 2 Dec 2020 13:54:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7AB54635A6; Wed, 2 Dec 2020 14:54:01 +0100 (CET) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5AD21635A3 for ; Wed, 2 Dec 2020 14:53:58 +0100 (CET) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 02ECB20010 for ; Wed, 2 Dec 2020 13:53:57 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Dec 2020 14:53:53 +0100 Message-Id: <20201202135354.264212-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201202135354.264212-1-jacopo@jmondi.org> References: <20201202135354.264212-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/4] libcamera: camera_sensor: Initialize PixelArray properties 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" Initialize pixel array properties 'PixelArraySize' and 'PixelArrayActiveAreas' by inspecting the V4L2 CROP_BOUNDS and CROP_DEFAULT selection targets. The properties are registered only if the sensor subdevice support the above mentioned selection targets. Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 7e6995c43010..1628ba9c892b 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -288,6 +288,25 @@ int CameraSensor::initProperties() propertyValue = 0; properties_.set(properties::Rotation, propertyValue); + Rectangle bounds; + ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_BOUNDS, &bounds); + if (!ret) + properties_.set(properties::PixelArraySize, bounds.size()); + + Rectangle crop; + ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_DEFAULT, &crop); + if (!ret) { + /* + * V4L2_SEL_TGT_CROP_DEFAULT and V4L2_SEL_TGT_CROP_BOUNDS are + * defined relatively to the sensor full pixel array size, + * while properties::PixelArrayActiveAreas is defined relatively + * to properties::PixelArraySize. Adjust it. + */ + crop.x -= bounds.x; + crop.y -= bounds.y; + properties_.set(properties::PixelArrayActiveAreas, { crop }); + } + return 0; } From patchwork Wed Dec 2 13:53:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10551 X-Patchwork-Delegate: jacopo@jmondi.org 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 02AA4BE178 for ; Wed, 2 Dec 2020 13:54:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AFE51635A3; Wed, 2 Dec 2020 14:54:01 +0100 (CET) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CDF44635AB for ; Wed, 2 Dec 2020 14:53:58 +0100 (CET) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 8610C2000E for ; Wed, 2 Dec 2020 13:53:58 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Dec 2020 14:53:54 +0100 Message-Id: <20201202135354.264212-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201202135354.264212-1-jacopo@jmondi.org> References: <20201202135354.264212-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/4] android: camera_device: Initialize pixel array properties 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" Initialize pixel array properties in the Android camera HAL inspecting the camera properties. If the camera does not provide any suitable property, not static metadata is registered to the Android framework. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 675af5705055..017a15cac284 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -593,6 +593,7 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() } const ControlInfoMap &controlsInfo = camera_->controls(); + const ControlList &properties = camera_->properties(); /* Color correction static metadata. */ { @@ -725,17 +726,29 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() staticMetadata_->addEntry(ANDROID_JPEG_MAX_SIZE, &maxJpegBufferSize_, 1); /* Sensor static metadata. */ - int32_t pixelArraySize[] = { - 2592, 1944, - }; - staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, - &pixelArraySize, 2); + if (properties.contains(properties::PixelArraySize)) { + const Size &size = + properties.get(properties::PixelArraySize); + std::vector data{ + static_cast(size.width), + static_cast(size.height), + }; + staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, + data.data(), data.size()); + } - int32_t sensorSizes[] = { - 0, 0, 2560, 1920, - }; - staticMetadata_->addEntry(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, - &sensorSizes, 4); + if (properties.contains(properties::PixelArrayActiveAreas)) { + const Span &rects = + properties.get>(properties::PixelArrayActiveAreas); + std::vector data{ + static_cast(rects[0].x), + static_cast(rects[0].y), + static_cast(rects[0].width), + static_cast(rects[0].height), + }; + staticMetadata_->addEntry(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, + data.data(), data.size()); + } int32_t sensitivityRange[] = { 32, 2400,