From patchwork Mon Mar 21 10:27:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15486 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 F38F5C3263 for ; Mon, 21 Mar 2022 10:27:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 56E04604E9; Mon, 21 Mar 2022 11:27:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647858430; bh=OxqN9wPG8w9e6CpTtvUEfPWMYZqPcncE8Vf26vFzLOs=; 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=BRKwTbJeeJdl72qVCqfmy6OCyNSFhatVPIDx44JOcQG7uAEE5hGpmChF1C85yKHH2 d6zq0TXLg/6JvoXY7EVhVcUHMcN2PsxqU4Y53dEgjmcfztLVp1g9dUnxyfLQgLo1gI WJQwWCBnokNqAl5g/LZ6Iyc4dyd0G71poUgSiwxvaPYDpeALso7id2g7SyS5568Ac1 AF8E2Xbp2GXI+m8E2h/Zi632gSFzYGvDTMLnDZKtnFwas6xIz4LpEUOTKI70XWF9b0 dx2+OG/fR3xUf9+n9tqDd4haaBkBD5ECXPGDiGzV5ALthn97zirXVNtqMTjczAWkC6 H9lifCj4xlrhw== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CD9FC604E6 for ; Mon, 21 Mar 2022 11:27:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="PIlQ5vyN"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id j18so10374210wrd.6 for ; Mon, 21 Mar 2022 03:27:07 -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=n8rXhvCEYFa+f6swEAKkBsiiVnN1PTWYev6x2wU9AhU=; b=PIlQ5vyNtzhcqtIQhcThmKLwfx/90FkpZp511hatj8DwTVIgFtWvwocKJXKaTdss6P EuWc36RpzY6Ji03h8HrRu9iCkeB1Y6GWDzVb/lI33BYUatV/m3l8n3EwBUp6Dvy6t6tx jCfW85y9/GcwAwMlZRNPcHnQ4kLdCxEbqRACPfmw3HaoEgMJ7JN/bz6EismQ8fKZG3iB dbgMGRwp3dy73LaxTEuEu5KiQbfR5wWfbvwdyx2kraeNT5tPPnjxmce+XbYMchPXirXO t0CCgHgGaJsBG9deruHZ6I2cQFS2XzgkNVx1UparYeXLnna9zcWvThMlNAGrsobeliad kNKQ== 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=n8rXhvCEYFa+f6swEAKkBsiiVnN1PTWYev6x2wU9AhU=; b=mnBv4gQx4cW+MMg2ATRR12gBUP0VhVSEwGS6b2NS8IcX+u2sC+KH+cN5+Jzc49YGdm za03FhvNL0PLr+CBpvgFL5qMrO5l+SoFV2D3S0PmlyDasUctmZ20jDMgY/KT8tSby33f mtFr5QJWR3qQOoOKQZPMCUswzdJckgV+KRZZErBVzqKNAi6Z7KNiqXsja6Ss+cBPmRwt nsNGiuehv/5H/zIVcW/acQLJqGrqkCnCrTWOgnJ6ZrBm9ahqZXRnIGyDA1DiLlz67hS7 hOzsPDZGWJ2Fvhd4rEym4OUPf/bicOME6EitBLvZMQiBPDiG7HTmst2mWwSxj8UMptAL 8O8w== X-Gm-Message-State: AOAM5325BkSPft3Gk8KkGTdhRNrVDSBk7NTpL26jBTl9sNzt7WRro+52 JK1JUVFM/dp8vl3GrV8IqmhB1dpWsYMTSg== X-Google-Smtp-Source: ABdhPJxAmQYgfkqRbaF5FHclJre4fig5/DR2/jZYWyqlnNmdrL5DW+bVuUmLP7bivMZ29Y9tMPy2Cg== X-Received: by 2002:a5d:4ecd:0:b0:203:fd7b:bdd1 with SMTP id s13-20020a5d4ecd000000b00203fd7bbdd1mr9833282wrv.265.1647858427288; Mon, 21 Mar 2022 03:27:07 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:77bd:7c6c:a8b9:8855]) by smtp.gmail.com with ESMTPSA id v10-20020a056000144a00b00203df06cf9bsm13530115wrx.106.2022.03.21.03.27.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 03:27:06 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Mar 2022 10:27:00 +0000 Message-Id: <20220321102702.1753800-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220321102702.1753800-1-naush@raspberrypi.com> References: <20220321102702.1753800-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/5] 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)