From patchwork Thu Mar 17 14:08:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15471 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 82094BD80A for ; Thu, 17 Mar 2022 14:08:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E8ABD604E8; Thu, 17 Mar 2022 15:08:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647526115; bh=i63d6hUH3isSXt4iyQ9OeO4uzCK+/jYWFH31E+5m1HE=; 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=xfo2hs5AARCwW7OvdK8jp+NMsB5iZdAt62tTwah/cjO1odqAyPVXip5UauhkvrvzN /Wd1lBc262wle+S5X2nxX5NEiNUv5lGkX8EIukAJe6XQr0F6DJlx0G9EoE3QiW9oJM snIsL9+u4Fsch8+9P1iPHTaHeQymL1x+5hX0UwBuyawsSzfv5UHt1fIT5yGRB80p1O 6SMSfytYzdJPnVzi6kiG0F/MAM6j0YIT9jWHY3VUQ7Rfq/h6pz0D2cWqVuSz56Y3vl N4RJT8w8Egq6caIMAE7mDBfVFgLe/z85qHIY56ry5JQifUUmc+Adrgpigti7bKvyGC ySJBWWM+9VVeQ== Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 938EE604DC for ; Thu, 17 Mar 2022 15:08:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="NWUNfTVx"; dkim-atps=neutral Received: by mail-wm1-x32f.google.com with SMTP id r64so3165561wmr.4 for ; Thu, 17 Mar 2022 07:08:33 -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=jcfkXUDyQsMHFwrfe/cenXQcfke3b/k+swts4GnZTjQ=; b=NWUNfTVxgZJmjEXWloMya5Yv40/Y/JOsaukTnshQO7iynv/lmYh9pq+6RLaPV4cjS+ LTwjvEqGtI0VGJNmWV+drvsMzGlGjXPnp5VF++P7zvKq72+6JMZIckKE8lxHJuqy+23h w/pJhCT7YrKBIZW2GPUoo6UT/gdoRz1zz9cX2m+wXeyNjbSq4nOXKLeEt7hXPtdfhxcq K5AnQRQpFxuHFY5zBdn/YZfPEwFDzCDO6MNXoAGWfFc9FGSepMTUf/IXu4s6L6S5qWe2 M9yDJ60mCsuGJMW3DuThXI1DPCytiD/zTu1gab8S9aqeyN9VV8PFQMoHS1p2O4OKxdGX R8VQ== 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=jcfkXUDyQsMHFwrfe/cenXQcfke3b/k+swts4GnZTjQ=; b=4Hk3e9mN79FDf8UjpbjSdwV77jxllrNsN3e0w6aGDQl8TaTviDHNaUPgxVvIc+62Rw MQNfwoLpRc2uC9zfYkFg49/CmTaLYZj8bQd3Hb2fRLrkWfNqbNKc2Ez7jpCXhHxhwq/p 6e6jfDmG07f448iVUPJuilu87JIrWahguA1CMXxan9wepVsVpyD5zTaCYsV6+Yq5gDao DOLl7P5GHoDQIZK6iR7/LUaGfGUMV3Brlu/uSJ7zyjOZR/l1ZdCKpL49YMZpQb8HlN2s q6eTJjn2/yTIjrTUHTK56tIBUtnjpvDpMVIC/nzubou2yKdie3dF9YR/M7Mxmbii5jms 027A== X-Gm-Message-State: AOAM531cioRVzPjSzOWmcOouTlKd9LYTn+gb/PE7TgGfMEfPgxmVBPOl EuEsiu2KKShu0BoiA1LZjrZG9KkjVeXGOQ== X-Google-Smtp-Source: ABdhPJzo0d4YjHnbQTnEyD4Xz7uoVXGOoRUc5gmVOmkYrkOgv51WXcroRfFZD9mI/79va4IxkM+CFg== X-Received: by 2002:a7b:c24d:0:b0:38c:68a4:eb4b with SMTP id b13-20020a7bc24d000000b0038c68a4eb4bmr8487972wmj.108.1647526113076; Thu, 17 Mar 2022 07:08:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 07:08:32 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Mar 2022 14:08:22 +0000 Message-Id: <20220317140827.1835029-2-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 1/6] pipeline: raspberrypi: Avoid over-allocation for ISP Output 1 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" The V4L2DeviceFormat structure for the ISP Output 1 node was a copy of what is used ISP Output 0 node, but with the size changed. However, the plane size and stride values were not updated. So there is a possibility that the buffer might be over-sized for the requested resolution. Fix this by only copying the relevant fields from the ISP Output 0 V4L2DeviceFormat structure, and let the device driver size the planes as needed. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index c2230199fed7..43e87a406036 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -845,11 +845,13 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) * colour denoise will not run. */ if (!output1Set) { - V4L2DeviceFormat output1Format = format; + V4L2DeviceFormat output1Format; constexpr Size maxDimensions(1200, 1200); const Size limit = maxDimensions.boundedToAspectRatio(format.size); output1Format.size = (format.size / 2).boundedTo(limit).alignedDownTo(2, 2); + output1Format.colorSpace = format.colorSpace; + output1Format.fourcc = V4L2PixelFormat::fromPixelFormat(formats::YUV420); LOG(RPI, Debug) << "Setting ISP Output1 (internal) to " << output1Format.toString(); From patchwork Thu Mar 17 14:08:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15472 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 7AD89C3263 for ; Thu, 17 Mar 2022 14:08:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6C0D9601F8; Thu, 17 Mar 2022 15:08:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647526116; bh=kXB2y+u+v0J4lOfnEEEK0fEHQi8UCDN+opF1eo2OslI=; 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=yWK+jD97rYfq3R1fzaw8Oq7O4+m4e4U8WAyzUyn6+E01Unhx5pB6iHGzeZ0TLmQHa jtPz+Nav16H7cbuzYiBbPEXa32xGcUQ6DB01s4RGGZwV6ADgnY/MpfNTDpFm11dcIA gsI6ohbTsW7Aqetj/WTMybYSL3fdC2WtfUljW7NukgVZOpKDUwwmr6ANZ+cpdkWZju +g0OMbLO0RQjj6RUQ/UyjX6bR1T1r3DrBoeSmacPg2BMkqNwWjLi4Ia0/Dz71+GS4I /hmSYO4mBT+2MdtgRvZGxeOstUyrQRy7zSb2pvxD4W2fwYPTYAho+W5wASrIULFFid W9o4u4jGr/WGA== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9863A604DC for ; Thu, 17 Mar 2022 15:08:34 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="e8oWdeSa"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id h15so7540407wrc.6 for ; Thu, 17 Mar 2022 07:08:34 -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=gxKs37xBf6jAcWLRbf5L/O2SlW/iZaDg6COx8v6by6c=; b=e8oWdeSajxxUuNt4YsII6biQyuOlh/56P5HnKFDb9GxwtD2jFI1/MW8iUqGgNWOTUt NQ84cPgeDVt+tsi8t6dHzch8KpVSmmcyHlHJ22+nHH7WQhERYo3VEXwAcG7itgk1ZMyG T/BthTVjaolLr0SfTFV1OBoEJKUYLOy66Et5BUeOiL4IGX+KIIAxEyPY9UJ6semBWylm SevW1WOi/25y++5BrHu6fGQWpHP+StSQvAeWuIvaUcB7Jxf8H+XOS01F5xiTUqybqpc+ OEDkO+VokuiuDqnqVQmDfUnNMQuGzoJQh0i76HyJ0avM4/Uprnx0zQErZYWTLh31ORQA ywxw== 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=gxKs37xBf6jAcWLRbf5L/O2SlW/iZaDg6COx8v6by6c=; b=VzNkkWOm1tEbiqUFGWvikAyYA64Ax4iOP+EooMjPIpeBcCM3sGhGfa3Z7yK1uxQAUo KCvaTCDdEDHgBUmxGxBvO2rpArMQhuonNFDyX+jhsXiphy07Ejn+c63wMgAKYb2tW1xM /jGzYCVmRL8vJPrXEYZoYq0ugbMjaLY6+L+bJPSJXbgsNSp9LZERFKLhd2nqSaM1VmLR YKlsK+c31Gq6laT2ucOhe9I+MTMNe4qu1EzRDodjISr/s/EQTnU2xEGYClw1pTgDag40 bgGqkP4rF+eQpAa6a60uVwNkLqK1G8u2okjdg6fpM+sBinggXzlAh3JnaLKIkXg0uNiL TZTw== X-Gm-Message-State: AOAM530ooM/YXyWu4uR2vD0PmHuP/NKrYp1Rq0Ul+uYweof7Yn9poKWL qk0nzTcx6w/WO6lkTvHq6NiSVZbHBYBz7g== X-Google-Smtp-Source: ABdhPJxllR70ZSaesga6KjsQZf2dstmsgZ/h61XMCbMLIhjazKCAo7zWO3s9ne6TPr6+34SD21k9rA== X-Received: by 2002:adf:efd2:0:b0:203:db42:c56c with SMTP id i18-20020adfefd2000000b00203db42c56cmr4096391wrp.698.1647526114027; 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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 07:08:33 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Mar 2022 14:08:23 +0000 Message-Id: <20220317140827.1835029-3-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 2/6] pipeline: raspberrypi: Move freeBuffers() to the RPiCameraData class 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" This function used to clear the camera buffers does not belong in the PipelineHandlerRPi class as it only access members of the RPiCameraData, so move it. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 43e87a406036..2281b43fc3ac 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -189,6 +189,7 @@ public: { } + void freeBuffers(); void frameStarted(uint32_t sequence); int loadIPA(ipa::RPi::SensorConfig *sensorConfig); @@ -330,7 +331,6 @@ private: int registerCamera(MediaDevice *unicam, MediaDevice *isp, MediaEntity *sensorEntity); int queueAllBuffers(Camera *camera); int prepareBuffers(Camera *camera); - void freeBuffers(Camera *camera); void mapBuffers(Camera *camera, const RPi::BufferMap &buffers, unsigned int mask); }; @@ -1056,7 +1056,7 @@ void PipelineHandlerRPi::stopDevice(Camera *camera) /* Stop the IPA. */ data->ipa_->stop(); - freeBuffers(camera); + data->freeBuffers(); } int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) @@ -1452,16 +1452,14 @@ void PipelineHandlerRPi::mapBuffers(Camera *camera, const RPi::BufferMap &buffer data->ipa_->mapBuffers(ipaBuffers); } -void PipelineHandlerRPi::freeBuffers(Camera *camera) +void RPiCameraData::freeBuffers() { - RPiCameraData *data = cameraData(camera); - /* Copy the buffer ids from the unordered_set to a vector to pass to the IPA. */ - std::vector ipaBuffers(data->ipaBuffers_.begin(), data->ipaBuffers_.end()); - data->ipa_->unmapBuffers(ipaBuffers); - data->ipaBuffers_.clear(); + std::vector ipaBuffers(ipaBuffers_.begin(), ipaBuffers_.end()); + ipa_->unmapBuffers(ipaBuffers); + ipaBuffers_.clear(); - for (auto const stream : data->streams_) + for (auto const stream : streams_) stream->releaseBuffers(); } 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) From patchwork Thu Mar 17 14:08:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15474 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 EDED8C3263 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 77382604E8; Thu, 17 Mar 2022 15:08:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647526119; bh=hmW0dmL2Wn0CwrkkMd1DI57vr+ZJMXzXlvy1PzDbD2M=; 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=VU7SDRnYwnINcmLUPw9O34c915MF35hvMcRwjPvx35W7eE2xELFU3LklCIcfGnu08 zHfltfcPx8FJoZWcFn19nbE4MCe7A5BCmV1yIMzpZMWLl/TxNgQPuUBBh6LLCbUjeq JoUpKhqisWPBcv7/MqUehK2dI6tbmkXCQZosLDFnSqnO0lMkl39suvY1BnBSq4IrYJ j4cXp7eNM8eXkPZjrgRFEtsjR5X+A8MOvgG4x3NKMQdanXgyGSBKGSbRo/qaD7nprq 5PtLLc+D1w7Y2Rp4C8hbde6JgCOZPX6H+5wuV8eu3N+CX1asiRyN+wMwxOn6BiVESj 4/gYOKC3TiruA== 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 6E82A610F8 for ; Thu, 17 Mar 2022 15:08:36 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="tPeplFVy"; dkim-atps=neutral Received: by mail-wm1-x331.google.com with SMTP id 7-20020a05600c228700b00385fd860f49so3262812wmf.0 for ; Thu, 17 Mar 2022 07:08:36 -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=uTP8kcdMePVoTNBWCwW1qpevafEXXGJwaf+aCHPyhj0=; b=tPeplFVy3Dm0HbpxESiFay7gTZm1DVaO00pIaL3H1vMjpfe9voFgaiN4JQx8M7NcC4 LZ/gE8AkexvTKgKug710HxU3uxrbeVu9Khtly6FTe5MLzUlPrsjidRKPKSFfS/raMUnE i53jwmfxqm+Z0q6iLAtVFQVa2qzmU9sX5Q/3VRdwjLKnSRiWRndc7Ns2gD0Qa0hxj1ya XA4+ADBSYpnN3Z1+rU3kK8iywbRCht8st60DWPWK//1jlmuhjxKK3WsCnJR3AgxxgVu1 W2I6ZMbUP8p2IJOzFyh63sE5/2gVV7eBAxBMCDwnUTgPDUcgCF7efcD4BvoJAae/ueYq w3fQ== 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=uTP8kcdMePVoTNBWCwW1qpevafEXXGJwaf+aCHPyhj0=; b=2AzuaWkMNYjtAxEgZxh7y2FMS9NctH1lipz40ndg9mwMG5ady8N30PO4nduF7Z3hBd b/unR7UaAx0MF9g1R+ELb2e3F1qmdss+EMXPJwp86O+ijZOvWZvHvemagST9Ly1gZ2I2 +4jbIjoXOpt6N1XwGb4lZR/Q9Y1BZw6Si1ITYfeC/5FR9hGzXiWqKS/3L4BXZtUpXyW9 fq/M6FkLG3NNwdPi6/hnUEvidsVRvLX+M0h5xUl6z98H3wdOd+D2ER6rKTuRmD8/ojwp 9MW9pcn3uNj092QvVu+ZbPGoDyh7zN8BCpnLo0qbOAc2GQe/Ba/VYuTzbfITXbfrtHPX zT5A== X-Gm-Message-State: AOAM533wvm5A6o/hV4akHQCo4RwOyEal2krzIdTEL0oQcalAP+AebyJH g4trFYDXUjJEJfcyaYU/okJXciS1RzcMCg== X-Google-Smtp-Source: ABdhPJxHq7Cq670cMcskQR2Hmxa0NyPC+qGQLOAFUNN0E39WdSYXqo8BN0MXjsmhdzjl95uX8mvWSA== X-Received: by 2002:a1c:f018:0:b0:37b:c13c:3128 with SMTP id a24-20020a1cf018000000b0037bc13c3128mr11577599wmb.157.1647526115869; Thu, 17 Mar 2022 07:08:35 -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:35 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Mar 2022 14:08:25 +0000 Message-Id: <20220317140827.1835029-5-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 4/6] pipeline: raspberrypi: Repurpose RPi::Stream::reset() 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" The original use of RPi::Stream::reset() was to clear the external flag state and free/clear out the framebuffers for the stream. However, the latter is now done through PipelineHandlerRPi::configure(). Rework PipelineHandlerRPi::configure() to call RPi::Stream::setExternal() instead of RPi::Stream::reset() to achieve the same thing. Repurpose RPi::Stream::reset() to instead reset the state of the buffer handling logic, where all internally allocated buffers are put back into the queue of available buffers. As such, rename the function to RPi::Stream::resetbuffers() This resetbuffers() is now called from PipelineHandlerRPi::start(), allowing the pipeline handler to correctly deal with start()/stop()/start() sequences and reusing the buffers allocated on the first start(). Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 7 +++++-- src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 13 ++++++------- src/libcamera/pipeline/raspberrypi/rpi_stream.h | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 082273828894..d3212b193ced 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -693,7 +693,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) /* Start by freeing all buffers and reset the Unicam and ISP stream states. */ data->freeBuffers(); for (auto const stream : data->streams_) - stream->reset(); + stream->setExternal(false); BayerFormat::Packing packing = BayerFormat::Packing::CSI2; Size maxSize, sensorSize; @@ -991,6 +991,9 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) RPiCameraData *data = cameraData(camera); int ret; + for (auto const stream : data->streams_) + stream->resetBuffers(); + if (data->reallocate_) { /* Allocate buffers for internal pipeline usage. */ ret = prepareBuffers(camera); @@ -1031,7 +1034,7 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true); /* - * Reset the delayed controls with the gain and exposure values set by + * resetBuffers the delayed controls with the gain and exposure values set by * the IPA. */ data->delayedCtrls_->reset(); diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp index f446e1ce66c7..7a93efaa29da 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp @@ -26,10 +26,12 @@ std::string Stream::name() const return name_; } -void Stream::reset() +void Stream::resetBuffers() { - external_ = false; - clearBuffers(); + /* Add all internal buffers to the queue of usable buffers. */ + availableBuffers_ = {}; + for (auto const &buffer : internalBuffers_) + availableBuffers_.push(buffer.get()); } void Stream::setExternal(bool external) @@ -97,10 +99,7 @@ int Stream::prepareBuffers(unsigned int count) /* Add these exported buffers to the internal/external buffer list. */ setExportedBuffers(&internalBuffers_); - - /* Add these buffers to the queue of internal usable buffers. */ - for (auto const &buffer : internalBuffers_) - availableBuffers_.push(buffer.get()); + resetBuffers(); } /* We must import all internal/external exported buffers. */ diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h index d6f49d34f8c8..c37f7e82eef6 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.h +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h @@ -45,7 +45,7 @@ public: V4L2VideoDevice *dev() const; std::string name() const; bool isImporter() const; - void reset(); + void resetBuffers(); void setExternal(bool external); bool isExternal() const; From patchwork Thu Mar 17 14:08:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15475 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 A9E82BD80A for ; Thu, 17 Mar 2022 14:08:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 442BF632E8; Thu, 17 Mar 2022 15:08:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647526120; bh=EuRdJnTXSIyH4FpDUOhhsDPhZIpTbM5FisvUXjsyyuo=; 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=PQElsLT1fEubwBhmBe+2UhUcZ8fV/e7WkBg7jduR5uoSVOxj676EEnPM5M5UR6lZy 550dZ/nnlceo2/T4TG2E6ir99C0/uEnJd96wvSquB31jGJPPHJaHtGq4be7iwhDnT3 PpvlxIQZ8Mc6RMipKVONsGp/HVhWR5fG4tlWdi8irTrFyZyr5dZCybQtzGNAw0OKHE 2rCZ7f+0VOIneQvxe78I3zbikFA4rzhrBYU4+/EGjkv+rRktpIOwalR1oJV7OE9QoN 23OlMRCdRcM3sIL3u8QkJa4qMxS89RR73ppKdZLOCBFmlNRRgXobMaXlYYKsgO9Eu2 ecSPPEronMVJw== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 310816118A for ; Thu, 17 Mar 2022 15:08:37 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="TwuwlrPB"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id j17so7623188wrc.0 for ; Thu, 17 Mar 2022 07:08:37 -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=5+KEwYvzqMylcdvXOeVzJt6BNlZhZQu/aJiLfyDW3WA=; b=TwuwlrPBLApbqL2RW/89+/rTJBXHTPExZPOIzYtfjnEU91Vv20QlGWh3dDh5Riazhp g20Hm+9Ke8Zv/iIpzTF1XxPpIqM12LxxyLtJ9SbvsVs7gnoEbp62/GKX8cRzP9b5mE/p a+iGFvNRBFaLTFNExm8L4agg3BhW/KmRUSO4aOmYr5IapvLMvUn/qtBZCLBRPajTQ3rH SWThjtxV8WpaWssFtL69sRUx44rLEENwJW042CfVgkyzqyVkxQ0fW0BuxlZ48OEoWNhF +Q5j2LPNulx16pxyW/kejICTSttaxnpNHYUbrUhb8slFWE8fT64bcETr0gg95rjw2wJr WqWA== 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=5+KEwYvzqMylcdvXOeVzJt6BNlZhZQu/aJiLfyDW3WA=; b=O7VWMOGn2vM/0Umucmg7p53GnRIG5TS7uYfcQgJ37Hr6c8ubyNO+3TbrZdV6hsf10A sP4WK6jDXLIk5/nzbH2c4QJFqpBbQwEdPtVFHEn4bjfql8pgjELvSL9vkgkgbTed0nVu SdL6QZmdBNdqSIQq1g0cNaV/WMWyk7o+vE6dpE7JnUbKIWMZDi0Aov6IfMKpVa4emBfe jVgOIl+DrUe1da/qdXe/CwFjrDGnRi4Zj1EpoDaBVZcY0EfSKd0XsWPEiH4W948rSgEQ 2J/hTyz0OaGeFTktK17Y66qwh18h+XGj7ue3v+nLbI+NftegA1u2/uHhXZbBkh8+OcLt Xm3A== X-Gm-Message-State: AOAM532Fy6d6F9LZcNRmat4yndZtfWgzK5+o2U3fKtcwA89rxkx5QhqS lQIhzRxHIwlc1oVn2RvJjNaOQ9q90LVIjw== X-Google-Smtp-Source: ABdhPJzq/oGWLzuTABPKpY8kIcFXPzfyLKxT3PQO+t6+k+GRnjZ8vGICr7POIpEIWSCU9i2jpkb8cw== X-Received: by 2002:a05:6000:1379:b0:203:ee50:45ad with SMTP id q25-20020a056000137900b00203ee5045admr1745311wrz.268.1647526116590; Thu, 17 Mar 2022 07:08:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 07:08:36 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Mar 2022 14:08:26 +0000 Message-Id: <20220317140827.1835029-6-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 5/6] pipeline: raspberrypi: Add a timeout to free buffers on stopDevice() 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" Start a 5 second timer when stopDevice() is called, and if it times out, free all internally allocated buffers. The timer is cleared when start() is subsequently called. This avoids the pipeline handler from holding onto internal buffers for long periods of time due to application inactivity. Signed-off-by: Naushir Patuck --- .../pipeline/raspberrypi/raspberrypi.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index d3212b193ced..32b282b4bdbd 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -45,6 +46,8 @@ #include "dma_heaps.h" #include "rpi_stream.h" +using namespace std::literals::chrono_literals; + namespace libcamera { LOG_DEFINE_CATEGORY(RPI) @@ -288,6 +291,9 @@ public: /* Has this camera been reconfigured? */ bool reallocate_; + /* Timer to free internal buffers once stopDevice() has been called. */ + Timer stopTimer_; + private: void checkRequestCompleted(); void fillRequestMetadata(const ControlList &bufferControls, @@ -991,6 +997,10 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) RPiCameraData *data = cameraData(camera); int ret; + /* Disable the stop timeout waiting to release buffers after a stop(). */ + data->stopTimer_.stop(); + data->stopTimer_.timeout.disconnect(); + for (auto const stream : data->streams_) stream->resetBuffers(); @@ -1071,6 +1081,13 @@ void PipelineHandlerRPi::stopDevice(Camera *camera) /* Stop the IPA. */ data->ipa_->stop(); + + /* + * Start a 5 second timer once the camera is stopped, and on a timeout, + * release all internally allocated buffers. + */ + data->stopTimer_.timeout.connect(data, &RPiCameraData::freeBuffers); + data->stopTimer_.start(5s); } int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) From patchwork Thu Mar 17 14:08:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15476 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 18AD8C3264 for ; Thu, 17 Mar 2022 14:08:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C8A7F632EC; Thu, 17 Mar 2022 15:08:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647526120; bh=Y82iiUEJJo6jzF5KeFHe8+WlpcmdbOvrdS0L5r4/L2g=; 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=gcAI3qjDpD6hbkXDzSoUZLkCcpRPXVcPb9YWM7bJHiL5g0QEnRYxSitkWIDnwkDfv LVUNOW8PccHO/W3aQp0ztowMfd6CXhETN0BYM46CvBR0MT7dhc6JWuFWXn+ZRUoDgM uergrUqBtVZVFyPCctDDYmJcAXPru7YkU5K+U/NbYxshy1hxQzfb6MK1qLaHO0f5uz i5I2iwLgZu7I7bs0uy1JGZm+cspaqHOs0CL9zO2XRcSDlNe9f5d/hJ0bHI4KQJF5tV rRZEf+HbAx5pCqd11c20SOERy35Z/KH7mlIHf/Zqq7X6a8yuiQjjrl/hLNVbJvizoq Hv5LdWmdPwldA== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D4A48632E6 for ; Thu, 17 Mar 2022 15:08:37 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lqaOCxgd"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id u10so7524542wra.9 for ; Thu, 17 Mar 2022 07:08:37 -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=QA3Po4T5fYY/+GjRjk1tO1oLz80EHEdU9NtOOneB35c=; b=lqaOCxgdmHWzlpwF8s+fQi9xBt+4+pyvDScYb5BZ/4u9I2LZGrN1oYOKOXdinkVJE4 JvLuPS+Nk+7K2ehoM8sYRdxcS6cNGqM6nOcsjXYSlkueQ8eMcb2vA4J/Crd8jSt8Rr6y IDS/LhYT5CwLBDQgEZsV3jOCmWzuNmffOVNHHmWjGHmzfk3lK18tSReRuc1EbtvHHD5J yiIK18u7480Z0xOOhLbJpP290M+NuATNvXMVGYoINenuFdV2KpXDdzlvlkDJtbKDJe/k ySGeELsmX5pEbC70EGH9u8qMJ4oFy0ZkTu+UAG4Us0SeDh+WM92WJKrF7dgn5JJk1Sth kGsA== 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=QA3Po4T5fYY/+GjRjk1tO1oLz80EHEdU9NtOOneB35c=; b=5oYggDB6uYdkACuqqF/6Mr8CLqIl0FPepYuBiPmIf2XYrmNRzGDzGQiSAOlx1Si1eb lRwjTdeKajbGbFVNr+sXOf2hkW3oL1CKB0dgpgyOxd54HasAh9Cp14XAQKgbP4qLMgWu GI4eshT2YskRsmXwTVWH1HA+dmpVpdD4iZr52bMJkln9glNI4knNb7p9vNgCPYDI3obB vyfJ83TgWEN9vR6RnBVyIWEWI+MF3J55WU08BlzqLRkHGd7oWaFWtxZSkVjZJypPzVAk zL+1/EGabEG0umAgMvKbcgXQqtumgT68KZ2lZF4VAL3Ala/KcpfjuI/DiVlGjvUiBdO9 6gFw== X-Gm-Message-State: AOAM532On3EFS13qUkU6QVTod9E8M+IWWibh1RclLJMUXnnPywEvlfZX 5ozD8m5pBa/Jq6xUgF0Tu5J2YaxSgINlRg== X-Google-Smtp-Source: ABdhPJzudLNbX4j7rMGyPo6Nkzk+nNl8AUraXgS8Xl6wtVkwmYXiGUhGWYZYAlXYROnw8g5H+I3Euw== X-Received: by 2002:a05:6000:381:b0:203:84bf:3faa with SMTP id u1-20020a056000038100b0020384bf3faamr4242565wrf.324.1647526117363; Thu, 17 Mar 2022 07:08:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 07:08:36 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Mar 2022 14:08:27 +0000 Message-Id: <20220317140827.1835029-7-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 6/6] libcamera: v4l2_videodevice: Empty the V4L2 buffer cache on streamOff() 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" When streamOff() is called, ensure the cache entires for the remaining queued buffers are freed since this will not happen via the dequeueBuffer() mechanism. Additionally, add a V4L2BufferCache::isEmpty() function and assert that the cache is empty at the end of the streamOff() call. Signed-off-by: Naushir Patuck Tested-by: David Plowman Reviewed-by: Kieran Bingham --- include/libcamera/internal/v4l2_videodevice.h | 1 + src/libcamera/v4l2_videodevice.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 2d2ccc477c91..37747c0b2f27 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -126,6 +126,7 @@ public: int get(const FrameBuffer &buffer); void put(unsigned int index); + bool isEmpty() const; private: class Entry diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 5f36ee20710d..9da82697e7f0 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -262,6 +262,19 @@ void V4L2BufferCache::put(unsigned int index) cache_[index].free_ = true; } +/** + * \brief Check if all the entries in the cache are unused + */ +bool V4L2BufferCache::isEmpty() const +{ + for (auto const &entry : cache_) { + if (!entry.free_) + return false; + } + + return true; +} + V4L2BufferCache::Entry::Entry() : free_(true), lastUsed_(0) { @@ -1832,10 +1845,13 @@ int V4L2VideoDevice::streamOff() for (auto it : queuedBuffers_) { FrameBuffer *buffer = it.second; + cache_->put(it.first); buffer->metadata_.status = FrameMetadata::FrameCancelled; bufferReady.emit(buffer); } + ASSERT(cache_->isEmpty()); + queuedBuffers_.clear(); fdBufferNotifier_->setEnabled(false); streaming_ = false;