{"id":15473,"url":"https://patchwork.libcamera.org/api/patches/15473/?format=json","web_url":"https://patchwork.libcamera.org/patch/15473/","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-4-naush@raspberrypi.com>","date":"2022-03-17T14:08:24","name":"[libcamera-devel,v2,3/6] pipeline: raspberrypi: Free buffers in the RPiCamera destructor and re-configure","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"155c5507aeb2edd0e826b66411300924621c0d3a","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/15473/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/15473/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15473/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 4EEBFBD80A\r\n\tfor <parsemail@patchwork.libcamera.org>;\r\n\tThu, 17 Mar 2022 14:08:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\r\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F2CDD6118A;\r\n\tThu, 17 Mar 2022 15:08:38 +0100 (CET)","from mail-wr1-x432.google.com (mail-wr1-x432.google.com\r\n\t[IPv6:2a00:1450:4864:20::432])\r\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A9197632E3\r\n\tfor <libcamera-devel@lists.libcamera.org>;\r\n\tThu, 17 Mar 2022 15:08:35 +0100 (CET)","by mail-wr1-x432.google.com with SMTP id u10so7524373wra.9\r\n\tfor <libcamera-devel@lists.libcamera.org>;\r\n\tThu, 17 Mar 2022 07:08:35 -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.34\r\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\r\n\tThu, 17 Mar 2022 07:08:34 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\r\n\ts=mail; t=1647526119;\r\n\tbh=XJ1pAOfIgnoLQrSP1otlKPEp/A3tyr+1rp/6dlRweSQ=;\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=tCDTe6YVuGHk+1aJsvayMySCgzxlrYwxhEbyw22+HcH+mz3RI3RgJ9LjICZeEibIV\r\n\tGqqf5k6nrUg6FkCXkHhqSZatu8V9CX2jeK5OiutpPZP9qrFtiCmF+m4rqiIMNuYV72\r\n\ttaVRpE6NoqTIn+OlmTP0+zFFw2h6KA7uJr/JRCYmRtY3BtXtCjUFOYd3TnAmoEEiIz\r\n\t72ObgDTlEbZsjz0h/OlolfBl/tqUz321oWWMy56rqd9gZXWxqeY0qmqa9UPhwVZBTR\r\n\tz03dp9iqVQRodJ0+KuX80mlU0DL3U3DTHRk8P5LwWpAYpjPHyvdY9r7lI50GAwoSqQ\r\n\tiOEGuOkJtIUbQ==","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=1jo8PyycZMxj9FXYeyEvPbN5X7sAU3cwjuWroYkyh4g=;\r\n\tb=pdedGJzg8/1VJZbWeX3bhDRoZcUd3Knxh2iHMn9g4ZI6wk+jB8lA7By563RjJzOKLo\r\n\t/kForPUaWmB8ZWN7O2vCm/YBQvSZ6TKJDfGDFs6c+cceriTNuir6BqfDMrxkFCTeDm1s\r\n\t+nQCesIVa8vHMR+kc/3U92Cyu9cEwKvF6sHk0sS4Bx6F/i+ChBYdIXcEKCCLmv7UHiSV\r\n\tlAvPMavCK25jlr/XsCuJQm313GxfdITCE6Zmo5zjAzkfnNSmkcNDnsIpVZYK8rRdxvrH\r\n\tJqYlMs5zj4v2JbnwEmaKfexGeqS/iM8NTigbk1TIFuGHl3aFqyvfKfnKirMv5jfQsbWO\r\n\tnSHw=="],"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=\"pdedGJzg\"; 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=1jo8PyycZMxj9FXYeyEvPbN5X7sAU3cwjuWroYkyh4g=;\r\n\tb=rtQtvGysnOtVSvGt0S/eoa/WAk66ZgUBYqIZP3r7U8V7ur4jQwLSy804maFFpRbLdX\r\n\tV3kG5z9dbk+WUjSaQRzfm82KmnzANSSd5pcrjQsft81UjkMpsVTe+JTiOMJvIPMp9aVM\r\n\tDtcgUxVUjREzG31ChqEoBnRyNMsKb/0KCFkC4Kk/sOMY9rACnQjXc5KSTHHJqq+rgl8k\r\n\tesF/fKt9dn4tFMnuu4e7vBK3B5AYMqhqwwUTFc1RQc2uSy35OsdRwcA4cDs7jQevZJKW\r\n\tyqWi8FXCiuKqa7SBeoUNXXyZWUbd+ukQoZNLLwQ+lD5cqv9ipd8uW9n2AgYAoUWad5q3\r\n\t5ivg==","X-Gm-Message-State":"AOAM531sAS0tNxT9IJ4ae/RFdO/gt92LP2NePrtlOXEoyv1QtJxpPjZy\r\n\td7N9g/Dl0VVgV59gPV3VjqOqgzdBsGEp4w==","X-Google-Smtp-Source":"ABdhPJzlxjVsE8+4oVmght3rdGWu6YyNKf3PYuHf2PJqoZPjLM0fETZkDBCGu1qBsHglyWqpNexZVw==","X-Received":"by 2002:adf:f70a:0:b0:1ee:33bf:3864 with SMTP id\r\n\tr10-20020adff70a000000b001ee33bf3864mr4087313wrp.4.1647526114817; \r\n\tThu, 17 Mar 2022 07:08:34 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 17 Mar 2022 14:08:24 +0000","Message-Id":"<20220317140827.1835029-4-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 3/6] pipeline: raspberrypi: Free\r\n\tbuffers in the RPiCamera destructor and re-configure","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":"Currently, all framebuffer allocations get freed and cleared on a stop in\nPipelineHandlerRPi::stopDevice(). If PipelineHandlerRPi::start() is then called\nwithout an intermediate PipelineHandlerRPi::configure(), it will re-allocate and\nprepare all the buffers again, which is unnecessary.\n\nFix this by not freeing the buffer in PipelineHandlerRPi::stopDevice(), but\ninsted doing it in PipelineHandlerRPi::configure(), as the buffers might have\nto be resized.\n\nAdd a flag to indicate that buffer allocations need to be done on the next\ncall to PipelineHandlerRPi::start().\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\nTested-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 33 +++++++++++++------\n 1 file changed, 23 insertions(+), 10 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\r\nindex 2281b43fc3ac..082273828894 100644\r\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\r\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\r\n@@ -185,10 +185,15 @@ public:\r\n \tRPiCameraData(PipelineHandler *pipe)\r\n \t\t: Camera::Private(pipe), state_(State::Stopped),\r\n \t\t  supportsFlips_(false), flipsAlterBayerOrder_(false),\r\n-\t\t  dropFrameCount_(0), ispOutputCount_(0)\r\n+\t\t  dropFrameCount_(0), reallocate_(true), ispOutputCount_(0)\r\n \t{\r\n \t}\r\n \r\n+\t~RPiCameraData()\r\n+\t{\r\n+\t\tfreeBuffers();\r\n+\t}\r\n+\r\n \tvoid freeBuffers();\r\n \tvoid frameStarted(uint32_t sequence);\r\n \r\n@@ -280,6 +285,9 @@ public:\r\n \t */\r\n \tstd::optional<int32_t> notifyGainsUnity_;\r\n \r\n+\t/* Has this camera been reconfigured? */\r\n+\tbool reallocate_;\r\n+\r\n private:\r\n \tvoid checkRequestCompleted();\r\n \tvoid fillRequestMetadata(const ControlList &bufferControls,\r\n@@ -682,7 +690,8 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\r\n \tRPiCameraData *data = cameraData(camera);\r\n \tint ret;\r\n \r\n-\t/* Start by resetting the Unicam and ISP stream states. */\r\n+\t/* Start by freeing all buffers and reset the Unicam and ISP stream states. */\r\n+\tdata->freeBuffers();\r\n \tfor (auto const stream : data->streams_)\r\n \t\tstream->reset();\r\n \r\n@@ -982,12 +991,16 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls)\r\n \tRPiCameraData *data = cameraData(camera);\r\n \tint ret;\r\n \r\n-\t/* Allocate buffers for internal pipeline usage. */\r\n-\tret = prepareBuffers(camera);\r\n-\tif (ret) {\r\n-\t\tLOG(RPI, Error) << \"Failed to allocate buffers\";\r\n-\t\tstop(camera);\r\n-\t\treturn ret;\r\n+\tif (data->reallocate_) {\r\n+\t\t/* Allocate buffers for internal pipeline usage. */\r\n+\t\tret = prepareBuffers(camera);\r\n+\t\tif (ret) {\r\n+\t\t\tLOG(RPI, Error) << \"Failed to allocate buffers\";\r\n+\t\t\tdata->freeBuffers();\r\n+\t\t\tstop(camera);\r\n+\t\t\treturn ret;\r\n+\t\t}\r\n+\t\tdata->reallocate_ = false;\r\n \t}\r\n \r\n \t/* Check if a ScalerCrop control was specified. */\r\n@@ -1055,8 +1068,6 @@ void PipelineHandlerRPi::stopDevice(Camera *camera)\r\n \r\n \t/* Stop the IPA. */\r\n \tdata->ipa_->stop();\r\n-\r\n-\tdata->freeBuffers();\r\n }\r\n \r\n int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request)\r\n@@ -1461,6 +1472,8 @@ void RPiCameraData::freeBuffers()\r\n \r\n \tfor (auto const stream : streams_)\r\n \t\tstream->releaseBuffers();\r\n+\r\n+\treallocate_ = true;\r\n }\r\n \r\n void RPiCameraData::frameStarted(uint32_t sequence)","prefixes":["libcamera-devel","v2","3/6"]}