[{"id":25710,"web_url":"https://patchwork.libcamera.org/comment/25710/","msgid":"<CAHW6GY+xyn6=fkhm6VES-twr8p5V7zzdo=SgA+Zo+Jdqxd7-eg@mail.gmail.com>","date":"2022-11-01T12:18:06","subject":"Re: [libcamera-devel] [PATCH v1 08/10] pipeline: raspberrypi: Allow\n\tpipeline handler to always use the newest frame","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Naush\n\nThanks for the patch!\n\nOn Fri, 14 Oct 2022 at 14:19, Naushir Patuck via libcamera-devel\n<libcamera-devel@lists.libcamera.org> wrote:\n>\n> Add a pipeline config parameter \"return_newest_frames\" to always use the\n> most recently captured Unicam frame when processing a request. This effectively\n> stops the pipeline handler from queuing Unicam buffers and processing requests\n> using the buffer at the front of the queue.\n>\n> Note that setting this parameter might incur unnecessary frame drops during\n> times of high transient CPU loads where the application might not be able to\n> provide requests quick enough.\n>\n> Signed-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(-)\n>\n> diff --git a/src/libcamera/pipeline/raspberrypi/data/default.json b/src/libcamera/pipeline/raspberrypi/data/default.json\n> index 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\ns/heavey/heavy/    (sorry!)\n\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nThanks!\nDavid\n\n> +                \"return_newest_frames\": false\n>          }\n>  }\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 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>                 unsigned int minTotalUnicamBuffers;\n>                 unsigned int numOutput0Buffers;\n>                 bool disableStartupFrameDrops;\n> +               bool returnNewestFrames;\n>         };\n>\n>         Config config_;\n> @@ -1432,6 +1433,7 @@ int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data)\n>                 .minTotalUnicamBuffers = 4,\n>                 .numOutput0Buffers = 1,\n>                 .disableStartupFrameDrops = false,\n> +               .returnNewestFrames = false,\n>         };\n>\n>         char const *configFromEnv = utils::secure_getenv(\"LIBCAMERA_RPI_CONFIG_FILE\");\n> @@ -1468,6 +1470,8 @@ int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data)\n>                 phConfig[\"num_output0_buffers\"].get<unsigned int>(config.numOutput0Buffers);\n>         config.disableStartupFrameDrops =\n>                 phConfig[\"disable_startup_frame_drops\"].get<bool>(config.disableStartupFrameDrops);\n> +       config.returnNewestFrames =\n> +               phConfig[\"return_newest_frames\"].get<bool>(config.returnNewestFrames);\n>\n>         if (config.minTotalUnicamBuffers < config.minUnicamBuffers || config.minTotalUnicamBuffers < 1) {\n>                 LOG(RPI, Error) << \"Invalid Unicam buffer configuration used!\";\n> @@ -2320,6 +2324,21 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em\n>         if (bayerQueue_.empty())\n>                 return false;\n>\n> +       /*\n> +        * If the pipeline is configured to only ever return the most recently\n> +        * captured frame, empty the buffer queue until a single element is\n> +        * left, corresponding to the most recent buffer. Note that this will\n> +        * likely result in possibly avoidable dropped frames.\n> +        */\n> +       if (config_.returnNewestFrames && !unicam_[Unicam::Image].isExternal()) {\n> +               while (bayerQueue_.size() > 1) {\n> +                       FrameBuffer *bayer = bayerQueue_.front().buffer;\n> +\n> +                       unicam_[Unicam::Image].returnBuffer(bayer);\n> +                       bayerQueue_.pop();\n> +               }\n> +       }\n> +\n>         /*\n>          * Find the embedded data buffer with a matching timestamp to pass to\n>          * the IPA. Any embedded buffers with a timestamp lower than the\n> --\n> 2.25.1\n>","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 D78F0BDB16\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  1 Nov 2022 12:18:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2EAA363031;\n\tTue,  1 Nov 2022 13:18:21 +0100 (CET)","from mail-pf1-x430.google.com (mail-pf1-x430.google.com\n\t[IPv6:2607:f8b0:4864:20::430])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 73E9563009\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  1 Nov 2022 13:18:19 +0100 (CET)","by mail-pf1-x430.google.com with SMTP id k22so13314212pfd.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 01 Nov 2022 05:18:19 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1667305101;\n\tbh=SOdN4oXQULaWDrK43hKClROwSJFL5HKHNeFYuTof9Mc=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=h/2CSAF/26FpPM0cWUu897GlqGW0MI5VZ6V0daCClki6dZ55aYf9LlT1H9Ha+7E2w\n\tjhuEg5ICmX+hkoC7VY49L4QAZX6K0MgIqKDjjYqz9h/fJmT18dTYpYOdCKg7P9KBQv\n\t1d7ZmF0afnu3kFVx6ZMRw5bu/2qSwYA8aBjBmh0pCIKX+RP8uz1i6pGWVNckLyJtSn\n\tfiBAGNGHmoAJRZftb6EhWxC9W9/ubVfTQZebeaBfT5l3q26kTPBhEXBzQqRRbSBRLt\n\t+yjYa4O9I7OSqQyYV75skjSo5aaRemTpeXUsghBjKicIjcJa1RRHPyIbAfMdA05SbK\n\tjLD0XP63Ose8w==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=X1cAZgByvvZNfmBYAiQ28VdABJeoQh1XSZQcHTm1QpY=;\n\tb=jrxa17jRAoyiKf4HLt2hrqJ46A0AKmRgiwhpwOs1nO3VUPov36rGo+HBPle78aem1x\n\tn2NEgz5DgfiRhmErf9U8suoWoKHy86vQ9laSirrVXPA4O4q37yFyf7OrIb9ZAKZkD8IG\n\tlAycv/lckoSLF5HYtkcFYickM6ju2BogqFrrzZ5ERx1avnmaKqw1X/LLHQWkbYnodeYK\n\tvyZX8dgdTwn8z4NOfOOVUHf+IuBvgXyNFdEHkjR9Vb70wBTJMMonK1LkRlL0rrEjJpy7\n\tPoa/cISXJETpPIcsS3WDTQWXETt6tCAjK0JhyEXhWX4WrOx4R/1neLzmT1Crni65qCiF\n\tRA4Q=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"jrxa17jR\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=X1cAZgByvvZNfmBYAiQ28VdABJeoQh1XSZQcHTm1QpY=;\n\tb=p65Kn7suU+cxg+rNaALnCLr+j/85+/TwGnT0IdRKqKmH2ZlBU2/e1BABZ4L49xApVR\n\tM9nxaYwUrb5rfh1NVDPClNazf5SVOW/FWKLaUdwMnM2eoLIZYawbHIRtXHSiFibrRheL\n\tclAmwp8HlRLM/RPCEyF4C5n90/c4u7TsaagtBxLBFWs9YFH9XoGApV9pxF1Oq5bNd313\n\tkvSSvMqG39IlcT9CR0Nd5fOCIBUycuYgmeX+1bVcWBkxGUxS+5OVLoq3bJsnC/06NoBz\n\tgWgw2T0OB8A5Hs5vDTi/0Ou6fYCj8+XOPrLhzhAkcyif9P5JQ3Imi9uiT7XjQ2ggr1Mk\n\tBWpA==","X-Gm-Message-State":"ACrzQf3UzMV6lBlpG1fkkZj1I5Q8gC5OSsqWapqzUBsiH3DDKNdTA8az\n\tOjMAJj0I4QNux9Ik6g0NBiFz2LBpAvIoaqQTq//FLDFzgdw=","X-Google-Smtp-Source":"AMsMyM4Ai1ACoD42MMwQd/pmRvQq1CTGv/AklGB76a524Zx4rhxhQogQsp09ysomkgvjp5E5UvLIJANsSM0KhkENu+s=","X-Received":"by 2002:a63:f103:0:b0:439:398f:80f8 with SMTP id\n\tf3-20020a63f103000000b00439398f80f8mr16741395pgi.494.1667305097928;\n\tTue, 01 Nov 2022 05:18:17 -0700 (PDT)","MIME-Version":"1.0","References":"<20221014131846.27169-1-naush@raspberrypi.com>\n\t<20221014131846.27169-9-naush@raspberrypi.com>","In-Reply-To":"<20221014131846.27169-9-naush@raspberrypi.com>","Date":"Tue, 1 Nov 2022 12:18:06 +0000","Message-ID":"<CAHW6GY+xyn6=fkhm6VES-twr8p5V7zzdo=SgA+Zo+Jdqxd7-eg@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [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":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]