From patchwork Sun Jan 24 14:05:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10974 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 01154BD808 for ; Sun, 24 Jan 2021 14:05:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 438F56829F; Sun, 24 Jan 2021 15:05:14 +0100 (CET) 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="OTNPaGlK"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 78CDE6823D for ; Sun, 24 Jan 2021 15:05:12 +0100 (CET) Received: by mail-wm1-x32f.google.com with SMTP id o10so9104342wmc.1 for ; Sun, 24 Jan 2021 06:05:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=n9D4J5SwNdhQcSxAfeArxWLUh8dmYZ/TT2l15nlspHA=; b=OTNPaGlK+pIpm4EP0UgWDz9O3jS84ojE5JIF65XWmC+945nsF+m6FZWlFktsvD6OWn 7ZyK3+4t2F+IWu64ajaUhtB4bAczbzrgYIiRHVTrntaPHFLOYlQhjYxvazef6nBXdRim eCFmTRHEQbvG0CWyykqkjsJ+v1QJQW23Za50qR3tjgU5JxnhyezeQFsaXzAiM++K2PPl +aDqrl6jDTbBF6ciW7VlrKL17VzPHVufIP9AbePxvbs/TmBJwsfx7n853zoixsrZAHL/ Q+GMGD4MJnE9eLn3ACf7rt4eOsrUloEnon6ks+3H7wMCuGeIWX+JXBjwTYeASod/hSSA kOeA== 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:mime-version :content-transfer-encoding; bh=n9D4J5SwNdhQcSxAfeArxWLUh8dmYZ/TT2l15nlspHA=; b=VhtWZfqkzVO2KZXyNC/BXig29C806QmURevjW3/pu9DJjvwd8ucXMYimhaGqKUgL0q rDxg4ZEvu9OGz/lyIs9ZrrvMNqBgAM6zOqaNF0orrMtx0vh/n4MGW2v9r+5BDe1AIBXy VeddGIrgsFtHbfWa4H5P/vIvvOM1zMXLwPcHcxhdwO7JBOFoffwdUnss1YCpY3BS9ydl EGAHYQnZSS9TxFBr7w5TViPmUT4qlLWiuwiletji0VZiXJHzEpw/ZpyQqF1a34Uerpy8 sZB04+ZkwtGyqxaK6n3Y240C44twJQcUkOIJ9MpWebUdeVUjdOtMOQ76O3RsrylvU8LU E9EA== X-Gm-Message-State: AOAM530wpV7BYSkb/oF+mc0s7k4zvpRHSC7VGxvU145E41N7RbA3ziak k1lbCTI/RK1DWXl47zf1J8HUjb/oYGTzqapy X-Google-Smtp-Source: ABdhPJzKIzwahf2sq/uEpxbJ0EFq3qxDVuyOO4n5/uvV57q6xV0DwYBeLNd824bf886bLSGMsNU9Nw== X-Received: by 2002:a1c:4057:: with SMTP id n84mr11915835wma.141.1611497111625; Sun, 24 Jan 2021 06:05:11 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id u16sm19311053wrn.68.2021.01.24.06.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Jan 2021 06:05:10 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Sun, 24 Jan 2021 14:05:03 +0000 Message-Id: <20210124140506.786503-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/4] raspberrypi: Add the correct integer const postfix for FrameDurations 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" At startup, ControlInfoMap::generateIdmap() threw a log message warning that the controls::FrameDurations had a type mismatch based on the min/max values provided in libcamera::RPi::Controls initialiser. Fix this warning by adding and explicit int64_t postfix to the const values for min and max. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/ipa/raspberrypi.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h index 1de36039cee0..4038428bdba4 100644 --- a/include/libcamera/ipa/raspberrypi.h +++ b/include/libcamera/ipa/raspberrypi.h @@ -7,6 +7,8 @@ #ifndef __LIBCAMERA_IPA_INTERFACE_RASPBERRYPI_H__ #define __LIBCAMERA_IPA_INTERFACE_RASPBERRYPI_H__ +#include + #include #include @@ -65,7 +67,7 @@ static const ControlInfoMap Controls = { { &controls::Sharpness, ControlInfo(0.0f, 16.0f, 1.0f) }, { &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) }, { &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) }, - { &controls::FrameDurations, ControlInfo(1000, 1000000000) }, + { &controls::FrameDurations, ControlInfo(INT64_C(1000), INT64_C(1000000000)) }, }; } /* namespace RPi */ From patchwork Sun Jan 24 14:05:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10975 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 12FD6BD808 for ; Sun, 24 Jan 2021 14:05:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9B382682A3; Sun, 24 Jan 2021 15:05:14 +0100 (CET) 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="juKR9ZkP"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 938646829E for ; Sun, 24 Jan 2021 15:05:13 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id c128so8462774wme.2 for ; Sun, 24 Jan 2021 06:05:13 -0800 (PST) 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=Iv2RfYLpcer8K9hi7RY1wi3KewqGhT3EI6OJHgoarH8=; b=juKR9ZkPWshgNscqXhbTtuWv3EEeEZ84kubPmpxkBt2M9/yaLR+B2cAKuBwmQrq7Xo YUSioQv22w5nbNUhuntk/+yOeWev//5KI4l5CEO+nIf8kgbrUJcRTxrYFsGCn8KI5Wm+ 4Y//SNf9BTsk67dw1PypnrDUOtLT2y3ADA4tMHR1gbqBcROZJzjAjC8GxtNzlKFkxs7m 9/IBrzQ4215RmrApvjckC+U+oRg9mK6foeXw60JcvDHp2fp65R1DVU+10ngiB7ItPh2I lLlJX0eV4vkJgDULwLH8XKArvsBH4yx167h1+IDNQS110t26Nh4qTkK21lUnKvoAga7J FcCg== 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=Iv2RfYLpcer8K9hi7RY1wi3KewqGhT3EI6OJHgoarH8=; b=G9h4FJREYJsKZlqW4Xh9/2Q5oD1ERswJV1gb3q7aPt7LbKECbmYciBVMg2zX98Rhpc u9dPRm0ZGDYTpSChnlKWuduWj6auKakJbNbpqGnd9/2yTFegA4nJxWGwOLt1w1fIQPb8 18DGw1hcoffexSSgFMFFNR2lMizYA2fNWyD1LboeG4HSSLsktYiUs+ydobWv3sKfmzDg MVRnKvVJ4e131TtOUljb7etmmkW9211jCUFWNm10Bq2E4QaUM9MMbRYS00sx6Tiv1TMm VZ4+bxyp2+6Fi05AIKoG6unry5VgfSOAKUc5eX2rYHlNW/Yy3xZgnRi5Y2/ttHxSqW0u zWFA== X-Gm-Message-State: AOAM530504QOENUMb7WVxBAOPOglf8UzRYTGvpR5DxK5ZwPZaWbjda1l PwAhkfoAUXc2H3067FEVwX2ZmriG7/j6WBzM X-Google-Smtp-Source: ABdhPJyMCfG87nmPA8ZKKxdx6C+wMoySbNjllbbqd9pQpzLCUUBzZidKSUYOXNfTPMbEOEok+lXWqg== X-Received: by 2002:a7b:c115:: with SMTP id w21mr1193163wmi.114.1611497112883; Sun, 24 Jan 2021 06:05:12 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id u16sm19311053wrn.68.2021.01.24.06.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Jan 2021 06:05:12 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Sun, 24 Jan 2021 14:05:04 +0000 Message-Id: <20210124140506.786503-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210124140506.786503-1-naush@raspberrypi.com> References: <20210124140506.786503-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/4] ipa: raspberrypi: Limit the calculated vblank based on the sensor mode 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 existing framerate/vblank calculations did not account for the sensor mode limits. This commit extracts vblank limits from the sensor v4l2 controls, and stores it in the camera modes structure. Exposure and vblank value calculations now use values clamped to the sensor mode limits. The libcamera::controls::FrameDurations metadata return values now reflect the minimum and maximum after clamping. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- src/ipa/raspberrypi/cam_helper.cpp | 16 +++--- src/ipa/raspberrypi/cam_helper.hpp | 5 +- src/ipa/raspberrypi/cam_helper_imx219.cpp | 6 +-- src/ipa/raspberrypi/cam_helper_imx477.cpp | 4 +- src/ipa/raspberrypi/cam_helper_ov5647.cpp | 4 +- src/ipa/raspberrypi/controller/camera_mode.h | 2 + src/ipa/raspberrypi/raspberrypi.cpp | 51 ++++++++++++++------ 7 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index b7b8faf09c69..3e17255737b2 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -34,9 +34,8 @@ CamHelper *CamHelper::Create(std::string const &cam_name) return nullptr; } -CamHelper::CamHelper(MdParser *parser, unsigned int maxFrameLength, - unsigned int frameIntegrationDiff) - : parser_(parser), initialized_(false), maxFrameLength_(maxFrameLength), +CamHelper::CamHelper(MdParser *parser, unsigned int frameIntegrationDiff) + : parser_(parser), initialized_(false), frameIntegrationDiff_(frameIntegrationDiff) { } @@ -67,13 +66,12 @@ uint32_t CamHelper::GetVBlanking(double &exposure, double minFrameDuration, assert(initialized_); /* - * Clamp frame length by the frame duration range and the maximum allowable - * value in the sensor, given by maxFrameLength_. + * minFrameDuration and maxFrameDuration will have been clamped to the + * maximum allowable values in the sensor for this mode. */ - frameLengthMin = std::clamp(1e3 * minFrameDuration / mode_.line_length, - mode_.height, maxFrameLength_); - frameLengthMax = std::clamp(1e3 * maxFrameDuration / mode_.line_length, - mode_.height, maxFrameLength_); + frameLengthMin = 1e3 * minFrameDuration / mode_.line_length; + frameLengthMax = 1e3 * maxFrameDuration / mode_.line_length; + /* * Limit the exposure to the maximum frame duration requested, and * re-calculate if it has been clipped. diff --git a/src/ipa/raspberrypi/cam_helper.hpp b/src/ipa/raspberrypi/cam_helper.hpp index b1739a57e342..14d70112cb62 100644 --- a/src/ipa/raspberrypi/cam_helper.hpp +++ b/src/ipa/raspberrypi/cam_helper.hpp @@ -62,8 +62,7 @@ class CamHelper { public: static CamHelper *Create(std::string const &cam_name); - CamHelper(MdParser *parser, unsigned int maxFrameLength, - unsigned int frameIntegrationDiff); + CamHelper(MdParser *parser, unsigned int frameIntegrationDiff); virtual ~CamHelper(); void SetCameraMode(const CameraMode &mode); MdParser &Parser() const { return *parser_; } @@ -86,8 +85,6 @@ protected: private: bool initialized_; - /* Largest possible frame length, in units of lines. */ - unsigned int maxFrameLength_; /* * Smallest difference between the frame length and integration time, * in units of lines. diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp index 8688ec091c44..95b8e698fe3b 100644 --- a/src/ipa/raspberrypi/cam_helper_imx219.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp @@ -56,15 +56,13 @@ private: * in units of lines. */ static constexpr int frameIntegrationDiff = 4; - /* Largest possible frame length, in units of lines. */ - static constexpr int maxFrameLength = 0xffff; }; CamHelperImx219::CamHelperImx219() #if ENABLE_EMBEDDED_DATA - : CamHelper(new MdParserImx219(), maxFrameLength, frameIntegrationDiff) + : CamHelper(new MdParserImx219(), frameIntegrationDiff) #else - : CamHelper(new MdParserRPi(), maxFrameLength, frameIntegrationDiff) + : CamHelper(new MdParserRPi(), frameIntegrationDiff) #endif { } diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp index 5396131003f1..eaa7be16d20e 100644 --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp @@ -45,12 +45,10 @@ private: * in units of lines. */ static constexpr int frameIntegrationDiff = 22; - /* Largest possible frame length, in units of lines. */ - static constexpr int maxFrameLength = 0xffdc; }; CamHelperImx477::CamHelperImx477() - : CamHelper(new MdParserImx477(), maxFrameLength, frameIntegrationDiff) + : CamHelper(new MdParserImx477(), frameIntegrationDiff) { } diff --git a/src/ipa/raspberrypi/cam_helper_ov5647.cpp b/src/ipa/raspberrypi/cam_helper_ov5647.cpp index 2bd8a754f133..a7f417324048 100644 --- a/src/ipa/raspberrypi/cam_helper_ov5647.cpp +++ b/src/ipa/raspberrypi/cam_helper_ov5647.cpp @@ -30,8 +30,6 @@ private: * in units of lines. */ static constexpr int frameIntegrationDiff = 4; - /* Largest possible frame length, in units of lines. */ - static constexpr int maxFrameLength = 0xffff; }; /* @@ -40,7 +38,7 @@ private: */ CamHelperOv5647::CamHelperOv5647() - : CamHelper(new MdParserRPi(), maxFrameLength, frameIntegrationDiff) + : CamHelper(new MdParserRPi(), frameIntegrationDiff) { } diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h index 920f11beb0b0..3baeadaca076 100644 --- a/src/ipa/raspberrypi/controller/camera_mode.h +++ b/src/ipa/raspberrypi/controller/camera_mode.h @@ -37,6 +37,8 @@ struct CameraMode { double line_length; // any camera transform *not* reflected already in the camera tuning libcamera::Transform transform; + // minimum and maximum vblanking limits for this mode + uint32_t vblank_min, vblank_max; }; #ifdef __cplusplus diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 5ccc7a6551f5..30ba9aef9d97 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -102,6 +102,7 @@ private: void reportMetadata(); bool parseEmbeddedData(unsigned int bufferId, struct DeviceStatus &deviceStatus); void processStats(unsigned int bufferId); + void applyFrameDurations(double minFrameDuration, double maxFrameDuration); void applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls); void applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls); void applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls); @@ -279,6 +280,14 @@ void IPARPi::setMode(const CameraSensorInfo &sensorInfo) * the line length in pixels and the pixel rate. */ mode_.line_length = 1e9 * sensorInfo.lineLength / sensorInfo.pixelRate; + + /* + * Set the vertical blanking (frame duration) limits for the mode to + * ensure exposure and framerate calculations are clipped appropriately. + */ + const auto itVblank = sensorCtrls_.find(V4L2_CID_VBLANK); + mode_.vblank_min = itVblank->second.min().get(); + mode_.vblank_max = itVblank->second.max().get(); } void IPARPi::configure(const CameraSensorInfo &sensorInfo, @@ -384,8 +393,8 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo, controller_.Initialise(); controllerInit_ = true; - minFrameDuration_ = defaultMinFrameDuration; - maxFrameDuration_ = defaultMaxFrameDuration; + /* Supply initial values for frame durations. */ + applyFrameDurations(defaultMinFrameDuration, defaultMaxFrameDuration); /* Supply initial values for gain and exposure. */ ControlList ctrls(sensorCtrls_); @@ -819,20 +828,7 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::FRAME_DURATIONS: { auto frameDurations = ctrl.second.get>(); - - /* This will be applied once AGC recalculations occur. */ - minFrameDuration_ = frameDurations[0] ? frameDurations[0] : defaultMinFrameDuration; - maxFrameDuration_ = frameDurations[1] ? frameDurations[1] : defaultMaxFrameDuration; - maxFrameDuration_ = std::max(maxFrameDuration_, minFrameDuration_); - - /* - * \todo The values returned in the metadata below must be - * correctly clipped by what the sensor mode supports and - * what the AGC exposure mode or manual shutter speed limits - */ - libcameraMetadata_.set(controls::FrameDurations, - { static_cast(minFrameDuration_), - static_cast(maxFrameDuration_) }); + applyFrameDurations(frameDurations[0], frameDurations[1]); break; } @@ -991,6 +987,29 @@ void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls) static_cast(awbStatus->gain_b * 1000)); } +void IPARPi::applyFrameDurations(double minFrameDuration, double maxFrameDuration) +{ + const double minSensorFrameDuration = 1e-3 * (mode_.vblank_min + mode_.height) * + mode_.line_length; + const double maxSensorFrameDuration = 1e-3 * (mode_.vblank_max + mode_.height) * + mode_.line_length; + /* + * This will only be applied once AGC recalculations occur. + * The values may be clamped based on the sensor mode capabilities as well. + */ + minFrameDuration_ = minFrameDuration ? minFrameDuration : defaultMaxFrameDuration; + maxFrameDuration_ = maxFrameDuration ? maxFrameDuration : defaultMinFrameDuration; + minFrameDuration_ = std::clamp(minFrameDuration_, + minSensorFrameDuration, maxSensorFrameDuration); + maxFrameDuration_ = std::clamp(maxFrameDuration_, + minSensorFrameDuration, maxSensorFrameDuration); + + /* Return the validated limits out though metadata. */ + libcameraMetadata_.set(controls::FrameDurations, + { static_cast(minFrameDuration_), + static_cast(maxFrameDuration_) }); +} + void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) { int32_t gainCode = helper_->GainCode(agcStatus->analogue_gain); From patchwork Sun Jan 24 14:05:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10976 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 6F177BD808 for ; Sun, 24 Jan 2021 14:05:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3A7DE682A9; Sun, 24 Jan 2021 15:05:18 +0100 (CET) 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="jhXjJkDz"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2211568297 for ; Sun, 24 Jan 2021 15:05:16 +0100 (CET) Received: by mail-wm1-x32d.google.com with SMTP id u14so8460345wmq.4 for ; Sun, 24 Jan 2021 06:05:16 -0800 (PST) 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=0zKQLmFZqtQ69uXUg75DSbHqfWVkgnhsBQOG3caM0NI=; b=jhXjJkDzPOClZ4nZNytcpkBOPJO1kJW21xzPV2ld2N7ycxaEyzgmJespTRmyP4lW0O bhd795TVjsYzYXFuE0M6tYqj1b7DvVhaLGk2F8jfavlsVE6rmIn5cj4TQkaYw7/Hv2b+ BiwIiciPDSzEEYWRyb/JBkzjCjXI/S499jJc2HKgZANT5vLQxQuof42baZMK0dsYwjR4 n0+ZPW/yHQc81LA98Bbakxs5SrNh6WTCbABKBbkQdb2y14ORocH2dwp9IjgHrRxZFNSa XFSZgguSVn5Ht1xaBTZRhQ97zNjE9Grc9vS5+nEcC36gS8lH5kmCKPqat6AUbyySYroO Lt0A== 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=0zKQLmFZqtQ69uXUg75DSbHqfWVkgnhsBQOG3caM0NI=; b=AF/SOJQuO683/9n6OZBbMjb1IgEmZ7cE6akpSzoLPgNQvo64vli3I3HRwTTlQzlQeR CcQh4wgU/523nL2Pmj6pVsJBMEWfE0SI7ccE2vytIf3IgEjX0d4rW4xxUthl4xsyktkq /bkjGZwkym4WzxK7ympNH9cRg4SblqMCKzb6eniKcPQmPXl1fpwiimZLvdGpRV04ZZI2 JQb75ULLKaUhl8rvo1fgEXKwMlWX+BUeZYqwJje1XPPWNjsyqHJKIfmIWdSe1aJ7iLLQ 18JriLAy8mbA+dmrOr4b119448IC+y5uL0Y+fWeEHU3E/sI+c7fYKbcft9LUvpFUxAbe TuHQ== X-Gm-Message-State: AOAM5339byeOECQ7Sa9HxV2/aVx5DWAJ/sI932CT1en7exB44o/isbJM yvAgq67pYdgrTU2AgbphCJEY21ac7l0GgBav X-Google-Smtp-Source: ABdhPJy4vOgQSwIvbGUFhsfIK9CWBRHMH0u7+TIYRWmKJcEdc87Vrjo/hipW52+SdNfvMcTjgD1Kvg== X-Received: by 2002:a1c:4107:: with SMTP id o7mr11809719wma.33.1611497115442; Sun, 24 Jan 2021 06:05:15 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id u16sm19311053wrn.68.2021.01.24.06.05.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Jan 2021 06:05:13 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Sun, 24 Jan 2021 14:05:05 +0000 Message-Id: <20210124140506.786503-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210124140506.786503-1-naush@raspberrypi.com> References: <20210124140506.786503-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/4] ipa: raspberrypi: Pass the maximum allowable shutter speed into the AGC 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" In order to provide an optimal split between shutter speed and gain, the AGC must know the maximum allowable shutter speed, as limited by the maximum frame duration (either application provided or the default). Add a new API function, SetMaxShutter, to the AgcAlgorihtm class. The IPA provides the the maximum shutter speed for AGC calculations. This applies to both the manual and auto AGC modes. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- .../raspberrypi/controller/agc_algorithm.hpp | 1 + src/ipa/raspberrypi/controller/rpi/agc.cpp | 49 +++++++++++++------ src/ipa/raspberrypi/controller/rpi/agc.hpp | 2 + src/ipa/raspberrypi/raspberrypi.cpp | 12 +++++ 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/ipa/raspberrypi/controller/agc_algorithm.hpp b/src/ipa/raspberrypi/controller/agc_algorithm.hpp index 981f1de2f0e4..f97deb0fca59 100644 --- a/src/ipa/raspberrypi/controller/agc_algorithm.hpp +++ b/src/ipa/raspberrypi/controller/agc_algorithm.hpp @@ -19,6 +19,7 @@ public: virtual void SetEv(double ev) = 0; virtual void SetFlickerPeriod(double flicker_period) = 0; virtual void SetFixedShutter(double fixed_shutter) = 0; // microseconds + virtual void SetMaxShutter(double max_shutter) = 0; // microseconds virtual void SetFixedAnalogueGain(double fixed_analogue_gain) = 0; virtual void SetMeteringMode(std::string const &metering_mode_name) = 0; virtual void SetExposureMode(std::string const &exposure_mode_name) = 0; diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index eddd1684da12..937bb70ece67 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -157,7 +157,7 @@ Agc::Agc(Controller *controller) frame_count_(0), lock_count_(0), last_target_exposure_(0.0), ev_(1.0), flicker_period_(0.0), - fixed_shutter_(0), fixed_analogue_gain_(0.0) + max_shutter_(0), fixed_shutter_(0), fixed_analogue_gain_(0.0) { memset(&awb_, 0, sizeof(awb_)); // Setting status_.total_exposure_value_ to zero initially tells us @@ -227,11 +227,23 @@ void Agc::SetFlickerPeriod(double flicker_period) flicker_period_ = flicker_period; } +static double clip_shutter(double shutter, double max_shutter) +{ + if (max_shutter) + shutter = std::min(shutter, max_shutter); + return shutter; +} + +void Agc::SetMaxShutter(double max_shutter) +{ + max_shutter_ = max_shutter; +} + void Agc::SetFixedShutter(double fixed_shutter) { fixed_shutter_ = fixed_shutter; // Set this in case someone calls Pause() straight after. - status_.shutter_time = fixed_shutter; + status_.shutter_time = clip_shutter(fixed_shutter_, max_shutter_); } void Agc::SetFixedAnalogueGain(double fixed_analogue_gain) @@ -261,7 +273,8 @@ void Agc::SwitchMode([[maybe_unused]] CameraMode const &camera_mode, { housekeepConfig(); - if (fixed_shutter_ != 0.0 && fixed_analogue_gain_ != 0.0) { + double fixed_shutter = clip_shutter(fixed_shutter_, max_shutter_); + if (fixed_shutter != 0.0 && fixed_analogue_gain_ != 0.0) { // We're going to reset the algorithm here with these fixed values. fetchAwbStatus(metadata); @@ -269,14 +282,14 @@ void Agc::SwitchMode([[maybe_unused]] CameraMode const &camera_mode, ASSERT(min_colour_gain != 0.0); // This is the equivalent of computeTargetExposure and applyDigitalGain. - target_.total_exposure_no_dg = fixed_shutter_ * fixed_analogue_gain_; + target_.total_exposure_no_dg = fixed_shutter * fixed_analogue_gain_; target_.total_exposure = target_.total_exposure_no_dg / min_colour_gain; // Equivalent of filterExposure. This resets any "history". filtered_ = target_; // Equivalent of divideUpExposure. - filtered_.shutter = fixed_shutter_; + filtered_.shutter = fixed_shutter; filtered_.analogue_gain = fixed_analogue_gain_; } else if (status_.total_exposure_value) { // On a mode switch, it's possible the exposure profile could change, @@ -290,7 +303,7 @@ void Agc::SwitchMode([[maybe_unused]] CameraMode const &camera_mode, // for any that weren't set. // Equivalent of divideUpExposure. - filtered_.shutter = fixed_shutter_ ? fixed_shutter_ : config_.default_exposure_time; + filtered_.shutter = fixed_shutter ? fixed_shutter : config_.default_exposure_time; filtered_.analogue_gain = fixed_analogue_gain_ ? fixed_analogue_gain_ : config_.default_analogue_gain; } @@ -403,7 +416,8 @@ void Agc::housekeepConfig() { // First fetch all the up-to-date settings, so no one else has to do it. status_.ev = ev_; - status_.fixed_shutter = fixed_shutter_; + double fixed_shutter = clip_shutter(fixed_shutter_, max_shutter_); + status_.fixed_shutter = fixed_shutter; status_.fixed_analogue_gain = fixed_analogue_gain_; status_.flicker_period = flicker_period_; LOG(RPiAgc, Debug) << "ev " << status_.ev << " fixed_shutter " @@ -582,13 +596,15 @@ void Agc::computeTargetExposure(double gain) target_.total_exposure = current_.total_exposure_no_dg * gain; // The final target exposure is also limited to what the exposure // mode allows. + double max_shutter = status_.fixed_shutter != 0.0 + ? status_.fixed_shutter + : exposure_mode_->shutter.back(); + max_shutter = clip_shutter(max_shutter, max_shutter_); double max_total_exposure = - (status_.fixed_shutter != 0.0 - ? status_.fixed_shutter - : exposure_mode_->shutter.back()) * + max_shutter * (status_.fixed_analogue_gain != 0.0 - ? status_.fixed_analogue_gain - : exposure_mode_->gain.back()); + ? status_.fixed_analogue_gain + : exposure_mode_->gain.back()); target_.total_exposure = std::min(target_.total_exposure, max_total_exposure); } @@ -671,6 +687,7 @@ void Agc::divideUpExposure() shutter_time = status_.fixed_shutter != 0.0 ? status_.fixed_shutter : exposure_mode_->shutter[0]; + shutter_time = clip_shutter(shutter_time, max_shutter_); analogue_gain = status_.fixed_analogue_gain != 0.0 ? status_.fixed_analogue_gain : exposure_mode_->gain[0]; @@ -678,14 +695,16 @@ void Agc::divideUpExposure() for (unsigned int stage = 1; stage < exposure_mode_->gain.size(); stage++) { if (status_.fixed_shutter == 0.0) { - if (exposure_mode_->shutter[stage] * - analogue_gain >= + double stage_shutter = + clip_shutter(exposure_mode_->shutter[stage], + max_shutter_); + if (stage_shutter * analogue_gain >= exposure_value) { shutter_time = exposure_value / analogue_gain; break; } - shutter_time = exposure_mode_->shutter[stage]; + shutter_time = stage_shutter; } if (status_.fixed_analogue_gain == 0.0) { if (exposure_mode_->gain[stage] * diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp index 05c334e4a1de..2ce3b1a1700a 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp @@ -78,6 +78,7 @@ public: unsigned int GetConvergenceFrames() const override; void SetEv(double ev) override; void SetFlickerPeriod(double flicker_period) override; + void SetMaxShutter(double max_shutter) override; // microseconds void SetFixedShutter(double fixed_shutter) override; // microseconds void SetFixedAnalogueGain(double fixed_analogue_gain) override; void SetMeteringMode(std::string const &metering_mode_name) override; @@ -126,6 +127,7 @@ private: std::string constraint_mode_name_; double ev_; double flicker_period_; + double max_shutter_; double fixed_shutter_; double fixed_analogue_gain_; }; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 30ba9aef9d97..75c9e404dcc1 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1008,6 +1008,18 @@ void IPARPi::applyFrameDurations(double minFrameDuration, double maxFrameDuratio libcameraMetadata_.set(controls::FrameDurations, { static_cast(minFrameDuration_), static_cast(maxFrameDuration_) }); + + /* + * Calculate the maximum exposure time possible for the AGC to use. + * GetVBlanking() will update maxShutter with the largest exposure + * value possible. + */ + double maxShutter = std::numeric_limits::max(); + helper_->GetVBlanking(maxShutter, minFrameDuration_, maxFrameDuration_); + + RPiController::AgcAlgorithm *agc = dynamic_cast( + controller_.GetAlgorithm("agc")); + agc->SetMaxShutter(maxShutter); } void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) From patchwork Sun Jan 24 14:05:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10977 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 3CCB7BD808 for ; Sun, 24 Jan 2021 14:05:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C7CDA682A8; Sun, 24 Jan 2021 15:05:18 +0100 (CET) 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="ft2gtgQI"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4382568297 for ; Sun, 24 Jan 2021 15:05:17 +0100 (CET) Received: by mail-wm1-x32f.google.com with SMTP id m2so8323198wmm.1 for ; Sun, 24 Jan 2021 06:05:17 -0800 (PST) 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=XZkrA0htXPzX/u0lkkrrfWXfV5BoVHTbgwzUv5sp3Hg=; b=ft2gtgQIyYh+e5VjH/rBTklKjjyM0ml20i7npXVPu+sH7UuQkfXjmkYBtrSltKOeXH WNo19i2ME4eSiYh3TUbhufTh6ot+EiLLNaEjzF1fkpaBjbsgpcQWsCIgwU9trnO/FqmA OhRuMrz6a3JSjrjkaKr3Y6pWyFUUkIFVg/EKQ3WkB8jLk4lgrJBKN9G5aBVj+5xhhdus rF9edFStX/TR3aB0Jk+itzDlbJuurtw/dApQrRHPBp+fCULOJXzID9mqJJkyFp4g8Nxe /u1fduvPvLL7YOOczeumtGdXzCJwy5sx/y/CSptKnLCkc0CDpY+4w+Uv+XemAYbAMjjy gqsA== 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=XZkrA0htXPzX/u0lkkrrfWXfV5BoVHTbgwzUv5sp3Hg=; b=WRfTurFcnimj78K5JGN1+76zA/dgyc0IDALGnD8tKv7KPuAYDAtRN7e4Gvs5Gj4AYl BA7r5n4XyAGk+Hz6cf0SrQFxZ6mQMUCH0VDD8NPyX3/jaR0reIALowLo62BAVTqOCN4A RqfzYP7raROdgQVAKzWqiRu/f/dcAdbEgY7xdtzoY0y2/XSANIAIYidof3rOXb82RMzr RI9NS8/AdUTG/8ZY05bsac6+0HEeLYg8sLL4uIr1xlCpuFnnTxUhTniz5XcMtjnpx09n KEYyadCSNWM6g/V18dLsH2h7ephx54yU/r3bbUswizZKV/7H5IA8X1zLhTFg2sMKkTPp s3gA== X-Gm-Message-State: AOAM5320Fgc4/aw0JcqrgmkPF49Vq73JZMmx7sHHJs/XfZOiDfMSJLih A90BZm0KpG7N6WNdNw8/R1RqppjSfCBDS34+ X-Google-Smtp-Source: ABdhPJwewkYsPs9UjYzhsoSiDREcSjjv5fx3/98xaS5p3QPXIH2m7hitbVmusffq/rQdbU5k1GyvaA== X-Received: by 2002:a1c:5454:: with SMTP id p20mr3990740wmi.128.1611497116691; Sun, 24 Jan 2021 06:05:16 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id u16sm19311053wrn.68.2021.01.24.06.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Jan 2021 06:05:15 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Sun, 24 Jan 2021 14:05:06 +0000 Message-Id: <20210124140506.786503-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210124140506.786503-1-naush@raspberrypi.com> References: <20210124140506.786503-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/4] pipeline: raspberrypi: Add notion of immediate write to StaggeredCtrl 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" If an exposure time change adjusts the vblanking limits, and we write both VBLANK and EXPOSURE controls as a set, the latter may fail if the value is outside of the limits calculated by the old VBLANK value. This is a limitation in V4L2 and cannot be fixed by writing VBLANK before EXPOSURE. The workaround here is to have the StaggeredCtrl mark the VBLANK control as "immediate write", which then write VBLANK separately from (and ahead of) any other controls. This way, the sensor driver will update the EXPOSURE control with new limits before the new values is presented, and will thus be seen as valid. StaggeredCtrl is due to be deprecated and replaced by DelayedCtrl, so this change serves more a working proof-of-concept on the workaround, and not much care has been taken to provide a nice new API for applying this immediate write flag to the control. A similar workaround must be available to DelayedCtrl eventually. Signed-off-by: Naushir Patuck --- src/ipa/raspberrypi/raspberrypi.cpp | 5 ++- .../pipeline/raspberrypi/raspberrypi.cpp | 11 ++++-- .../pipeline/raspberrypi/staggered_ctrl.cpp | 39 ++++++++++++++----- .../pipeline/raspberrypi/staggered_ctrl.h | 3 +- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 75c9e404dcc1..fefca32ce187 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1040,8 +1040,9 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) /* * Due to the behavior of V4L2, the current value of VBLANK could clip the - * exposure time without us knowing. The next time though this function should - * clip exposure correctly. + * exposure time without us knowing. We get around this by ensuring the + * staggered write component submits VBLANK separately from, and before the + * EXPOSURE control. */ ctrls.set(V4L2_CID_VBLANK, vblanking); ctrls.set(V4L2_CID_EXPOSURE, exposureLines); diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 524cc960dd37..1485999ad2a0 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1229,12 +1229,17 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config) /* * Setup our staggered control writer with the sensor default * gain and exposure delays. + * + * VBLANK must be flagged as "immediate write" to allow it to + * be set immediately instead of being batched with all other + * controls. This is needed so that any update to the EXPOSURE + * control will be validated based on the new VBLANK control value. */ if (!staggeredCtrl_) { staggeredCtrl_.init(unicam_[Unicam::Image].dev(), - { { V4L2_CID_ANALOGUE_GAIN, result.data[resultIdx++] }, - { V4L2_CID_EXPOSURE, result.data[resultIdx++] }, - { V4L2_CID_VBLANK, result.data[resultIdx++] } }); + { { V4L2_CID_ANALOGUE_GAIN, result.data[resultIdx++], false }, + { V4L2_CID_EXPOSURE, result.data[resultIdx++], false }, + { V4L2_CID_VBLANK, result.data[resultIdx++], true } }); sensorMetadata_ = result.data[resultIdx++]; } } diff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp index 62605c0fceee..07f8c95d4f2c 100644 --- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp +++ b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp @@ -22,21 +22,29 @@ LOG_DEFINE_CATEGORY(RPI_S_W) namespace RPi { void StaggeredCtrl::init(V4L2VideoDevice *dev, - std::initializer_list> delayList) + std::initializer_list> delayList) { std::lock_guard lock(lock_); dev_ = dev; - delay_ = delayList; + delay_.clear(); ctrl_.clear(); - /* Find the largest delay across all controls. */ maxDelay_ = 0; - for (auto const &p : delay_) { + for (auto const &c : delayList) { + uint32_t id = std::get<0>(c); + uint8_t delay = std::get<1>(c); + bool immediateWrite = std::get<2>(c); + + delay_[id] = delay; + immediateWrite_[id] = immediateWrite; + LOG(RPI_S_W, Info) << "Init ctrl " - << utils::hex(p.first) << " with delay " - << static_cast(p.second); - maxDelay_ = std::max(maxDelay_, p.second); + << utils::hex(id) << " with delay " + << static_cast(delay); + + /* Find the largest delay across all controls. */ + maxDelay_ = std::max(maxDelay_, delay); } init_ = true; @@ -121,8 +129,21 @@ int StaggeredCtrl::write() int index = std::max(0, setCount_ - delayDiff); if (p.second[index].updated) { - /* We need to write this value out. */ - controls.set(p.first, p.second[index].value); + if (immediateWrite_[p.first]) { + /* + * This control must be written now, it could + * affect validity of the other controls. + */ + ControlList immediate(dev_->controls()); + immediate.set(p.first, p.second[index].value); + dev_->setControls(&immediate); + } else { + /* + * Batch up the list of controls and write them + * at the end of the function. + */ + controls.set(p.first, p.second[index].value); + } p.second[index].updated = false; LOG(RPI_S_W, Debug) << "Writing ctrl " << utils::hex(p.first) << " to " diff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h index 382fa31a6853..7c920c3a13c7 100644 --- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h +++ b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h @@ -34,7 +34,7 @@ public: } void init(V4L2VideoDevice *dev, - std::initializer_list> delayList); + std::initializer_list> delayList); void reset(); void get(std::unordered_map &ctrl, uint8_t offset = 0); @@ -85,6 +85,7 @@ private: uint8_t maxDelay_; V4L2VideoDevice *dev_; std::unordered_map delay_; + std::unordered_map immediateWrite_; std::unordered_map ctrl_; std::mutex lock_; };