From patchwork Fri Dec 9 09:00:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17975 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 622F9BDE6B for ; Fri, 9 Dec 2022 09:01:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 08C4363369; Fri, 9 Dec 2022 10:01:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1670576503; bh=rEqIEbuaGZgs29+h7K/U15YmT6g+aKk1ijX90G+xZnU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=lsoK3PoktQxiszPeRnBi0CZ9DOYpexXzusUZub7xCJbL4VGi9/UWrvc62JHZ/WwdU sqvyhEMkf9GRsJMrzN/8+7UMraa2HAsLsbGlkh5sS8pccXA4eCDVN/RCVD0fg/gHlv /GCO/9IeMhmnjSRpH41MXEFToTcnPzD19DU8GWJvSTHlyrFfdveCKB6zpA54uuVL5U 69pxwdilv9vxw7O4oFBOzhF4+ehxS3QYkXHP/pm99BGopYsLfUSqxVm9/DZOSw7Sze ZDwP5ZD+kSLWpLougu8AKhSRkmxk2obMbRijQzEZ/hxBUEMezMttxYo5hCu0mExyTv 1uGJz3wMo4GgA== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F06561F1E for ; Fri, 9 Dec 2022 10:01:37 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="BIlIPRuF"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id p13-20020a05600c468d00b003cf8859ed1bso2912508wmo.1 for ; Fri, 09 Dec 2022 01:01:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=b9p3hmsDwsTnR3TtFnBMbkk9Es9Dkr0IvE7b5jVv5W0=; b=BIlIPRuFhpuucDzOu14c2AIMEuoQfemOKBQ1Tj0ssU7J/P0FS4yF5ScV0iHQ9bJbvg S0B5tb/d2EiPkgh4mpqGZ1xhkd3If7Jc56Rdzi41fdsDiuyzPF2X/VRzhQ5QV0NF7Bho U6dDRSkNrjre9u8qw69Tdi2BS3hqGCGuki6AhgmlACRWPL85c6hdok73eQwAegzzv4mI h3XFPwxO1FggukdWEDbhvImX91tO5fDbVqWRxDEascZ4ABLVbrGVLJXqKiCXaVCChs/e cDOfBhz7DWunyBSM2nPCcR+N/+upeMMX1vrhAKKCEy4Mr7bOdP9XZiuEr8U/GQW7mczI sasg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b9p3hmsDwsTnR3TtFnBMbkk9Es9Dkr0IvE7b5jVv5W0=; b=sogVWB40qGb4Ez3q9mvgMInYLnr0/CVrMvycsey+V5bvLmjF9MJnN27K6aszvGi6ik WA7i3WxOzbpamezfDXrVwYlVU1/Sr56/3Tt8hJCeqovW9WMKvjq41IT0l77rDzVH78T6 uFmQB9BQ7aF73Y8/CasL+yYEn/1MFVz5cPwghb5jSkgtULZm7AOrC2QQevYHlOolqkum 4Z9YGxNTMueqVq/6abbEp4qGJL6UQY4vgL1p54y5YcnZLIvemO/ZP70S+YubzBuRTSgg PeyFd4yroY16WOCD0jU01zltuchpDN8mLwadAOlREl+6uiv129B3oSkxNYfp3JcWOOrj RZhw== X-Gm-Message-State: ANoB5pkRaz0k0XMzDzmg5etJ61DkVM0dnd5dr6d8NganwdRpT7m2Zcjh b/a6HMrgHiDgXZ8+3eccAr86dsOkmhywTVfk X-Google-Smtp-Source: AA0mqf77tEQUaQD7JJWuDK4aLGsIosHzB7YADVsd0Wno2MP18EhyKLlenEiaTw7OXkH+3GD/ta0cCw== X-Received: by 2002:a05:600c:35c4:b0:3cf:85f7:bbc4 with SMTP id r4-20020a05600c35c400b003cf85f7bbc4mr4272428wmq.2.1670576496889; Fri, 09 Dec 2022 01:01:36 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id bd10-20020a05600c1f0a00b003cf774c31a0sm7773674wmb.16.2022.12.09.01.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 01:01:36 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 9 Dec 2022 09:00:49 +0000 Message-Id: <20221209090050.19441-12-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221209090050.19441-1-naush@raspberrypi.com> References: <20221209090050.19441-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 11/12] pipeline: raspberrypi: Allow pipeline handler to always use the newest frame 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: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a pipeline config parameter "return_newest_frames" to always use the most recently captured Unicam frame when processing a request. This effectively stops the pipeline handler from queuing Unicam buffers and processing requests using the buffer at the front of the queue. Note that setting this parameter might incur unnecessary frame drops during times of high transient CPU loads where the application might not be able to provide requests quick enough. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- .../pipeline/raspberrypi/data/example.yaml | 7 +++++- .../pipeline/raspberrypi/raspberrypi.cpp | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/data/example.yaml b/src/libcamera/pipeline/raspberrypi/data/example.yaml index 421f30e62aa3..04a117f38ada 100644 --- a/src/libcamera/pipeline/raspberrypi/data/example.yaml +++ b/src/libcamera/pipeline/raspberrypi/data/example.yaml @@ -19,6 +19,11 @@ # Override any request from the IPA to drop a number of startup # frames. - "disable_startup_frame_drops": false + "disable_startup_frame_drops": false, + + # Always process a pending request with the last captured sensor + # frame. Note that this might lead to avoidable frame drops + # during periods of transient heavy CPU loading. + "return_newest_frames": false } } diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 4f15bcf0052a..68c70cc19995 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -313,6 +313,11 @@ public: * frames. */ bool disableStartupFrameDrops; + /* + * Always process a pending request with the last captured sensor + * frame. + */ + bool returnNewestFrames; }; Config config_; @@ -1712,6 +1717,7 @@ int RPiCameraData::configurePipeline() .minUnicamBuffers = 2, .minTotalUnicamBuffers = 4, .disableStartupFrameDrops = false, + .returnNewestFrames = false, }; char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RPI_CONFIG_FILE"); @@ -1747,6 +1753,8 @@ int RPiCameraData::configurePipeline() phConfig["min_total_unicam_buffers"].get(config_.minTotalUnicamBuffers); config_.disableStartupFrameDrops = phConfig["disable_startup_frame_drops"].get(config_.disableStartupFrameDrops); + config_.returnNewestFrames = + phConfig["return_newest_frames"].get(config_.returnNewestFrames); if (config_.minTotalUnicamBuffers < config_.minUnicamBuffers) { LOG(RPI, Error) << "Invalid configuration: min_total_unicam_buffers must be >= min_unicam_buffers"; @@ -2326,6 +2334,21 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em if (bayerQueue_.empty()) return false; + /* + * If the pipeline is configured to only ever return the most recently + * captured frame, empty the buffer queue until a single element is + * left, corresponding to the most recent buffer. Note that this will + * likely result in possibly avoidable dropped frames. + */ + if (config_.returnNewestFrames && !unicam_[Unicam::Image].isExternal()) { + while (bayerQueue_.size() > 1) { + FrameBuffer *bayer = bayerQueue_.front().buffer; + + unicam_[Unicam::Image].returnBuffer(bayer); + bayerQueue_.pop(); + } + } + /* * Find the embedded data buffer with a matching timestamp to pass to * the IPA. Any embedded buffers with a timestamp lower than the