From patchwork Fri Nov 11 13:30:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17787 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 AD475BE08B for ; Fri, 11 Nov 2022 13:30:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7C8B263083; Fri, 11 Nov 2022 14:30:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1668173432; bh=fKCjuchVPMbesWQYjeiftTEko07Xml5FLwoitmHa4Cg=; 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=v5KqQvOW/tf4WGk1sMfu56qk2N8CLbzPZhgUY8AQuVSvy7Io4ZGCPt+WtGChjaDVu BoMSvI+onE8MZ46FLX5Qh02UD4HL3+Ya2uCKx0wT+lTrXKt8Jgw6QaI7xttC5eyOZB 15dFLJB+k6d3GDW8QD3LXbArVvnbxFa76MN1YVSJPGPYGiv5TF+TWFEN6mGd8tFG2r sx7t/uB7sy/Ck09IrZj6T4dhe0yOdVz+axaUCqAJXiAbZNWqXPVtgAzLWjTNaNVTO4 gkUfEoBKOzUnLziEtbpMu2dIpejFVEtLPGJm0+GAQXRoJYtM1ob6Zrk2aIwysaVEfq j1DO8AfMi7Zgw== Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5CB4A61F3F for ; Fri, 11 Nov 2022 14:30:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="QEyZ+PSt"; dkim-atps=neutral Received: by mail-wr1-x42a.google.com with SMTP id bs21so6499358wrb.4 for ; Fri, 11 Nov 2022 05:30:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zo4d71AdERN8fZ/JHuXKVhjeQpHhFVQuWoMCupOI2Pg=; b=QEyZ+PStte+fktFlS00Y/77mZNEikdodixXBorzy/S07V6wnX9ZQ3wVGRFe1iuyppo 1aArnN9YkQtNnVLRRFVZMz0mBp3KSgr0T0zLba7gYax9jzLj7gtjhR2W87553z5LnR1n RVMoyBzWBtQl8yKyEeyL9RuZzCSj/+zCnD097oN1PjblSQkdf/cXHIOB06DKjQmdMAID s7CZAUPrTt3zt/G09NbmP95tVQ9D4vB6S6xldfQ73H7E/YQtY6fd4gcl591Ce2wSwKH1 7CJkxARBJA7rmWxeIo/776+dVKw1XTs6t34rnKOHxQS1ibLpjNDxP/DPYfGO0nOUALUL d2dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zo4d71AdERN8fZ/JHuXKVhjeQpHhFVQuWoMCupOI2Pg=; b=PGJB4zqYakzIRnFH5qRgon2Yo6OAtk6QMrOnGa0IlMhmU2WgcMZ+nYIpXAusNsPtWA Zftn3rDHQcCukWpj8Ecc/0BOch1OUbHe9wZTCtFe378wQMxQk2Emk+2tNxcGbIhHf+bo ayyeT6zEQ99Av95gWRVA8Zdim1ynAk2yumtiaw2PtNe/5wQPNfbc69i0fZ4+Wy+3a3QF yXpD8R19qyXeEZSG8bmLhL+zdb45sjTrbZJqvEmTbvml8AxFBlxD/SBhcYZ+H8GW7EGc HkdSCpC4hOUIfvLZl5kkil+F8+CjBRSHrOKjASviDoSB9dYTkTmeJZ+rg78V7C+t/1Km cqHA== X-Gm-Message-State: ANoB5pm3deL4SDzY3VeM7ptsD0dhjw+vxK+FHLciA/tQw1b8er50t4EZ 6wNMnPnj5HciFf4towi2PxACC75r2aLV+w== X-Google-Smtp-Source: AA0mqf7SV0BjYlla2iubTzbHDt/adL+1urIOzHb7WuvUIxtzpvxo7DZo/Fq9Oz02bIqandG3K1VJbw== X-Received: by 2002:a05:6000:1373:b0:236:c206:b2b1 with SMTP id q19-20020a056000137300b00236c206b2b1mr1240840wrz.624.1668173429543; Fri, 11 Nov 2022 05:30:29 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id bk11-20020a0560001d8b00b002416f0f1e96sm1511487wrb.43.2022.11.11.05.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 05:30:28 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 11 Nov 2022 13:30:24 +0000 Message-Id: <20221111133025.3102-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221111133025.3102-1-david.plowman@raspberrypi.com> References: <20221111133025.3102-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: Add a PipelineHandler::releaseDevice method 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: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This notifies pipeline handlers when a camera is released, in case they want to free any resources or memory buffers. Signed-off-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Naushir Patuck --- include/libcamera/internal/pipeline_handler.h | 4 +++- src/libcamera/camera.cpp | 2 +- src/libcamera/pipeline_handler.cpp | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 96aab9d6..ec4f662d 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -46,7 +46,7 @@ public: const DeviceMatch &dm); bool acquire(); - void release(); + void release(Camera *camera); virtual std::unique_ptr generateConfiguration(Camera *camera, const StreamRoles &roles) = 0; @@ -74,6 +74,8 @@ protected: virtual int queueRequestDevice(Camera *camera, Request *request) = 0; virtual void stopDevice(Camera *camera) = 0; + virtual void releaseDevice(Camera *camera); + CameraManager *manager_; private: diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index c4f65c1a..2d947a44 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -870,7 +870,7 @@ int Camera::release() return ret == -EACCES ? -EBUSY : ret; if (d->isAcquired()) - d->pipe_->release(); + d->pipe_->release(this); d->setState(Private::CameraAvailable); diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 825aff5a..cfade490 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -183,6 +183,7 @@ bool PipelineHandler::acquire() /** * \brief Release exclusive access to the pipeline handler + * \param[in] camera The camera for which to release data * * This function releases access to the pipeline handler previously acquired by * a call to acquire(). Every release() call shall match a previous successful @@ -196,7 +197,7 @@ bool PipelineHandler::acquire() * * \sa acquire() */ -void PipelineHandler::release() +void PipelineHandler::release(Camera *camera) { MutexLocker locker(lock_); @@ -204,9 +205,22 @@ void PipelineHandler::release() unlockMediaDevices(); + releaseDevice(camera); + --useCount_; } +/** + * \brief Release resources associated with this camera + * \param[in] camera The camera for which to release resources + * + * Pipeline handlers may override this in order to perform cleanup operations + * when a camera is released, such as freeing memory. + */ +void PipelineHandler::releaseDevice([[maybe_unused]] Camera *camera) +{ +} + void PipelineHandler::unlockMediaDevices() { for (std::shared_ptr &media : mediaDevices_)