From patchwork Tue Apr 6 10:40:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 11844 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 304A3C0DA5 for ; Tue, 6 Apr 2021 10:41:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E94706877C; Tue, 6 Apr 2021 12:41:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="f5qbJ1XQ"; dkim-atps=neutral Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A336860518 for ; Tue, 6 Apr 2021 12:40:59 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id u17so14857705ejk.2 for ; Tue, 06 Apr 2021 03:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iW6Slu5SHB6NZU7CidwsLoo0btcdnJVJJ2S8lR/hWDE=; b=f5qbJ1XQh4pKT9oetmaw1elDiJyL4AXtUQj8WUEK8ajCQ62RDE4Ah7F8xH0TDaX2uF Gv8KKBOEzc/xFY8HIWwFDlDiPHtM2G1k76Brm53xGtIbCbtdtpOOmL/lJhfGz30HU3j/ w2c0s8H6fUuKn9YHFtL6ZHpCWUt5DJmEU0sq0Pu1KDoJWdGRWUxaPlJI0mUbCb64o7yv Re/+bZ6vP9HNHi2ZjZn0eSAlyHqVJrxC5ZFGksRPiVL99H78+8WHYJh5tPOmBNwWW2J3 HwSw6tdiNYHt2559NXGa7l59MxDSlhuJcxqVQAVoqC+R86tbX4ke4dkCFEE3j8hvGyfX GarA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iW6Slu5SHB6NZU7CidwsLoo0btcdnJVJJ2S8lR/hWDE=; b=YGmLM7qHuqmCRFlJt9JUzzuEbgBg313g1GN8etVqwkPNy1TXi2qfotdYiChyxIlPfF JikcgvZHti7lSL/AFW1KKT02MAfpIcgYYd7GZOq2QjI15gCZ2qySOlYGOKjZkeEAvJQy i573LjBwNl5cLRKU75mF48lG0jt6s/u9hX0zNDBT2yfHsxavbJUXbuD7yPb45TIDV4tS 7TqggT3LkV3pcYPi00QoGe8grVCd9AtS4injVfCHMVZ4wb0BSHR48+07M2ICogsm1kFK gCsQrEwHXhl/3g/K9Kpz85Apk+J5g3NFMSw6h8iKBG8UB9BCX4xuPHG9A2GcP14bPzOp TS0A== X-Gm-Message-State: AOAM533IL0EZaHKQn2tV9n4+jGbDoPXmJoft3xaYweZzNph14DDR0BYn /qlstiasrFHnifnwIcVBXqSbuzJRVh8dHQ== X-Google-Smtp-Source: ABdhPJxC+XqzXIcFcp9CgQp+y0zxpaRov3HU4PVkzVvqJ3WbiD7wcPj+QHC3hpK2ChSFb7eP+Ws4mQ== X-Received: by 2002:a17:906:7ac9:: with SMTP id k9mr33844634ejo.229.1617705658960; Tue, 06 Apr 2021 03:40:58 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id df8sm4068486edb.4.2021.04.06.03.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 03:40:58 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Tue, 6 Apr 2021 11:40:49 +0100 Message-Id: <20210406104050.23814-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210406104050.23814-1-david.plowman@raspberrypi.com> References: <20210406104050.23814-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] libcamera: camera_sensor: Fix frame lengths calculated by sensorInfo() 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 minimum and maximum vblanking can change when a new format is applied to the sensor subdevice, so be sure to retrieve up-to-date values. The V4L2Device acquires the new updateControlInfos() method to perform this function, and which the CameraSensor calls automatically if its setFormat method is used to update the sensor. However, not all pipeline handlers invoke the setFormat method directly, so the new method must be made publicly available for pipeline handlers to call if they need to. Signed-off-by: David Plowman Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- include/libcamera/internal/camera_sensor.h | 2 ++ include/libcamera/internal/v4l2_device.h | 2 ++ src/libcamera/camera_sensor.cpp | 31 +++++++++++++++++++++- src/libcamera/v4l2_device.cpp | 26 ++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 3e98f71b..c94744f0 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -68,6 +68,8 @@ public: const ControlList &properties() const { return properties_; } int sensorInfo(CameraSensorInfo *info) const; + void updateControlInfos(); + protected: std::string logPrefix() const override; diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index d006bf68..274cbe65 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -41,6 +41,8 @@ public: int setFrameStartEnabled(bool enable); Signal frameStart; + void updateControlInfos(); + protected: V4L2Device(const std::string &deviceNode); ~V4L2Device(); diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index f7ed91d9..5dbe47a7 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -656,15 +656,30 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector &mbu /** * \brief Set the sensor output format * \param[in] format The desired sensor output format + * + * The sensor output format is set. The ranges of any controls associated + * with the sensor are also updated. + * * \return 0 on success or a negative error code otherwise */ int CameraSensor::setFormat(V4L2SubdeviceFormat *format) { - return subdev_->setFormat(pad_, format); + int ret = subdev_->setFormat(pad_, format); + + if (ret == 0) + updateControlInfos(); + + return ret; } /** * \brief Retrieve the supported V4L2 controls and their information + * + * Pipeline handlers that do not change the sensor format using the + * CameraSensor::setFormat method may need to call + * CameraSensor::updateControlInfos beforehand, to ensure all the control + * ranges are up to date. + * * \return A map of the V4L2 controls supported by the sensor */ const ControlInfoMap &CameraSensor::controls() const @@ -750,6 +765,11 @@ int CameraSensor::setControls(ControlList *ctrls) * Sensor information is only available for raw sensors. When called for a YUV * sensor, this function returns -EINVAL. * + * Pipeline handlers that do not change the sensor format using the + * CameraSensor::setFormat method may need to call + * CameraSensor::updateControlInfos beforehand, to ensure all the control + * ranges are up to date. + * * \return 0 on success, a negative error code otherwise */ int CameraSensor::sensorInfo(CameraSensorInfo *info) const @@ -821,6 +841,15 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const return 0; } +/** + * \fn void CameraSensor::updateControlInfos() + * \brief Update the sensor's ControlInfos in case they have changed + */ +void CameraSensor::updateControlInfos() +{ + subdev_->updateControlInfos(); +} + std::string CameraSensor::logPrefix() const { return "'" + entity_->name() + "'"; diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index decd19ef..9678962c 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -514,6 +514,32 @@ void V4L2Device::listControls() controls_ = std::move(ctrls); } +/* + * \brief Update the control information that was previously stored by + * listControls(). Some parts of this information, such as min and max + * values of some controls, are liable to change when a new format is set. + */ +void V4L2Device::updateControlInfos() +{ + for (auto &controlId : controlIds_) { + unsigned int id = controlId->id(); + + struct v4l2_query_ext_ctrl ctrl = {}; + ctrl.id = id; + + if (ioctl(VIDIOC_QUERY_EXT_CTRL, &ctrl)) { + LOG(V4L2, Debug) + << "Could not refresh control " + << utils::hex(ctrl.id); + continue; + } + + /* Assume these are present - listControls() made them. */ + controlInfo_[id] = ctrl; + controls_.at(controlId.get()) = V4L2ControlInfo(ctrl); + } +} + /* * \brief Update the value of the first \a count V4L2 controls in \a ctrls using * values in \a v4l2Ctrls