From patchwork Fri Oct 14 13:18:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17604 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 516CDC0DA4 for ; Fri, 14 Oct 2022 13:19:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0A29B62DE1; Fri, 14 Oct 2022 15:19:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665753544; bh=Sx94jdwybthZB2u6g3tjU5CI9+F1KFjRSPOcsPRcxLE=; 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=J078x1/avHt2CWZvPT2KVV6Lt77kiBaq9QLBuTTE+1J/2PY9Lsj2lbgTAmACrGdUz NmvMS70rqHiUR/TCRo97X+wxtCxjkUH9jIR/oeLk/iY+9NhPaYAoOT+5LdQueFA6KF 4CxyNfVAfgL55c3gDnJL8kPZ3wwBorA53OQvmhCljqAFImvKPXhKHktu/ISdohsCV3 D18YavjgJ6e7qMHd6F/2CXkIKP+ZYcZcxuP6o7HmSu6Xj1rHi+kwVKTF8ty6wLgFpI QCFjSfZguMmKnyTDigOSBbo5+tG4QqEXsr0wJ91Z4+MG6YRGDvZcTo5AHJHLtyYDOM kGVGUII1G3PXA== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7B6CB62DC7 for ; Fri, 14 Oct 2022 15:18:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ElZ+RUkp"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id j7so7547672wrr.3 for ; Fri, 14 Oct 2022 06:18:58 -0700 (PDT) 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=/JfxSj6icGHMD+GjblGRyWFSbev1nXgdNOIATEO+/Es=; b=ElZ+RUkp/958Iwu9OCQEOAlUo5Z5wbJGZAPvPwry5lV3Pt4LtLkCLISfA63g29J3re 81UZjwZG9p5PoJdtYbUAAVS7wYIV99+dSb9/3rwxEp5XFsrteqec2n3rxNfaTT7Pa8Mr 8+1Sq/jjNfP3Ghv/F/5I7Xns5PpwfizrGuoNnUbqY0fCgT9nsyRWaKNRe2ZL7Dr/WZrE 9ulXR5Ah+UHIkdr3y3cDNXxZ7Vzv8rkgjrj7lFq2x+XzMd9SpShV2aSkDBF+50696tr8 GUKKSUJfjvKs3NSDVmDSAcr+ftF9Y0BV+qEok33G661AbNKDThC4bne5AkNffRDWPWB0 mUPw== 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=/JfxSj6icGHMD+GjblGRyWFSbev1nXgdNOIATEO+/Es=; b=Hl2gE8l2S9y+jUwkDYmtP5u+7blvHvv2fUWJHSn0lWGje9inKiuQzGh+DZnQV94L/w wUW30JvbOfDgxEKOm94AFcZJVzVN7XxCGzEk+cXPLym+ZnrlQqoOE7Q5sFPh1XFGs6VP HtfMInvReo/M0Ainy7zBLnnoJh4QXAqIn8qW7Jvyf1Q1PqXpuNd8/ZMQnf5nFQj/7iGI Q4S1WKQWeXCOerA5Oc8JfwQ34xK4Sb4fQyYqS2uPyfEyNfkoZxVX0VJSBABNqZmdAE9C Y9rvQS+IOi4/VWl3UHOT6lXpHgX/xV9Ds15XkrkjWs7rqk8J5XF6f/kKWfYndolLmzB+ YSAw== X-Gm-Message-State: ACrzQf2idR3jRiIaUGNW6pwpSxRJeyuZzcg6/pk7sLLzWSR+tQYBLMDT e0JDJXyQrSkXaCesamvLxgav0E5SPPWkRg== X-Google-Smtp-Source: AMsMyM4odAL1BT9hLc0THqF2wVvfB49vmy1ADwpHSKLhiBkA4MGn3gQlMLy0HZbAb1h0UDcnGVOxNg== X-Received: by 2002:a5d:4683:0:b0:22e:6be0:dfc6 with SMTP id u3-20020a5d4683000000b0022e6be0dfc6mr3412587wrq.573.1665753537527; Fri, 14 Oct 2022 06:18:57 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id g17-20020a05600c001100b003c6bbe910fdsm8282458wmc.9.2022.10.14.06.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 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 Subject: [libcamera-devel] [PATCH v1 08/10] 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/default.json | 7 ++++++- .../pipeline/raspberrypi/raspberrypi.cpp | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/data/default.json b/src/libcamera/pipeline/raspberrypi/data/default.json index 707414bcc5c5..f900ca824523 100644 --- a/src/libcamera/pipeline/raspberrypi/data/default.json +++ b/src/libcamera/pipeline/raspberrypi/data/default.json @@ -18,6 +18,11 @@ "num_output0_buffers": 1, # 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 heavey CPU loading. + "return_newest_frames": false } } diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 135948d82f41..d9bea35c88a3 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -301,6 +301,7 @@ public: unsigned int minTotalUnicamBuffers; unsigned int numOutput0Buffers; bool disableStartupFrameDrops; + bool returnNewestFrames; }; Config config_; @@ -1432,6 +1433,7 @@ int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data) .minTotalUnicamBuffers = 4, .numOutput0Buffers = 1, .disableStartupFrameDrops = false, + .returnNewestFrames = false, }; char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RPI_CONFIG_FILE"); @@ -1468,6 +1470,8 @@ int PipelineHandlerRPi::configurePipelineHandler(RPiCameraData *data) phConfig["num_output0_buffers"].get(config.numOutput0Buffers); config.disableStartupFrameDrops = phConfig["disable_startup_frame_drops"].get(config.disableStartupFrameDrops); + config.returnNewestFrames = + phConfig["return_newest_frames"].get(config.returnNewestFrames); if (config.minTotalUnicamBuffers < config.minUnicamBuffers || config.minTotalUnicamBuffers < 1) { LOG(RPI, Error) << "Invalid Unicam buffer configuration used!"; @@ -2320,6 +2324,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