From patchwork Fri Mar 25 09:08:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15542 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 734B5C3264 for ; Fri, 25 Mar 2022 09:09:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 04446604E8; Fri, 25 Mar 2022 10:09:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648199349; 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=maJJr/lxWpwyBLjqvrDnKkB0u0WCXZY1MjjFq/XJEX4nJE1ALx65wfrtrP4z4o8Xm Ql7WBUH/fZ0DwUU3MJo+8lGjCokNE05TeRKx8VGDgqo6J9M2gcmBDMNFpbG+JGl+KC ZDYME2RoD3EXh26Att8bewFb11LE5nsxzZXnw4Nb5uOCyNcUEojALtW/IAQYvKG9pR /gHaEiBg9ec8BKVQXWEJT+9XbVPShhoomQIm1wXerk+27zCZW5R02OTtlz2BEpVvzl NDfEaL8fGqX4fXuaokPjpR4TysmvbLiACbE5NpRd5pTfPT2zz1bXXAbLmjF8a7Fegt 40HKN+p60AB7A== Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AB55260136 for ; Fri, 25 Mar 2022 10:09:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="QKONn7bI"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id i67-20020a1c3b46000000b0038ce25c870dso506650wma.1 for ; Fri, 25 Mar 2022 02:09: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=jcfkXUDyQsMHFwrfe/cenXQcfke3b/k+swts4GnZTjQ=; b=QKONn7bIny5rbEB1IRawLgBY5Z4KVqFDjp/SIvAJQ8DwN0PCBuNoMHuxI32GahvcRz eqO0sU3F2+9M0yYX41CrqksAmxnvGKIEDDYfuI2w9BRHy1EoCV1pWw2O5Hdl/2hli9Xa eHW3L2XdSmTP3k1Fq0evHMZVY0JPbyd5KbodmzsRCe4f9djV9Lj1wL9i+0TvTWqdBmVl PWZxJR6neY/ctpC3MFGInhnabzlo3mZhq/QscEBVKGdiBRKHluux2na6cOKiu2EknhmH tbbRxSWAXrtZCizTuZSzwxX3kFPoAT2Hf6PeoEXnbxO4aZHr4mJx1ga/ARa7/NC8BFFr QjkA== 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=QpmxKtSLgg2nnEkBlE7uYiPcY4mj7Df9jMcc5LdCpU1LulgTyLZlEP6NxjbeoH4mKw xo3mfH2zL5Q31bl+x2UhyNKLQ0vTWebKtFyudYsQs1NrmziTluuR6gjgQx/CHa+J6+ZR 8OVH+46/gfLzDkpGADNASbC6OGKgQV/KYdNaB1PS68XSfYztAg0TBS7C2d2ryApSaBZO iCDPXiS4Ng6MT9kyO5ejDHJyjeOCrHUfb5/max16pshfnbI2QwzNPqv7imipxeEmkcD/ thlwVThJ8tUQhdRA3N7N8mA7QBOrWfMyyFgvyAr7rVihqlQmF0oZ6rr2xs+tfL/i+QjN geDg== X-Gm-Message-State: AOAM530tv9bPzfkpir8eis/EswaQA5X4M712FWu8WGaZLgUnFQUa6DHT dh/LMnew8vKTc7Ep3S/5CeMrVEcLVdtRgw== X-Google-Smtp-Source: ABdhPJyJMrXtbzQcH0j9dBg+ovQ1CWKpvQ8gpOvHMZL+BxYXlI5ck2jQtGSK8fq2IGizT7XA85jEzA== X-Received: by 2002:a1c:7219:0:b0:38c:a4f8:484f with SMTP id n25-20020a1c7219000000b0038ca4f8484fmr18069189wmc.99.1648199347157; Fri, 25 Mar 2022 02:09:07 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:478c:773f:4734:d0bc]) by smtp.gmail.com with ESMTPSA id c4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 02:09:06 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Mar 2022 09:08:56 +0000 Message-Id: <20220325090903.880311-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325090903.880311-1-naush@raspberrypi.com> References: <20220325090903.880311-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 1/8] 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 Fri Mar 25 09:08:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15543 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 CB3ACC0F1B for ; Fri, 25 Mar 2022 09:09:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8E2C261FBD; Fri, 25 Mar 2022 10:09:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648199350; 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=A1nuv6x95HOjHFgbX7SRYcmTMgQJwBGqtavNzqkB3H1Xqvk7YZMBFWuNkWkKCorvf 8vkT3GqPybfcEwf6aszOUPegS3g1lh9X6fvZd7tAHHWgMxnBLJU9eWKCbPeyqJwNTn H43rtafbIdoH6Cia81MpYX7rmB5mss4dYujEh6HUCkCksqDO8znvc90WfkPQV6USvA sof2AG9p/9tk5zAxoGXDK/GyldSx8P0sK7fV6UUfdqWNNYmf/BHCytwkZgd5JtaCbN q70G3Y/dnDKn7IATwmWzaUn9nTsoz3l0Pu/aDl2SmnA4yGteG6/MwHGYCWZ5M7FEpT LNx/Apo5TkUpg== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BD97360136 for ; Fri, 25 Mar 2022 10:09:08 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="HAYeHmeX"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id r7so8841695wrc.0 for ; Fri, 25 Mar 2022 02:09:08 -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=HAYeHmeXyx4S6yTTGTVRCSP5UlFgVHiUwwFA5+XIhqL/TD6GOz4P0bgcN39fDmeqUZ pgObMpD6jbPkLADVkceXSGcgpR/vR2rHYlZOUg9QUr9GAawQNbKQVw5FRRMlH9xRlGHN JcuCChOjkdfl0/m2yc8fb5uH9SzABWH3XJjpEyAS/O/limrkGArprArjLRLvrSMbdTE2 R++YxrAxSMWB+bS39yzubUzvGFECbbiFjsNZG8SL2GkuzNNHSWHyDUrEV5IZRg29aLH2 Un3Z3oVY/TjOPAiMNfIOjDRmJ9AyBiRq4tcl0VyKdQ3q8uMh82tctqs1hnn//urwteQ5 X0/g== 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=6CC+UtpZaejqbrmjVlanN5ZzOCDArbMp+tFZXWkz4sFc4s9RFZpJ9FkL7STuDXtgBg glxj3Vn+BNqVQLVaZU8EBZjNwGzrM/WdKkfaCjbkIUh9as6Ri60QZTnOZrp4cZ/eb1dP 3OXsmgZScRmb5X5GDZnY5iCAL83ggAkG+xWPECvx+H8PyUi8yMeX7EqioYX706fVMjjX Z6FFN6iDyOAr++w9jjlMi7aP33rgO2VY1XvxD6JvL+q5Cgr1AQmwUqoWuXmuDMKkZPRJ ERFUjAvmGcuOfWy4TgYJcrEoHBoGDx6yztm10fswTYymVfJXMBDluU926YTkZ3o+AZpW ci8A== X-Gm-Message-State: AOAM533HAa+W15YfMSZs1EwJSLJHQh/F7Ztr/LcOAXCbYPte6r7Vjvja Jmb4VtuoeLyOgzWFkG34gIoEQzD0McuYGg== X-Google-Smtp-Source: ABdhPJzGDHkGtuKCGk3W1+rGFvyEcnSu7N7D5mLZu5yjjZB/U+sLPRWpg5N+tvp4zoi65gB1tOHrOA== X-Received: by 2002:adf:eb4d:0:b0:1ed:c1f7:a951 with SMTP id u13-20020adfeb4d000000b001edc1f7a951mr7908323wrn.454.1648199348048; Fri, 25 Mar 2022 02:09:08 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:478c:773f:4734:d0bc]) by smtp.gmail.com with ESMTPSA id c4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 02:09:07 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Mar 2022 09:08:57 +0000 Message-Id: <20220325090903.880311-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325090903.880311-1-naush@raspberrypi.com> References: <20220325090903.880311-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 2/8] 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 Fri Mar 25 09:08:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15544 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 55733C3264 for ; Fri, 25 Mar 2022 09:09:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EDFE361FBC; Fri, 25 Mar 2022 10:09:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648199350; bh=a+cNZ9Tsd22nFCcFkFyh9j5GpX5K4dniFlP0YmtW2EU=; 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=foHBg+OlX1HaSIjEtn96rgOGBKo2gUHdxsnDKQUH/HMShRGkrlGk0JzCUlnmhvo95 QzWCJCwDR2nkyzosNKk9cILRsiw1QFONS6b05lf3TSKO1f5kn8QNPDCfQzzLuUxQSU E5LZzgsQWojIPoN1RzTIPnN8xIwXAzLhcF5CAulngyiR+VFVq54UrIFa54XVZDAlVw g47MYDpl6OMuHbLfrNnZ93cmh6NVj3InfjhU5waZJWIzIdJXKAEvx7beyw2+EIiBSp XqnzKdj5VqKqLJN1DkR4uNVa2sN/OutOmddzRFB/713GBDqu1yluLCfDkcEiwYZdN5 9WAMCqPAxDR4w== Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 73ED8604EA for ; Fri, 25 Mar 2022 10:09:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lZFiYRnB"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id a1so9946089wrh.10 for ; Fri, 25 Mar 2022 02:09:09 -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=4XNcvihWbSxz/8G2fcOly9PICUFjPwd6G8x0Dy4evVA=; b=lZFiYRnBt3MRNOzmo1L9FZ+Tx3JqzC9RB04Y0ApylTUkssD6/64Wq7rQpRWS2gDkyX H//rzbjzCw1p3mvtG/zNrdru7SEQm3amrQevjLDCUQIVqVlUdETDE95PGY5wnc9uI/oE 9vPli3rr7ybHKkUx1MSXdAgQUnHIYU1m60QWaATp0OVx1WHCWQFmZQZcE3etCDxixQpK BzH4ceX03DydTMcdZO9ZPkId/GxTb1gFLsKWgz7gKjhIrd1m7RF47t68EUk83vWIMpCG 9nR1Cw9hNH83gnq46pUjJ6hlyVS18PrMKI+4yJYPWR20m23+nl3i/Zot6D5uB8p53Odo o8vw== 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=4XNcvihWbSxz/8G2fcOly9PICUFjPwd6G8x0Dy4evVA=; b=OaCQOxURmRWlAgJPzshXpNSi4fPsNFurj6c+YTxN5dzSRZd8K+pvT46Y7iu2wbB+2S F40bzr59OGykMMiv+6VInm+/jPqnct0VtmBlBeN/gng0U1szxGUaq0nzIQlJC8SbuWe3 d881Sl9UvvDgnVmhLs8mDpZNQQgK6kskX+STdhD+8akAcQHyznth8fsB/aSywOb8Ba4d 1qNqv6BDMPgPI10cJpyDwuSHLgvNVJ4sz1Gw9bwfVOohGDOrkpH3knfVVVAaZnU4qqTL gF1Gpnn6dJhRYac0blN/UYJKPYwW8jRphKK9673BO4vza6JLBfqzlE+SEpj+d4E+1/CH rtGQ== X-Gm-Message-State: AOAM531e0zhoLKW8BwcazKh5HkQ6J/NitQMxEx7y7YLn4bBiu4pTIdLS IePhca3MWOEs4mrPPh1FTWS8Dg81HLKIzQ== X-Google-Smtp-Source: ABdhPJx7A313eCVaHjqCRBZCLJY4Fthk9xisjhhdJNL+fxqdXNthFS8uzZOF7tpkfoFEVAdTa1hTFg== X-Received: by 2002:a5d:588d:0:b0:204:217a:d9b0 with SMTP id n13-20020a5d588d000000b00204217ad9b0mr8294029wrf.428.1648199348906; Fri, 25 Mar 2022 02:09:08 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:478c:773f:4734:d0bc]) by smtp.gmail.com with ESMTPSA id c4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 02:09:08 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Mar 2022 09:08:58 +0000 Message-Id: <20220325090903.880311-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325090903.880311-1-naush@raspberrypi.com> References: <20220325090903.880311-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 3/8] 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) From patchwork Fri Mar 25 09:08:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15545 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 4E653C0F1B for ; Fri, 25 Mar 2022 09:09:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EE7AD604EA; Fri, 25 Mar 2022 10:09:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648199353; bh=LAyJvKIGT2q0yec59HHtU1koPIGLOBZBSrRmPJWFo0Y=; 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=HuQdvgV7GFOII407ml0X0rFA7273Sj2YVeJLG/n2W+tB4wdIgNjHAeOkyHc1SFHOZ PvAsTmqcsK6Tckrbr46356W1zxZJGFQyJSPxGlnFCWDtGkbhb+qvQoPCZ7b/FdjZfG +rPBy8/47uWucNLGLrU4ti0xkGZ4r4VjjO6GzkFXraBUt1f3NyJmoQczAi7K5YB+4q 9KvPFF3C+BTD9Eyvj4OjUJMRMIRWLSrA//wK6nKYl79sEWKgx4/EVynNJemN1pK3ar Rc+5lg9mh9nXh1jSz3EyJuf6uHJ6sjOH23u2jSsvP+kEnF98zTV49I1rF71krbp+C2 f10rKulzQOtnw== Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 70A7660136 for ; Fri, 25 Mar 2022 10:09:10 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="NOl8nIL7"; dkim-atps=neutral Received: by mail-wm1-x333.google.com with SMTP id r64so4075225wmr.4 for ; Fri, 25 Mar 2022 02:09:10 -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=y+AU3uHdQY363TBVi7RlIPz9CMOUvtyCfstDvCKShdo=; b=NOl8nIL7fd8pgPaD0niAYHEeYWSc2nFhKsdGhOI+jy14v/fKVNwUDrdRMdDvXk0x0g Tqgz+Ogzs4TUYJlzLRTAiFgk00SC/rE2vauCXrAxjA9QeF6M7L88VkMFMnN9892ott0B R1Jy+1A2w25jwAXJ8ZGohAgkup5UMpfjjOyJzZ86hdKfPU0nCFwxqtR3Su3wps5Z1TVN NI3aY0rf+oJXp2PsOPMi/nfBZnw50Cjhp0pJulVyxUmx4Es+qypV7oau2YqSdVWiDV0i gn54qsZ3wjSLyzagCORU8lgZCUlpe1Qm6l5fjq0xOo30Sqtp6q85A1iihPJFMu9cyiAN C0eQ== 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=y+AU3uHdQY363TBVi7RlIPz9CMOUvtyCfstDvCKShdo=; b=qF79z5ISDUyXXB1yrhkKRyVEvhNIh22bqRJlzj9aEnO+HCfpJ4G2Xy+Ly1zkPK7YcH 67xfRPncWYkjrIzFbmVA/9r/tqDrgEYK11gRst0KV873bll81RomvwbtpLm4055ryp5l Jal07dddz2TVXfIGU/Ev5Z0Z/woYC7mRJFG23j7jLqPKcgsF5jWSVdC5H/KhDZAEYjW7 ZX3O4yObAug2tX7FW4MXMXwU1zGNd0V7gj0uWi1+dhMdESGf+sdtlMu/iOnpgaYBNzUC G8hd6kKQ3I0YNAODrb2fiNYDbRN3IqMPVfr2A3mfSjKzrM2hAIU2IVGqtC1YSUjFRDH+ 3OoQ== X-Gm-Message-State: AOAM530nME803Aha6JTfcdC0eEULQL8hvLzZ2PsZhNTtEaxPm5zGqYG4 ILoOWMZIlG0j+gi0QlK+S2dzOLzIknn0ZA== X-Google-Smtp-Source: ABdhPJwQoYPJtTVaL9zTYPGZzjdigSLYXMsY9RhoW3HPV3AcM0R6ZOImel1cNxvT4EOk0pZTf7dp6Q== X-Received: by 2002:a05:600c:20a:b0:38c:95bf:3289 with SMTP id 10-20020a05600c020a00b0038c95bf3289mr18266049wmi.134.1648199349926; Fri, 25 Mar 2022 02:09:09 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:478c:773f:4734:d0bc]) by smtp.gmail.com with ESMTPSA id c4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 02:09:09 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Mar 2022 09:08:59 +0000 Message-Id: <20220325090903.880311-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325090903.880311-1-naush@raspberrypi.com> References: <20220325090903.880311-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 4/8] 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 Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 5 ++++- src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 13 ++++++------- src/libcamera/pipeline/raspberrypi/rpi_stream.h | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 92043962494b..8fd79be67988 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->buffersAllocated_) { /* Allocate buffers for internal pipeline usage. */ ret = prepareBuffers(camera); 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 Fri Mar 25 09:09: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: 15548 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 35145C3264 for ; Fri, 25 Mar 2022 09:09:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E65CD604D5; Fri, 25 Mar 2022 10:09:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648199356; bh=Q3pB5gwKJwI3YcvZWJDX8RjHEP1L+Gzz2Qm7b36XTW0=; 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=kFzx16KZsedb0ZrJUb8cfN6fuqHFZm/TMwlnm95pdFYRVXGtG4y2WcvGxM6IvIBoE +CMHrIb8AKDxrBlGxA47LmUOTxuP0NA+lz8F90H0h+1bsLemBVfkeaKYoraY/7tgf5 ZqALzUoENQ26DlrHJwYW7jAULpSHpTjIEeijn9QH7d9UeqcjR8XaYqFwOtpZp2sggS 0AFu0CO1/SeBZPY1LhYb/eWoO3I04KeTPF8O3PwO0eGPrSLr3p0QhEIGRcWkqhM/Xd qby6toK8ea5z3xyY0wJqoYrY44DFUIM1sk5I2roF8QhRAJSa5Rj3CyVJ8NGa/tPRdv XNvsi312FoazQ== 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 5483B604C4 for ; Fri, 25 Mar 2022 10:09:13 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="AbJ3m93G"; dkim-atps=neutral Received: by mail-wm1-x331.google.com with SMTP id 123-20020a1c1981000000b0038b3616a71aso3978129wmz.4 for ; Fri, 25 Mar 2022 02:09:13 -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=HWiqsZ82lu+4g9I2xyM3lrW/napbwZNOsGa/P4WcuqY=; b=AbJ3m93GA5nk2+YsiFwIjZ/1U568mSHusvwYIfcCfRiCX7vVCdD4hJEuvmGD7M5txU NN94uMqwzmT6Dq364ftTHVb6axOIi7NdM05hDFDSqpkUI6aQ4WU5ciKYv08Lf2c9TlZ3 bUJsWbrlG84DwnOqeEXq7aRrjOaWr4m5RfGtazJEbiGm067VYdda/AiPX5bSLZj1hItk EOJ/tSt7jCEkJrU+5O5DcRgP97bYRDeDGIsm0cYEMvA+iu43VnQ/aQNHf6EfS7mjSnJ5 kFSnRNpNrOtSzzwFIsisN8fCLGdy1GTF6vOxvNzthXLa1QEXzoS2eDiMqlb83xaxUZBg Ukhg== 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=HWiqsZ82lu+4g9I2xyM3lrW/napbwZNOsGa/P4WcuqY=; b=Z1f9kB0ujk/4mW8PgCijuDdWe4y6mQ3Kt9uFCuI0XUdR1t08JXPI3no4WuMEaUBWh7 SKbWsdgkhxERc8AvLtPJgyhDPeNLL+z8DFXtx9Y0y/m0XCM4sA84Xievq7fqf6Ashtwm tuMLtzCjPtVWveen64t4ykF1Shpz+PC20azNHpbG96LdlZTij8sWKHfd1IqPEb7wz+5U Fy/3Gct/dPa7L5HEh/14rmIOccH/z6QDrrnyrEul2+lzdqXs/TYBHsqGneV9GM1F7G6X u9lc1jKsoDQVsOp6Omg2wuQBIrv6MoEOI9SY5rdrYU9dcdy95scQMj/sYH5AKjX1gUm8 g3fw== X-Gm-Message-State: AOAM533RxWc+MjWYqy7HRe7QBX5oJ84wTgV2AwI2E71HtwRMaQORztXp 3mjud4I5WrwYJBoRoHAZoL8mqVw6G0KFEQ== X-Google-Smtp-Source: ABdhPJwuqOZX3XP0sqWj806E6cukTxPXpZqiP2OSaRphETaABQu1kkSiIxJNfr1xDeX38hBiuJjkGA== X-Received: by 2002:a05:600c:3512:b0:38c:be56:fc9c with SMTP id h18-20020a05600c351200b0038cbe56fc9cmr15376466wmq.197.1648199351119; Fri, 25 Mar 2022 02:09:11 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:478c:773f:4734:d0bc]) by smtp.gmail.com with ESMTPSA id c4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 02:09:10 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Mar 2022 09:09:00 +0000 Message-Id: <20220325090903.880311-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325090903.880311-1-naush@raspberrypi.com> References: <20220325090903.880311-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 5/8] libcamera: v4l2_videodevice: Better tracking of the device state 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" Replace the existing streaming_ state variable with an enum to track the following three state: Streaming, Stopping, and Stopped. The alternate states will be used in a subsequent commit. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_videodevice.h | 3 ++- src/libcamera/v4l2_videodevice.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 2d2ccc477c91..32e022543385 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -258,7 +258,8 @@ private: EventNotifier *fdBufferNotifier_; - bool streaming_; + enum class State { Streaming, Stopping, Stopped }; + State state_; }; class V4L2M2MDevice diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 5f36ee20710d..9cea6a608660 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -507,7 +507,7 @@ const std::string V4L2DeviceFormat::toString() const */ V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode) : V4L2Device(deviceNode), formatInfo_(nullptr), cache_(nullptr), - fdBufferNotifier_(nullptr), streaming_(false) + fdBufferNotifier_(nullptr), state_(State::Stopped) { /* * We default to an MMAP based CAPTURE video device, however this will @@ -1796,7 +1796,7 @@ int V4L2VideoDevice::streamOn() return ret; } - streaming_ = true; + state_ = State::Streaming; return 0; } @@ -1818,7 +1818,7 @@ int V4L2VideoDevice::streamOff() { int ret; - if (!streaming_ && queuedBuffers_.empty()) + if (state_ != State::Streaming && queuedBuffers_.empty()) return 0; ret = ioctl(VIDIOC_STREAMOFF, &bufferType_); @@ -1828,6 +1828,8 @@ int V4L2VideoDevice::streamOff() return ret; } + state_ = State::Stopping; + /* Send back all queued buffers. */ for (auto it : queuedBuffers_) { FrameBuffer *buffer = it.second; @@ -1838,7 +1840,7 @@ int V4L2VideoDevice::streamOff() queuedBuffers_.clear(); fdBufferNotifier_->setEnabled(false); - streaming_ = false; + state_ = State::Stopped; return 0; } From patchwork Fri Mar 25 09:09:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15546 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 2829FC0F1B for ; Fri, 25 Mar 2022 09:09:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D2867632E8; Fri, 25 Mar 2022 10:09:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648199354; bh=s5y2qLBZYfMPw4FyQu8zhn3G4H/9ocLISzpueUvx/F0=; 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=fVCNLMqXzmfe3/+8kZcoH3fSNZhjVDRqU9GJgJI9Gzh81XO6C6MRzfVNhy2fGpU+k hqxDIwKw4eBa6zrvWjaJ/Yk2ejtEngGTGEzU63IQldt53aSUyEu/c/LXEzGDNWJdTC FTxu+iT78mjnBUmAJxOvHjTKsJocAs+ibz6eOTbk0h0OQqObwbN1NWOv2CcZXdKVA9 AV7QectAApUJKoyCJWI4KE27Rr2huJdD9dBUsN0Go0bnG+QSjmMPnSlY14qD9B5hnj pZp32zmCBMTGPUOUDhngYcm29nQTUutMvHPuH3E0JNnYfu290/ghQ+EhxmYaOQq0Gm Y4OQcC7L2MHwQ== Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 50B65604C4 for ; Fri, 25 Mar 2022 10:09:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="nnaRRZMl"; dkim-atps=neutral Received: by mail-wr1-x429.google.com with SMTP id h4so9925444wrc.13 for ; Fri, 25 Mar 2022 02:09:12 -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=1H2qLEHnAgihB+y26jW/31zTk3ZzfqSkaZ7pYckt22c=; b=nnaRRZMlOUoWbvD6tqISlRJwOFV9/4pVgR7EuAIblUmXhFzHMcp++YEzlcbf1ZH2FO hzgYYduKPnfu7xNXlMQkMwDEbF2spy+2g6T5yYt20dxnv44YliewxMWiKY3LBItQryk6 /usg4ha/ZkXGC/OJwTzeOQ5nUcbQ29sXDAwiO161vjZl8+POXv/uThMTEw8OLLlOUiTn 3WJCWKQrC5txWIxDoTyiVzM9mhec0dCzj3VNa9nNFQ/5mPagX7wP5fEBg+FafN5KTn7n vFlaK5eg7IBpzVLXyW4eEBZn1Kn0wrTEbTLOZRK0lkUBQ8FlE2O5478EWWNrS9lwkQz5 TC7Q== 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=1H2qLEHnAgihB+y26jW/31zTk3ZzfqSkaZ7pYckt22c=; b=pJDs4sjQGZ+feWmddjJdKJgOKlS1QfCMiyT/s7n+bM6JrY5ySNG6I1wRWEjJtxbPkg MNue/vLuncZPjbxKPoasPTyAkMBeFq4WKwaYk5P7Li1H9YsfQH5oJL4gGomy3wJDSdYX 67L+ZE6pKmJTmSQ1k/x+oFBjLkwISH/Es6W9mI5kxnrP+TiAdgGuvK2Quwi31xgbca5w ZmgqyjDOXZgDwmoprG1Qc1KtohrKEihjuWk0emq1rGHLmkzNjee2qmuObP15kPRJLfzI 9x+AoPFYicpIXjZ9cH1X+2uHtUtwBlczodDR2P9jwU6YWx7FtHychlMFH586DF5aWD62 DyIQ== X-Gm-Message-State: AOAM530AX/hq6Uybnlnm04q76G0T+5qiqIJKbOitHzfOu2So/TmhGC11 VEvywpkP/zBhTpcRJalo7sxUjnESFlLNtw== X-Google-Smtp-Source: ABdhPJyV+dFiZ5TlrUZTRQHUzM5HchpQmf1HehlwKF3p5WL4dwjOm0plp70/tTGz138vPbJou6D2RQ== X-Received: by 2002:adf:e108:0:b0:1ef:97ad:5372 with SMTP id t8-20020adfe108000000b001ef97ad5372mr8037972wrz.658.1648199351812; Fri, 25 Mar 2022 02:09:11 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:478c:773f:4734:d0bc]) by smtp.gmail.com with ESMTPSA id c4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 02:09:11 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Mar 2022 09:09:01 +0000 Message-Id: <20220325090903.880311-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325090903.880311-1-naush@raspberrypi.com> References: <20220325090903.880311-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 6/8] libcamera: v4l2_videodevice: Do not allow buffer queueing in stopping state 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" If the device is in the process of being stopped (i.e. Stopping state), any call to queueBuffer() must fail. This is to ensure the integrity of the buffer queue, as it gets cleared at the end of streamOff. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/v4l2_videodevice.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 9cea6a608660..28f336086b49 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1491,6 +1491,9 @@ int V4L2VideoDevice::releaseBuffers() * The best available V4L2 buffer is picked for \a buffer using the V4L2 buffer * cache. * + * Note that queueBuffer() will fail if the device is in the process of being + * stopped from a streaming state through streamOff(). + * * \return 0 on success or a negative error code otherwise */ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) @@ -1499,6 +1502,11 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) struct v4l2_buffer buf = {}; int ret; + if (state_ == State::Stopping) { + LOG(V4L2, Error) << "Device is in a stopping state."; + return -ESHUTDOWN; + } + /* * Pipeline handlers should not requeue buffers after releasing the * buffers on the device. Any occurence of this error should be fixed From patchwork Fri Mar 25 09:09:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15547 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 A51E0C0F1B for ; Fri, 25 Mar 2022 09:09:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5EE966118A; Fri, 25 Mar 2022 10:09:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648199356; bh=0jgW9DVYMaUjCXrDmW7oJlH5cBKoQpmyQ82oO3SyVdM=; 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=lfVE4r6Dn+ABYjZP5xGu+mEL4Mz/OCskAzKUhkz8nls39xQMPGrZQVLASbSti3OSR Bh+Jpp3CY3QewLXyfXMrnAnIqHVAoi6gFC3wW144/UlL+1RDWWh52kBJussGOIKFTY tAmR0gnFzW0DhxydhNuU9ZLEeX+97SgeTlB7uzimIf3QFwBLp8NHGn1Ij/13e8739/ lWZVf5R0bndqOzcjUNC30dKVL8jw/3z6ZYIJtjsJDxRaLTMmvZ+d/GEpHgZ0DxoC0m KV+3f4eHzqQ76Wg60JLDS5TkQARBw4BMISO/FRdFl5bNbUxfFwE+65Rgb1ZN0sqdF8 ee8UOixTEgYew== 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 2BD8A632E6 for ; Fri, 25 Mar 2022 10:09:13 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="luAWWEpO"; dkim-atps=neutral Received: by mail-wm1-x331.google.com with SMTP id p12-20020a05600c430c00b0038cbdf52227so3995205wme.2 for ; Fri, 25 Mar 2022 02:09:13 -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=aPAyUYGMojuKxVmvgFges/HhTEcWeAcOkI7bHjlME1E=; b=luAWWEpOtziDYteD77lcDqGEbA/D1xeiRECyeHe0io3csSFLJ1NaxRo5fZkoFs3JmK Er5BKqbvEvaXYBJgRnwa3CjPrRwtKjk0ZJW93ldE3mFwS2HH4khHxBIXwjJw+/ZwTnJU yn/d6Mxiu5Av+kWSXKZ4mkAKlm46AZbOifas6vEt7pLhx8VMu/Ic8PEHOT6S19cnRYW2 GtUZ5GAoY16npJJCWFBSrfPcuXM+TeHB42U/Zo/pCbA6waq3u3ZpjYImZfezZ7V5rLxY Ww2CFplfS1Q7i/OVQR2Pv/aJc3hj0qxeNlc76m5YXYzLCWD4jHj8njA2fIf3KQTzU54c ID9g== 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=aPAyUYGMojuKxVmvgFges/HhTEcWeAcOkI7bHjlME1E=; b=U0GIPA0BVO+yrOXv7vY/1QyL3sknEzTPMtrO3jjBF5k4ZxEX/E0Wz3FNTdzvJDS27J 0ygT3LYbXiyErGMGGPf1zWTsqiVm+20O2H8XI6BXUytV7dFbea0U3ISLCYx1hzfUP6UP yw1daYb2sHDr9zucpu9VH5Y5+sXgNtmTO2fFxSTAi4+6Q6vbMhO9uhSLgFJfGwbpZ2No kskdUWauw17iFqxIS5/X3ZsOyVxmgFByxV1XLCKn6lKZ9eXJs9wnaoE7LRPK6bJOvKVe 0yPlAoIvZbhjdx9SyvCmPbEyuQzDjSLuwgIYhdCwodRUQRaM7GGNThKVh9hHdWogxGCr 5m7Q== X-Gm-Message-State: AOAM533/43BrDxIhcQ6bHNGTiKGaxBLkRXYJebOsq5sMAzOPyCUxkEid BJp2JaGxwFHZI1xZ9o7SZSEW7TYsyWo4/A== X-Google-Smtp-Source: ABdhPJwEG1/UZtH6J93vnIuLOK+MUF8S2LGQkNJa35gg9T4+oC7u54TfzN0YCcEg6Tg6L8TnT21WuQ== X-Received: by 2002:a05:600c:3c9d:b0:37f:a5c3:fccf with SMTP id bg29-20020a05600c3c9d00b0037fa5c3fccfmr8778554wmb.13.1648199352648; Fri, 25 Mar 2022 02:09:12 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:478c:773f:4734:d0bc]) by smtp.gmail.com with ESMTPSA id c4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 02:09:12 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Mar 2022 09:09:02 +0000 Message-Id: <20220325090903.880311-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325090903.880311-1-naush@raspberrypi.com> References: <20220325090903.880311-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 7/8] 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 entries 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 Reviewed-by: Laurent Pinchart --- 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 32e022543385..60d62212bfe1 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -124,6 +124,7 @@ public: V4L2BufferCache(const std::vector> &buffers); ~V4L2BufferCache(); + bool isEmpty() const; int get(const FrameBuffer &buffer); void put(unsigned int index); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 28f336086b49..1621a013e29d 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -201,6 +201,19 @@ V4L2BufferCache::~V4L2BufferCache() LOG(V4L2, Debug) << "Cache misses: " << missCounter_; } +/** + * \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; +} + /** * \brief Find the best V4L2 buffer for a FrameBuffer * \param[in] buffer The FrameBuffer @@ -1842,10 +1855,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); state_ = State::Stopped; From patchwork Fri Mar 25 09:09:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15549 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 C8ACBC0F1B for ; Fri, 25 Mar 2022 09:09:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8490C604E9; Fri, 25 Mar 2022 10:09:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648199357; bh=hLTmYuojHMjmtUh8gzJl2+HUWdtodTUsIN7+OUJacFM=; 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=dRrg0afGS0zbHW53ZDWFltI7E5l68zl2i86eHYSX9+8vLWLycVO5W3NwfFvQmDpVM IA1kFjspLk9MqZUE2kbQeNa1jF4D1P1tj8gG1xyDcn1sBrpADKL5ffbIkhjpK6IdXB a++QojN8ILk2Lx2SpHwx4KCDwEFEeFqHhhfb0jITzsMvseuvVOAbt0X+9FUk7o1zy5 JHxlCRqNx/EwP6qs9/uFpc9mYdaCdfO+6klF/oWZj9Mm0LND4qTkH0x5DtuD72f95w T7pJmGwLI1L1IDmWwIh83bAQEdXDCtoozKUMVPQ7lCSIG3hdGmL8A1KwkZ4r7o9xmH DU8WT4O0wZ+ww== 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 28D3E604E6 for ; Fri, 25 Mar 2022 10:09:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="CF3bepqC"; dkim-atps=neutral Received: by mail-wr1-x42a.google.com with SMTP id w4so9927216wrg.12 for ; Fri, 25 Mar 2022 02:09:14 -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=QSeLD6l2fNDLnVAXmscZh+AApyC398AN3impDShO8DQ=; b=CF3bepqCgGaH6okHE4GGcGrwEz2kWjKKWt3M/VJ8/7M/UHbH5rT90nlR1W3ffI+uof e+2daqUkmlqkb6L3wC8L/x6Q8WfWhrc2eaKXH5ybsKWPCMmmdl0mhGzJjz98KsPDQDrw EgrHzUPRtulSWAAYp7zSnfKFzRV4Uk0yy8Zk7Y3VEn43FGkFTpHNSuL1Kib6RZFt2sjJ 19Tm1WLl46Ix1KK8ppAvgpzC+LvZ6FowUGmOJvYqUUyR84ttb69GsBN/ey9IMkxXjxMD PaUuwPExNLZ1vBCDk2Su8pUfC8q8dLVLy9nJwqcVKY/CLH08p2QAsRN7wSGGLal5AmQu eSHw== 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=QSeLD6l2fNDLnVAXmscZh+AApyC398AN3impDShO8DQ=; b=TxQk3vb3Y7Y2tunSF+gpkYN1Gq2tTmyfBRQ1txdyLDzU+A99XYmATJEjliMk0zQ4HQ tDGWRG3IcRbKlSpc0Qbn3sx+ghDRI50s0DK8DCCZHTNEFLrSQ4TXXIpUhFQxKnJEv0Il Rk03DFHic6kQp7sAY3YTsGTFn4hX2SHl0nTQPN0ndBoWiMh1H0GyLnMKl7+LTOyAi32U o41vt07eorArgvuvMuJDVWfRPtHe8vuldFCpcXyDCAt7aeRycwjX7rsdvXTEmZ7mSJTk 46x8T5Oh6VIGO2SjCyPJcNGgjV3eNgsGQ3DNZl0SOnQsDIbJ58MJ37wuKcjCCgESk3dP Rdlg== X-Gm-Message-State: AOAM532FnIpNcny4GE3IJ6WdSfzH1VFVp3C8R7dq6j8meOv7quKa042k C8FaoJ1J+gK0GhGrQwHEx43gU8Yncu/ETw== X-Google-Smtp-Source: ABdhPJzKOXn/jCfLdbJNJOPcGT+16MTXA8KFe6DdU9UpEYe6ksSUvTS5w5qBUupCkyYLI0hfe23xqw== X-Received: by 2002:a5d:5406:0:b0:205:a2c2:3530 with SMTP id g6-20020a5d5406000000b00205a2c23530mr2587361wrv.587.1648199353696; Fri, 25 Mar 2022 02:09:13 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:478c:773f:4734:d0bc]) by smtp.gmail.com with ESMTPSA id c4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 02:09:12 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Mar 2022 09:09:03 +0000 Message-Id: <20220325090903.880311-9-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325090903.880311-1-naush@raspberrypi.com> References: <20220325090903.880311-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 8/8] test: Test V4L2BufferCache::isEmpty() member function 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" Add a test for V4L2BufferCache::isEmpty() for various levels for cache fullness. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- test/v4l2_videodevice/buffer_cache.cpp | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/v4l2_videodevice/buffer_cache.cpp b/test/v4l2_videodevice/buffer_cache.cpp index b3f2bec11783..5a9aa2199c50 100644 --- a/test/v4l2_videodevice/buffer_cache.cpp +++ b/test/v4l2_videodevice/buffer_cache.cpp @@ -126,6 +126,35 @@ public: return TestPass; } + int testIsEmpty(const std::vector> &buffers) + { + V4L2BufferCache cache(buffers.size()); + + if (!cache.isEmpty()) + return TestFail; + + for (auto const &buffer : buffers) { + FrameBuffer &b = *buffer.get(); + cache.get(b); + } + + if (cache.isEmpty()) + return TestFail; + + unsigned int i; + for (i = 0; i < buffers.size() - 1; i++) + cache.put(i); + + if (cache.isEmpty()) + return TestFail; + + cache.put(i); + if (!cache.isEmpty()) + return TestFail; + + return TestPass; + } + int init() override { std::random_device rd; @@ -204,6 +233,13 @@ public: if (testHot(&cacheHalf, buffers, numBuffers / 2) != TestPass) return TestFail; + /* + * Test that the isEmpty function reports the correct result at + * various levels of cache fullness. + */ + if (testIsEmpty(buffers) != TestPass) + return TestFail; + return TestPass; }