{"id":17604,"url":"https://patchwork.libcamera.org/api/patches/17604/?format=json","web_url":"https://patchwork.libcamera.org/patch/17604/","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":"<20221014131846.27169-9-naush@raspberrypi.com>","date":"2022-10-14T13:18:44","name":"[libcamera-devel,v1,08/10] pipeline: raspberrypi: Allow pipeline handler to always use the newest frame","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"57ce004b87307b406b098c8f9bd686c6bfe9b233","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/17604/mbox/","series":[{"id":3555,"url":"https://patchwork.libcamera.org/api/series/3555/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3555","date":"2022-10-14T13:18:37","name":"Raspberry Pi: Platform configuration and buffer allocation improvements","version":1,"mbox":"https://patchwork.libcamera.org/series/3555/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17604/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17604/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 516CDC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 14 Oct 2022 13:19:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0A29B62DE1;\n\tFri, 14 Oct 2022 15:19:04 +0200 (CEST)","from mail-wr1-x433.google.com (mail-wr1-x433.google.com\n\t[IPv6:2a00:1450:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7B6CB62DC7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 14 Oct 2022 15:18:58 +0200 (CEST)","by mail-wr1-x433.google.com with SMTP id j7so7547672wrr.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 14 Oct 2022 06:18:58 -0700 (PDT)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tg17-20020a05600c001100b003c6bbe910fdsm8282458wmc.9.2022.10.14.06.18.56\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 14 Oct 2022 06:18:57 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1665753544;\n\tbh=Sx94jdwybthZB2u6g3tjU5CI9+F1KFjRSPOcsPRcxLE=;\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=J078x1/avHt2CWZvPT2KVV6Lt77kiBaq9QLBuTTE+1J/2PY9Lsj2lbgTAmACrGdUz\n\tNmvMS70rqHiUR/TCRo97X+wxtCxjkUH9jIR/oeLk/iY+9NhPaYAoOT+5LdQueFA6KF\n\t4CxyNfVAfgL55c3gDnJL8kPZ3wwBorA53OQvmhCljqAFImvKPXhKHktu/ISdohsCV3\n\tD18YavjgJ6e7qMHd6F/2CXkIKP+ZYcZcxuP6o7HmSu6Xj1rHi+kwVKTF8ty6wLgFpI\n\tQCFjSfZguMmKnyTDigOSBbo5+tG4QqEXsr0wJ91Z4+MG6YRGDvZcTo5AHJHLtyYDOM\n\tkGVGUII1G3PXA==","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=/JfxSj6icGHMD+GjblGRyWFSbev1nXgdNOIATEO+/Es=;\n\tb=ElZ+RUkp/958Iwu9OCQEOAlUo5Z5wbJGZAPvPwry5lV3Pt4LtLkCLISfA63g29J3re\n\t81UZjwZG9p5PoJdtYbUAAVS7wYIV99+dSb9/3rwxEp5XFsrteqec2n3rxNfaTT7Pa8Mr\n\t8+1Sq/jjNfP3Ghv/F/5I7Xns5PpwfizrGuoNnUbqY0fCgT9nsyRWaKNRe2ZL7Dr/WZrE\n\t9ulXR5Ah+UHIkdr3y3cDNXxZ7Vzv8rkgjrj7lFq2x+XzMd9SpShV2aSkDBF+50696tr8\n\tGUKKSUJfjvKs3NSDVmDSAcr+ftF9Y0BV+qEok33G661AbNKDThC4bne5AkNffRDWPWB0\n\tmUPw=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"ElZ+RUkp\"; 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=/JfxSj6icGHMD+GjblGRyWFSbev1nXgdNOIATEO+/Es=;\n\tb=Hl2gE8l2S9y+jUwkDYmtP5u+7blvHvv2fUWJHSn0lWGje9inKiuQzGh+DZnQV94L/w\n\twUW30JvbOfDgxEKOm94AFcZJVzVN7XxCGzEk+cXPLym+ZnrlQqoOE7Q5sFPh1XFGs6VP\n\tHtfMInvReo/M0Ainy7zBLnnoJh4QXAqIn8qW7Jvyf1Q1PqXpuNd8/ZMQnf5nFQj/7iGI\n\tQ4S1WKQWeXCOerA5Oc8JfwQ34xK4Sb4fQyYqS2uPyfEyNfkoZxVX0VJSBABNqZmdAE9C\n\tY9rvQS+IOi4/VWl3UHOT6lXpHgX/xV9Ds15XkrkjWs7rqk8J5XF6f/kKWfYndolLmzB+\n\tYSAw==","X-Gm-Message-State":"ACrzQf2idR3jRiIaUGNW6pwpSxRJeyuZzcg6/pk7sLLzWSR+tQYBLMDT\n\te0JDJXyQrSkXaCesamvLxgav0E5SPPWkRg==","X-Google-Smtp-Source":"AMsMyM4odAL1BT9hLc0THqF2wVvfB49vmy1ADwpHSKLhiBkA4MGn3gQlMLy0HZbAb1h0UDcnGVOxNg==","X-Received":"by 2002:a5d:4683:0:b0:22e:6be0:dfc6 with SMTP id\n\tu3-20020a5d4683000000b0022e6be0dfc6mr3412587wrq.573.1665753537527; \n\tFri, 14 Oct 2022 06:18:57 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 14 Oct 2022 14:18:44 +0100","Message-Id":"<20221014131846.27169-9-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20221014131846.27169-1-naush@raspberrypi.com>","References":"<20221014131846.27169-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1 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>\n---\n .../pipeline/raspberrypi/data/default.json    |  7 ++++++-\n .../pipeline/raspberrypi/raspberrypi.cpp      | 19 +++++++++++++++++++\n 2 files changed, 25 insertions(+), 1 deletion(-)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/data/default.json b/src/libcamera/pipeline/raspberrypi/data/default.json\nindex 707414bcc5c5..f900ca824523 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 heavey 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 135948d82f41..d9bea35c88a3 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -301,6 +301,7 @@ public:\n \t\tunsigned int minTotalUnicamBuffers;\n \t\tunsigned int numOutput0Buffers;\n \t\tbool disableStartupFrameDrops;\n+\t\tbool returnNewestFrames;\n \t};\n \n \tConfig config_;\n@@ -1432,6 +1433,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@@ -1468,6 +1470,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 || config.minTotalUnicamBuffers < 1) {\n \t\tLOG(RPI, Error) << \"Invalid Unicam buffer configuration used!\";\n@@ -2320,6 +2324,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","v1","08/10"]}