From patchwork Sun Jan 31 18:17:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11073 X-Patchwork-Delegate: laurent.pinchart@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 B6017BD808 for ; Sun, 31 Jan 2021 18:17:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 80F42683D5; Sun, 31 Jan 2021 19:17:49 +0100 (CET) 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="pUOHHs1u"; 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 D8384683D0 for ; Sun, 31 Jan 2021 19:17:46 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6EFE48A0 for ; Sun, 31 Jan 2021 19:17:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1612117066; bh=B93rKEFIsKSv1e9z4QLZsekDGzSyG+XXysRBBjTmEq8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pUOHHs1uUGBXhbFe5BPsfp8Mo91PaLLc1AxaK2U/H3onlxx4T30YbHvY4pcDbz2M3 g3i9XgVHHlzO+Mu54Ben4H/LECkZe18dqXHgHCAMi7T+Urk1dSggCP0wVQPjyvcEjI pTR/RSEMGhL6o/ulZgN4xtY2ZGZqWgzFaMiiM7cs= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 31 Jan 2021 20:17:20 +0200 Message-Id: <20210131181722.5410-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210131181722.5410-1-laurent.pinchart@ideasonboard.com> References: <20210131181722.5410-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] libcamera: camera_sensor: Store Bayer pattern in class member 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 Bayer pattern is retrieved based on the media bus formats supported by the sensor, when registering camera sensor properties. To prepare for its usage elsewhere in the CameraSensor class, store it in a private member variable. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- include/libcamera/internal/camera_sensor.h | 2 ++ src/libcamera/camera_sensor.cpp | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index bf83d53134bf..a662807ab504 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -20,6 +20,7 @@ namespace libcamera { +class BayerFormat; class MediaEntity; struct CameraSensorInfo { @@ -89,6 +90,7 @@ private: Size pixelArraySize_; Rectangle activeArea_; + const BayerFormat *bayerFormat_; ControlList properties_; }; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 2d15043431aa..35312857ff90 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -133,7 +133,8 @@ LOG_DEFINE_CATEGORY(CameraSensor) * Once constructed the instance must be initialized with init(). */ CameraSensor::CameraSensor(const MediaEntity *entity) - : entity_(entity), pad_(UINT_MAX), properties_(properties::properties) + : entity_(entity), pad_(UINT_MAX), bayerFormat_(nullptr), + properties_(properties::properties) { } @@ -223,6 +224,15 @@ int CameraSensor::init() return initProperties(); } + /* Get the color filter array pattern (only for RAW sensors). */ + for (unsigned int mbusCode : mbusCodes_) { + const BayerFormat &bayerFormat = BayerFormat::fromMbusCode(mbusCode); + if (bayerFormat.isValid()) { + bayerFormat_ = &bayerFormat; + break; + } + } + ret = validateSensorDriver(); if (ret) return ret; @@ -405,14 +415,9 @@ int CameraSensor::initProperties() properties_.set(properties::PixelArrayActiveAreas, { activeArea_ }); /* Color filter array pattern, register only for RAW sensors. */ - for (const auto &format : formats_) { - unsigned int mbusCode = format.first; - BayerFormat bayerFormat = BayerFormat::fromMbusCode(mbusCode); - if (!bayerFormat.isValid()) - continue; - + if (bayerFormat_) { int32_t cfa; - switch (bayerFormat.order) { + switch (bayerFormat_->order) { case BayerFormat::BGGR: cfa = properties::draft::BGGR; break; @@ -428,7 +433,6 @@ int CameraSensor::initProperties() } properties_.set(properties::draft::ColorFilterArrangement, cfa); - break; } return 0; From patchwork Sun Jan 31 18:17:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11074 X-Patchwork-Delegate: laurent.pinchart@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 BDDB4BD808 for ; Sun, 31 Jan 2021 18:17:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 59243683E0; Sun, 31 Jan 2021 19:17:50 +0100 (CET) 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="XcO6DvCK"; 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 44060683D0 for ; Sun, 31 Jan 2021 19:17:47 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CED7B813 for ; Sun, 31 Jan 2021 19:17:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1612117067; bh=TfzdSlaQsQ8zYZbBfJMLhBO3eZ20WrPDWWeyelTBvCE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XcO6DvCKC+pyLN6y4Idi8GlQ0NpXpSGelT8EDanDgiPEKMcYMy4lGDHLxlWzAnGsp K2K51SzmnSjbpitJjZdTH8COe0+vswScQg9WnYbRltDl+RvWu2UVUqhVv6/Zptnbiw hVBrR/LsKuSJo/wsDhGq9BDq/Fd1TBaRo/E2LH44= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 31 Jan 2021 20:17:21 +0200 Message-Id: <20210131181722.5410-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210131181722.5410-1-laurent.pinchart@ideasonboard.com> References: <20210131181722.5410-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] libcamera: camera_sensor: Restrict sensor info to raw sensors 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" YUV sensors don't provide the necessary information to fill CameraSensorInfo, as they include an ISP and provide a higher-level API that doesn't always expose low-level information. The CameraSensor class makes low-level V4L2 controls mandatory for all sensors, which prevents usage of YUV sensors with the simple pipeline handler. Make CameraSensor::sensorInfo() available for raw sensors only. This won't introduce any regression in pipeline handlers that currently use the sensorInfo() function as they all operate with raw sensors, and won't be a limitation for the simple pipeline handler as well as it doesn't use sensor info. If part of the sensor info (such as the active pixel array size for instance) becomes useful to expose for YUV sensors in the future, the sensorInfo() function can be extended to report that information only and skip data that is only available for raw sensors. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Documentation/sensor_driver_requirements.rst | 2 +- src/libcamera/camera_sensor.cpp | 59 ++++++++++++-------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/Documentation/sensor_driver_requirements.rst b/Documentation/sensor_driver_requirements.rst index 6dcd4e68d64d..64e00fd5fc7c 100644 --- a/Documentation/sensor_driver_requirements.rst +++ b/Documentation/sensor_driver_requirements.rst @@ -22,7 +22,7 @@ Mandatory Requirements The sensor driver is assumed to be fully compliant with the V4L2 specification. -The sensor driver shall support the following V4L2 controls: +For RAW sensors, the sensor driver shall support the following V4L2 controls: * `V4L2_CID_EXPOSURE`_ * `V4L2_CID_HBLANK`_ diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 35312857ff90..10713d3a0c29 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -246,27 +246,6 @@ int CameraSensor::init() int CameraSensor::validateSensorDriver() { - /* - * Make sure the sensor driver supports the mandatory controls - * required by the CameraSensor class. - */ - const std::vector mandatoryControls{ - V4L2_CID_EXPOSURE, - V4L2_CID_HBLANK, - V4L2_CID_PIXEL_RATE, - }; - - ControlList ctrls = subdev_->getControls(mandatoryControls); - if (ctrls.empty()) { - LOG(CameraSensor, Error) - << "Mandatory V4L2 controls not available"; - LOG(CameraSensor, Error) - << "The sensor kernel driver needs to be fixed"; - LOG(CameraSensor, Error) - << "See Documentation/sensor_driver_requirements.rst in the libcamera sources for more information"; - return -EINVAL; - } - /* * Optional controls are used to register optional sensor properties. If * not present, some values will be defaulted. @@ -276,7 +255,7 @@ int CameraSensor::validateSensorDriver() V4L2_CID_CAMERA_SENSOR_ROTATION, }; - ctrls = subdev_->getControls(optionalControls); + ControlList ctrls = subdev_->getControls(optionalControls); if (ctrls.empty()) LOG(CameraSensor, Debug) << "Optional V4L2 controls not supported"; @@ -326,6 +305,30 @@ int CameraSensor::validateSensorDriver() << "See Documentation/sensor_driver_requirements.rst in the libcamera sources for more information"; } + if (!bayerFormat_) + return 0; + + /* + * For raw sensors, make sure the sensor driver supports the controls + * required by the CameraSensor class. + */ + const std::vector mandatoryControls{ + V4L2_CID_EXPOSURE, + V4L2_CID_HBLANK, + V4L2_CID_PIXEL_RATE, + }; + + ctrls = subdev_->getControls(mandatoryControls); + if (ctrls.empty()) { + LOG(CameraSensor, Error) + << "Mandatory V4L2 controls not available"; + LOG(CameraSensor, Error) + << "The sensor kernel driver needs to be fixed"; + LOG(CameraSensor, Error) + << "See Documentation/sensor_driver_requirements.rst in the libcamera sources for more information"; + return -EINVAL; + } + return 0; } @@ -662,13 +665,21 @@ int CameraSensor::setControls(ControlList *ctrls) * \brief Assemble and return the camera sensor info * \param[out] info The camera sensor info * - * The CameraSensorInfo content is assembled by inspecting the currently - * applied sensor configuration and the sensor static properties. + * This function fills \a info with information that describes the camera sensor + * and its current configuration. The information combines static data (such as + * the the sensor model or active pixel array size) and data specific to the + * current sensor configuration (such as the line length and pixel rate). + * + * Sensor information is only available for raw sensors. When called for a YUV + * sensor, this function returns -EINVAL. * * \return 0 on success, a negative error code otherwise */ int CameraSensor::sensorInfo(CameraSensorInfo *info) const { + if (!bayerFormat_) + return -EINVAL; + info->model = model(); /* From patchwork Sun Jan 31 18:17:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11075 X-Patchwork-Delegate: laurent.pinchart@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 52BADBD808 for ; Sun, 31 Jan 2021 18:17:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E298683D9; Sun, 31 Jan 2021 19:17:51 +0100 (CET) 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="G+4r1oL1"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 968D5683D0 for ; Sun, 31 Jan 2021 19:17:47 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 38F9C8A0 for ; Sun, 31 Jan 2021 19:17:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1612117067; bh=dcJwG2XpfNR/G2aAvoQAU0d4wh+95hkGxA1ahstmEqw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=G+4r1oL1gaRk7g5PwUj7pvYkLXOh/GBDymHH9bTCFb9fvObTcL2RtS5ffT0dnKjqk wnVoBnvBywFDFbOk671CVLFHn1hW/c7kqkyJ0AJLcLdQAuMTirU0+MqLNCxaCYoGYN x/NECPL7UAL41jgs+PUUPNt14GYxdsOH/42tcGNg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 31 Jan 2021 20:17:22 +0200 Message-Id: <20210131181722.5410-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210131181722.5410-1-laurent.pinchart@ideasonboard.com> References: <20210131181722.5410-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] libcamera: camera_sensor: Check control availability from idmap 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 presence of mandatory and optional controls is checked in CameraSensor::validateSensorDriver() by trying to retrieve them. This cases an error message to be printed in the V4L2Device class if an optional control isn't present, while this isn't an error. To fix this, use the control idmap reported by the V4L2Device to check for control availability. The function can now print the whole list of missing controls, making debugging easier. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 10713d3a0c29..85813befbf58 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -250,14 +250,18 @@ int CameraSensor::validateSensorDriver() * Optional controls are used to register optional sensor properties. If * not present, some values will be defaulted. */ - const std::vector optionalControls{ + static constexpr uint32_t optionalControls[] = { V4L2_CID_CAMERA_ORIENTATION, V4L2_CID_CAMERA_SENSOR_ROTATION, }; - ControlList ctrls = subdev_->getControls(optionalControls); - if (ctrls.empty()) - LOG(CameraSensor, Debug) << "Optional V4L2 controls not supported"; + const ControlIdMap &controls = subdev_->controls().idmap(); + for (uint32_t ctrl : optionalControls) { + if (!controls.count(ctrl)) + LOG(CameraSensor, Debug) + << "Optional V4L2 control " << utils::hex(ctrl) + << " not supported"; + } /* * Make sure the required selection targets are supported. @@ -312,21 +316,28 @@ int CameraSensor::validateSensorDriver() * For raw sensors, make sure the sensor driver supports the controls * required by the CameraSensor class. */ - const std::vector mandatoryControls{ + static constexpr uint32_t mandatoryControls[] = { V4L2_CID_EXPOSURE, V4L2_CID_HBLANK, V4L2_CID_PIXEL_RATE, }; - ctrls = subdev_->getControls(mandatoryControls); - if (ctrls.empty()) { - LOG(CameraSensor, Error) - << "Mandatory V4L2 controls not available"; + err = 0; + for (uint32_t ctrl : mandatoryControls) { + if (!controls.count(ctrl)) { + LOG(CameraSensor, Error) + << "Mandatory V4L2 control " << utils::hex(ctrl) + << " not available"; + err = -EINVAL; + } + } + + if (err) { LOG(CameraSensor, Error) << "The sensor kernel driver needs to be fixed"; LOG(CameraSensor, Error) << "See Documentation/sensor_driver_requirements.rst in the libcamera sources for more information"; - return -EINVAL; + return err; } return 0;