{"id":23612,"url":"https://patchwork.libcamera.org/api/patches/23612/?format=json","web_url":"https://patchwork.libcamera.org/patch/23612/","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":"<20250620124452.557855-5-naush@raspberrypi.com>","date":"2025-06-20T12:42:25","name":"[v1,4/8] ipa: rpi: controller: Autofocus CAF/PDAF stability tweak","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"bd7cc17d6744266cb2b1d2e3f8e7b057111ebfa7","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23612/mbox/","series":[{"id":5235,"url":"https://patchwork.libcamera.org/api/series/5235/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5235","date":"2025-06-20T12:42:21","name":"Raspberry Pi: AF improvements","version":1,"mbox":"https://patchwork.libcamera.org/series/5235/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23612/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23612/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 A6543BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Jun 2025 12:45:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4BF7261538;\n\tFri, 20 Jun 2025 14:45:09 +0200 (CEST)","from mail-wr1-x431.google.com (mail-wr1-x431.google.com\n\t[IPv6:2a00:1450:4864:20::431])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5C20968DEC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Jun 2025 14:45:00 +0200 (CEST)","by mail-wr1-x431.google.com with SMTP id\n\tffacd0b85a97d-3a577f164c8so288296f8f.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Jun 2025 05:45:00 -0700 (PDT)","from NAUSH-P-DELL.pitowers.org ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-45361461375sm41561525e9.14.2025.06.20.05.44.59\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 20 Jun 2025 05:44:59 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"gbIhFK7c\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1750423500; x=1751028300;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=ZtR9/ErdKUSfx6biHWA2K9BllLNkDfqCLyVdT4Rw+b8=;\n\tb=gbIhFK7c78OFkcQTyE+YuhwTuKf7RcnYDjCQvdXttZER24g7NKyX8O6aL9svo/fju0\n\tlgslcCrtVmlaGa8mpjRV9EfspQv5yUIPvJWS35pN3qMbn6mls2NDVEAmoeco9SIpicex\n\tJfQ1p5pX2BCs03AOgc2wmEMXMzBEjXRmgiA8OSQ+cMGHoYkERaV/ODA7zSbg2MEddLJT\n\tQrS9bDVT8zbCex9S7BECfJkWqdkO6IF9nqCsADO9J9weG33JcVriEhUoANYFx9dn1RzC\n\tOOvTFKd0uq9lgK6Y5o6LLXxnmTM8uYvJyIP8L4ZpB+CMZb0nFCBWwRNp7B4Sormi2CC3\n\tn0Jg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1750423500; x=1751028300;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=ZtR9/ErdKUSfx6biHWA2K9BllLNkDfqCLyVdT4Rw+b8=;\n\tb=DNX6fTRipl5zEqdD+1vWWr9pqEmP+DwxapEXQkN84C0v88y3/S5Ra2gO/jNPzYCRaM\n\txdhw6vt43hU8Wy5NH3yrs8gBCw/3Qtwv4ZT4jLdW6dUbfV5Hd4l6ULacRmSQVWT+eao9\n\t2vXrXGBMFCthYdU37fmchb/Y3WgrDPdsBJrZlw/oBReREjiKZy++ph0dHDJ5FUcDgRsd\n\tgXc1jMuVpaTgamJAi0eL2wT09QtYv0qNh4QUGtDP6bd667QoPE1TVbHrac53Izd3SMvV\n\teIv0F9T9685h7eO+6YkcqLKEX1wttlim2sOEXY2TgcLKA31zvO2dPqMgS/jVgEbDuGup\n\tmnZA==","X-Gm-Message-State":"AOJu0Yzgt9i2JtnlqjKY2/gh3kvljnj4RIT7wEJZdAeHHL7jpcimagmA\n\tt9nZVgh7TwB4nA2WmGSRYEETEYa53cgVXUpr0/aMcIv/wFiNmro/B8uQ775KC1hg+vRxQzQ9tQ3\n\t+fgOn","X-Gm-Gg":"ASbGncukm6OKLzyh5+e4T9g2w6mn26A4/ej2gCd4gK4ZZEGpr0aM4DlMu/Voe0ZKA5q\n\tiTVmicQSJzmK6urlxcONaYFMpBGVcP7jLqGBMQ4oSFS/Sqp04IIIWJcsWp7e8jatiMT3YDYgXVs\n\t3yeUZ8EaWqZz9jl2/n/x8P/mv1Vl5rsh9R99qHuj3juTaljvvMBj8uj5kXQudzqpKDcA76p3OMg\n\tRubNjTQlJ4Q1V/pp5tIMto53Hj12OHUsnF5KTz/XmfcklHpxf1EbeXASmr82v9KSXBEa8YLYhyq\n\tRDL0xB4wMKLBXMlCErKkpghnm0t0kFi33pwYWA6mE+aB30JDLLyV6WK8HxtfSfWyNQ5uJh4xcXL\n\t64a2zug==","X-Google-Smtp-Source":"AGHT+IEm+Fmnq9dEsZe60wPFdFCigAjle+kLrRC7WkeF+oRlF01b0ILE6Ukt/Ej640THCx6Y50GRdQ==","X-Received":"by 2002:a05:600c:6989:b0:43d:fa58:81d2 with SMTP id\n\t5b1f17b1804b1-453659b60b2mr10262525e9.9.1750423499612; \n\tFri, 20 Jun 2025 05:44:59 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>,\n\tNaushir Patuck <naush@raspberrypi.com>","Subject":"[PATCH v1 4/8] ipa: rpi: controller: Autofocus CAF/PDAF stability\n\ttweak","Date":"Fri, 20 Jun 2025 13:42:25 +0100","Message-ID":"<20250620124452.557855-5-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20250620124452.557855-1-naush@raspberrypi.com>","References":"<20250620124452.557855-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>\n\nWhen in Continuous AF mode using PDAF, only move the lens when\nphase has had the same sign for at least 4 frames. This reduces\nlens wobble in e.g. noisy conditions.\n\nSigned-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/rpi/controller/rpi/af.cpp | 12 +++++++++++-\n src/ipa/rpi/controller/rpi/af.h   |  2 ++\n 2 files changed, 13 insertions(+), 1 deletion(-)","diff":"diff --git a/src/ipa/rpi/controller/rpi/af.cpp b/src/ipa/rpi/controller/rpi/af.cpp\nindex 5304f54ca967..3b2d6167df61 100644\n--- a/src/ipa/rpi/controller/rpi/af.cpp\n+++ b/src/ipa/rpi/controller/rpi/af.cpp\n@@ -181,9 +181,11 @@ Af::Af(Controller *controller)\n \t  ftarget_(-1.0),\n \t  fsmooth_(-1.0),\n \t  prevContrast_(0.0),\n+\t  prevPhase_(0.0),\n \t  skipCount_(0),\n \t  stepCount_(0),\n \t  dropCount_(0),\n+\t  sameSignCount_(0),\n \t  scanMaxContrast_(0.0),\n \t  scanMinContrast_(1.0e9),\n \t  scanData_(),\n@@ -513,6 +515,13 @@ void Af::doAF(double contrast, double phase, double conf)\n \t\treturn;\n \t}\n \n+\t/* Count frames for which PDAF phase has had same sign */\n+\tif (phase * prevPhase_ <= 0.0)\n+\t\tsameSignCount_ = 0;\n+\telse\n+\t\tsameSignCount_++;\n+\tprevPhase_ = phase;\n+\n \tif (scanState_ == ScanState::Pdaf) {\n \t\t/*\n \t\t * Use PDAF closed-loop control whenever available, in both CAF\n@@ -522,7 +531,8 @@ void Af::doAF(double contrast, double phase, double conf)\n \t\t * scan only after a number of frames with low PDAF confidence.\n \t\t */\n \t\tif (conf > (dropCount_ ? 1.0 : 0.25) * cfg_.confEpsilon) {\n-\t\t\tdoPDAF(phase, conf);\n+\t\t\tif (mode_ == AfModeAuto || sameSignCount_ >= 3)\n+\t\t\t\tdoPDAF(phase, conf);\n \t\t\tif (stepCount_ > 0)\n \t\t\t\tstepCount_--;\n \t\t\telse if (mode_ != AfModeContinuous)\ndiff --git a/src/ipa/rpi/controller/rpi/af.h b/src/ipa/rpi/controller/rpi/af.h\nindex d8ece1ab119c..b06a3a16fab5 100644\n--- a/src/ipa/rpi/controller/rpi/af.h\n+++ b/src/ipa/rpi/controller/rpi/af.h\n@@ -158,7 +158,9 @@ private:\n \tbool initted_;\n \tdouble ftarget_, fsmooth_;\n \tdouble prevContrast_;\n+\tdouble prevPhase_;\n \tunsigned skipCount_, stepCount_, dropCount_;\n+\tunsigned sameSignCount_;\n \tunsigned scanMaxIndex_;\n \tdouble scanMaxContrast_, scanMinContrast_;\n \tstd::vector<ScanRecord> scanData_;\n","prefixes":["v1","4/8"]}