From patchwork Tue Mar 22 09:22:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15498 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 E92F1BD80A for ; Tue, 22 Mar 2022 09:23:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 31B35610F8; Tue, 22 Mar 2022 10:23:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940983; 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=DTtBh0YwNX/6VLHB1MwbSXs2bWjcS/c1l0ThxbxqNt+PLIkcHf+AKl0Y2c9eScAXH mZJ8LU7FUfjrK+i/QF+wxUZyT4vsXGAiNKQFZPnosaIRVRi1ikyZdTOMSV9hrE7Y2R xCTdAf2Sqq2BiOUy/fdahCisgVau5gklUL07wEM1KRSJ22Dh4sWvo2PPCopvHgK8F/ ew4aB93sT4E7JnoY4o0Yoy/F7Nk2d3iVZXk2bxrE0pKey/ifsoIYZDlPg4oPuvZ6zf Nrqmje68U+V6DNh7h7FCxocqVQh6ncOnentP7mbPMcN3qPZsX3xT+GJXPA3KAdFR6z nB+pOmSQQhrYg== Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E71C5604C7 for ; Tue, 22 Mar 2022 10:23:01 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="UoVdijD9"; dkim-atps=neutral Received: by mail-wm1-x329.google.com with SMTP id j13-20020a05600c1c0d00b0038c8f94aac2so1016104wms.3 for ; Tue, 22 Mar 2022 02:23:01 -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=UoVdijD9k5czPIoKj/3QiCmKvQe52efw9ZGcCgunseFVsCDSh2LQprq2q1lp1LM4ih Y8Stur8IfgONf4+RUiGSGeXkIIKq+fL6kaa06idGk8R5B2PO06so/3B0LpmAjtjAHsHG 1N4xIt60VdD2G7RX9wJsHSKle/vdDjMyJeAbuPVsTzjRKePnCy0+z8NyT2xuib0I2ZS7 CqByNxPt2AM3+xsx+XbnWEwFJcF2H+N8gbLfz77/4TAOv+Fe2adaAQ0cSbn5CnqNuDir FaJCzFWepxw7+nJ/i2mMszCVD36OBeR4xINyDgDs40C3dDYncKcQ1hyZl8hU/AEW78B6 pOYQ== 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=menPD9fCee8XKEYcZEZqnhs0wVsEmqpJiDQbLEfa0dMkeBBNTra0LpVWVYTvIfWXhI Dd6BXInmm75MmcmrFPxvm3qTifrWpUfdEnHZmThdy/31wcLlcy9qWfLSK8CBatZ5/VCQ 7eBSEOqQX2ixjUKkImgxhOHM3vurU9lru5o8utvmBzGWEgDQ8/ieJM5JdPJo5N4lblFP vXRnYeMQL36+OAX78sUl7Kc3JddSzZ6ZkPvSaDVZPNB1jtgEwi4XGB7Hb9lhU/vwNBdt yedDOllJwws+0lZaVgv7rooJw0cYyQrTEhW8x0p80ADmxh8oszGnTw7iNtSEDF3KmLrD zoVA== X-Gm-Message-State: AOAM533enRoo3VmPzloptKogNmXzZR+OFYQ7RGOxphiOn76l5EL7Kxmh EB6kaEuxa9ty9lDdF+HZ3B+iSeXMeiAGdg== X-Google-Smtp-Source: ABdhPJwG7XQLDbZiTQq9Ioawk6fZI2nGATWWfG75sX1OoIqPPErz4xg5fFWVy+6HtbDKPfSjqvPNrQ== X-Received: by 2002:a5d:59a1:0:b0:204:1777:fc08 with SMTP id p1-20020a5d59a1000000b002041777fc08mr5875151wrr.545.1647940981434; Tue, 22 Mar 2022 02:23:01 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:01 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:50 +0000 Message-Id: <20220322092257.2713521-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 Tue Mar 22 09:22:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15499 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 D8966BD80A for ; Tue, 22 Mar 2022 09:23:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 73007632E6; Tue, 22 Mar 2022 10:23:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940986; 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=hs1TuPaqrL9VWGUDOeWI0LXuz85iWubLoap36AKh+u1FDB3Z4mvlQ29/4YC/D9I4N gvzfvbPdn8A7BJG8yhHcmaF9tFXDPHGC4yi7otItp0UMlu6ntXKJf6HJBi5PRrbTOa GZTWyHlNg0b/keREv9tf2v3Jm8iALU9a8nF5Zqi1AlNVz2nYUvHnANNaoVTCaH3N8W eGk6H7gd3RhGEphdthyjV19mukYtNUwj4hHcm7HjRczoc0Ws2OF8+WwvQ3e7JzuFnR WwcE5QhhYGUWErWd3nHavzzFDxQ3kGDHx2xVaSfuDxUBUa7nJp/4+5kr7KaJrd1oPR kC9WT99txUdMQ== Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EF2860397 for ; Tue, 22 Mar 2022 10:23:02 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="FC+4xYZ1"; dkim-atps=neutral Received: by mail-wm1-x329.google.com with SMTP id n35so8366753wms.5 for ; Tue, 22 Mar 2022 02:23:02 -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=FC+4xYZ1gFaQy5dA2sAPcut9nfjGJrGtXSfbOuTtyF62zgBEcErQYBeS//EJa99v00 iGZEEfFOGEFj5m3XN9IeODY1hKxaAOeO3cI5GEblmRJCnjDqw3RVap+zhrHfhM/ZIbG3 Jmj3U2o8BC6J7eTDt1dG273rG5SnrWEDgkdzHLkz/5jUEupomrvxBf7VVgXgVz/kZhCL 2DtqSp+2k4LxKIsxhD+KYkQk8JCcKJgs0nYWgY0UEAZOm6d8Br2IFLH0vgdp34T93twS JfQUmJJ+bzyvIi/gzPRkMd7OHdL92Z8Z/YQLC47Mqh9x88EcxmTBGnvlU6uUq5R0q4zV TIBA== 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=mE87f2yMSuU2FdxRyohSq8fqJF+BwTfiAY/0Kp6S8dfd/9xjT/iP8ZBRSEhKZshnOJ 8HRHSIdAamG/bBT5tYvMblg17suJBNxu7UhwX7qmPAYPIPf1VGE3dklI7ANgl2zW8F4R tJwRx5xw0moqcIe0ghVXysqYgvF5kptQqw4w3SqvXNCpN+YEbh1xL8HtW3y7aWV7Pjhp 3Duv5iNgB7sAv4U4FaKux6mQLpNq8bQYycadlLjf9iaaYtwA602/RKoRL7KvQK0DfV9I nJtVv/7S/NK/xABBYSBIEatI1zgbaHmzdKkvVEclBS1dvxyV8VADJSOeOg/TO5XQct6o ZAdA== X-Gm-Message-State: AOAM533Rk2cvFC4vN4+3hPuKSv5OEkEXl+cHvbQlhZ97fdTQHOuffHzN 3DxmPPVATFgMc4vTzFCfVxVbGqOLYqjYVQ== X-Google-Smtp-Source: ABdhPJyxnwreB2bPFI9hg+c8LlF4KieOJC1MOWNqVkVMfXyY5oFG2aWt3SA1CmoCOCVwPMqdrhjjZQ== X-Received: by 2002:a1c:6a01:0:b0:37f:1b18:6b17 with SMTP id f1-20020a1c6a01000000b0037f1b186b17mr2742007wmc.146.1647940982101; Tue, 22 Mar 2022 02:23:02 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:01 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:51 +0000 Message-Id: <20220322092257.2713521-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 Tue Mar 22 09:22:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15500 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 B770DC3264 for ; Tue, 22 Mar 2022 09:23:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0292D632E2; Tue, 22 Mar 2022 10:23:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940987; 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=Kebno7PGZXQzOq2i+LlcI2n67otkMZDiWDdUx5jiD6Ndd2pyYw83SL4V9QyH8H9I2 W57siq5RMpXnc0fXYuBiZQv7o+yCJFpdn1VobmlPdbG0bT+WJ2j9rPvRIwS8r1wN8R SvujXDfqtC5cKEP32sIUQ8lqgiGdA62pDNo7PHwYMWTpgx0qCUCzcAWOgng8gFktWq WZYIoFwQYNqqv2ZMfHcPJ+F8R6YFoKXjRp5HatHzSCiHmagl2wEr/OWNg9bRUCv4W1 ckBbW9bmSdlXI6fLQi/XX6LcbEcfUOaNw5aWPgGXbqTX+9ilz3lo7gbbHcDHWb0RgX FsAMetuTOK5YA== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6CA77604C7 for ; Tue, 22 Mar 2022 10:23:03 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DWwulMRn"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id v2-20020a7bcb42000000b0037b9d960079so1057390wmj.0 for ; Tue, 22 Mar 2022 02:23:03 -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=DWwulMRnfOB2inueInUAqOlxTanlA2gEHXmI1LAwkKxJMdRkIFoked7ayhPrsh7Psw Ty0N4Byha0juF3lUYVE1n9+7OMC+6aKJNIrRmvZ+xRX2yaI6oZpoXHCpPnAC0RTpReKP DP6EN2FHm5oiqrJfGb47LB4+s1dM5nf2vh6xjEMRopm7JtI8BBgDX4V4GofYzw+lcPb9 4w5HSpWptkAqlMZvZjoaMVezfQx9VGWuMTyvUfP5xA3LvjbtVEgAP/hYUD25m9D2fQzY rjLs40mgahEj6XN5Qr8NC4KlQDtWPJ5BC20XxIL4Y8NNH3fZ4sUrDIdSBadvj0k/nxSk VFlA== 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=TD/6zsf+p8w8ltE0q10ejkYyBLsYmc1fRoVI4TTgtZWBcf/qSurjTnn11K+kTi93oO uZwMvXEx/gN0/jpgfIz2UI5LUImLLbZUiSw0vNvjWwXe+u1aRBkt2Q8EuAq29rCeetlB vhxLYbqMvtN8VYp4hvqXurrOHXW8x6SzjZXD1uiB9r4oTUKsJgWPT33oStU8cEIsUNo3 EK0pkyWjIm1SQPlFHeixBB7iIrIEh0Bw39P+riY5OQJEd34dbYhHQ3hUkibpa+hVewcS AkRA95U/FguVSu+SKQZ/cC4k9foTSOKXozp2l/6Qpz7X6ugsVdl2xq1y7X4veL4KtyVv WK4A== X-Gm-Message-State: AOAM532EbYy17utlmxKGDRehr6sQEA2fb1xYqAVG5E9n7/QOx2PLbTW9 sZD3Y+9sTRtECzpE8mc/8Gj2OQS+nIVpNg== X-Google-Smtp-Source: ABdhPJwCgQJlsvc9dpR2TjhD5HEkLuA681bz2GrKIfaJ+X9T2bB4I2RbQYdWDS84N9m0wkxrMD8OTg== X-Received: by 2002:a7b:c319:0:b0:38c:8655:4019 with SMTP id k25-20020a7bc319000000b0038c86554019mr2906672wmj.60.1647940982789; Tue, 22 Mar 2022 02:23:02 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:52 +0000 Message-Id: <20220322092257.2713521-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 Tue Mar 22 09:22:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15501 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 39DC1BD80A for ; Tue, 22 Mar 2022 09:23:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 93E01610F8; Tue, 22 Mar 2022 10:23:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940987; 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=qmZAH7cu1K29ToSzzGqTRa3Tbmf23kM6QdqKl9vlT3TDWhx8TXsvWmxLVQx66t8F7 EMnvVIr0m89oKxZgW5hRmRxIQEO1ufun92t4TQuDZftFX3jhKa4S+hScPTPAVJVu8d NIIcJ4LzDnCOjAIU4MA05DfzBGDPD/Q9Cipt1mmGjbrwJ1TzhkHo/JTpKv0Q27UT/3 SCn5DA/N7nTxGprqWP4a0siOCODU22sM7Odqv3GOqCHHalHiswzSwpF1zWKnWCK8Rl kIw9xSmzNEHLn0PrVDBt8DOK5b+xe3Ldgp1Wn7lSPhzsWrVfh2G2YR5rcnqyMM4hBq bUHZrnZdnh3rg== Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 02085604E9 for ; Tue, 22 Mar 2022 10:23:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SH+6Sp3O"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id j13-20020a05600c1c0d00b0038c8f94aac2so1016316wms.3 for ; Tue, 22 Mar 2022 02:23:03 -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=SH+6Sp3OZ+BxwKDy2RkHKHNyPCrUBuX2qcl/TZghRS5irAogZIok7KtlPA6Zwras5z 3TSZ4eiBLZUx0VBclt6K8GaqFDlFSwlhYtxyA9cf910h4Wv9DOwTsY9CxT4Eu97kvoAH VlRlSAA4HOOZhdQYneUOfzrQw9TaVf3SyLWv6oThfsrYTBW7tVzPIQszB8MP5JKeKq+D rxyAUyY/Kt4kLiuoIilW9PbfNHykS5ruNfHkj8Kxe3Nd90/7umCMOwnwcvRQS/zfJBSH fvOoqhi/vz/2DPku7/WFGtZDXAXzOR0mk/Eu6Zm6vLGluQL0sOzNQXh7MFoYpppb6I1J B0ew== 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=vkCqPe2hQbMy1L5lD6Z02XMmH6BwThDq8FqfGUZnfJ3PgDcZ1BsSzvqqc9Uh3Ipz+E wJuYi78gF1MElVIeNey4zwti9Ywbsb/rR9w3Vag9ICKxpWD4F7siZGdRbnWRHMiRmOuE DgJFEGlWYWYuz9y2XhsKQpjhfncewZJo9ZYumL0wn5vVFjcrqrvMIhPbfxh7aSR/MM0x MXQTysjFtpv41WA/Dl3Y7aNaENaAqhbD0wEslPC3wO3yO0K7BP17IqTGQLQIdaFxcwU1 kIQ32DC/TvSUfAUgGmpJOnqgB+R9i8uPfu5beikcuLQSozLzbyuS8mDcxoraOQhIy5Wu AGUg== X-Gm-Message-State: AOAM531dePAmYyPSowKKoDneW4fArfiODhCCe4ehilkQA2qrfaQQJ/f8 A2KG3U8yAGFSDiqqkVfZxPdFPvjLsI8bUQ== X-Google-Smtp-Source: ABdhPJwXtFDPMmjLgtK0rd3ynoC42dsmVZu5vaM3URRafdnQg3WjgiWysuXe9/l6U6IGpkzxRxHjQg== X-Received: by 2002:a1c:f415:0:b0:37f:ab4d:1df2 with SMTP id z21-20020a1cf415000000b0037fab4d1df2mr2746893wma.75.1647940983474; Tue, 22 Mar 2022 02:23:03 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:53 +0000 Message-Id: <20220322092257.2713521-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 Tue Mar 22 09:22:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15502 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 183CAC3265 for ; Tue, 22 Mar 2022 09:23:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8BFB5632E8; Tue, 22 Mar 2022 10:23:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940988; 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=I6Z759dPxn0L64vbO7ZU++9WmX/4j/z/5QdQcUh7rSUzJ3/+ER013uZi9gFod+hXs 75enmAD99hIsTdFarKtNF+buxEtYTHstHAqoEebIdjugykb92X5bF5W8sa6GAcVT8O mk3/z8SLwB4pKqB2fO0CNa6kiIWkKhONKV8KsuBpYK0a27lM0uxTm5s3Q6Azzx2UoY ayiQmBAo3ALLhlI+CA3JchpJlBLCQujmy1Z0WIUZXNK8ah+yyfknYWcquXeW87Vjxe ZfFPj1fw2M0x402wskW3M/ei7h34V0iEx418fQr0Dsudgdlp4XDeg2IFT0qfN3KiKC Qz+nJgtvmK+LQ== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 179CF60397 for ; Tue, 22 Mar 2022 10:23:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="hCv/Y/cb"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id 123-20020a1c1981000000b0038b3616a71aso922684wmz.4 for ; Tue, 22 Mar 2022 02:23:05 -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=hCv/Y/cbVnBqkVk4fyaNFcvOfSIVI+4guz4LNUmxE/hObeOryN+NuAucpKqZzpoBSa a8GnNt2f8fXL5GMuGl6+UuEaaaOHUXHtN+m7nmEJNBlzmbruE1+uHH/YAWR0TOloDEzK ZPbe9N1AWIllSQE5hta0sLZi4Fvx5OWl4rFECkSY6x7HXsobX9Le+NCYGbipaMWl65P3 E5dlWCmg+DE4WfPf1cmVz+GjByrD3eQEo74t49e0kMPUG1IfGZB0GgB6iU9X+nVPavMY 9FVorm5xf3qDIC2K9u5SB2WEgq1macQiA/jXBms3wIl3YJ5j9GUyyQlz7NoaMZ1Lreea cb2w== 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=X7XXkyBrWTklEp57/wSskD5yajuPwvGmovMQ5ONB5rfawllu/5nw8dquzjnQuks589 K4T7dlFGUVsiz18KsvwmVYCVGDTnNh5hq8R5V/4kx6qsFRL+mxIT59E4a7uoJ1q++Rtb BeIKRoh6o9azTJzsK75uKzu7a0qn+Q1InIcpQeq3B7s71/O2BfDm1dhr3vxmMX8auuED OPXMYnwbJkgeEi+bXbd1fEyM9k5mO2NQMUVbS4LuJEBGnh0JSvBl3VCJDRr5yR/gxyO5 mt5ohGadQr+cP5TL+XWJSW1avTjhX1ji2uAqqhw7ghTADTac98oow2UDvTlQNH14cVWU MwmQ== X-Gm-Message-State: AOAM530PETB6R7JogS9G+Gx/LX/1xfu19rylVIVAXub4T3+QarArV838 BHxfFwgiO/EBhAL2cczLP9qu9OMzY5234A== X-Google-Smtp-Source: ABdhPJym4Qvu7hMr/AfuxW3JNkBcpMKeNTgYPmWIoiIozTZLTBxOKrtK6/7zAMKnkTJKlmmRsCZ3iw== X-Received: by 2002:a5d:6d05:0:b0:203:781d:3f7b with SMTP id e5-20020a5d6d05000000b00203781d3f7bmr21167021wrq.442.1647940984288; Tue, 22 Mar 2022 02:23:04 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:54 +0000 Message-Id: <20220322092257.2713521-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 Reviewed-by: Kieran Bingham --- 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 Tue Mar 22 09:22:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15503 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 E6B3DC3264 for ; Tue, 22 Mar 2022 09:23:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9B7C9632E7; Tue, 22 Mar 2022 10:23:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940989; bh=kLdJCoGqn9EWuZ/Y6wCBPOrNjqTq2/GaVdwfFx+Kr1I=; 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=KCD5bD8LOcgGvwbvpmz9vvAEtfQ/m1YviWUzyWNgYUkOUvk/MLROP0YR5f0PV5ryC 34o32iB5ieUSWTbF+6dv86LpWTsszG1OULwdPDyaYSsC0OrdyqmkrJZ7zecY9AC+QE n9/hlKew/dIG44SB0LAl17+mOBQfwoxf9wTERoyqabCDobVOzRTuGq17gF/C3sjS39 W3zOLwm4Szt+2LfPk2lp/mPo4i2XZKBK756SBrbNxiqd+hSwmT/beW+xQuM3q3aTMa ytgphGvAqAA/aCjTYDQ11OC8GHQvHf2VsCqpu2MUA+VUXCITWSkITj1z+9ke70hhOc xDJvIzRCEubuQ== 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 61206604E9 for ; Tue, 22 Mar 2022 10:23:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="C9BJbsT8"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id o7-20020a05600c4fc700b0038c87edc21eso1233729wmq.0 for ; Tue, 22 Mar 2022 02:23:05 -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=XJt33N1ljP6weawLqxc7eqhgx8mv7TXz3ylgqjbNO8U=; b=C9BJbsT8td3C47nEb49XPsJOEHf3FOtqKVB3GteUmCjoo351+M+UuozXXniMePiEBO Ml+ujDOqXj+/2lCf+TKV56ApoTiVzW7qYWLPdcrn2Wv2JgAGvUs+T39IAwzs6lb30rFz JNqDcmUJpWTOSMDuxFxvLgT2i1SnpqOHohUX1W2KLOLf0w2e+5RcihW+aetlEhqfOEp1 vkBDXEA3dNQRTYH07IJ3fKqkrZY10cP1ur/g9NfotN1BHFec0Wr5W3tyExhQD5oj3gWl BWQnjpmhvMXajFrKsJnAbmlZX0KWWyGG7J4TEc7hklIgrK3bzJ4JrgKO7LJl5i7nSw0y j/Iw== 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=XJt33N1ljP6weawLqxc7eqhgx8mv7TXz3ylgqjbNO8U=; b=tT4eGB48GMaQGGK3cLMP68w0oJxX5t5hnN4DUxbMdeARBw/X3iNVzv+SqQolxpEFO3 fF0bxbBcSNc2t/bEZVOojgVzb66MAnjpjACS1rv2lCcjiG1lUtOjreGg5+w/xwG0Gtet 4qzB2/4iCG6a326iqv3BLMKkfhyLhn6MiTK/bc7j+Vy2Ae3SLzqyWtX63kTxO/q/Cr1j sw8bh+GKCi12i+b7j7l1tqDOOYa2AErWwC8l6osIsFVISk1KkJmvbAaKPl2OHfQy4duF aoBPLvsJvgwwSo3794EnOaSvEoq4H0QeKmUsN89duB3ID55p4buP23s3PAzc41C1za2u G0lg== X-Gm-Message-State: AOAM533D6irdslvduSmQCS8P76XUj/fz+JknWxK4sxbrfWma+oNBs5Tx Z4VO4kq189ctEiNssWtHvaUz2hkneDIn/g== X-Google-Smtp-Source: ABdhPJyCkM3svCV6/nln8mKlclYscMBiJMgYq7HwCclxZO0NMxKNAViXZ/gqU22o3+IjFp6dTMPovw== X-Received: by 2002:a05:600c:4b83:b0:38c:49b5:5bfc with SMTP id e3-20020a05600c4b8300b0038c49b55bfcmr2882952wmp.33.1647940984851; Tue, 22 Mar 2022 02:23:04 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:04 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:55 +0000 Message-Id: <20220322092257.2713521-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 --- 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..1516be129d73 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 \a queueBuffer will fail if the device is in the process of being + * stopped from a streaming state through the \a streamOff function. + * * \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 -EPERM; + } + /* * Pipeline handlers should not requeue buffers after releasing the * buffers on the device. Any occurence of this error should be fixed From patchwork Tue Mar 22 09:22: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: 15504 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 74255C3266 for ; Tue, 22 Mar 2022 09:23:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0A095604E9; Tue, 22 Mar 2022 10:23:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940990; bh=kfT4ZWkCPG3/gdZFNdt4nHwbshCKHdwdNoIP/9MpcQo=; 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=KdcIFFaJg/Ye3SeZBBuqFnmZtgei1ezxNcLix2igg5wLBit3QJaZNVouts3puL+f3 qJ9RU0HGaGlsFbPRWaE26sq14SIAX46399WKW17JvUp22SQzpzevkOxI0ow3dcD/dN Z90yZ+1axuDgCT9UWurRC+XHYvkLjuwtjvvz5ovTF3SBZiMUA/zSnqGC63R9k6QKMh iUaGJp0yylR+pDG69+cDY3PQMuK4QEIgdjwLjY/ycnwYUuzLbpP0jZDlKhg4entJ0K 8obfoRS4KO9qRR8gVm/Xytlv6HEV49+v8JQKWHPlHnmei2kalKGq9qy+Af2kbRoIWp oCENUQN7AYv4g== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 20DD4632E5 for ; Tue, 22 Mar 2022 10:23:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DbbwHCmY"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id m26-20020a05600c3b1a00b0038c8b999f58so1033279wms.1 for ; Tue, 22 Mar 2022 02:23:06 -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=TdgSbJYfrkGKhFpU5Csv2hwqt6vlahDqMHurCng86MM=; b=DbbwHCmYLyz/BFn+zYVIYC/ai9PJfZRRla5bZXCIII4iUCJRjExAZUdmtRzRv8GvzG OTQFktlF1mLJRYY0T5Vt5F7tL/cOnICdSrYtDHwFd+1SLBIRD8FUgakH/xMLdzSQiiNt lHGVAneleOk12bZRR3CA79sp7Z4EbHrjhAl7iaEOFSDN6AmnALZiBkmlld9oq7r5SkxY Q4Q+8xfv0M1ge4ramwAsZLSmsYRfHGiXMNpiS0H+2BO29EcIfX7Xkuid0+aFtMvdM26h qZoYxeOAIdtvHCZhmbcyDWhx3uTrRxTnAShHYO9ePj5eO2kzXDJojSU2tf0N1mk72RDv OWBA== 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=TdgSbJYfrkGKhFpU5Csv2hwqt6vlahDqMHurCng86MM=; b=UsWoWX4c3befrl7SVgOEhe4uocOOPjaUs3MAf125TuvIbVY4knQjz27L/aBJKfyLWH S4JrMn0SNn0kpporRaUkBsZ57qw3zptS5i2TFmreW74KT3iA6VUTFWDRWcpgKQ2xasdi IrfRrMMvchdOSrjUtesTMkFzs+1Y26644Kg+DwK2cXS5DXrrZPI88nTMfHUwsKcADAgv aR/VCjl64a8DOEkcoEo9s9LYPujR2BPdAgXk91b+w0A5qvFbAI/TbyddfkvWdrRy4GpI BoBM08MBFi4feoIugCalKfkmzPXY/7NTAo4OvQUXce+EuBo/CIAK4nnNfjy1uabECeck c7EQ== X-Gm-Message-State: AOAM5310UjhP9kwZBAgns94MExsd7l5Suan+0ayBlvO9CW+F4orX27TO lcmT9IXUK6+hAQCHtua9Z7NEoysjBS0Gqw== X-Google-Smtp-Source: ABdhPJzbDNnj7MqqKrq3iGw0zqRPh0kul1HrO7Ep96KVUpUOVnWNvFtpXQb1ucyHygh+hTPKjBX9NQ== X-Received: by 2002:a05:600c:2244:b0:38c:a3ff:ef67 with SMTP id a4-20020a05600c224400b0038ca3ffef67mr2694603wmm.122.1647940985582; Tue, 22 Mar 2022 02:23:05 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:05 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:56 +0000 Message-Id: <20220322092257.2713521-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 1516be129d73..a384de7507ba 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 Tue Mar 22 09:22: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: 15505 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 69263BD80A for ; Tue, 22 Mar 2022 09:23:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 27882632F0; Tue, 22 Mar 2022 10:23:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940991; 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=e/fvcaecdHJY15LFVKu6kgE3mVD7/Rujxv5cDyoF0iP6kI1DfPc+jQsMZ/XfSLgzX ADzhOoe+ndg7t62Bg3dKpsuITIbwpC3Qx0E7uJeU+r2lk7riY6THXpdc+fy7/KAM1L rk3QepZ7BNfqc1jKYgn0u4gzHp80OCvg5h59xu1mQ5u5tRdFWr0+kcAKID12MQ0egN O8KGg5lty67hLRw1w8PnMO1Z/nfuNH0H06KmbErO9uxRpVDOLuN0Snn1SHIFYwkPZL QQ9OcNw3FwkB7f7iOPj1xKPsqCG4PwoMvRnyMghvuZ8uj2Ye7mZdwfWvi/yxkLBoZj SG3nj8TOG8nRg== Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C14A5604DC for ; Tue, 22 Mar 2022 10:23:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Xp7b1x7G"; dkim-atps=neutral Received: by mail-wm1-x329.google.com with SMTP id n35so8367024wms.5 for ; Tue, 22 Mar 2022 02:23:06 -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=Xp7b1x7GnKst9uEYrj3xbJDYbjz1Cdznm6NkuXWJxSuN/jSyaEfJ20tDhoqbcENMA5 7otLVfqVq9PqM7NoQY6yHQ2EMm3KueboxcaEX1uCClsgrRGXq4eew/csvTMRdmVtICUK 8VRpWSxK7sIsvowiUKmXQux2ZOTfFH05kht/aC0Cl8Z9Vq5WqhOhNaAR9qEOZRSHgEVd sHIL6J8czYQL4Hr08XopijiyLkv7UBoEALGmpVi+v4B9427zt/xVyUCLl9dIkJKqA62q q9pnjd4omJcGL8U5OCxc22Cp5nQzV1w87/bXXexaar1P9eOo1+3EtVEqnFkr+Lie+J04 Jhhw== 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=wO00jxC4Da3Tyvm7rP4qE6jL5iZce7+QXDdFD6QdpmKFnNzNN3rHLGOsPjHO7l+VhO 3s2h/fWqePk0YEK2fUoMWVsX98EYzZH5O20aJM8od/QKOyLcx6qJYkpaOrKI7vZGGVDE Lou+08IhJPlxQqZYXVJx37kIEMTFIathf87a1JDwpv2x5mz75+s7pKuzGnbQI7D/A6Z1 Vc9X189A8PxMTz7x5hRUGbFC82OKfZMTN76Pzy9HjW1gwdl5DXNb9osoj62hYfq6kFP2 1/DsV8bOXqfoRxmn6BhDFKf3r75CaCPSPBuTHlyI29+YqbAfka422lviRi/S033exqUE PwhA== X-Gm-Message-State: AOAM5323AoxppaDKYOcWLTfDbgnfnhbs/qq1GBQF6iF+XZ2a3Jobo5ph ah7scMTL3wxcayE1y+c7v8r0zC0LNYh+SA== X-Google-Smtp-Source: ABdhPJwawlTTYlCx6mMKDygpnEkz1frbt86sGt0TPLGvrVm2xh994jNuov7caEhMnyPKT1I2Sp/zlQ== X-Received: by 2002:adf:fd4d:0:b0:204:ec5:bd62 with SMTP id h13-20020adffd4d000000b002040ec5bd62mr7911223wrs.403.1647940986263; Tue, 22 Mar 2022 02:23:06 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:05 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:57 +0000 Message-Id: <20220322092257.2713521-9-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 Reviewed-by: Kieran Bingham --- 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; }