From patchwork Tue Dec 6 13:54:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17955 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 9C844BE08B for ; Tue, 6 Dec 2022 13:55:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5727B63359; Tue, 6 Dec 2022 14:55:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1670334920; bh=tDBmBwb4sA+f2nCv8hrEGm2SYDvJRfswWxPT3X7S88U=; 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=H5owGACbSo2pRJxgGRQNTfNjDSn/hC61t3cz7MlpM92eRUzoS6CJSXYXwntHNhdVx 7Npv+9JtYeDARbCDgrT8NsGjtsnOgfx7Ht/WxTl/3lV+ySg1uIsdjaQ6uccmrG29lu vE2ITI16WvEyAouzH01oImikA6kje8DqzQmc8LeYddZiRmn//XOge3eIo7wE3z6GXl HoMHCcoPvPr3ofi64Nci22U28FvBb7kiw7sU9xIvzQONmjzGSxRq+sH2XBX/gK+Ioa nByKZGLFsvq5XcXPMAaw6GfydoIvfJFhHSzkGMYtecA8NcnyGs6rhMWlEcnwWWKldp 2/oSTOQ+cptZg== Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0390663359 for ; Tue, 6 Dec 2022 14:55:15 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="cpzQ9C7G"; dkim-atps=neutral Received: by mail-wm1-x336.google.com with SMTP id m4-20020a05600c3b0400b003d1cb516ce0so663330wms.4 for ; Tue, 06 Dec 2022 05:55:15 -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=oe40j38Jy/tRf8WT1pUPWYm8Sw3EeiCXbQh8FbPbkeA=; b=cpzQ9C7G7Y3ATpVmPMLYYE3o6fajc4/gW/yErGM3JtSZt244RgQNVjJJp+1SMPof1a bby+Em+F+00fI4bzeY6TI7iJYkxta9Nhoxo+FFMdWORZ/se+LjUFgqdJBU25uo67Jf9R YWBR/xFtSGInpWoQVfE/fUyBOD7vlJNUX7oc0UFgOPhVcKfyv41UYhQMWMRNg0YR+z+G Q2/xNV5DZemGsUrNNMoG0o+FqjADkoVyaYZfl9/KjDqAYADKMVtPRAk0fEf0tTaZbwQT s7BCCZpQRVtyD5m4zd0W1ersinmyiVl71rvppiZYSf98RjVV3qX0/fAtoNgZGiPZ5/of SVOA== 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=oe40j38Jy/tRf8WT1pUPWYm8Sw3EeiCXbQh8FbPbkeA=; b=RUWL5B6JOpJJUsTJpQ3oeHDfc5BHy9ugSCQU/qCL03PwZESRsmXukS/7iv9ahzvouc 5c66+BNMNIbsAdZ3MbmuCD1DZESwLivmZkjHttcSJM+ur5kH+ZUSMUEvzzFZOLsDQ/Ei z6kKELxc/Pm4zXcg/Vbo5010WFgxwZ7PlTGgIaTR2O4FCGtLOL+5OvXP0oU52U9t65Sn 7bRqx3vw3SDCeCWir2mK3zYqLFHPPpT5D5uk5yg10apXTgUg/uHlcxMcmQ1cjBG2+lIm A6pNQDluyiU3gs59Y9gbonDeF4pusoFur2uQxRmwRkVkHzEkFcBhaosxWABTthkdd+MD BbOA== X-Gm-Message-State: ANoB5plHZywzpr2Ty6pbyzubRlyLQ1xx4OYK4gvj7XcKpSJa/Utx1U6V 59od6wmPv3p/VgXluiTgbCWPPP6e5+V0QGaf X-Google-Smtp-Source: AA0mqf4LN+qx1JDCwRAbWj2BVTPjfycUF0CMcd0QQkNEv8KDHZTyrXXb+mym3LVpU+TMao1dv3jOEw== X-Received: by 2002:a05:600c:1d09:b0:3cf:6ab3:4a0b with SMTP id l9-20020a05600c1d0900b003cf6ab34a0bmr65556823wms.91.1670334914204; Tue, 06 Dec 2022 05:55:14 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q6-20020a05600c2e4600b003c6bd91caa5sm19444059wmf.17.2022.12.06.05.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 05:55:13 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 6 Dec 2022 13:54:58 +0000 Message-Id: <20221206135459.25521-13-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221206135459.25521-1-naush@raspberrypi.com> References: <20221206135459.25521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 12/13] 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 ffd2ba85182f..acf81a5beb83 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -313,6 +313,11 @@ public: * frames. */ bool disableStartupFrameDrops; + /* + * Always process a pending request with the last captured sensor + * frame. + */ + bool returnNewestFrames; }; Config config_; @@ -1730,6 +1735,7 @@ int RPiCameraData::configurePipeline() .minUnicamBuffers = 2, .minTotalUnicamBuffers = 4, .disableStartupFrameDrops = false, + .returnNewestFrames = false, }; char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RPI_CONFIG_FILE"); @@ -1765,6 +1771,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"; @@ -2354,6 +2362,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