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_) From patchwork Fri Nov 11 13:30:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17788 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 59BCBC3285 for ; Fri, 11 Nov 2022 13:30:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D190963087; 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=ezy0mYD0YxRPxt1lRUUw8BL2nEP7GeoH4VvjV61NBdE=; 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=l9PM3Dhp8IMju35vrYXBTwYAjZewMHYqSR0MspCPdTeyNHNzRFUhHtZZn01qM906O ooWj61uebOZpfcn9mkw0tI/d/bbMKaUHVHqYzFnqeSAiPAJWX9tT4T2cr1Li0NXIxd fsAaWNK+k2CSpbCR6BaA0BNJRRo9hfrdChnFqnsw5RpdLjTkMSvoNZ0b3aMOhLEV4z jzM3IQz+SVoJzlwJ0YWPISYo/RTXIShCsXkcVkS5SqcN5v3KhGDzvqB5fNYdshaCTR +iQgqg9ovIvLxq0SPlpZ7T6f379i3U1/vwFyxP6eVLXdHZSoqmQkYEmg34dF4dpNG0 HQwp4OdGxsi8Q== Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4FA216307E for ; Fri, 11 Nov 2022 14:30:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="sOPY69Tp"; dkim-atps=neutral Received: by mail-wm1-x331.google.com with SMTP id r203-20020a1c44d4000000b003cfa97c05cdso3868250wma.4 for ; Fri, 11 Nov 2022 05:30:31 -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=IhibtisHB+sjCPzG5P0lOz5qlZRGGKdQlitZDDgL3Zo=; b=sOPY69TpQIM7/ZSGESGo9Jybfd5IpauOrEOlgQsHAaUzm5/v3SuTxanwuBBr/T77/V EOuSJls+kUNSzMiBdFsE2iF5qaHo1kkWFtt8Z4wkGFoA4gTByUG9Z+EneI3z2GV6+qgP nHgaKd0m5fHTCdN8Wzh28sPQmVVUaL2bS+ZtxZrRG2DVQgYrDmSN3bB93K2ws1ULKXit qzbOskFQD658pUysiU3Fv7bJHadb0TsQ18Y4xv++fL1N5j9iFLLnr4iIp8znD+Q40T8+ E9qndmjzFyRT82gDdq6R2z5w+UxWYNZNNB7EYtAO30oI+Wg8TM3dHrlZvxm8d+O2blhW kOLg== 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=IhibtisHB+sjCPzG5P0lOz5qlZRGGKdQlitZDDgL3Zo=; b=l3vgn7oh76bI9SQFQeWfPA15PypDFY/gVn75MZjusRNEOuv987asrnz1v3oFYoEk0F JBiscNbIaF4nqFDJE80gIbaagK5Nlqs6/o4aEKXHKjkC3vkiamYTFLC8R0nOIK4Z3hCq 6bn8szR9tabd4hw/nT9ucV1fR2CxwbwMOFtGnR5AFjWZlJkzMy6eJmnJI1L7yfs40yd0 5Xs3JPK9R2IzqJsu6rztYh2hNRSB+FOTL/jnhBVO9PyiKeuWT02TgWIyHYCq5JOrvTUz 2fHNT7D3545+LS3uHUfuM54ZufHaI/imew4dxZMKs5sXblfBByR7OFIhz8HTbiqUJFHs TNtg== X-Gm-Message-State: ANoB5plYFJwlloHmH+vstab/R2Bg1EzjfDK4BjN98/n60Y/76RDzPucX jYljRB+Lx5fvt6haCt9mNKTCPA456j3x1A== X-Google-Smtp-Source: AA0mqf5GjGNTb6OFBubTsANLZT2/FNs/oIf4BCYx0ONN/cH7O/rV2VFONPBG2WW/GtNyfyLcCl5i3A== X-Received: by 2002:a05:600c:3b03:b0:3cf:b49e:1638 with SMTP id m3-20020a05600c3b0300b003cfb49e1638mr1262382wms.50.1668173430639; Fri, 11 Nov 2022 05:30:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 05:30:29 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 11 Nov 2022 13:30:25 +0000 Message-Id: <20221111133025.3102-3-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 2/2] libcamera: pipeline: raspberrypi: Free buffers when a camera is released 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" Implement the PipelineHandlerRPi::releaseDevice method which allows us to free any allocated buffers when a camera is released. Signed-off-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Naushir Patuck --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index f15fa28b..785eddf9 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -337,6 +337,8 @@ public: bool match(DeviceEnumerator *enumerator) override; + void releaseDevice(Camera *camera) override; + private: RPiCameraData *cameraData(Camera *camera) { @@ -1193,6 +1195,12 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) return !!numCameras; } +void PipelineHandlerRPi::releaseDevice(Camera *camera) +{ + RPiCameraData *data = cameraData(camera); + data->freeBuffers(); +} + int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, MediaEntity *sensorEntity) { std::unique_ptr data = std::make_unique(this);