From patchwork Mon Dec 7 18:01:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10598 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 7FFDFBDB1F for ; Mon, 7 Dec 2020 18:01:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 49CCA67E6A; Mon, 7 Dec 2020 19:01:57 +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="mHrEhWOa"; dkim-atps=neutral Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 58FB0635A0 for ; Mon, 7 Dec 2020 19:01:55 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id d17so20761022ejy.9 for ; Mon, 07 Dec 2020 10:01:55 -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=DH+SHOeKlT6c2ZRs8mi0dfzgwQzv992L13kp55/VB20=; b=mHrEhWOaW/D6Y6X/RnSZ3ESMMQNgUKNQGYNso0a71bebfmZkhU9YSbexLn+JzpAgMm zCGdCAPBqfEMCnzcH6Iy+mVHPQ4Nzw44vh2EZD7Nq8xaUkntKQhJ+FvvTq0/qNkKk3RS QaTGmoe5l051ZdBw9w5Ax9HSsJ3zyc7h6huNE4rUJJTY/VI5x7iWrmv8o6GoWKaW4O26 MgY6eBCW1+EpkgoEc12h2IBpYUZzspY9iluP6P/ZCMGG0zKNn67JJHUURL71lP6iXFkC RjPG8UQueZijX7JVx908zxKuXpSiD1YJfANEL5iY+EhmF/48uwXgpEeh7HxORTBXeiks z/fQ== 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=DH+SHOeKlT6c2ZRs8mi0dfzgwQzv992L13kp55/VB20=; b=o71K4eQ7v1GZvWDjZKmwM7Rw/asuRl1/dMv9BQW0s2UM6CkEWV+7nrClWHGBuOfLAw XGAb2u/S1LE4d1X9UnwzDarvVeIvmSCZRH2TECe5bN8TtLMwYzMVrwQqf92xBbm96/Id ZNsQe2R2HXYM+2cQJfrJ8O1QD13jLAXitJzoaurHbgH3vozW5Kxc4yAPIPhdvyac0xoh VyOMZTPwWywukfNBKu5PMkWbIFxV1Y/JhmwnOCCwR6kKKCmQpek8fH2ZcDlVZodmFFKY dxo1IVqiqPji3N3tDF/X6EvCGHzhp8UGBykXPZ2JIxtfeKDw8ey4WcSxqXgQSJ18DL7K HOKg== X-Gm-Message-State: AOAM531kNCOvDjmT5SAeDU3q2c9r5/argThk1FeC8fyzGQh8zu4fvkWP 0UMeaOnmjrF8upxrTKMh9hCW0jAXQ8/AsIJw X-Google-Smtp-Source: ABdhPJxC/iSWV9H3llOx0xgCAxWEtaZ1jb9VHfY6JmSMP5BfaFahj6IARYSn80HlDZWvxh1JMG9O6Q== X-Received: by 2002:a17:906:6091:: with SMTP id t17mr20418739ejj.476.1607364114686; Mon, 07 Dec 2020 10:01:54 -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.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 10:01:49 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Dec 2020 18:01:16 +0000 Message-Id: <20201207180121.6374-2-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 1/6] 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. Note how we need to be able to tell the very first time we start the camera from subsequent restarts, hence addition of the "firstStart_" flag. Both the IPA implementation file and the pipeline handler need matching modifications. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/raspberrypi.cpp | 45 ++++++++++--------- .../pipeline/raspberrypi/raspberrypi.cpp | 25 ++++++----- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 2027f1c0..0e89af00 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,27 @@ 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; } @@ -293,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.