From patchwork Wed Jan 18 08:59:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18137 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 4A8D2C3296 for ; Wed, 18 Jan 2023 09:01:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0967E62608; Wed, 18 Jan 2023 10:01:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674032489; bh=sxi3z4CTMGPw3NMx/xRPBi3JYi/YJTSm90v0e0/aqNQ=; 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=dogR+PUbd1tiw4QXZ3o7TuWbMqak4Djs4JrsgtvgLSGlN5rXBD1voDJY0COI7nR6q z7HCoZCL8aVbSM//h3kuWpp2cs7vhDvmVW7Hmz3c2/5jUcc6akroK5L/kqX79Ou4oS XoyhYZE5CNjFVcCIV4EMSdOuUYSR2zWyfS+Vs7tNkbMdf+/l2pB8FjpGY8pi+AcAZU 3UeqATeMA8G3UKYVA27zELEF4BHAvElb7nxY+SZo/8Qrd26Ft9FN0EkMGzImITP9Sz GLSkuuYggO+cIYOl1jTEbgtEzF54SV3You3NKsZA6hrjpzhINVrIme17SjSEpMJnqM RCz/X8GK8okbQ== Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E4C1A625F6 for ; Wed, 18 Jan 2023 10:01:23 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="NAA70eWv"; dkim-atps=neutral Received: by mail-wr1-x432.google.com with SMTP id k8so18695011wrc.9 for ; Wed, 18 Jan 2023 01:01:23 -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=x5JG3wUYq4xcmcSB2omZlxtc+5jDqfCvpE5cZCfhkuI=; b=NAA70eWvMXW3R4n46g7aj5SLm1aMljJfsDyf0el2wCEVwhb22nddPOFtkazHA3yvSh I7HOqGcxzG/WwsJ4z7ClBn7N8r6hvQDuXSfX3f6q50jUKEjWwjbNPYCJRmcgXE2Jp4Ik UAFLJ7qWr5t8DGtqxD9UBmW/gaHyvAA+xEE7EqN80WT7KNsckIAdOfn2xnmtzoXKdkAe fyzL4YLoZL9ROD6ndpSXqaH3wNZgwWK8JZzbuyqOmlXpORNwl+msPkBBbuqEi90ECMs5 6UxK4Wvj1a7r+SXLDFpbP7QbXl0jFIGHyEfGDUEVUWiZCTiajJwAifQPUtGx92XQmeSt mcSA== 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=x5JG3wUYq4xcmcSB2omZlxtc+5jDqfCvpE5cZCfhkuI=; b=FhhoxeBo0O2Kzk7f7uKNAq5eqguIaGPONO33RZNggRdzN0NG/SqQaqlyACVRD/uCW4 WorY5uBKNjeDO5V/Wc09BEjjtqVSF401002X95p1XlXBJbI/ISXFxHlm5YSss3MCOnGj 5V4Ki3GHWC38UdxDvPJTgpRebD2W99nnbIeP5JfLmTG1D+tpx8BvDQ1vC3tpv5YuWHI3 zsBWB/ZdYf6X9KKU+aBzfG6NXEimxCuLBwEvWA/xsIolEsMPEYZU+oUzyZK02nglRvVo 0zIgCEAkvIiOZQu6LGorftZiR7BU3Xk9+pIWzM/3/obk38F+tIo0sQ0Km4q7e/DO3ATr lZYw== X-Gm-Message-State: AFqh2kpYDFSDSsnZEXqceRn81k1FhnDx4YUdASO2/jDAe0e5ltVHZbJF BYgNVfNhVxxPomz/ScACW2U0764hfMI+3U5LJ20= X-Google-Smtp-Source: AMrXdXv1TQRZXy0aliKibyoMNdZA6o1E3QY9HYnqxll0GCY0UGJKQyX5NCNKjKCTl7xChace9MfU1A== X-Received: by 2002:adf:d0c5:0:b0:2be:34fa:7bdb with SMTP id z5-20020adfd0c5000000b002be34fa7bdbmr373198wrh.39.1674032482536; Wed, 18 Jan 2023 01:01:22 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id i6-20020adfe486000000b002423dc3b1a9sm30312464wrm.52.2023.01.18.01.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 01:01:22 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Wed, 18 Jan 2023 08:59:52 +0000 Message-Id: <20230118085953.7027-12-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230118085953.7027-1-naush@raspberrypi.com> References: <20230118085953.7027-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 3529d331deb6..21edc8e05469 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -314,6 +314,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"; @@ -2329,6 +2337,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