{"id":15547,"url":"https://patchwork.libcamera.org/api/1.1/patches/15547/?format=json","web_url":"https://patchwork.libcamera.org/patch/15547/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220325090903.880311-8-naush@raspberrypi.com>","date":"2022-03-25T09:09:02","name":"[libcamera-devel,v5,7/8] libcamera: v4l2_videodevice: Empty the V4L2 buffer cache on streamOff()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"e7fa881c0358ac6df00af49cf896672dc0184a05","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15547/mbox/","series":[{"id":2999,"url":"https://patchwork.libcamera.org/api/1.1/series/2999/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2999","date":"2022-03-25T09:08:55","name":"Raspberry Pi: Efficient start/stop/start sequences","version":5,"mbox":"https://patchwork.libcamera.org/series/2999/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15547/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15547/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A51E0C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 25 Mar 2022 09:09:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5EE966118A;\n\tFri, 25 Mar 2022 10:09:16 +0100 (CET)","from mail-wm1-x331.google.com (mail-wm1-x331.google.com\n\t[IPv6:2a00:1450:4864:20::331])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2BD8A632E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Mar 2022 10:09:13 +0100 (CET)","by mail-wm1-x331.google.com with SMTP id\n\tp12-20020a05600c430c00b0038cbdf52227so3995205wme.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Mar 2022 02:09:13 -0700 (PDT)","from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:478c:773f:4734:d0bc])\n\tby smtp.gmail.com with ESMTPSA id\n\tc4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.11\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 25 Mar 2022 02:09:12 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648199356;\n\tbh=0jgW9DVYMaUjCXrDmW7oJlH5cBKoQpmyQ82oO3SyVdM=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=lfVE4r6Dn+ABYjZP5xGu+mEL4Mz/OCskAzKUhkz8nls39xQMPGrZQVLASbSti3OSR\n\tBh+Jpp3CY3QewLXyfXMrnAnIqHVAoi6gFC3wW144/UlL+1RDWWh52kBJussGOIKFTY\n\ttAmR0gnFzW0DhxydhNuU9ZLEeX+97SgeTlB7uzimIf3QFwBLp8NHGn1Ij/13e8739/\n\tlWZVf5R0bndqOzcjUNC30dKVL8jw/3z6ZYIJtjsJDxRaLTMmvZ+d/GEpHgZ0DxoC0m\n\tKV+3f4eHzqQ76Wg60JLDS5TkQARBw4BMISO/FRdFl5bNbUxfFwE+65Rgb1ZN0sqdF8\n\tee8UOixTEgYew==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=aPAyUYGMojuKxVmvgFges/HhTEcWeAcOkI7bHjlME1E=;\n\tb=luAWWEpOtziDYteD77lcDqGEbA/D1xeiRECyeHe0io3csSFLJ1NaxRo5fZkoFs3JmK\n\tEr5BKqbvEvaXYBJgRnwa3CjPrRwtKjk0ZJW93ldE3mFwS2HH4khHxBIXwjJw+/ZwTnJU\n\tyn/d6Mxiu5Av+kWSXKZ4mkAKlm46AZbOifas6vEt7pLhx8VMu/Ic8PEHOT6S19cnRYW2\n\tGtUZ5GAoY16npJJCWFBSrfPcuXM+TeHB42U/Zo/pCbA6waq3u3ZpjYImZfezZ7V5rLxY\n\tWw2CFplfS1Q7i/OVQR2Pv/aJc3hj0qxeNlc76m5YXYzLCWD4jHj8njA2fIf3KQTzU54c\n\tID9g=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"luAWWEpO\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=aPAyUYGMojuKxVmvgFges/HhTEcWeAcOkI7bHjlME1E=;\n\tb=U0GIPA0BVO+yrOXv7vY/1QyL3sknEzTPMtrO3jjBF5k4ZxEX/E0Wz3FNTdzvJDS27J\n\t0ygT3LYbXiyErGMGGPf1zWTsqiVm+20O2H8XI6BXUytV7dFbea0U3ISLCYx1hzfUP6UP\n\tyw1daYb2sHDr9zucpu9VH5Y5+sXgNtmTO2fFxSTAi4+6Q6vbMhO9uhSLgFJfGwbpZ2No\n\tkskdUWauw17iFqxIS5/X3ZsOyVxmgFByxV1XLCKn6lKZ9eXJs9wnaoE7LRPK6bJOvKVe\n\t0yPlAoIvZbhjdx9SyvCmPbEyuQzDjSLuwgIYhdCwodRUQRaM7GGNThKVh9hHdWogxGCr\n\t5m7Q==","X-Gm-Message-State":"AOAM533/43BrDxIhcQ6bHNGTiKGaxBLkRXYJebOsq5sMAzOPyCUxkEid\n\tBJp2JaGxwFHZI1xZ9o7SZSEW7TYsyWo4/A==","X-Google-Smtp-Source":"ABdhPJwEG1/UZtH6J93vnIuLOK+MUF8S2LGQkNJa35gg9T4+oC7u54TfzN0YCcEg6Tg6L8TnT21WuQ==","X-Received":"by 2002:a05:600c:3c9d:b0:37f:a5c3:fccf with SMTP id\n\tbg29-20020a05600c3c9d00b0037fa5c3fccfmr8778554wmb.13.1648199352648; \n\tFri, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 7/8] libcamera: v4l2_videodevice: Empty\n\tthe V4L2 buffer cache on streamOff()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"When streamOff() is called, ensure the cache entries for the remaining queued\nbuffers are freed since this will not happen via the dequeueBuffer() mechanism.\n\nAdditionally, add a V4L2BufferCache::isEmpty() function and assert that the\ncache is empty at the end of the streamOff() call.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nTested-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/v4l2_videodevice.h |  1 +\n src/libcamera/v4l2_videodevice.cpp            | 16 ++++++++++++++++\n 2 files changed, 17 insertions(+)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 32e022543385..60d62212bfe1 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -124,6 +124,7 @@ public:\n \tV4L2BufferCache(const std::vector<std::unique_ptr<FrameBuffer>> &buffers);\n \t~V4L2BufferCache();\n \n+\tbool isEmpty() const;\n \tint get(const FrameBuffer &buffer);\n \tvoid put(unsigned int index);\n \ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 28f336086b49..1621a013e29d 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -201,6 +201,19 @@ V4L2BufferCache::~V4L2BufferCache()\n \t\tLOG(V4L2, Debug) << \"Cache misses: \" << missCounter_;\n }\n \n+/**\n+ * \\brief Check if all the entries in the cache are unused\n+ */\n+bool V4L2BufferCache::isEmpty() const\n+{\n+\tfor (auto const &entry : cache_) {\n+\t\tif (!entry.free_)\n+\t\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n /**\n  * \\brief Find the best V4L2 buffer for a FrameBuffer\n  * \\param[in] buffer The FrameBuffer\n@@ -1842,10 +1855,13 @@ int V4L2VideoDevice::streamOff()\n \tfor (auto it : queuedBuffers_) {\n \t\tFrameBuffer *buffer = it.second;\n \n+\t\tcache_->put(it.first);\n \t\tbuffer->metadata_.status = FrameMetadata::FrameCancelled;\n \t\tbufferReady.emit(buffer);\n \t}\n \n+\tASSERT(cache_->isEmpty());\n+\n \tqueuedBuffers_.clear();\n \tfdBufferNotifier_->setEnabled(false);\n \tstate_ = State::Stopped;\n","prefixes":["libcamera-devel","v5","7/8"]}