[{"id":22256,"web_url":"https://patchwork.libcamera.org/comment/22256/","msgid":"<CAHW6GY+eKZKwfDokZK7WYwVAb0dr2bDisM+pSBS2ps_TMH-aWw@mail.gmail.com>","date":"2022-03-10T10:59:50","subject":"Re: [libcamera-devel] [PATCH v1 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":"Hi Naush\n\nThanks for this patch!\n\nOn Mon, 7 Mar 2022 at 12:46, Naushir Patuck via libcamera-devel\n<libcamera-devel@lists.libcamera.org> wrote:\n>\n> When streamOff() is called, ensure the cache entires for the remaining queued\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> ---\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>\n\nNot sure I'm entirely qualified to give a very strong opinion on the\ncorrectness of this, but nonetheless we've been using it for some time\nso:\n\nTested-by: David Plowman <david.plowman@raspberrypi.com>\n\nThanks!\nDavid","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 0CAF1BE08A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Mar 2022 11:00:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6ED5E632E6;\n\tThu, 10 Mar 2022 12:00:03 +0100 (CET)","from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com\n\t[IPv6:2a00:1450:4864:20::32c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DE15C601F8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Mar 2022 12:00:01 +0100 (CET)","by mail-wm1-x32c.google.com with SMTP id q20so3005129wmq.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Mar 2022 03:00:01 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1646910003;\n\tbh=eW3TOKgQOfF6EORfJz9ZsThDsd0Sm2HZmCsZjLbbops=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=c+P7pxJQbeYWcFcEb7XOf9IX7vbSacTZHaHUaO5/pmlfqFnWR+l9V8wCzJ8cMeDNr\n\twxuEX+I/7hbgjHT6zGfBBApka+RAlAX7PMMJfaM4m+U7IbEkR3i/1tdBmIWGaBSvEj\n\t6Ef59RsEq/UgnS9fF3TCqUuNexOODwFBKym3NpiR6zVTrigVbAjJhFgr+i6MDGpTUD\n\t7qQ6KrI29HrywXmUlzU4uqmTA3RVbfrpczXpAhMHZ74oFzafQtB5mPBP6EAVdqN2i2\n\tGYjekyIPR+69VkMvgtflK3gB1cm5dVWGiHrXA22LfkS0X5rmq9BBXUHIo/jCDieDMA\n\tEekgOiU7yyq0w==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=UyqzeCLJlcWqM/pRg5BBIRXKNtBuE2tWyhizkudAL/M=;\n\tb=W7NT1F/+jovzMbSnQJrqE4oP92EagbT5oIqYBtn0zLS9oZSeN5EwSXkxr8IXdGdE7m\n\taY4AJGN/4XL1o/OH5jH7MRb3kQBHOg4dak0w4koyLMhTgm07MZaDa6Y3a/wB77VaxjPP\n\tf+zyKS6SiKSzbDTHsY+OF1sK+DvT8HR5s6/wnuXWIkzc1+CE0T0M1dKVkP/muyZtmsA4\n\tgaG5muzUa4e4lmDW2t95/S5/PSltsb2OQQut+5qfVBHmCkRluy5B9VwN1CBOgLo78u3f\n\tJ+9O46ZfXb4U88RLnjep7uPAv/5DFtW1WcebQKI/Unvkr8OlRG6sKN0cWgfYMxPQGXiv\n\tQHIw=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"W7NT1F/+\"; 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:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=UyqzeCLJlcWqM/pRg5BBIRXKNtBuE2tWyhizkudAL/M=;\n\tb=kncu7paart9JNh7qEQFz7xN9wiZA9wgxzxLRh+H1U6E+cNlT2EyFshM5HhGToOmmq9\n\tQ3rdSshHH+6d+h7hGFX2HxDfNLdMJbXlyrqTXyyId4rS3avmLumkVA3V0Ps7KbgW/ATj\n\tpx2hsYUxyzg9H77MRraAURLl1Ms9naYyDR7SziGe3NHydcUaEU/Oo82asd6/JQDgxeRw\n\toPzRPeXzsXWQolUep8q5mGXTObH0Ri6cBku/eDgFeoaM2p5Qv7dmxU+MXUWuB5fnEHlZ\n\tLMiUUMuLm0Z/g6GePH4OWeKx1XA09nGJjKvpqvO5t83VIJL1+S6LAXiTGQfgkH18bhuF\n\t7KMw==","X-Gm-Message-State":"AOAM533gFB3eznWsX5N7foZ5jcofxm3yJvs0EOtzTZXMv4ta1Wp0v7ag\n\t5I+2bAW7RA1DDYg/4UkIqM7FcmVwvRnfTa2KHFsI2M4IAok=","X-Google-Smtp-Source":"ABdhPJzmUz1AYhk8NloxhhcmbmPJ48y/z0HxQoZqZp1B1xDWOuuWykmEu8NqZ6JFJz9qZnMugEQm381wfuwIC4i+I2M=","X-Received":"by 2002:a05:600c:3b13:b0:389:cf43:da5f with SMTP id\n\tm19-20020a05600c3b1300b00389cf43da5fmr6895548wms.201.1646910001511;\n\tThu, 10 Mar 2022 03:00:01 -0800 (PST)","MIME-Version":"1.0","References":"<20220307124633.115452-1-naush@raspberrypi.com>\n\t<20220307124633.115452-7-naush@raspberrypi.com>","In-Reply-To":"<20220307124633.115452-7-naush@raspberrypi.com>","Date":"Thu, 10 Mar 2022 10:59:50 +0000","Message-ID":"<CAHW6GY+eKZKwfDokZK7WYwVAb0dr2bDisM+pSBS2ps_TMH-aWw@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v1 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":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]