From patchwork Mon Dec 7 18:01:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10603 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 822D0BDB1F for ; Mon, 7 Dec 2020 18:02:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4A64967E6E; Mon, 7 Dec 2020 19:02:39 +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="qVGZKTh1"; dkim-atps=neutral Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A755267E6A for ; Mon, 7 Dec 2020 19:02:37 +0100 (CET) Received: by mail-ej1-x62d.google.com with SMTP id x16so20769098ejj.7 for ; Mon, 07 Dec 2020 10:02:37 -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=GUZ3CHBFUgzFpk0zl/qO1zEra+JQmulzfklWh6O0kWA=; b=qVGZKTh1bHWtkAskB52Urx6XmpZVMzyIQRMzXEutZof/FohfyBkFGJjNcjNFCnCyTV p9COUlaggoru19ZVYUobSsI7xw+2KtODv5BUQEw7Yiz6V/6r9plcJWjpf09Qz2szhVsF yQbpmS8yLMFufggcuWF2BekcZrZGdANzDmv+0BYBTRMiyxEOxSbhZ524U+VYym15Bigo 1WhgccuWXu9/2BKKyC8eX4eccRhXs+pR+WebXxuKPVqr637ljEGHuMoZ2u7AeUrUVphL LlR+jkX9kuFGnQINpspaehRvoET3Gy/fHIge2MPHwGjMqYi6n8IEfu8NUPzkR5UP3nzI CtXQ== 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=GUZ3CHBFUgzFpk0zl/qO1zEra+JQmulzfklWh6O0kWA=; b=Aedy00ZUfnqLOn63CCMj3i3MZ2x94E5c5IR7GQZfjYv7dwKi36QuH9pT1MnshXKs/D r1J4231KeNsKs/58R+0LlIzjr8f7DMRsViABObYUBcXhqP2tXfwOVVFHD+JiLvyWZa4+ sd9gPYiCFTQwaq0+6u4FXfxBJqWFj/ceISZTZuXN3pJaatAu12cuqcnJXHty+HUR/7ey ajTu86LESoCVaQLcGDV0QdwOrPgy/aN7v48PTQbdMIkoXqx3e9hsOyiEe3kyCI4q9e9p N5ktsL+APfhB1A6PRivUaQ+smSEZaaL+F/8cyMNCkFYqqwrv8M/MXjPe0RoWX5uX5qNP EKAA== X-Gm-Message-State: AOAM5330ViDEsUDC1x7f9mhsBCGxoOl5tndGkAVgJlvqLHZ+rnOwkfn5 agxk+mZQbaQ4S5XJ3jBT9r9L0B84HVeia2Ow X-Google-Smtp-Source: ABdhPJzoomxM7azf4Zk4JbyXW9YHCosPP+nQ/QyKFnZirw9pxmUIrJTxWRmVEpJD4pYNm57e7BTpkQ== X-Received: by 2002:a17:906:c20f:: with SMTP id d15mr19828842ejz.341.1607364156876; Mon, 07 Dec 2020 10:02:36 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id be6sm14657977edb.29.2020.12.07.10.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 10:02:33 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Dec 2020 18:01:21 +0000 Message-Id: <20201207180121.6374-7-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201207180121.6374-1-david.plowman@raspberrypi.com> References: <20201207180121.6374-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 6/6] src: ipa: raspberrypi: Move initial frame drop decision to AGC/AWB 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" Previously the CamHelper was returning the number of frames to drop (on account of AGC/AWB converging). This wasn't really appropriate, it's better for the algorithms to do it as they know how many frames they might need. The CamHelper::HideFramesStartup method should now just be returning the number of frames to hide because they're bad/invalid in some way, not worrying about the AGC/AWB. For many sensors, the correct value for this is zero. But the ov5647 needs updating as it must return 2. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper.cpp | 6 +++--- src/ipa/raspberrypi/cam_helper_ov5647.cpp | 10 ++++++++++ src/ipa/raspberrypi/raspberrypi.cpp | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index c8ac3232..6efa0d7f 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -82,10 +82,10 @@ bool CamHelper::SensorEmbeddedDataPresent() const unsigned int CamHelper::HideFramesStartup() const { /* - * By default, hide 6 frames completely at start-up while AGC etc. sort - * themselves out (converge). + * The number of frames when a camera first starts that shouldn't be + * displayed as they are invalid in some way. */ - return 6; + return 0; } unsigned int CamHelper::HideFramesModeSwitch() const diff --git a/src/ipa/raspberrypi/cam_helper_ov5647.cpp b/src/ipa/raspberrypi/cam_helper_ov5647.cpp index dc5d8275..0b841cd1 100644 --- a/src/ipa/raspberrypi/cam_helper_ov5647.cpp +++ b/src/ipa/raspberrypi/cam_helper_ov5647.cpp @@ -19,6 +19,7 @@ public: uint32_t GainCode(double gain) const override; double Gain(uint32_t gain_code) const override; void GetDelays(int &exposure_delay, int &gain_delay) const override; + unsigned int HideFramesStartup() const override; unsigned int HideFramesModeSwitch() const override; unsigned int MistrustFramesStartup() const override; unsigned int MistrustFramesModeSwitch() const override; @@ -54,6 +55,15 @@ void CamHelperOv5647::GetDelays(int &exposure_delay, int &gain_delay) const gain_delay = 2; } +unsigned int CamHelperOv5647::HideFramesStartup() const +{ + /* + * On startup, we get a couple of under-exposed frames which + * we don't want shown. + */ + return 2; +} + unsigned int CamHelperOv5647::HideFramesModeSwitch() const { /* diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 0e89af00..da92e492 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -193,6 +193,22 @@ int IPARPi::start(const IPAOperationData &ipaConfig, IPAOperationData *result) if (firstStart_) { dropFrame = helper_->HideFramesStartup(); mistrustCount_ = helper_->MistrustFramesStartup(); + + /* The AGC and/or AWB algorithms may want us to drop more frames. */ + unsigned int convergence_frames = 0; + RPiController::AgcAlgorithm *agc = dynamic_cast( + controller_.GetAlgorithm("agc")); + if (agc) + convergence_frames = agc->GetConvergenceFrames(mistrustCount_); + + RPiController::AwbAlgorithm *awb = dynamic_cast( + controller_.GetAlgorithm("awb")); + if (awb) + convergence_frames = std::max(convergence_frames, + awb->GetConvergenceFrames(mistrustCount_)); + + dropFrame = std::max(dropFrame, convergence_frames); + LOG(IPARPI, Debug) << "Drop " << dropFrame << " frames on startup"; } else { dropFrame = helper_->HideFramesModeSwitch(); mistrustCount_ = helper_->MistrustFramesModeSwitch();