From patchwork Wed Dec 2 11:52:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10542 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 8C5BCBE177 for ; Wed, 2 Dec 2020 11:53:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D2525634A2; Wed, 2 Dec 2020 12:53:00 +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="Ja/daMsS"; dkim-atps=neutral Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D826635A2 for ; Wed, 2 Dec 2020 12:52:59 +0100 (CET) Received: by mail-wr1-x42a.google.com with SMTP id p8so3558234wrx.5 for ; Wed, 02 Dec 2020 03:52:59 -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=Hmm1WGdx4I+pN4Vv1vhTrXS7T6AbovSVEaKZpFzO8uc=; b=Ja/daMsSeYgdmdU5Be+e/S/848Hc+B3LhxFRD5m8EuOZJBnmAWL6YRlkluDzU99G7M s1SlX8ca2MFlnspptWvTiqHKYAcV6n17aiVyUS52dFKg/Xeo3eUtJzB1oAQhrpQoi+oT /FF9NevHcJkHzTTdMWfLf7EpEtpSWxtDCf91/pd+Kh7dO/5h2pvfZ6YOgMW/p8EmC7ye VcbiNvA+1U+8VHwOAg/6b7Ow1nIZDGGryajf4wEp0TupulxCdSbYIXSRBEurdqgPl/XF NB10jOk7dcFZs9wqzpvQUhyZC5XPcPsanvFDb3hOg8ZLxUXgtOPMVTWkxXmsV47XAN22 9T0g== 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=Hmm1WGdx4I+pN4Vv1vhTrXS7T6AbovSVEaKZpFzO8uc=; b=Cgh2PS1UaNIgmZD9NhClfZSDACtSfvQiQT80Dgpzye56Y2UjFSr0ZHjvBxLx4hSvD4 sVstBGHccy2uuG00GEz2X1QzftEDruFVxWfbLbIW0phQFcP69t9H3ke8QOEqY+TcABdt B6elufttqKKxA0E8XKepr/OKFDed0GfGud59FpRpA1w2BAScH7R17TN9vmp5ZdR8R+R3 BRfaT8k59Hdk1QEDgOKRP1wYIv2uWyP4vZgfSwsmZqcO6tBgyOvS/lAXFBt04sr9MUIE znh9G1WTcYgNOjyVzpdKpkua3EZ6jDc5uyKlp3TAVOAZTbgI+Ne+FkzwFZ+2lPx3nGqt 24ug== X-Gm-Message-State: AOAM531B+kGneylNcf3lDX8+K1Q2sYwq+CWRAWOA0HsIIwD9lmVKNCw2 lp8VdZu/BKgoX0d7W6N5oCxIaCPbTPwX0bku X-Google-Smtp-Source: ABdhPJzxv/nYP74jYUkmGJp9s48hl55AD5e6jGCyohgtnE+Mh1duFAJ9Zd0jcZ6GGYB3uD5qlF4BNw== X-Received: by 2002:adf:a3c1:: with SMTP id m1mr3184816wrb.28.1606909978639; Wed, 02 Dec 2020 03:52:58 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id n189sm1739215wmf.20.2020.12.02.03.52.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:52:58 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Dec 2020 11:52:49 +0000 Message-Id: <20201202115253.14705-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202115253.14705-1-david.plowman@raspberrypi.com> References: <20201202115253.14705-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/5] src: ipa: raspberrypi: Distinguish the first camera start from others 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" This makes it possible to tell whether we're starting the sensor for the first time, or whether it's happening because of a mode switch or because the camera has been paused and re-started. Depending on this, some sensors may require us to drop different numbers of frames. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/raspberrypi.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 69be5e4e..b8298768 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -67,7 +67,7 @@ public: IPARPi() : lastMode_({}), controller_(), controllerInit_(false), frameCount_(0), checkCount_(0), mistrustCount_(0), - lsTable_(nullptr) + lsTable_(nullptr), firstStart_(true) { } @@ -145,6 +145,9 @@ private: /* LS table allocation passed in from the pipeline handler. */ FileDescriptor lsTableHandle_; void *lsTable_; + + /* Distinguish the first camera start from others. */ + bool firstStart_; }; int IPARPi::init(const IPASettings &settings) @@ -179,6 +182,8 @@ int IPARPi::start(const IPAOperationData &ipaConfig, IPAOperationData *result) result->operation |= RPi::IPA_CONFIG_SENSOR; } + firstStart_ = false; + return 0; } From patchwork Wed Dec 2 11:52:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10543 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 60378BE177 for ; Wed, 2 Dec 2020 11:53:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2F76D635A3; Wed, 2 Dec 2020 12:53:02 +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="JI1C4A5E"; dkim-atps=neutral Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A336634A2 for ; Wed, 2 Dec 2020 12:53:00 +0100 (CET) Received: by mail-wr1-x443.google.com with SMTP id s8so3521167wrw.10 for ; Wed, 02 Dec 2020 03:53:00 -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=ekSVYZR1R2TpVJqM/5kfzNoQQzPb4N/VRXvaptAxp6E=; b=JI1C4A5E4p4cqcZAcIbJXcfuv2s6t90870h38AT1y9U2v1TwqfXl48ye/TYf60XJhY 2o8Vwoy4jE2xy3/2aW2CHzF/0xR0LgQCyylcwh9XNrHPWhJVO8qdz6tzuY1lhaSDUlt6 kZfPkGi/unJdf5J5LrIjPXN/4urP4920hsM7jtDOi9qPn7qBNP8FI00uoNxOw41mA55r 7InUUgmuoxaBCgXb9numVgYveaIn7yUgKdIvGkerlXKriIywaMaGmr2p60iRks7438fr X2et6MPn6RvoFuqUY15RiivfTHQJr8bxuSniGBCnxDfL/yPDc1xCisZGQunhu6o0y4J1 ps1Q== 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=ekSVYZR1R2TpVJqM/5kfzNoQQzPb4N/VRXvaptAxp6E=; b=ZMTgXLB9jKgL8r+t0YKHuQEWhT72u5sCPJbW+PICN1ejXd6Z09Hg2BHIf55JSfi0PC FqWW39/AJ8/s9auYXMkr+P9Bhc3uFHeobJl+yf5e3TjKIXv7m2tRne2km88ZWoxh6JOO vJ8mAkmVIWcCCBpCOEMBkIWYQ77Vc4RPukQQK4Ei0zhLCnjP0aogUXDAn5G31ZdaBn4M FIif/v4swp96hjwRBFx7LNPM49UySFl/bxDt96jp+7U1JxgYyDgsSCD4jZAregBCXD3y 68ozzhR78HchOkZIpOhvKftnd3AZ99G04tLIFGSuh3IqcZomqu+hvA+QF64ZfaspYItk iqYg== X-Gm-Message-State: AOAM531idIaAP56sZ6C8p+Hc5b+kVKW4UKCa/UDptWTZ4UVjRv0Qu9gV GxrkewgrdX6Mo+i0yZfav3xaXKdxJOn8CuLy X-Google-Smtp-Source: ABdhPJy1+BrHTsTX2Jw15oZ80M9bUY6NvYNSVA7vMzTJ3zKz00nnwBWWZ+5vcZuCh2rz8enW+2+R9w== X-Received: by 2002:adf:c452:: with SMTP id a18mr3024151wrg.189.1606909979584; Wed, 02 Dec 2020 03:52:59 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id n189sm1739215wmf.20.2020.12.02.03.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:52:59 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Dec 2020 11:52:50 +0000 Message-Id: <20201202115253.14705-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202115253.14705-1-david.plowman@raspberrypi.com> References: <20201202115253.14705-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/5] src: raspberrypi: Pass the drop frame count in start, not configure 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 number of frames to drop (not display) is passed back now from the start method, not configure. This means applications have a chance to set fixed exposure/gain before starting the camera and this can affect the frame drop count that is returned. Both the IPA implementation file and the pipeline handler need matching modifications. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck --- src/ipa/raspberrypi/raspberrypi.cpp | 38 +++++++++---------- .../pipeline/raspberrypi/raspberrypi.cpp | 25 ++++++------ 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index b8298768..0300b8d9 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -182,6 +182,25 @@ int IPARPi::start(const IPAOperationData &ipaConfig, IPAOperationData *result) result->operation |= RPi::IPA_CONFIG_SENSOR; } + /* + * Initialise frame counts, and decide how many frames must be hidden or + *"mistrusted", which depends on whether this is a startup from cold, + * or merely a mode switch in a running system. + */ + frameCount_ = 0; + checkCount_ = 0; + unsigned int dropFrame = 0; + if (firstStart_) { + dropFrame = helper_->HideFramesStartup(); + mistrustCount_ = helper_->MistrustFramesStartup(); + } else { + dropFrame = helper_->HideFramesModeSwitch(); + mistrustCount_ = helper_->MistrustFramesModeSwitch(); + } + + result->data.push_back(dropFrame); + result->operation |= RPi::IPA_CONFIG_DROP_FRAMES; + firstStart_ = false; return 0; @@ -298,25 +317,6 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo, /* Pass the camera mode to the CamHelper to setup algorithms. */ helper_->SetCameraMode(mode_); - /* - * Initialise frame counts, and decide how many frames must be hidden or - *"mistrusted", which depends on whether this is a startup from cold, - * or merely a mode switch in a running system. - */ - frameCount_ = 0; - checkCount_ = 0; - unsigned int dropFrame = 0; - if (controllerInit_) { - dropFrame = helper_->HideFramesModeSwitch(); - mistrustCount_ = helper_->MistrustFramesModeSwitch(); - } else { - dropFrame = helper_->HideFramesStartup(); - mistrustCount_ = helper_->MistrustFramesStartup(); - } - - result->data.push_back(dropFrame); - result->operation |= RPi::IPA_CONFIG_DROP_FRAMES; - if (!controllerInit_) { /* Load the tuning file for this sensor. */ controller_.Read(tuningFile_.c_str()); diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 89a44763..5ae56628 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -745,13 +745,6 @@ int PipelineHandlerRPi::start(Camera *camera, [[maybe_unused]] ControlList *cont return ret; } - ret = queueAllBuffers(camera); - if (ret) { - LOG(RPI, Error) << "Failed to queue buffers"; - stop(camera); - return ret; - } - /* Check if a ScalerCrop control was specified. */ if (controls) data->applyScalerCrop(*controls); @@ -778,6 +771,19 @@ int PipelineHandlerRPi::start(Camera *camera, [[maybe_unused]] ControlList *cont LOG(RPI, Error) << "V4L2 staggered set failed"; } + if (result.operation & RPi::IPA_CONFIG_DROP_FRAMES) { + /* Configure the number of dropped frames required on startup. */ + data->dropFrameCount_ = result.data[0]; + } + + /* We need to set the dropFrameCount_ before queueing buffers. */ + ret = queueAllBuffers(camera); + if (ret) { + LOG(RPI, Error) << "Failed to queue buffers"; + stop(camera); + return ret; + } + /* * IPA configure may have changed the sensor flips - hence the bayer * order. Get the sensor format and set the ISP input now. @@ -1231,11 +1237,6 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config) LOG(RPI, Error) << "V4L2 staggered set failed"; } - if (result.operation & RPi::IPA_CONFIG_DROP_FRAMES) { - /* Configure the number of dropped frames required on startup. */ - dropFrameCount_ = result.data[resultIdx++]; - } - /* * Configure the H/V flip controls based on the combination of * the sensor and user transform. From patchwork Wed Dec 2 11:52:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10544 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 C962FBE177 for ; Wed, 2 Dec 2020 11:53:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 85477635AF; Wed, 2 Dec 2020 12:53:02 +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="pQYEFlNm"; dkim-atps=neutral Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F002635A1 for ; Wed, 2 Dec 2020 12:53:01 +0100 (CET) Received: by mail-wr1-x42b.google.com with SMTP id g14so3505179wrm.13 for ; Wed, 02 Dec 2020 03:53:01 -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=rHVELqS19rTQ4tecujAhRQFO0ru7LWVkfSyFhbGD/bA=; b=pQYEFlNmCHkhR8QdgLVu5pTH2KKevhIKhJ74rar+HOt8tY1O00tmp+e5x243Eow2IX wBGboqe0ud3m9dfpOQNayWZbOrSStQjF/LrzhcCt8TICohtrcZk6vJUlreOGpd950zzN Tu9uK0YIYhIvf+Xhqe3p8lQ1e3R8wueOJf2i0i69jYy6agKNGnsybpeH1fENodvBFVS3 K2Gr4cMN1Qt8iVl1gEUf0otdJyaq6RAOtGAVrhahi/LBpn+noZukxznFyfiu43lXOs2Z 60grsNrkvNFavvB2V/ywERJmNA0N8HTH+V7VCZdPkTwE6IcK/uummKQP3xddN/d1WdKP d9uA== 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=rHVELqS19rTQ4tecujAhRQFO0ru7LWVkfSyFhbGD/bA=; b=YAsaVPFy4RDaGTRzLpE6zi1C9TY7T/itz7/oWBvKhb5uGEiC9HcGvUAGnwK8TinKvj r6fL3jR+u6ZaK3vAcCgSpcjZtgpxtz1gXMBSZPq4E6fsM6RrbxxX5I0oTGrXCsY0VB4j kAvjYXFmkaDtyBhaXwXYP530gGtg9NtK+3ZfGQAI3uTncwLkeuVuWcGQIio/5ospeYKo g4sdTML4KASjTr0fFxsZqn3vMio5ZSEmLBDihG37XN/+Mhm1KHKULr5wh6aCY0VGI5Vr BX7c9Tonjpa2u28FQV/XzD93fXjx4B8JsNw8E/wasKCvk6K2o6MgdQ485/9b27LLNr67 NsxA== X-Gm-Message-State: AOAM531x7jhteS1iZ+pwvNvHoRBH5T2KfgjRJu3KeuAdUD6v7sp7ZkIO D9t45U1tuIqpd9V3HnrVe0Q4wcXM/Sra8Ofg X-Google-Smtp-Source: ABdhPJyqqpZyiW/57Sn3NUfP2mPwsltUyFTH305D0cirTS8t47bBprSTSwvnlgP+XfoQadAjfBsxZA== X-Received: by 2002:adf:dd04:: with SMTP id a4mr2999482wrm.77.1606909980599; Wed, 02 Dec 2020 03:53:00 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id n189sm1739215wmf.20.2020.12.02.03.52.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:52:59 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Dec 2020 11:52:51 +0000 Message-Id: <20201202115253.14705-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202115253.14705-1-david.plowman@raspberrypi.com> References: <20201202115253.14705-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/5] src: ipa: raspberrypi: agc: Add GetDropFrames method to AGC base class 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" We add a GetDropFrames method to the AgcAlgorithm class which can be called when the AGC is started from scratch. It suggests how many frames should be dropped before displaying any (while the AGC converges). The Raspberry Pi specific implementation makes this customisable from the tuning file. Signed-off-by: David Plowman --- src/ipa/raspberrypi/controller/agc_algorithm.hpp | 1 + src/ipa/raspberrypi/controller/rpi/agc.cpp | 11 +++++++++++ src/ipa/raspberrypi/controller/rpi/agc.hpp | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/ipa/raspberrypi/controller/agc_algorithm.hpp b/src/ipa/raspberrypi/controller/agc_algorithm.hpp index b4ea54fb..bfc9743f 100644 --- a/src/ipa/raspberrypi/controller/agc_algorithm.hpp +++ b/src/ipa/raspberrypi/controller/agc_algorithm.hpp @@ -15,6 +15,7 @@ class AgcAlgorithm : public Algorithm public: AgcAlgorithm(Controller *controller) : Algorithm(controller) {} // An AGC algorithm must provide the following: + virtual unsigned int GetDropFrames() const = 0; virtual void SetEv(double ev) = 0; virtual void SetFlickerPeriod(double flicker_period) = 0; virtual void SetFixedShutter(double fixed_shutter) = 0; // microseconds diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index 9da18c31..94c02d47 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -142,6 +142,7 @@ void AgcConfig::Read(boost::property_tree::ptree const ¶ms) Y_target.Read(params.get_child("y_target")); speed = params.get("speed", 0.2); startup_frames = params.get("startup_frames", 10); + drop_frames = params.get("drop_frames", 6); fast_reduce_threshold = params.get("fast_reduce_threshold", 0.4); base_ev = params.get("base_ev", 1.0); @@ -206,6 +207,16 @@ void Agc::Resume() fixed_analogue_gain_ = 0; } +unsigned int Agc::GetDropFrames() const +{ + // If shutter and gain have been explicitly set, there is no + // convergence to happen, so no need to drop any frames. + if (fixed_shutter_ && fixed_analogue_gain_) + return 0; + else + return config_.drop_frames; +} + void Agc::SetEv(double ev) { ev_ = ev; diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp index 95db1812..1de4d505 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp @@ -52,6 +52,7 @@ struct AgcConfig { Pwl Y_target; double speed; uint16_t startup_frames; + unsigned int drop_frames; double max_change; double min_change; double fast_reduce_threshold; @@ -74,6 +75,7 @@ public: bool IsPaused() const override; void Pause() override; void Resume() override; + unsigned int GetDropFrames() const override; void SetEv(double ev) override; void SetFlickerPeriod(double flicker_period) override; void SetFixedShutter(double fixed_shutter) override; // microseconds From patchwork Wed Dec 2 11:52:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10545 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 0E282BE177 for ; Wed, 2 Dec 2020 11:53:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CED17635B3; Wed, 2 Dec 2020 12:53:03 +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="TpHGzGwG"; dkim-atps=neutral Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1AA5E635AB for ; Wed, 2 Dec 2020 12:53:02 +0100 (CET) Received: by mail-wr1-x441.google.com with SMTP id u12so3593229wrt.0 for ; Wed, 02 Dec 2020 03:53:02 -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=a8CEGHnRSlkm553eVUvpub/RWAwm0vCjsHV2IRyer0k=; b=TpHGzGwGndEwTowvI0z/KCDUKWDf4atPN9NVb1Iv71ka74n7QQ9C7GRqhjX+H3XSdZ 5b0TU8wH6W7FPKAdZkqyBjS5AUZBNAEbqwMml032v6hsCDtX9DyjQXMSJuRNHaITFzod TkrYenrnQD5xMSw08R5b/x6I5BJYZ+ozHPtpqU6xmpDDWvbErh2gSg/23Adism1PJ/a/ jAgZN5RBlh+is9TSFZ5eEMIQPuNFQhnr8NzwBonHgEaX0uMRHOfJl6pIvuDaQb2n2zeb SIpELUKF6SAXeVv6ByCF9Ti5f0lYSdL2WKYmDkMNG+up7RxE3t4Z5lXnCOyqE/Lt6Nx7 Aagg== 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=a8CEGHnRSlkm553eVUvpub/RWAwm0vCjsHV2IRyer0k=; b=QbwJJyjfkiKawwb6RuEZLSo03NDRdrXALLYVDRAxQ81pKcyGSyawZgIj1ku1EOJFca VLKzV5JqZ853Yjk4Jjs83qAf8uDIpMXY0Kfo7hyys4sIIxseEnZkjgTA3M/ejix6zK8W aKOtv3Y7CPyAINK13EtZ6RavbbIY+vozN6p35WW1Ke2O77ntMGYwBQiDahJ06s/a6KCq p8qQMieDPWuHQwKy7ZryM1/pFAmLnZYBcJaVaSwCo89A03gQlmY1lFTILgIlFahUMK+l Egbo/daMqQDZezWQ5v6v/WJTPjnmsjVTsmfK82YDiA/vpLTxjjzAY2UsD0u0+3NYmpXB XWnQ== X-Gm-Message-State: AOAM532ItTRCe2kEAQK+B8Krhw5MiPJOCRbkdEgTYshmB/6HJYedeyT2 TKFGqPGhULGMY3FcJdlYQaq7btGzMVMLoX0v X-Google-Smtp-Source: ABdhPJyR17/r8sBDKJ9MEwCGSoZ2QdkcK7BkHPPoDUk6yR8fADbWS4HfwQLmZJm2U4OcFhwVuLChmA== X-Received: by 2002:adf:bd84:: with SMTP id l4mr3065040wrh.41.1606909981612; Wed, 02 Dec 2020 03:53:01 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id n189sm1739215wmf.20.2020.12.02.03.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:53:00 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Dec 2020 11:52:52 +0000 Message-Id: <20201202115253.14705-5-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202115253.14705-1-david.plowman@raspberrypi.com> References: <20201202115253.14705-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/5] src: ipa: raspberrypi: Move initial frame drop decision to 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" Previously the CamHelper was returning the number of frames to drop (on account of AGC converging). This wasn't really appropriate, it's better for the AGC to do it, which now also knows when exposure and gain have been explicitly set and therefore fewer (or no) frame drops are necessary at all. 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. For many sensors, the correct value for this is zero. Signed-off-by: David Plowman --- src/ipa/raspberrypi/cam_helper.cpp | 6 +++--- src/ipa/raspberrypi/raspberrypi.cpp | 8 ++++++++ 2 files changed, 11 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/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 0300b8d9..ddabdb31 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -192,6 +192,14 @@ int IPARPi::start(const IPAOperationData &ipaConfig, IPAOperationData *result) unsigned int dropFrame = 0; if (firstStart_) { dropFrame = helper_->HideFramesStartup(); + + /* The AGC algorithm may want us to drop more frames. */ + RPiController::AgcAlgorithm *agc = dynamic_cast( + controller_.GetAlgorithm("agc")); + if (agc) + dropFrame = std::max(dropFrame, agc->GetDropFrames()); + LOG(IPARPI, Debug) << "Drop " << dropFrame << " frames on startup"; + mistrustCount_ = helper_->MistrustFramesStartup(); } else { dropFrame = helper_->HideFramesModeSwitch(); From patchwork Wed Dec 2 11:52:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10546 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 69837BE177 for ; Wed, 2 Dec 2020 11:53:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 374A2635AB; Wed, 2 Dec 2020 12:53:05 +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="gG2P9mer"; dkim-atps=neutral Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C8DC635AB for ; Wed, 2 Dec 2020 12:53:03 +0100 (CET) Received: by mail-wm1-x342.google.com with SMTP id v14so6444035wml.1 for ; Wed, 02 Dec 2020 03:53:03 -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=kS/s/B8ia6i0CSyDvuDHlL2Gy/xkSTrmSZjKbtjVXbg=; b=gG2P9merZaUHHaorMfRGiLiKXNAzctRxKqwkpC5NQmGo1ZtVVxGnAnJ1nyRtoZUpDz 0LdlDf2Qhh/daq7K8cfruJEwX6HaqTFTOSRtmisA7NkwPzcD47Vc/RXQczt+2x0SCJHD 8yjhgTb57t6AEY4YOhIJU+TPMeCLW6B9h40lSr5RnZxQs4uXJAvMdiEaf3NWKxKSIqfF DwU4C/0+4HlOOHHIxqicOjhla9WjwihhwaL1+lqI6sASIG9Q/ozIxLJDpTJedllpX3Nc sSSi+JWhhuX/ApM/Q2VlKM6cRRaQ/Ht8pWU3bp9luHXWIYBI1sZorLhSVLM+oxMXoK87 DhKw== 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=kS/s/B8ia6i0CSyDvuDHlL2Gy/xkSTrmSZjKbtjVXbg=; b=sivqxDFqwy7PUxBpbwyvwX2DRotV+LwDFiSHiNFNHuOjer/Wpc8KS02Nd3rQwpMF7L O4T/bIwQIvOMU66vPMCNJ8okFq3At9KdY8dgtZ33j9ngnK2qTVpNUj7NQH3DMst0K/Yr Ty5LwSg6M0KXNpQexIxLEu7rr6po8Sx4AufvXWMJVHc6MI+fIAH7sKSvWMykVp6uvFEL W/phaT5h5Knm0QCMs/ocySp8TpGcrjQxbigr60thk/yXdXmBuRV/Z0vasBVACZkx38j5 fJQe4WEwlVdTT3usn19Qv/iQTA4HIuh4wSOHHtgFT1MUBWzAWiOvh2kmfMBTzeAZO05i V9DA== X-Gm-Message-State: AOAM530Na7LpfOYNj2mUyQOeyOsc1vdLiGzrXV8uUhDuxW/6OSL1j7v+ +5bD6AcOiAkRUnIzFJUHT2ZlWaHuqD9gF0ET X-Google-Smtp-Source: ABdhPJzEcROacJ/pNddkUw4e6zMh+ntUCPWBz9VMZPU6U3hCf7KHMJlCx2mnYNEYEbOkXrPGQkiV/g== X-Received: by 2002:a05:600c:22d9:: with SMTP id 25mr2735364wmg.158.1606909982531; Wed, 02 Dec 2020 03:53:02 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id n189sm1739215wmf.20.2020.12.02.03.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:53:01 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Dec 2020 11:52:53 +0000 Message-Id: <20201202115253.14705-6-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202115253.14705-1-david.plowman@raspberrypi.com> References: <20201202115253.14705-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] src: ipa: raspberrypi: Drop the correct number of frames on startup for ov5647 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 ov5647 delivers two under-exposed frames at startup, even when the exposure and gain are explicitly programmed. The system needs to be told to drop these. Signed-off-by: David Plowman --- src/ipa/raspberrypi/cam_helper_ov5647.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 { /*