From patchwork Tue Mar 22 09:22:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15500 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 B770DC3264 for ; Tue, 22 Mar 2022 09:23:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0292D632E2; Tue, 22 Mar 2022 10:23:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940987; bh=a+cNZ9Tsd22nFCcFkFyh9j5GpX5K4dniFlP0YmtW2EU=; 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=Kebno7PGZXQzOq2i+LlcI2n67otkMZDiWDdUx5jiD6Ndd2pyYw83SL4V9QyH8H9I2 W57siq5RMpXnc0fXYuBiZQv7o+yCJFpdn1VobmlPdbG0bT+WJ2j9rPvRIwS8r1wN8R SvujXDfqtC5cKEP32sIUQ8lqgiGdA62pDNo7PHwYMWTpgx0qCUCzcAWOgng8gFktWq WZYIoFwQYNqqv2ZMfHcPJ+F8R6YFoKXjRp5HatHzSCiHmagl2wEr/OWNg9bRUCv4W1 ckBbW9bmSdlXI6fLQi/XX6LcbEcfUOaNw5aWPgGXbqTX+9ilz3lo7gbbHcDHWb0RgX FsAMetuTOK5YA== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6CA77604C7 for ; Tue, 22 Mar 2022 10:23:03 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DWwulMRn"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id v2-20020a7bcb42000000b0037b9d960079so1057390wmj.0 for ; Tue, 22 Mar 2022 02:23:03 -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=4XNcvihWbSxz/8G2fcOly9PICUFjPwd6G8x0Dy4evVA=; b=DWwulMRnfOB2inueInUAqOlxTanlA2gEHXmI1LAwkKxJMdRkIFoked7ayhPrsh7Psw Ty0N4Byha0juF3lUYVE1n9+7OMC+6aKJNIrRmvZ+xRX2yaI6oZpoXHCpPnAC0RTpReKP DP6EN2FHm5oiqrJfGb47LB4+s1dM5nf2vh6xjEMRopm7JtI8BBgDX4V4GofYzw+lcPb9 4w5HSpWptkAqlMZvZjoaMVezfQx9VGWuMTyvUfP5xA3LvjbtVEgAP/hYUD25m9D2fQzY rjLs40mgahEj6XN5Qr8NC4KlQDtWPJ5BC20XxIL4Y8NNH3fZ4sUrDIdSBadvj0k/nxSk VFlA== 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=4XNcvihWbSxz/8G2fcOly9PICUFjPwd6G8x0Dy4evVA=; b=TD/6zsf+p8w8ltE0q10ejkYyBLsYmc1fRoVI4TTgtZWBcf/qSurjTnn11K+kTi93oO uZwMvXEx/gN0/jpgfIz2UI5LUImLLbZUiSw0vNvjWwXe+u1aRBkt2Q8EuAq29rCeetlB vhxLYbqMvtN8VYp4hvqXurrOHXW8x6SzjZXD1uiB9r4oTUKsJgWPT33oStU8cEIsUNo3 EK0pkyWjIm1SQPlFHeixBB7iIrIEh0Bw39P+riY5OQJEd34dbYhHQ3hUkibpa+hVewcS AkRA95U/FguVSu+SKQZ/cC4k9foTSOKXozp2l/6Qpz7X6ugsVdl2xq1y7X4veL4KtyVv WK4A== X-Gm-Message-State: AOAM532EbYy17utlmxKGDRehr6sQEA2fb1xYqAVG5E9n7/QOx2PLbTW9 sZD3Y+9sTRtECzpE8mc/8Gj2OQS+nIVpNg== X-Google-Smtp-Source: ABdhPJwCgQJlsvc9dpR2TjhD5HEkLuA681bz2GrKIfaJ+X9T2bB4I2RbQYdWDS84N9m0wkxrMD8OTg== X-Received: by 2002:a7b:c319:0:b0:38c:8655:4019 with SMTP id k25-20020a7bc319000000b0038c86554019mr2906672wmj.60.1647940982789; Tue, 22 Mar 2022 02:23:02 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:52 +0000 Message-Id: <20220322092257.2713521-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/8] pipeline: raspberrypi: Free buffers in the RPiCamera destructor and re-configure 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" Currently, all framebuffer allocations get freed and cleared on a stop in PipelineHandlerRPi::stopDevice(). If PipelineHandlerRPi::start() is then called without an intermediate PipelineHandlerRPi::configure(), it will re-allocate and prepare all the buffers again, which is unnecessary. Fix this by not freeing the buffer in PipelineHandlerRPi::stopDevice(), but insted doing it in PipelineHandlerRPi::configure(), as the buffers might have to be resized. Add a flag to indicate that buffer allocations need to be done on the next call to PipelineHandlerRPi::start(). Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 2281b43fc3ac..92043962494b 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -185,10 +185,15 @@ public: RPiCameraData(PipelineHandler *pipe) : Camera::Private(pipe), state_(State::Stopped), supportsFlips_(false), flipsAlterBayerOrder_(false), - dropFrameCount_(0), ispOutputCount_(0) + dropFrameCount_(0), buffersAllocated_(false), ispOutputCount_(0) { } + ~RPiCameraData() + { + freeBuffers(); + } + void freeBuffers(); void frameStarted(uint32_t sequence); @@ -280,6 +285,9 @@ public: */ std::optional notifyGainsUnity_; + /* Have internal buffers been allocated? */ + bool buffersAllocated_; + private: void checkRequestCompleted(); void fillRequestMetadata(const ControlList &bufferControls, @@ -682,7 +690,8 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) RPiCameraData *data = cameraData(camera); int ret; - /* Start by resetting the Unicam and ISP stream states. */ + /* Start by freeing all buffers and reset the Unicam and ISP stream states. */ + data->freeBuffers(); for (auto const stream : data->streams_) stream->reset(); @@ -982,12 +991,16 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) RPiCameraData *data = cameraData(camera); int ret; - /* Allocate buffers for internal pipeline usage. */ - ret = prepareBuffers(camera); - if (ret) { - LOG(RPI, Error) << "Failed to allocate buffers"; - stop(camera); - return ret; + if (!data->buffersAllocated_) { + /* Allocate buffers for internal pipeline usage. */ + ret = prepareBuffers(camera); + if (ret) { + LOG(RPI, Error) << "Failed to allocate buffers"; + data->freeBuffers(); + stop(camera); + return ret; + } + data->buffersAllocated_ = true; } /* Check if a ScalerCrop control was specified. */ @@ -1055,8 +1068,6 @@ void PipelineHandlerRPi::stopDevice(Camera *camera) /* Stop the IPA. */ data->ipa_->stop(); - - data->freeBuffers(); } int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) @@ -1461,6 +1472,8 @@ void RPiCameraData::freeBuffers() for (auto const stream : streams_) stream->releaseBuffers(); + + buffersAllocated_ = false; } void RPiCameraData::frameStarted(uint32_t sequence)