From patchwork Thu Mar 17 14:08:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15475 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 A9E82BD80A for ; Thu, 17 Mar 2022 14:08:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 442BF632E8; Thu, 17 Mar 2022 15:08:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647526120; bh=EuRdJnTXSIyH4FpDUOhhsDPhZIpTbM5FisvUXjsyyuo=; 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=PQElsLT1fEubwBhmBe+2UhUcZ8fV/e7WkBg7jduR5uoSVOxj676EEnPM5M5UR6lZy 550dZ/nnlceo2/T4TG2E6ir99C0/uEnJd96wvSquB31jGJPPHJaHtGq4be7iwhDnT3 PpvlxIQZ8Mc6RMipKVONsGp/HVhWR5fG4tlWdi8irTrFyZyr5dZCybQtzGNAw0OKHE 2rCZ7f+0VOIneQvxe78I3zbikFA4rzhrBYU4+/EGjkv+rRktpIOwalR1oJV7OE9QoN 23OlMRCdRcM3sIL3u8QkJa4qMxS89RR73ppKdZLOCBFmlNRRgXobMaXlYYKsgO9Eu2 ecSPPEronMVJw== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 310816118A for ; Thu, 17 Mar 2022 15:08:37 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="TwuwlrPB"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id j17so7623188wrc.0 for ; Thu, 17 Mar 2022 07:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5+KEwYvzqMylcdvXOeVzJt6BNlZhZQu/aJiLfyDW3WA=; b=TwuwlrPBLApbqL2RW/89+/rTJBXHTPExZPOIzYtfjnEU91Vv20QlGWh3dDh5Riazhp g20Hm+9Ke8Zv/iIpzTF1XxPpIqM12LxxyLtJ9SbvsVs7gnoEbp62/GKX8cRzP9b5mE/p a+iGFvNRBFaLTFNExm8L4agg3BhW/KmRUSO4aOmYr5IapvLMvUn/qtBZCLBRPajTQ3rH SWThjtxV8WpaWssFtL69sRUx44rLEENwJW042CfVgkyzqyVkxQ0fW0BuxlZ48OEoWNhF +Q5j2LPNulx16pxyW/kejICTSttaxnpNHYUbrUhb8slFWE8fT64bcETr0gg95rjw2wJr WqWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5+KEwYvzqMylcdvXOeVzJt6BNlZhZQu/aJiLfyDW3WA=; b=O7VWMOGn2vM/0Umucmg7p53GnRIG5TS7uYfcQgJ37Hr6c8ubyNO+3TbrZdV6hsf10A sP4WK6jDXLIk5/nzbH2c4QJFqpBbQwEdPtVFHEn4bjfql8pgjELvSL9vkgkgbTed0nVu SdL6QZmdBNdqSIQq1g0cNaV/WMWyk7o+vE6dpE7JnUbKIWMZDi0Aov6IfMKpVa4emBfe jVgOIl+DrUe1da/qdXe/CwFjrDGnRi4Zj1EpoDaBVZcY0EfSKd0XsWPEiH4W948rSgEQ 2J/hTyz0OaGeFTktK17Y66qwh18h+XGj7ue3v+nLbI+NftegA1u2/uHhXZbBkh8+OcLt Xm3A== X-Gm-Message-State: AOAM532Fy6d6F9LZcNRmat4yndZtfWgzK5+o2U3fKtcwA89rxkx5QhqS lQIhzRxHIwlc1oVn2RvJjNaOQ9q90LVIjw== X-Google-Smtp-Source: ABdhPJzq/oGWLzuTABPKpY8kIcFXPzfyLKxT3PQO+t6+k+GRnjZ8vGICr7POIpEIWSCU9i2jpkb8cw== X-Received: by 2002:a05:6000:1379:b0:203:ee50:45ad with SMTP id q25-20020a056000137900b00203ee5045admr1745311wrz.268.1647526116590; Thu, 17 Mar 2022 07:08:36 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:371b:8e01:111f:5322]) by smtp.gmail.com with ESMTPSA id z5-20020a05600c0a0500b0037fa93193a8sm5287831wmp.44.2022.03.17.07.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 07:08:36 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Mar 2022 14:08:26 +0000 Message-Id: <20220317140827.1835029-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220317140827.1835029-1-naush@raspberrypi.com> References: <20220317140827.1835029-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/6] pipeline: raspberrypi: Add a timeout to free buffers on stopDevice() 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" Start a 5 second timer when stopDevice() is called, and if it times out, free all internally allocated buffers. The timer is cleared when start() is subsequently called. This avoids the pipeline handler from holding onto internal buffers for long periods of time due to application inactivity. Signed-off-by: Naushir Patuck --- .../pipeline/raspberrypi/raspberrypi.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index d3212b193ced..32b282b4bdbd 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -45,6 +46,8 @@ #include "dma_heaps.h" #include "rpi_stream.h" +using namespace std::literals::chrono_literals; + namespace libcamera { LOG_DEFINE_CATEGORY(RPI) @@ -288,6 +291,9 @@ public: /* Has this camera been reconfigured? */ bool reallocate_; + /* Timer to free internal buffers once stopDevice() has been called. */ + Timer stopTimer_; + private: void checkRequestCompleted(); void fillRequestMetadata(const ControlList &bufferControls, @@ -991,6 +997,10 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) RPiCameraData *data = cameraData(camera); int ret; + /* Disable the stop timeout waiting to release buffers after a stop(). */ + data->stopTimer_.stop(); + data->stopTimer_.timeout.disconnect(); + for (auto const stream : data->streams_) stream->resetBuffers(); @@ -1071,6 +1081,13 @@ void PipelineHandlerRPi::stopDevice(Camera *camera) /* Stop the IPA. */ data->ipa_->stop(); + + /* + * Start a 5 second timer once the camera is stopped, and on a timeout, + * release all internally allocated buffers. + */ + data->stopTimer_.timeout.connect(data, &RPiCameraData::freeBuffers); + data->stopTimer_.start(5s); } int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request)