{"id":15475,"url":"https://patchwork.libcamera.org/api/patches/15475/?format=json","web_url":"https://patchwork.libcamera.org/patch/15475/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220317140827.1835029-6-naush@raspberrypi.com>","date":"2022-03-17T14:08:26","name":"[libcamera-devel,v2,5/6] pipeline: raspberrypi: Add a timeout to free buffers on stopDevice()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"da725b91163881f29da0d89d622212370dea3565","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15475/mbox/","series":[{"id":2972,"url":"https://patchwork.libcamera.org/api/series/2972/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2972","date":"2022-03-17T14:08:21","name":"Raspberry Pi: Efficient start/stop/start sequences","version":2,"mbox":"https://patchwork.libcamera.org/series/2972/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15475/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15475/checks/","tags":{},"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\r\n\t[92.243.16.209])\r\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A9E82BD80A\r\n\tfor <parsemail@patchwork.libcamera.org>;\r\n\tThu, 17 Mar 2022 14:08:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\r\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 442BF632E8;\r\n\tThu, 17 Mar 2022 15:08:40 +0100 (CET)","from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com\r\n\t[IPv6:2a00:1450:4864:20::42e])\r\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 310816118A\r\n\tfor <libcamera-devel@lists.libcamera.org>;\r\n\tThu, 17 Mar 2022 15:08:37 +0100 (CET)","by mail-wr1-x42e.google.com with SMTP id j17so7623188wrc.0\r\n\tfor <libcamera-devel@lists.libcamera.org>;\r\n\tThu, 17 Mar 2022 07:08:37 -0700 (PDT)","from naush-laptop.pitowers.org\r\n\t([2a00:1098:3142:14:371b:8e01:111f:5322])\r\n\tby smtp.gmail.com with ESMTPSA id\r\n\tz5-20020a05600c0a0500b0037fa93193a8sm5287831wmp.44.2022.03.17.07.08.35\r\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\r\n\tThu, 17 Mar 2022 07:08:36 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\r\n\ts=mail; t=1647526120;\r\n\tbh=EuRdJnTXSIyH4FpDUOhhsDPhZIpTbM5FisvUXjsyyuo=;\r\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\r\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\r\n\tFrom;\r\n\tb=PQElsLT1fEubwBhmBe+2UhUcZ8fV/e7WkBg7jduR5uoSVOxj676EEnPM5M5UR6lZy\r\n\t550dZ/nnlceo2/T4TG2E6ir99C0/uEnJd96wvSquB31jGJPPHJaHtGq4be7iwhDnT3\r\n\tPpvlxIQZ8Mc6RMipKVONsGp/HVhWR5fG4tlWdi8irTrFyZyr5dZCybQtzGNAw0OKHE\r\n\t2rCZ7f+0VOIneQvxe78I3zbikFA4rzhrBYU4+/EGjkv+rRktpIOwalR1oJV7OE9QoN\r\n\t23OlMRCdRcM3sIL3u8QkJa4qMxS89RR73ppKdZLOCBFmlNRRgXobMaXlYYKsgO9Eu2\r\n\tecSPPEronMVJw==","v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n\td=raspberrypi.com; s=google;\r\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\r\n\t:mime-version:content-transfer-encoding;\r\n\tbh=5+KEwYvzqMylcdvXOeVzJt6BNlZhZQu/aJiLfyDW3WA=;\r\n\tb=TwuwlrPBLApbqL2RW/89+/rTJBXHTPExZPOIzYtfjnEU91Vv20QlGWh3dDh5Riazhp\r\n\tg20Hm+9Ke8Zv/iIpzTF1XxPpIqM12LxxyLtJ9SbvsVs7gnoEbp62/GKX8cRzP9b5mE/p\r\n\ta+iGFvNRBFaLTFNExm8L4agg3BhW/KmRUSO4aOmYr5IapvLMvUn/qtBZCLBRPajTQ3rH\r\n\tSWThjtxV8WpaWssFtL69sRUx44rLEENwJW042CfVgkyzqyVkxQ0fW0BuxlZ48OEoWNhF\r\n\t+Q5j2LPNulx16pxyW/kejICTSttaxnpNHYUbrUhb8slFWE8fT64bcETr0gg95rjw2wJr\r\n\tWqWA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \r\n\tunprotected) header.d=raspberrypi.com\r\n\theader.i=@raspberrypi.com\r\n\theader.b=\"TwuwlrPB\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n\td=1e100.net; s=20210112;\r\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r\n\t:references:mime-version:content-transfer-encoding;\r\n\tbh=5+KEwYvzqMylcdvXOeVzJt6BNlZhZQu/aJiLfyDW3WA=;\r\n\tb=O7VWMOGn2vM/0Umucmg7p53GnRIG5TS7uYfcQgJ37Hr6c8ubyNO+3TbrZdV6hsf10A\r\n\tsP4WK6jDXLIk5/nzbH2c4QJFqpBbQwEdPtVFHEn4bjfql8pgjELvSL9vkgkgbTed0nVu\r\n\tSdL6QZmdBNdqSIQq1g0cNaV/WMWyk7o+vE6dpE7JnUbKIWMZDi0Aov6IfMKpVa4emBfe\r\n\tjVgOIl+DrUe1da/qdXe/CwFjrDGnRi4Zj1EpoDaBVZcY0EfSKd0XsWPEiH4W948rSgEQ\r\n\t2J/hTyz0OaGeFTktK17Y66qwh18h+XGj7ue3v+nLbI+NftegA1u2/uHhXZbBkh8+OcLt\r\n\tXm3A==","X-Gm-Message-State":"AOAM532Fy6d6F9LZcNRmat4yndZtfWgzK5+o2U3fKtcwA89rxkx5QhqS\r\n\tlQIhzRxHIwlc1oVn2RvJjNaOQ9q90LVIjw==","X-Google-Smtp-Source":"ABdhPJzq/oGWLzuTABPKpY8kIcFXPzfyLKxT3PQO+t6+k+GRnjZ8vGICr7POIpEIWSCU9i2jpkb8cw==","X-Received":"by 2002:a05:6000:1379:b0:203:ee50:45ad with SMTP id\r\n\tq25-20020a056000137900b00203ee5045admr1745311wrz.268.1647526116590; \r\n\tThu, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 5/6] pipeline: raspberrypi: Add a\r\n\ttimeout to free buffers on stopDevice()","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>,\r\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>,\r\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\r\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Start a 5 second timer when stopDevice() is called, and if it times out,\nfree all internally allocated buffers. The timer is cleared when start() is\nsubsequently called.\n\nThis avoids the pipeline handler from holding onto internal buffers for long\nperiods of time due to application inactivity.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp        | 17 +++++++++++++++++\n 1 file changed, 17 insertions(+)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\r\nindex d3212b193ced..32b282b4bdbd 100644\r\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\r\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\r\n@@ -15,6 +15,7 @@\r\n #include <utility>\r\n \r\n #include <libcamera/base/shared_fd.h>\r\n+#include <libcamera/base/timer.h>\r\n #include <libcamera/base/utils.h>\r\n \r\n #include <libcamera/camera.h>\r\n@@ -45,6 +46,8 @@\r\n #include \"dma_heaps.h\"\r\n #include \"rpi_stream.h\"\r\n \r\n+using namespace std::literals::chrono_literals;\r\n+\r\n namespace libcamera {\r\n \r\n LOG_DEFINE_CATEGORY(RPI)\r\n@@ -288,6 +291,9 @@ public:\r\n \t/* Has this camera been reconfigured? */\r\n \tbool reallocate_;\r\n \r\n+\t/* Timer to free internal buffers once stopDevice() has been called. */\r\n+\tTimer stopTimer_;\r\n+\r\n private:\r\n \tvoid checkRequestCompleted();\r\n \tvoid fillRequestMetadata(const ControlList &bufferControls,\r\n@@ -991,6 +997,10 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls)\r\n \tRPiCameraData *data = cameraData(camera);\r\n \tint ret;\r\n \r\n+\t/* Disable the stop timeout waiting to release buffers after a stop(). */\r\n+\tdata->stopTimer_.stop();\r\n+\tdata->stopTimer_.timeout.disconnect();\r\n+\r\n \tfor (auto const stream : data->streams_)\r\n \t\tstream->resetBuffers();\r\n \r\n@@ -1071,6 +1081,13 @@ void PipelineHandlerRPi::stopDevice(Camera *camera)\r\n \r\n \t/* Stop the IPA. */\r\n \tdata->ipa_->stop();\r\n+\r\n+\t/*\r\n+\t * Start a 5 second timer once the camera is stopped, and on a timeout,\r\n+\t * release all internally allocated buffers.\r\n+\t */\r\n+\tdata->stopTimer_.timeout.connect(data, &RPiCameraData::freeBuffers);\r\n+\tdata->stopTimer_.start(5s);\r\n }\r\n \r\n int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request)","prefixes":["libcamera-devel","v2","5/6"]}