From patchwork Tue Mar 30 16:57:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 11797 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 DB159C0DA3 for ; Tue, 30 Mar 2021 16:57:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9E81668786; Tue, 30 Mar 2021 18:57:53 +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="KqrRJhXI"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 89576602DB for ; Tue, 30 Mar 2021 18:57:50 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id w203-20020a1c49d40000b029010c706d0642so1332053wma.0 for ; Tue, 30 Mar 2021 09:57:50 -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=QHDoLoAUL/R93Owuukrgf+27dpMKbdjQ6Sz/zQdv/9c=; b=KqrRJhXIVEN4EiZXKz5aMaMwCfTKW31n1PhNJxkcOEyEBMetfGsrzECTyOOA36GUhy Wrl1TumhN4Vu5QTd1AiIbWGf4DLsDnXjTrk9YlB1hrgY6GTU6mNDonaIu4AJe2RVp3Bv dpEP32yYrAcqKkh7X4SfDFpsuRvlvdcSsPuxhKC8C5Nv8DkQB7clf2QVk47/DZ67Qx8u iOcd3zV9u208PDSI6EUBT4SlVpQxq6VE0NWYwR+DJoTJ0CIxPKUV9h81Y/s20zzaqvOj 7bjYwiSRtmv4BpY7mtASaLDmiSwNmR/CjFwcQ8gQdSbDUyilqlQ8wWw4aVRugfYWLTUJ E/LQ== 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=QHDoLoAUL/R93Owuukrgf+27dpMKbdjQ6Sz/zQdv/9c=; b=o0LWnI6XPcf+io0xIXuZtG8H08dkgrp2BbNoa85r9AMS1dRr3oXTYm5gHLqsvVA+I4 ycIhsZ0q3cytApjeaRD8YMRUo1t6IQQ8NmKSnBjTRt5PPXZTEPunSOq57VTzjZVBqqur SOlU1Ikm36XlS5hxXF5YhmgY49V6Q4BbYT6O3+tgWf6SfOLis+7RsRaxHLQJPOndgBXD GvIJ7UsWqmyTwWxFjIR4fuL22UpMrr6AOEFQfwsay+OyyvLhjFzj1uGjk+giGQuyfvRk fKvrVEqtgG7yBOfUxTJrRFllMF2mVC3AdVNxyxW86ss9B8GXYMdLiFDo39RsqGrxYP5F s2jQ== X-Gm-Message-State: AOAM531UR8Yo4sBCHlCs0W4gmOBsEbxSkdtbjOyCC8WMXQOmGKix5Qfo FLCSLW7fBd8tM3RDdt2NRrs4i4ona1B5Ew== X-Google-Smtp-Source: ABdhPJzxTwtArI1HrN9MgPnoZHwP19VwgL7LdmvU2G7USBzDnHuYhS+7CLRYQHYZARWr8mavxC9gBQ== X-Received: by 2002:a7b:c396:: with SMTP id s22mr4961505wmj.38.1617123470091; Tue, 30 Mar 2021 09:57:50 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id s13sm3695448wrv.80.2021.03.30.09.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Mar 2021 09:57:49 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Mar 2021 17:57:43 +0100 Message-Id: <20210330165743.4924-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210330165743.4924-1-david.plowman@raspberrypi.com> References: <20210330165743.4924-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/1] 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 refreshControls() method to perform this function. Note that not all pipeline handlers invoke the subdevice's setFormat method directly, so the new method must be made publicly available. Signed-off-by: David Plowman --- include/libcamera/internal/v4l2_device.h | 2 ++ src/libcamera/camera_sensor.cpp | 7 +++++++ src/libcamera/v4l2_device.cpp | 26 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index d006bf68..6efcb0db 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 refreshControls(); + protected: V4L2Device(const std::string &deviceNode); ~V4L2Device(); diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index f7ed91d9..9f99ce3e 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -796,6 +796,13 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const info->bitsPerPixel = format.bitsPerPixel(); info->outputSize = format.size; + /* + * Some controls, specifically the vblanking, may have different min + * or max values if the sensor format has been changed since it was + * opened, so be sure to update them first. + */ + subdev_->refreshControls(); + /* * Retrieve the pixel rate, line length and minimum/maximum frame * duration through V4L2 controls. Support for the V4L2_CID_PIXEL_RATE, diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index decd19ef..6d396f89 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::refreshControls() +{ + 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