From patchwork Fri Mar 25 09:08:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15544 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 55733C3264 for ; Fri, 25 Mar 2022 09:09:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EDFE361FBC; Fri, 25 Mar 2022 10:09:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648199350; 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=foHBg+OlX1HaSIjEtn96rgOGBKo2gUHdxsnDKQUH/HMShRGkrlGk0JzCUlnmhvo95 QzWCJCwDR2nkyzosNKk9cILRsiw1QFONS6b05lf3TSKO1f5kn8QNPDCfQzzLuUxQSU E5LZzgsQWojIPoN1RzTIPnN8xIwXAzLhcF5CAulngyiR+VFVq54UrIFa54XVZDAlVw g47MYDpl6OMuHbLfrNnZ93cmh6NVj3InfjhU5waZJWIzIdJXKAEvx7beyw2+EIiBSp XqnzKdj5VqKqLJN1DkR4uNVa2sN/OutOmddzRFB/713GBDqu1yluLCfDkcEiwYZdN5 9WAMCqPAxDR4w== Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 73ED8604EA for ; Fri, 25 Mar 2022 10:09:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lZFiYRnB"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id a1so9946089wrh.10 for ; Fri, 25 Mar 2022 02:09:09 -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=lZFiYRnBt3MRNOzmo1L9FZ+Tx3JqzC9RB04Y0ApylTUkssD6/64Wq7rQpRWS2gDkyX H//rzbjzCw1p3mvtG/zNrdru7SEQm3amrQevjLDCUQIVqVlUdETDE95PGY5wnc9uI/oE 9vPli3rr7ybHKkUx1MSXdAgQUnHIYU1m60QWaATp0OVx1WHCWQFmZQZcE3etCDxixQpK BzH4ceX03DydTMcdZO9ZPkId/GxTb1gFLsKWgz7gKjhIrd1m7RF47t68EUk83vWIMpCG 9nR1Cw9hNH83gnq46pUjJ6hlyVS18PrMKI+4yJYPWR20m23+nl3i/Zot6D5uB8p53Odo o8vw== 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=OaCQOxURmRWlAgJPzshXpNSi4fPsNFurj6c+YTxN5dzSRZd8K+pvT46Y7iu2wbB+2S F40bzr59OGykMMiv+6VInm+/jPqnct0VtmBlBeN/gng0U1szxGUaq0nzIQlJC8SbuWe3 d881Sl9UvvDgnVmhLs8mDpZNQQgK6kskX+STdhD+8akAcQHyznth8fsB/aSywOb8Ba4d 1qNqv6BDMPgPI10cJpyDwuSHLgvNVJ4sz1Gw9bwfVOohGDOrkpH3knfVVVAaZnU4qqTL gF1Gpnn6dJhRYac0blN/UYJKPYwW8jRphKK9673BO4vza6JLBfqzlE+SEpj+d4E+1/CH rtGQ== X-Gm-Message-State: AOAM531e0zhoLKW8BwcazKh5HkQ6J/NitQMxEx7y7YLn4bBiu4pTIdLS IePhca3MWOEs4mrPPh1FTWS8Dg81HLKIzQ== X-Google-Smtp-Source: ABdhPJx7A313eCVaHjqCRBZCLJY4Fthk9xisjhhdJNL+fxqdXNthFS8uzZOF7tpkfoFEVAdTa1hTFg== X-Received: by 2002:a5d:588d:0:b0:204:217a:d9b0 with SMTP id n13-20020a5d588d000000b00204217ad9b0mr8294029wrf.428.1648199348906; Fri, 25 Mar 2022 02:09:08 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:478c:773f:4734:d0bc]) by smtp.gmail.com with ESMTPSA id c4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 02:09:08 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Mar 2022 09:08:58 +0000 Message-Id: <20220325090903.880311-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325090903.880311-1-naush@raspberrypi.com> References: <20220325090903.880311-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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)