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;