From patchwork Wed May 5 13:53:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 12194 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 54CC5BDE7D for ; Wed, 5 May 2021 13:53:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 657496891C; Wed, 5 May 2021 15:53:15 +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="dpCaB3vA"; dkim-atps=neutral Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 347D968909 for ; Wed, 5 May 2021 15:53:14 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id t11-20020a05600c198bb02901476e13296aso1200200wmq.0 for ; Wed, 05 May 2021 06:53:14 -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=rDPglO4GDcKMyBaoO/q0/6fSNdkDChx5+gSNjAfnVIM=; b=dpCaB3vASuGZIDr5jB03Dvu4IdFM6J8u2sydmlvoYA1xzmWnX+l9YDjF8MHNFiZvkR ASpvHDaELPEWdnf/Bd4UUpdlEGtlYw999UmriNJX0n3Hf0/jsZYMD4aHP1sKX3zvblYM M8XjwWPI1LgbliouWyfUkYm+ryxm2amXmI1QTrcDG/j6YpGu7yZ6JZA1ChEWjgu8ZtHu hT/bqwAthATKGrtWPzsI4TBiH6uC0WtKMkQTX/7JE5YKSgpPzx/OtrMPnFADKSwBe/Sv dQ4Lnk+TOGLLJ173XOih4nXouKSEFJNAKniDwi/X2FbO2gWpAI6cqXVOff2/y+mOh2a4 5Ljw== 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=rDPglO4GDcKMyBaoO/q0/6fSNdkDChx5+gSNjAfnVIM=; b=HWyM7/rGjIjl7Bbtgk68oXU6q6pyrWV9nWb6jBBPUoOu2XNcIQoH2fXDIrxXig61Lo E0giXjd9kBOJZBdJ4aigiR3KmrvSZvMqK7TStohP48+i7o9XWhm5RrjNcqSDZ2x1IYgc zqL+SAc5vlDDcD+Zel2Gpv8hBH8cC783m9zy/3lEPJjSp+hl+VOc9rCkjyj4btqNGdqB QB7TDfbTuSyPQZruu/MyV5SfOMjuSGhgHkQn9Fj7dutbB9yCS8D/ECjf55CoMx1DtOHl c6jzYJUvehXcgjVm42ms9yijk0ZSTMhJLy8CvfR6zZJrsIDwYT3iLXzVQBvtsXhz56RB 5V4Q== X-Gm-Message-State: AOAM532HALT++0i8gEWvWJ32JCG4HZ47cML/7oJxEVj5BbdUxhomrpHS q6mibgiXiBUINdt8jZtI7mlraPYhUyBzAA== X-Google-Smtp-Source: ABdhPJztX/fHc6v+ODS1H8VdSS4h/6epz2ZLUlk8r8iZOn17tlK2egmeUfRH6F+/IK+5bHAPaSXdYA== X-Received: by 2002:a7b:c8ca:: with SMTP id f10mr33631238wml.118.1620222793565; Wed, 05 May 2021 06:53:13 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id q10sm5901645wmc.31.2021.05.05.06.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 06:53:13 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 5 May 2021 14:53:07 +0100 Message-Id: <20210505135308.1404-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210505135308.1404-1-david.plowman@raspberrypi.com> References: <20210505135308.1404-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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: , Cc: Kieran Bingham 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 updateControlInfo() 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 Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 2 ++ include/libcamera/internal/v4l2_device.h | 2 ++ src/libcamera/camera_sensor.cpp | 32 ++++++++++++++++++- src/libcamera/v4l2_device.cpp | 37 ++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 3e98f71b..6ce513b7 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 updateControlInfo(); + protected: std::string logPrefix() const override; diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index 087f07e7..5ba9b23b 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -42,6 +42,8 @@ public: int setFrameStartEnabled(bool enable); Signal frameStart; + void updateControlInfo(); + protected: V4L2Device(const std::string &deviceNode); ~V4L2Device(); diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 2887bb69..322678c8 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 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) + return ret; + + updateControlInfo(); + return 0; } /** * \brief Retrieve the supported V4L2 controls and their information + * + * Control information is updated automatically to reflect the current sensor + * configuration when the setFormat() function is called, without invalidating + * any iterator on the ControlInfoMap. A manual update can also be forced by + * calling the updateControlInfo() function for pipeline handlers that change + * the sensor configuration wihtout using setFormat(). + * * \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::updateControlInfo 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,16 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const return 0; } +/** + * \fn void CameraSensor::updateControlInfo() + * \brief Update the sensor's ControlInfoMap in case they have changed + * \sa V4L2Device::updateControlInfo() + */ +void CameraSensor::updateControlInfo() +{ + subdev_->updateControlInfo(); +} + std::string CameraSensor::logPrefix() const { return "'" + entity_->name() + "'"; diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 397029ac..515cbdfe 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -511,6 +511,43 @@ void V4L2Device::listControls() controls_ = std::move(ctrls); } +/** +* \brief Update the information for all device controls + * + * The V4L2Device class caches information about all controls supported by the + * device and exposes it through the controls() and controlInfo() functions. + * Control information may change at runtime, for instance when formats on a + * subdev are modified. When this occurs, this function can be used to refresh + * control information. The information is refreshed in-place, all pointers to + * v4l2_query_ext_ctrl instances previously returned by controlInfo() and + * iterators to the ControlInfoMap returned by controls() remain valid. + * + * Note that control information isn't refreshed automatically is it may be an + * expensive operation. The V4L2Device users are responsible for calling this + * function when required, based on their usage pattern of the class. + */ +void V4L2Device::updateControlInfo() +{ + for (auto &[controlId, info] : controls_) { + unsigned int id = controlId->id(); + + /* + * Assume controlInfo_ has a corresponding entry, as it has been + * generated by listControls(). + */ + struct v4l2_query_ext_ctrl &ctrl = controlInfo_[id]; + + if (ioctl(VIDIOC_QUERY_EXT_CTRL, &ctrl)) { + LOG(V4L2, Debug) + << "Could not refresh control " + << utils::hex(id); + continue; + } + + info = V4L2ControlInfo(ctrl); + } +} + /* * \brief Update the value of the first \a count V4L2 controls in \a ctrls using * values in \a v4l2Ctrls From patchwork Wed May 5 13:53:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 12195 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 36C15BDE7C for ; Wed, 5 May 2021 13:53:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ABE1B68919; Wed, 5 May 2021 15:53:16 +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="ZjBmndS/"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C8C0468901 for ; Wed, 5 May 2021 15:53:14 +0200 (CEST) Received: by mail-wr1-x429.google.com with SMTP id t18so1951194wry.1 for ; Wed, 05 May 2021 06:53:14 -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=Nnuaul9JxLvXBFAxzfREl6f2jmdSNj5M51MWow4y9o0=; b=ZjBmndS/+WJx/D2LuItCM8XWKCe/ELtX8ilaAT206Ucxq0rcL4hVEmQ0Z3eXVQ0pm7 6pdOL57hR5JJoXWvXErt+rQrQ5LBxTOGXQ0CVX+daxW+9HejIS+/n0d4koH7c08rWuU7 zKv6kpyQ7gc5cEDPNJUdUds4Ehm4txLJOyACY2ulaqzh/Bsg4ENEeyA7yCAzVmrH416D yJ6BvkJBkcknOZZye/ptryDhhRLJJ4OjZIXNVXf9IODfxINpG+ol+k4tU6s9LUwyY5Od 9Aa63kHz+eaK+lsMxufNfPWYPnLzHppGtl1DRUAUWhUc+vQaJyK9jHM4LIcyTKzY1frK njfw== 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=Nnuaul9JxLvXBFAxzfREl6f2jmdSNj5M51MWow4y9o0=; b=GSvE/T5LHQx5ySXxFlvtecJ0gj/Ni7Mu7oKbigyRo6I5vDaKHqhMfmZdO4bBHmKpF2 mlSdYXanwxtCX6zJWFT7xUreWs1OnseVknc5jQxRdmfGZIr6NOlWwZYILatwkeb1PsO/ iLNAW2DnB9cNAEjPw9hm4t+HX+Ilb2kICnyVLTpWWuhBrHaloBhID2pWZLs/2Bxg/KlC fzKJWzDQSlu+duIQ43y5xyb31qynMB+QVPPCuKj/CI6gekXss6HZMYTmJF8+Mha8QCAS xIULMl4HD40defL/ifjv/4bTkgUNaue5lOHzzz2OYbHW55McKv4AsALlXhh0L0Ovq2LB Eesw== X-Gm-Message-State: AOAM533jH8AMZG5oISo+GrQEL1OUkXMWat4yaAuSPSULBZPUw/bgXkSO oIdo3rB0+9ZGUv961Am2NAeWKZXnhXEJGA== X-Google-Smtp-Source: ABdhPJw9D7jjwFWkAVsU36vahtT61oBOHHH2hRUTfKsriGq/MK3WFaY7guU2lb/riQ4fm3xQZnkGCg== X-Received: by 2002:a05:6000:1789:: with SMTP id e9mr39414015wrg.110.1620222794386; Wed, 05 May 2021 06:53:14 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id q10sm5901645wmc.31.2021.05.05.06.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 06:53:13 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 5 May 2021 14:53:08 +0100 Message-Id: <20210505135308.1404-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210505135308.1404-1-david.plowman@raspberrypi.com> References: <20210505135308.1404-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/2] libcamera: pipeline: raspberrypi: Update ControlInfos after sensor format change 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 Raspberry Pi pipeline handler does not update the sensor format using CameraSensor::setFormat, so it must manually force the update of the associated ControlInfos. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 2a917455..6288108d 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -608,6 +608,13 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) if (ret) return ret; + /* + * The control ranges associated with the sensor may need updating + * after a format change. + * \todo Use the CameraSensor::setFormat API instead. + */ + data->sensor_->updateControlInfo(); + LOG(RPI, Info) << "Sensor: " << camera->id() << " - Selected mode: " << sensorFormat.toString();