From patchwork Thu Mar 17 14:08:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15473 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 4EEBFBD80A for ; Thu, 17 Mar 2022 14:08:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F2CDD6118A; Thu, 17 Mar 2022 15:08:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647526119; bh=XJ1pAOfIgnoLQrSP1otlKPEp/A3tyr+1rp/6dlRweSQ=; 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=tCDTe6YVuGHk+1aJsvayMySCgzxlrYwxhEbyw22+HcH+mz3RI3RgJ9LjICZeEibIV Gqqf5k6nrUg6FkCXkHhqSZatu8V9CX2jeK5OiutpPZP9qrFtiCmF+m4rqiIMNuYV72 taVRpE6NoqTIn+OlmTP0+zFFw2h6KA7uJr/JRCYmRtY3BtXtCjUFOYd3TnAmoEEiIz 72ObgDTlEbZsjz0h/OlolfBl/tqUz321oWWMy56rqd9gZXWxqeY0qmqa9UPhwVZBTR z03dp9iqVQRodJ0+KuX80mlU0DL3U3DTHRk8P5LwWpAYpjPHyvdY9r7lI50GAwoSqQ iOEGuOkJtIUbQ== Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A9197632E3 for ; Thu, 17 Mar 2022 15:08:35 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="pdedGJzg"; dkim-atps=neutral Received: by mail-wr1-x432.google.com with SMTP id u10so7524373wra.9 for ; Thu, 17 Mar 2022 07:08:35 -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=1jo8PyycZMxj9FXYeyEvPbN5X7sAU3cwjuWroYkyh4g=; b=pdedGJzg8/1VJZbWeX3bhDRoZcUd3Knxh2iHMn9g4ZI6wk+jB8lA7By563RjJzOKLo /kForPUaWmB8ZWN7O2vCm/YBQvSZ6TKJDfGDFs6c+cceriTNuir6BqfDMrxkFCTeDm1s +nQCesIVa8vHMR+kc/3U92Cyu9cEwKvF6sHk0sS4Bx6F/i+ChBYdIXcEKCCLmv7UHiSV lAvPMavCK25jlr/XsCuJQm313GxfdITCE6Zmo5zjAzkfnNSmkcNDnsIpVZYK8rRdxvrH JqYlMs5zj4v2JbnwEmaKfexGeqS/iM8NTigbk1TIFuGHl3aFqyvfKfnKirMv5jfQsbWO nSHw== 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=1jo8PyycZMxj9FXYeyEvPbN5X7sAU3cwjuWroYkyh4g=; b=rtQtvGysnOtVSvGt0S/eoa/WAk66ZgUBYqIZP3r7U8V7ur4jQwLSy804maFFpRbLdX V3kG5z9dbk+WUjSaQRzfm82KmnzANSSd5pcrjQsft81UjkMpsVTe+JTiOMJvIPMp9aVM DtcgUxVUjREzG31ChqEoBnRyNMsKb/0KCFkC4Kk/sOMY9rACnQjXc5KSTHHJqq+rgl8k esF/fKt9dn4tFMnuu4e7vBK3B5AYMqhqwwUTFc1RQc2uSy35OsdRwcA4cDs7jQevZJKW yqWi8FXCiuKqa7SBeoUNXXyZWUbd+ukQoZNLLwQ+lD5cqv9ipd8uW9n2AgYAoUWad5q3 5ivg== X-Gm-Message-State: AOAM531sAS0tNxT9IJ4ae/RFdO/gt92LP2NePrtlOXEoyv1QtJxpPjZy d7N9g/Dl0VVgV59gPV3VjqOqgzdBsGEp4w== X-Google-Smtp-Source: ABdhPJzlxjVsE8+4oVmght3rdGWu6YyNKf3PYuHf2PJqoZPjLM0fETZkDBCGu1qBsHglyWqpNexZVw== X-Received: by 2002:adf:f70a:0:b0:1ee:33bf:3864 with SMTP id r10-20020adff70a000000b001ee33bf3864mr4087313wrp.4.1647526114817; Thu, 17 Mar 2022 07:08:34 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:371b:8e01:111f:5322]) by smtp.gmail.com with ESMTPSA id z5-20020a05600c0a0500b0037fa93193a8sm5287831wmp.44.2022.03.17.07.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 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 Subject: [libcamera-devel] [PATCH v2 3/6] 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 --- .../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..082273828894 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), reallocate_(true), ispOutputCount_(0) { } + ~RPiCameraData() + { + freeBuffers(); + } + void freeBuffers(); void frameStarted(uint32_t sequence); @@ -280,6 +285,9 @@ public: */ std::optional notifyGainsUnity_; + /* Has this camera been reconfigured? */ + bool reallocate_; + 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->reallocate_) { + /* 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->reallocate_ = false; } /* 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(); + + reallocate_ = true; } void RPiCameraData::frameStarted(uint32_t sequence)