{"id":15431,"url":"https://patchwork.libcamera.org/api/patches/15431/?format=json","web_url":"https://patchwork.libcamera.org/patch/15431/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20220307124633.115452-7-naush@raspberrypi.com>","date":"2022-03-07T12:46:33","name":"[libcamera-devel,v1,6/6] libcamera: v4l2_videodevice: Empty the V4L2 buffer cache on streamOff()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"410257105047434d75e8289b9623c54c64e26147","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15431/mbox/","series":[{"id":2954,"url":"https://patchwork.libcamera.org/api/series/2954/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2954","date":"2022-03-07T12:46:27","name":"Raspberry Pi: Efficient start/stop/start sequences","version":1,"mbox":"https://patchwork.libcamera.org/series/2954/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15431/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15431/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\r\n\t[92.243.16.209])\r\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 29282C3261\r\n\tfor <parsemail@patchwork.libcamera.org>;\r\n\tMon,  7 Mar 2022 12:46:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\r\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D696761192;\r\n\tMon,  7 Mar 2022 13:46:46 +0100 (CET)","from mail-wr1-x436.google.com (mail-wr1-x436.google.com\r\n\t[IPv6:2a00:1450:4864:20::436])\r\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BBDB761189\r\n\tfor <libcamera-devel@lists.libcamera.org>;\r\n\tMon,  7 Mar 2022 13:46:43 +0100 (CET)","by mail-wr1-x436.google.com with SMTP id u1so23051409wrg.11\r\n\tfor <libcamera-devel@lists.libcamera.org>;\r\n\tMon, 07 Mar 2022 04:46:43 -0800 (PST)","from naush-laptop.pitowers.org\r\n\t([2a00:1098:3142:14:c644:e9b3:de0b:54c5])\r\n\tby smtp.gmail.com with ESMTPSA id\r\n\tz6-20020a1cf406000000b0037c4e2d3baesm19759582wma.19.2022.03.07.04.46.42\r\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\r\n\tMon, 07 Mar 2022 04:46:42 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\r\n\ts=mail; t=1646657206;\r\n\tbh=j1yifcg2H5tqFnHv5TxW4VZaUjGkXmlKngikuNYDKKU=;\r\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\r\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\r\n\tFrom;\r\n\tb=VFdU59WONTNb0hMSL+4X/6LbD3vujt65mXWqeKA+CFnrmZs1gM1O7wenqBZBNwmvi\r\n\t8rpuw8+47RglGsCFMmH3orXxDFlLOEGWfs9P2cRgPKOZYlfbE5pc7awYDW19cethH9\r\n\tNaKQ/Yf8sfKQPSZf4amFiyAU9r8i7iR/3Cuog/iW4W+mtVhqml3ArGkWSqZLXUfEL6\r\n\t0f31PUfZAn16Svln0mIrwSQU8B7hI26eBBrlogOHdHHtEmQ0aBeS4vm+mZcQ2mVjAh\r\n\tptx9TykYEEhJoTwd3VTNJ6zshw1MT61xJ9LP1qhRRpmW1vdHV+eeQ9yUW6MTHHc4h1\r\n\tuNRc8D14DwugA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n\td=raspberrypi.com; s=google;\r\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\r\n\t:mime-version:content-transfer-encoding;\r\n\tbh=PRkhqrlp04FHuT3lgzDxfAUE/vo6bJn9nSQyQ3qDDVQ=;\r\n\tb=f9lzWf3G7OIDRAoSKWl1YLJqgzVINBtEdrq+w69QuV5t/v4AkHf4qAoXBz7deLa4ZP\r\n\tVRCwjURp6ufZ5teFeV3TllWt2EDL1nzNmYZ+RWYNUbNrkb/RIoHR+Vmsu4a/eSxitl5R\r\n\tcvZrAgakNNzIUjhlDkhgiR5mcDH84VpcHvN9Isjce0PNbd/mat9B0e2a71scRgsP7xkY\r\n\tHRv71Q09YF1xYEXALKgyVaDAHnryxyMm3nzkqw1u8N5wkBuityoe7qHyvm/2AU+1MGZi\r\n\t/QfcKsiyY4/QxBnXJJg1xTkORPJf6LCiaPwtalkip2J7axsa+6RuXhhDFdhbVeFE02PD\r\n\t6LXA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \r\n\tunprotected) header.d=raspberrypi.com\r\n\theader.i=@raspberrypi.com\r\n\theader.b=\"f9lzWf3G\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n\td=1e100.net; s=20210112;\r\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r\n\t:references:mime-version:content-transfer-encoding;\r\n\tbh=PRkhqrlp04FHuT3lgzDxfAUE/vo6bJn9nSQyQ3qDDVQ=;\r\n\tb=ayWcLpj5wJnz+Ww0AVS3bIIioA2rYouq7G91nyCzi6LF49KqQz2DVjQuhjNXIAw6e7\r\n\tT6fLp6dx/xiNBUrbpY8TRA6vif3TZnatG4KQiMI0ORQ479D6m4BUVH7R/NYnzfQYnMz/\r\n\tI4tOVGZQ6rPMJh2sU0wNkIv89925fa7f5wajQ0weWluGvaEKFEv+ucMTn4fKSPNWxrc5\r\n\tKwT4Vlrna2U6wCShiqUaYHZeNVH/ASZDLj4dDVfnT3aKXLL9/wuEW09t7TSFmrUP5U7x\r\n\tQDK2CF4wdVaA/2CSY9MbaClfJD0PrzrqIUePc5WzvsKUF3zaxkv9l3C34BusEkVES/EM\r\n\tnTVQ==","X-Gm-Message-State":"AOAM531MWUQKmDvFEOy9lUVlMVwHQiT/is/nyQvYYROwhjW9apsaNl5C\r\n\tJw03b1KMgoLYfq/qqb7g98f0AdK3XM+OZA==","X-Google-Smtp-Source":"ABdhPJxke08C4cGunZzAowhxRMzVxMnRtJWGXX3Kkrrxocln93zHO1Htesai7RgbKdttpuheFhpVQw==","X-Received":"by 2002:a5d:538b:0:b0:1f1:e60b:20c2 with SMTP id\r\n\td11-20020a5d538b000000b001f1e60b20c2mr5982636wrv.294.1646657203211; \r\n\tMon, 07 Mar 2022 04:46:43 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  7 Mar 2022 12:46:33 +0000","Message-Id":"<20220307124633.115452-7-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20220307124633.115452-1-naush@raspberrypi.com>","References":"<20220307124633.115452-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1 6/6] libcamera: v4l2_videodevice: Empty\r\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>,\r\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>,\r\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\r\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 entires 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>\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\r\nindex 2d2ccc477c91..37747c0b2f27 100644\r\n--- a/include/libcamera/internal/v4l2_videodevice.h\r\n+++ b/include/libcamera/internal/v4l2_videodevice.h\r\n@@ -126,6 +126,7 @@ public:\r\n \r\n \tint get(const FrameBuffer &buffer);\r\n \tvoid put(unsigned int index);\r\n+\tbool isEmpty() const;\r\n \r\n private:\r\n \tclass Entry\r\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\r\nindex 5f36ee20710d..9da82697e7f0 100644\r\n--- a/src/libcamera/v4l2_videodevice.cpp\r\n+++ b/src/libcamera/v4l2_videodevice.cpp\r\n@@ -262,6 +262,19 @@ void V4L2BufferCache::put(unsigned int index)\r\n \tcache_[index].free_ = true;\r\n }\r\n \r\n+/**\r\n+ * \\brief Check if all the entries in the cache are unused\r\n+ */\r\n+bool V4L2BufferCache::isEmpty() const\r\n+{\r\n+\tfor (auto const &entry : cache_) {\r\n+\t\tif (!entry.free_)\r\n+\t\t\treturn false;\r\n+\t}\r\n+\r\n+\treturn true;\r\n+}\r\n+\r\n V4L2BufferCache::Entry::Entry()\r\n \t: free_(true), lastUsed_(0)\r\n {\r\n@@ -1832,10 +1845,13 @@ int V4L2VideoDevice::streamOff()\r\n \tfor (auto it : queuedBuffers_) {\r\n \t\tFrameBuffer *buffer = it.second;\r\n \r\n+\t\tcache_->put(it.first);\r\n \t\tbuffer->metadata_.status = FrameMetadata::FrameCancelled;\r\n \t\tbufferReady.emit(buffer);\r\n \t}\r\n \r\n+\tASSERT(cache_->isEmpty());\r\n+\r\n \tqueuedBuffers_.clear();\r\n \tfdBufferNotifier_->setEnabled(false);\r\n \tstreaming_ = false;","prefixes":["libcamera-devel","v1","6/6"]}