{"id":12194,"url":"https://patchwork.libcamera.org/api/patches/12194/?format=json","web_url":"https://patchwork.libcamera.org/patch/12194/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210505135308.1404-2-david.plowman@raspberrypi.com>","date":"2021-05-05T13:53:07","name":"[libcamera-devel,v3,1/2] libcamera: camera_sensor: Fix frame lengths calculated by sensorInfo()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"0640e09fa183f040f180a537cfd5da1229aea3c4","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12194/mbox/","series":[{"id":1998,"url":"https://patchwork.libcamera.org/api/series/1998/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1998","date":"2021-05-05T13:53:06","name":"Fix CameraSensor::sensorInfo by updating VBLANK ControlInfo","version":3,"mbox":"https://patchwork.libcamera.org/series/1998/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12194/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12194/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 54CC5BDE7D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 May 2021 13:53:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 657496891C;\n\tWed,  5 May 2021 15:53:15 +0200 (CEST)","from mail-wm1-x330.google.com (mail-wm1-x330.google.com\n\t[IPv6:2a00:1450:4864:20::330])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 347D968909\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 May 2021 15:53:14 +0200 (CEST)","by mail-wm1-x330.google.com with SMTP id\n\tt11-20020a05600c198bb02901476e13296aso1200200wmq.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 05 May 2021 06:53:14 -0700 (PDT)","from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tq10sm5901645wmc.31.2021.05.05.06.53.12\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 05 May 2021 06:53:13 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"dpCaB3vA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=rDPglO4GDcKMyBaoO/q0/6fSNdkDChx5+gSNjAfnVIM=;\n\tb=dpCaB3vASuGZIDr5jB03Dvu4IdFM6J8u2sydmlvoYA1xzmWnX+l9YDjF8MHNFiZvkR\n\tASpvHDaELPEWdnf/Bd4UUpdlEGtlYw999UmriNJX0n3Hf0/jsZYMD4aHP1sKX3zvblYM\n\tM8XjwWPI1LgbliouWyfUkYm+ryxm2amXmI1QTrcDG/j6YpGu7yZ6JZA1ChEWjgu8ZtHu\n\thT/bqwAthATKGrtWPzsI4TBiH6uC0WtKMkQTX/7JE5YKSgpPzx/OtrMPnFADKSwBe/Sv\n\tdQ4Lnk+TOGLLJ173XOih4nXouKSEFJNAKniDwi/X2FbO2gWpAI6cqXVOff2/y+mOh2a4\n\t5Ljw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=rDPglO4GDcKMyBaoO/q0/6fSNdkDChx5+gSNjAfnVIM=;\n\tb=HWyM7/rGjIjl7Bbtgk68oXU6q6pyrWV9nWb6jBBPUoOu2XNcIQoH2fXDIrxXig61Lo\n\tE0giXjd9kBOJZBdJ4aigiR3KmrvSZvMqK7TStohP48+i7o9XWhm5RrjNcqSDZ2x1IYgc\n\tzqL+SAc5vlDDcD+Zel2Gpv8hBH8cC783m9zy/3lEPJjSp+hl+VOc9rCkjyj4btqNGdqB\n\tQB7TDfbTuSyPQZruu/MyV5SfOMjuSGhgHkQn9Fj7dutbB9yCS8D/ECjf55CoMx1DtOHl\n\tc6jzYJUvehXcgjVm42ms9yijk0ZSTMhJLy8CvfR6zZJrsIDwYT3iLXzVQBvtsXhz56RB\n\t5V4Q==","X-Gm-Message-State":"AOAM532HALT++0i8gEWvWJ32JCG4HZ47cML/7oJxEVj5BbdUxhomrpHS\n\tq6mibgiXiBUINdt8jZtI7mlraPYhUyBzAA==","X-Google-Smtp-Source":"ABdhPJztX/fHc6v+ODS1H8VdSS4h/6epz2ZLUlk8r8iZOn17tlK2egmeUfRH6F+/IK+5bHAPaSXdYA==","X-Received":"by 2002:a7b:c8ca:: with SMTP id\n\tf10mr33631238wml.118.1620222793565; \n\tWed, 05 May 2021 06:53:13 -0700 (PDT)","From":"David Plowman <david.plowman@raspberrypi.com>","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\n\tframe lengths calculated by sensorInfo()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"Kieran Bingham <kieran.bingham@raspberrypi.com>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The minimum and maximum vblanking can change when a new format is\napplied to the sensor subdevice, so be sure to retrieve up-to-date\nvalues.\n\nThe V4L2Device acquires the new updateControlInfo() method to perform\nthis function, and which the CameraSensor calls automatically if its\nsetFormat method is used to update the sensor.\n\nHowever, not all pipeline handlers invoke the setFormat method\ndirectly, so the new method must be made publicly available for\npipeline handlers to call if they need to.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Kieran Bingham <kieran.bingham@raspberrypi.com>\n---\n include/libcamera/internal/camera_sensor.h |  2 ++\n include/libcamera/internal/v4l2_device.h   |  2 ++\n src/libcamera/camera_sensor.cpp            | 32 ++++++++++++++++++-\n src/libcamera/v4l2_device.cpp              | 37 ++++++++++++++++++++++\n 4 files changed, 72 insertions(+), 1 deletion(-)","diff":"diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex 3e98f71b..6ce513b7 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -68,6 +68,8 @@ public:\n \tconst ControlList &properties() const { return properties_; }\n \tint sensorInfo(CameraSensorInfo *info) const;\n \n+\tvoid updateControlInfo();\n+\n protected:\n \tstd::string logPrefix() const override;\n \ndiff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\nindex 087f07e7..5ba9b23b 100644\n--- a/include/libcamera/internal/v4l2_device.h\n+++ b/include/libcamera/internal/v4l2_device.h\n@@ -42,6 +42,8 @@ public:\n \tint setFrameStartEnabled(bool enable);\n \tSignal<uint32_t> frameStart;\n \n+\tvoid updateControlInfo();\n+\n protected:\n \tV4L2Device(const std::string &deviceNode);\n \t~V4L2Device();\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 2887bb69..322678c8 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -656,15 +656,30 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu\n /**\n  * \\brief Set the sensor output format\n  * \\param[in] format The desired sensor output format\n+ *\n+ * The ranges of any controls associated with the sensor are also updated.\n+ *\n  * \\return 0 on success or a negative error code otherwise\n  */\n int CameraSensor::setFormat(V4L2SubdeviceFormat *format)\n {\n-\treturn subdev_->setFormat(pad_, format);\n+\tint ret = subdev_->setFormat(pad_, format);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tupdateControlInfo();\n+\treturn 0;\n }\n \n /**\n  * \\brief Retrieve the supported V4L2 controls and their information\n+ *\n+ * Control information is updated automatically to reflect the current sensor\n+ * configuration when the setFormat() function is called, without invalidating\n+ * any iterator on the ControlInfoMap. A manual update can also be forced by\n+ * calling the updateControlInfo() function for pipeline handlers that change\n+ * the sensor configuration wihtout using setFormat().\n+ *\n  * \\return A map of the V4L2 controls supported by the sensor\n  */\n const ControlInfoMap &CameraSensor::controls() const\n@@ -750,6 +765,11 @@ int CameraSensor::setControls(ControlList *ctrls)\n  * Sensor information is only available for raw sensors. When called for a YUV\n  * sensor, this function returns -EINVAL.\n  *\n+ * Pipeline handlers that do not change the sensor format using the\n+ * CameraSensor::setFormat method may need to call\n+ * CameraSensor::updateControlInfo beforehand, to ensure all the control\n+ * ranges are up to date.\n+ *\n  * \\return 0 on success, a negative error code otherwise\n  */\n int CameraSensor::sensorInfo(CameraSensorInfo *info) const\n@@ -821,6 +841,16 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const\n \treturn 0;\n }\n \n+/**\n+ * \\fn void CameraSensor::updateControlInfo()\n+ * \\brief Update the sensor's ControlInfoMap in case they have changed\n+ * \\sa V4L2Device::updateControlInfo()\n+ */\n+void CameraSensor::updateControlInfo()\n+{\n+\tsubdev_->updateControlInfo();\n+}\n+\n std::string CameraSensor::logPrefix() const\n {\n \treturn \"'\" + entity_->name() + \"'\";\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 397029ac..515cbdfe 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -511,6 +511,43 @@ void V4L2Device::listControls()\n \tcontrols_ = std::move(ctrls);\n }\n \n+/**\n+* \\brief Update the information for all device controls\n+ *\n+ * The V4L2Device class caches information about all controls supported by the\n+ * device and exposes it through the controls() and controlInfo() functions.\n+ * Control information may change at runtime, for instance when formats on a\n+ * subdev are modified. When this occurs, this function can be used to refresh\n+ * control information. The information is refreshed in-place, all pointers to\n+ * v4l2_query_ext_ctrl instances previously returned by controlInfo() and\n+ * iterators to the ControlInfoMap returned by controls() remain valid.\n+ *\n+ * Note that control information isn't refreshed automatically is it may be an\n+ * expensive operation. The V4L2Device users are responsible for calling this\n+ * function when required, based on their usage pattern of the class.\n+ */\n+void V4L2Device::updateControlInfo()\n+{\n+\tfor (auto &[controlId, info] : controls_) {\n+\t\tunsigned int id = controlId->id();\n+\n+\t\t/*\n+\t\t * Assume controlInfo_ has a corresponding entry, as it has been\n+\t\t * generated by listControls().\n+\t\t */\n+\t\tstruct v4l2_query_ext_ctrl &ctrl = controlInfo_[id];\n+\n+\t\tif (ioctl(VIDIOC_QUERY_EXT_CTRL, &ctrl)) {\n+\t\t\tLOG(V4L2, Debug)\n+\t\t\t\t<< \"Could not refresh control \"\n+\t\t\t\t<< utils::hex(id);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tinfo = V4L2ControlInfo(ctrl);\n+\t}\n+}\n+\n /*\n  * \\brief Update the value of the first \\a count V4L2 controls in \\a ctrls using\n  * values in \\a v4l2Ctrls\n","prefixes":["libcamera-devel","v3","1/2"]}