[{"id":22325,"web_url":"https://patchwork.libcamera.org/comment/22325/","msgid":"<164761374818.1484799.17315788499895479302@Monstersaurus>","date":"2022-03-18T14:29:08","subject":"Re: [libcamera-devel] [PATCH v2 6/6] libcamera: v4l2_videodevice:\n\tEmpty the V4L2 buffer cache on streamOff()","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"Quoting Naushir Patuck via libcamera-devel (2022-03-17 14:08:27)\n> When streamOff() is called, ensure the cache entires for the remaining queued\n\ns/entires/entries/\n\n> buffers are freed since this will not happen via the dequeueBuffer() mechanism.\n> \n> Additionally, add a V4L2BufferCache::isEmpty() function and assert that the\n> cache is empty at the end of the streamOff() call.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Tested-by: David Plowman <david.plowman@raspberrypi.com>\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/v4l2_videodevice.h |  1 +\n>  src/libcamera/v4l2_videodevice.cpp            | 16 ++++++++++++++++\n>  2 files changed, 17 insertions(+)\n> \n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index 2d2ccc477c91..37747c0b2f27 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -126,6 +126,7 @@ public:\n>  \n>         int get(const FrameBuffer &buffer);\n>         void put(unsigned int index);\n> +       bool isEmpty() const;\n>  \n>  private:\n>         class Entry\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 5f36ee20710d..9da82697e7f0 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -262,6 +262,19 @@ void V4L2BufferCache::put(unsigned int index)\n>         cache_[index].free_ = true;\n>  }\n>  \n> +/**\n> + * \\brief Check if all the entries in the cache are unused\n> + */\n> +bool V4L2BufferCache::isEmpty() const\n> +{\n> +       for (auto const &entry : cache_) {\n> +               if (!entry.free_)\n> +                       return false;\n> +       }\n> +\n> +       return true;\n> +}\n> +\n>  V4L2BufferCache::Entry::Entry()\n>         : free_(true), lastUsed_(0)\n>  {\n> @@ -1832,10 +1845,13 @@ int V4L2VideoDevice::streamOff()\n>         for (auto it : queuedBuffers_) {\n>                 FrameBuffer *buffer = it.second;\n>  \n> +               cache_->put(it.first);\n>                 buffer->metadata_.status = FrameMetadata::FrameCancelled;\n>                 bufferReady.emit(buffer);\n>         }\n>  \n> +       ASSERT(cache_->isEmpty());\n> +\n>         queuedBuffers_.clear();\n>         fdBufferNotifier_->setEnabled(false);\n>         streaming_ = false;\n> -- \n> 2.25.1\n>","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 93A46BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 18 Mar 2022 14:29:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F14D0601F5;\n\tFri, 18 Mar 2022 15:29:11 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9CB39601F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Mar 2022 15:29:10 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 36224EE;\n\tFri, 18 Mar 2022 15:29:10 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647613752;\n\tbh=OjgdY0ILFRkyVp4Lu7d2A91u9r0l+6IIafqMdD8OviE=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=uDDgeH0y399z+XhwcPodid6QNsp7obKjfF49eQBxSm06ZPpOjSGyZmWTYtO1P5Fdm\n\t+wt6aKODnAIdl2JNl6C6UD+UAu6wrsFJMfTwRiEM7ijE8N5tcpUk4jH9OVxwgMYUMx\n\tkWlbfA277zYp433vEDrvqz18ebEavuucCVma9a2UcynJD2FSAZHn5lCJoiw6EC6LGi\n\tExxb0cjclEMzFgdspXQjJMplzVfQCE0ZxO4nqRxohHRV2OJB/2a2KisJv1rNIURJTY\n\tFgT0vRX9f/gZB49PMxlHganqxipG8z3GgOvk5YPYdfRRX7js/AUqN7QoQ+FDDgd08W\n\texk38Mlazd8tw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1647613750;\n\tbh=OjgdY0ILFRkyVp4Lu7d2A91u9r0l+6IIafqMdD8OviE=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=R/uN3CqrU9gkVA0PylUur53AObXptNcx7vWoAAKry0e+EVMjDQkKQb09hX5o7/ONW\n\tQzplrqsqWktq+ptfVLIxraZj1+mUMOC6XAK140hSY/9GG8rIR8yNppCF/z/tkf3IjI\n\tWVKVuWq+xg+motl1mCNbnj2p6ymJkEaiQTOAKHps="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"R/uN3Cqr\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220317140827.1835029-7-naush@raspberrypi.com>","References":"<20220317140827.1835029-1-naush@raspberrypi.com>\n\t<20220317140827.1835029-7-naush@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 18 Mar 2022 14:29:08 +0000","Message-ID":"<164761374818.1484799.17315788499895479302@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v2 6/6] libcamera: v4l2_videodevice:\n\tEmpty the 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":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]