From patchwork Tue Nov 29 13:45:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17915 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 4EAECBE08B for ; Tue, 29 Nov 2022 13:45:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0254D6334B; Tue, 29 Nov 2022 14:45:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669729551; bh=jUW5kSgJZ0cyJT+RYMdONK0L9oZuYffToSENJa65fwQ=; 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=H1abapNmIKK+9HptkcU6xThJO9A2CE2c260aBx+K8D/hpCj0xBDO6D+s5Xx/aMqT8 Wkv3ZGI9WOQIb3XZSrQJFv0xepcyNh2wTJAZhWWB8Laiz8lWvr37hznY3BnPOlTMUl TMpv4ZrKPNFifOQZVG+TUwMGOvCcujTLzMhcipsuEVH8uv189eGeGfTyO6B0Hp6Kli 7lM89ctiSLVmAeGdQG1AdqIuVH/YCmoIXGlvGmQhFucItLq+Q37xlTxFuxZeIQZmrV onW9/XkmO7K7o0BMMUp14GlAE3oED1xZSKP+bwVYTEozCXHpAyRndQ5oa1bE82WVia KvFnSvJ8yLdeQ== Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3441F6334E for ; Tue, 29 Nov 2022 14:45:44 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Fy2PfYFG"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id l39-20020a05600c1d2700b003cf93c8156dso10846359wms.4 for ; Tue, 29 Nov 2022 05:45:44 -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=AAjQKP/RW4k0UC1sBsQ3vu92QPpJTB9qQfTD6RkbYDM=; b=Fy2PfYFGjB3yHmADodINJ1gewL/r/tPHAJQ4YW/rBCKq3dEwVW7DyxtzjyVhrl9fFA Dmc/ZGK62O/7u4EkTxNi20XQ8E1IBZaWo9IQB0Pfh0mNp4OuSbbV8Ceml+sK2WUykMlv iR45fvIQIRrQxzVeUGbql/BN8OLHxJhBZvu9fy8CVxV5VlIRWvmCz14LAYCozI0TloiY WkP6n5u6XSyOLQtyTbGC1lb3cODTByiMtuc6Cci9S1VVQT1k8lNmX3pixQbtBmMWjMax Upno2fIqjMM8ts0eRQXvq3SKdtr3w3gybu9VHeKHnv6GctEXVlRKO+pgoBFNM0IuRkis 7xyA== 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=AAjQKP/RW4k0UC1sBsQ3vu92QPpJTB9qQfTD6RkbYDM=; b=l4ewdep10YHLqsXHJXUgNXSfvnEpQSHOH4S1oSfRaLFq5NCVc0MC0AOnlGF24Sa9Rn Z7+K7JAy0qgnWehiVLgRA7/zDl38Zq6qJOsuXp14F7/eEQm2NkVAler2dzbPDhl631Q9 Us3awPaNNcGwT7WPzeH4mUQNhsZsueFbKh5WBiyjPN7mCWhoc7SrECfiga5PoEpVihDO vo00BZ2ebzlkvZc4mNp6p/JMrGmPsRiwB1UqlTLkrO/y24t+pE69lUi1WYkC82fWWt2q QH4svducB25C5VqSqqL9o1+Qa8cS2k4JqcMLT3XG9q4/ZKt0dJ+qu0geZdRuQbOWPPuA ckEg== X-Gm-Message-State: ANoB5plyyLySSBmjzt9DtCh8Q9z1g4ECdSkvyXopEKi5DXr5oQwxrGor O/rE5thcl4cjTOKadjZz0MyA936+/p/pNQ== X-Google-Smtp-Source: AA0mqf7GqneGSIyczTX+sDNDxNvYEpAtdKukflatXthkZ7e+VuUNo5u0QdBNwTptKqR/1pYk3G/OhA== X-Received: by 2002:a05:600c:4f12:b0:3cf:e7bd:303a with SMTP id l18-20020a05600c4f1200b003cfe7bd303amr29421179wmq.151.1669729543514; Tue, 29 Nov 2022 05:45:43 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id n8-20020a05600c3b8800b003cfbbd54178sm3565636wms.2.2022.11.29.05.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 05:45:43 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Nov 2022 13:45:32 +0000 Message-Id: <20221129134534.2933-9-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221129134534.2933-1-naush@raspberrypi.com> References: <20221129134534.2933-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/10] 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/default.json | 7 +++++- .../pipeline/raspberrypi/raspberrypi.cpp | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/data/default.json b/src/libcamera/pipeline/raspberrypi/data/default.json index 707414bcc5c5..eda053258c67 100644 --- a/src/libcamera/pipeline/raspberrypi/data/default.json +++ b/src/libcamera/pipeline/raspberrypi/data/default.json @@ -18,6 +18,11 @@ "num_output0_buffers": 1, # 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 ef49d32037af..a369fbd2a528 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -317,6 +317,11 @@ public: * frames. */ bool disableStartupFrameDrops; + /* + * Always process a pending request with the last captured sensor + * frame. + */ + bool returnNewestFrames; }; Config config_; @@ -1457,6 +1462,7 @@ int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data) .minTotalUnicamBuffers = 4, .numOutput0Buffers = 1, .disableStartupFrameDrops = false, + .returnNewestFrames = false, }; char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RPI_CONFIG_FILE"); @@ -1493,6 +1499,8 @@ int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data) phConfig["num_output0_buffers"].get(config.numOutput0Buffers); 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!"; @@ -2349,6 +2357,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