{"id":17915,"url":"https://patchwork.libcamera.org/api/patches/17915/?format=json","web_url":"https://patchwork.libcamera.org/patch/17915/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20221129134534.2933-9-naush@raspberrypi.com>","date":"2022-11-29T13:45:32","name":"[libcamera-devel,v2,08/10] pipeline: raspberrypi: Allow pipeline handler to always use the newest frame","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"7596ef450dbb9a61962dab45b0a21fcc5f9964a8","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17915/mbox/","series":[{"id":3647,"url":"https://patchwork.libcamera.org/api/series/3647/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3647","date":"2022-11-29T13:45:24","name":"Raspberry Pi: Platform configuration and buffer allocation improvements","version":2,"mbox":"https://patchwork.libcamera.org/series/3647/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17915/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17915/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 4EAECBE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Nov 2022 13:45:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0254D6334B;\n\tTue, 29 Nov 2022 14:45:50 +0100 (CET)","from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com\n\t[IPv6:2a00:1450:4864:20::32a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3441F6334E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Nov 2022 14:45:44 +0100 (CET)","by mail-wm1-x32a.google.com with SMTP id\n\tl39-20020a05600c1d2700b003cf93c8156dso10846359wms.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Nov 2022 05:45:44 -0800 (PST)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tn8-20020a05600c3b8800b003cfbbd54178sm3565636wms.2.2022.11.29.05.45.42\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 29 Nov 2022 05:45:43 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1669729551;\n\tbh=jUW5kSgJZ0cyJT+RYMdONK0L9oZuYffToSENJa65fwQ=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=H1abapNmIKK+9HptkcU6xThJO9A2CE2c260aBx+K8D/hpCj0xBDO6D+s5Xx/aMqT8\n\tWkv3ZGI9WOQIb3XZSrQJFv0xepcyNh2wTJAZhWWB8Laiz8lWvr37hznY3BnPOlTMUl\n\tTMpv4ZrKPNFifOQZVG+TUwMGOvCcujTLzMhcipsuEVH8uv189eGeGfTyO6B0Hp6Kli\n\t7lM89ctiSLVmAeGdQG1AdqIuVH/YCmoIXGlvGmQhFucItLq+Q37xlTxFuxZeIQZmrV\n\tonW9/XkmO7K7o0BMMUp14GlAE3oED1xZSKP+bwVYTEozCXHpAyRndQ5oa1bE82WVia\n\tKvFnSvJ8yLdeQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=AAjQKP/RW4k0UC1sBsQ3vu92QPpJTB9qQfTD6RkbYDM=;\n\tb=Fy2PfYFGjB3yHmADodINJ1gewL/r/tPHAJQ4YW/rBCKq3dEwVW7DyxtzjyVhrl9fFA\n\tDmc/ZGK62O/7u4EkTxNi20XQ8E1IBZaWo9IQB0Pfh0mNp4OuSbbV8Ceml+sK2WUykMlv\n\tiR45fvIQIRrQxzVeUGbql/BN8OLHxJhBZvu9fy8CVxV5VlIRWvmCz14LAYCozI0TloiY\n\tWkP6n5u6XSyOLQtyTbGC1lb3cODTByiMtuc6Cci9S1VVQT1k8lNmX3pixQbtBmMWjMax\n\tUpno2fIqjMM8ts0eRQXvq3SKdtr3w3gybu9VHeKHnv6GctEXVlRKO+pgoBFNM0IuRkis\n\t7xyA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"Fy2PfYFG\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=AAjQKP/RW4k0UC1sBsQ3vu92QPpJTB9qQfTD6RkbYDM=;\n\tb=l4ewdep10YHLqsXHJXUgNXSfvnEpQSHOH4S1oSfRaLFq5NCVc0MC0AOnlGF24Sa9Rn\n\tZ7+K7JAy0qgnWehiVLgRA7/zDl38Zq6qJOsuXp14F7/eEQm2NkVAler2dzbPDhl631Q9\n\tUs3awPaNNcGwT7WPzeH4mUQNhsZsueFbKh5WBiyjPN7mCWhoc7SrECfiga5PoEpVihDO\n\tvo00BZ2ebzlkvZc4mNp6p/JMrGmPsRiwB1UqlTLkrO/y24t+pE69lUi1WYkC82fWWt2q\n\tQH4svducB25C5VqSqqL9o1+Qa8cS2k4JqcMLT3XG9q4/ZKt0dJ+qu0geZdRuQbOWPPuA\n\tckEg==","X-Gm-Message-State":"ANoB5plyyLySSBmjzt9DtCh8Q9z1g4ECdSkvyXopEKi5DXr5oQwxrGor\n\tO/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\n\tl18-20020a05600c4f1200b003cfe7bd303amr29421179wmq.151.1669729543514; \n\tTue, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 08/10] pipeline: raspberrypi: Allow\n\tpipeline handler to always use the newest frame","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add a pipeline config parameter \"return_newest_frames\" to always use the\nmost recently captured Unicam frame when processing a request. This effectively\nstops the pipeline handler from queuing Unicam buffers and processing requests\nusing the buffer at the front of the queue.\n\nNote that setting this parameter might incur unnecessary frame drops during\ntimes of high transient CPU loads where the application might not be able to\nprovide requests quick enough.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../pipeline/raspberrypi/data/default.json    |  7 +++++-\n .../pipeline/raspberrypi/raspberrypi.cpp      | 23 +++++++++++++++++++\n 2 files changed, 29 insertions(+), 1 deletion(-)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/data/default.json b/src/libcamera/pipeline/raspberrypi/data/default.json\nindex 707414bcc5c5..eda053258c67 100644\n--- a/src/libcamera/pipeline/raspberrypi/data/default.json\n+++ b/src/libcamera/pipeline/raspberrypi/data/default.json\n@@ -18,6 +18,11 @@\n                 \"num_output0_buffers\": 1,\n \n                 # Override any request from the IPA to drop a number of startup frames.\n-                \"disable_startup_frame_drops\": false\n+                \"disable_startup_frame_drops\": false,\n+\n+                # Always process a pending request with the last captured sensor frame.\n+                # Note that this might lead to avoidable frame drops during periods\n+                # of transient heavy CPU loading.\n+                \"return_newest_frames\": false\n         }\n }\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex ef49d32037af..a369fbd2a528 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -317,6 +317,11 @@ public:\n \t\t * frames.\n \t\t */\n \t\tbool disableStartupFrameDrops;\n+\t\t/*\n+\t\t * Always process a pending request with the last captured sensor\n+\t\t * frame.\n+\t\t */\n+\t\tbool returnNewestFrames;\n \t};\n \n \tConfig config_;\n@@ -1457,6 +1462,7 @@ int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data)\n \t\t.minTotalUnicamBuffers = 4,\n \t\t.numOutput0Buffers = 1,\n \t\t.disableStartupFrameDrops = false,\n+\t\t.returnNewestFrames = false,\n \t};\n \n \tchar const *configFromEnv = utils::secure_getenv(\"LIBCAMERA_RPI_CONFIG_FILE\");\n@@ -1493,6 +1499,8 @@ int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data)\n \t\tphConfig[\"num_output0_buffers\"].get<unsigned int>(config.numOutput0Buffers);\n \tconfig.disableStartupFrameDrops =\n \t\tphConfig[\"disable_startup_frame_drops\"].get<bool>(config.disableStartupFrameDrops);\n+\tconfig.returnNewestFrames =\n+\t\tphConfig[\"return_newest_frames\"].get<bool>(config.returnNewestFrames);\n \n \tif (config.minTotalUnicamBuffers < config.minUnicamBuffers) {\n \t\tLOG(RPI, Error) << \"Invalid configuration: min_total_unicam_buffers must be >= min_unicam_buffers!\";\n@@ -2349,6 +2357,21 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em\n \tif (bayerQueue_.empty())\n \t\treturn false;\n \n+\t/*\n+\t * If the pipeline is configured to only ever return the most recently\n+\t * captured frame, empty the buffer queue until a single element is\n+\t * left, corresponding to the most recent buffer. Note that this will\n+\t * likely result in possibly avoidable dropped frames.\n+\t */\n+\tif (config_.returnNewestFrames && !unicam_[Unicam::Image].isExternal()) {\n+\t\twhile (bayerQueue_.size() > 1) {\n+\t\t\tFrameBuffer *bayer = bayerQueue_.front().buffer;\n+\n+\t\t\tunicam_[Unicam::Image].returnBuffer(bayer);\n+\t\t\tbayerQueue_.pop();\n+\t\t}\n+\t}\n+\n \t/*\n \t * Find the embedded data buffer with a matching timestamp to pass to\n \t * the IPA. Any embedded buffers with a timestamp lower than the\n","prefixes":["libcamera-devel","v2","08/10"]}