[{"id":22337,"web_url":"https://patchwork.libcamera.org/comment/22337/","msgid":"<Yjh4yDqRmxeCi7l+@pendragon.ideasonboard.com>","date":"2022-03-21T13:08:24","subject":"Re: [libcamera-devel] [PATCH v3 5/5] libcamera: v4l2_videodevice:\n\tEmpty the V4L2 buffer cache on streamOff()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Naush,\n\nThank you for the patch.\n\nOn Mon, Mar 21, 2022 at 10:27:02AM +0000, Naushir Patuck via libcamera-devel wrote:\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> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.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>  \tint get(const FrameBuffer &buffer);\n>  \tvoid put(unsigned int index);\n> +\tbool isEmpty() const;\n\nI'd move this before get() and put(), as we usually declare the const\nquery functions first. Same in the .cpp file. This can be handled when\napplying.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  private:\n>  \tclass 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>  \tcache_[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> +\tfor (auto const &entry : cache_) {\n> +\t\tif (!entry.free_)\n> +\t\t\treturn false;\n> +\t}\n> +\n> +\treturn true;\n> +}\n> +\n>  V4L2BufferCache::Entry::Entry()\n>  \t: free_(true), lastUsed_(0)\n>  {\n> @@ -1832,10 +1845,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>  \tstreaming_ = false;","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 0FB3ABDE17\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Mar 2022 13:08:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1180E604DC;\n\tMon, 21 Mar 2022 14:08:44 +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 9E143604C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Mar 2022 14:08:42 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1DAFA291;\n\tMon, 21 Mar 2022 14:08:42 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647868124;\n\tbh=S0B5xzl8MmBeXgv9bHE04zInNOj9Xn6+ktN1O6AFJUg=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=zeGqtRCYpRwCCsKNLkP7rQULRyp3JuJUtHXzOM+APDc7uagR7c0JQC92bMZV5KXE6\n\thoNVK9jee541oGkco/ouwsoimzozR/WQRlSAOzFrH5WQMk20LQKxoqB1MwiAHXtWIl\n\tPvAk6yNJ7Mcx4rK50JTIAs8oBr6AZLsCvMGh8BHoLBNypFA+46QrgaqRYzik/KdZE1\n\tDqOWd1BUJYD2wFoVXMQ5zt0HOl9PTi3hd45M81MqSgciTKbzJEWM95wgbhblTcFpzE\n\tf/r3OAq0KnPaXdtbHXtRwrgtypD0TuCVONPcexcsvXRVjEM5TSB5rKOyFam1IIFV7P\n\toLxJZwCLGSvYA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1647868122;\n\tbh=S0B5xzl8MmBeXgv9bHE04zInNOj9Xn6+ktN1O6AFJUg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=L6synlO8T0J2qqrJnJ4nH6ZxKE1Oj3JswPhrmjF6YVxA9NjPf/AQRv7Hj/zZzcARB\n\tp3h5vRjS77leuRszn69kU8F2resYx9h/FC8gfIQQewrGqsSWLoj+Ehb7aWB/0h7Prn\n\tk43JQLQbS+N/w2SCGUVQCGLVCCBnDB/OYxeI9rOM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"L6synlO8\"; dkim-atps=neutral","Date":"Mon, 21 Mar 2022 15:08:24 +0200","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<Yjh4yDqRmxeCi7l+@pendragon.ideasonboard.com>","References":"<20220321102702.1753800-1-naush@raspberrypi.com>\n\t<20220321102702.1753800-6-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220321102702.1753800-6-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v3 5/5] 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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":22341,"web_url":"https://patchwork.libcamera.org/comment/22341/","msgid":"<164786964227.2130830.10345500067316208132@Monstersaurus>","date":"2022-03-21T13:34:02","subject":"Re: [libcamera-devel] [PATCH v3 5/5] libcamera: v4l2_videodevice:\n\tEmpty the V4L2 buffer cache on streamOff()","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck (2022-03-21 10:27:02)\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> Tested-by: David Plowman <david.plowman@raspberrypi.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nOhh I love an assert addition. It catches things. I wonder if these are\ngood things or bad things to catch:\n\nProcessed 31 frames\nBuffer received\nBuffer received\nBuffer received\nBuffer received\nBuffer received\nBuffer received\nBuffer received\nBuffer received\nstderr:\n[339:43:53.887319781] [3693294]  WARN CameraSensorProperties camera_sensor_properties.cpp:148 No static properties available for 'Sensor A'\n[339:43:53.887388240] [3693294]  WARN CameraSensorProperties camera_sensor_properties.cpp:150 Please consider updating the camera sensor properties database\n[339:43:53.887416152] [3693294]  WARN CameraSensor camera_sensor.cpp:411 'Sensor A': Failed to retrieve the camera location\n[339:43:54.491916393] [3693294] FATAL default v4l2_videodevice.cpp:1854 /dev/video6[7:cap]: assertion \"cache_->isEmpty()\" failed in streamOff()\nBacktrace:\nlibcamera::V4L2VideoDevice::streamOff()+0x14c2 (../../src/libcamera/src/libcamera/v4l2_videodevice.cpp:1854)\nCaptureAsyncTest::run()+0x2dbb (../../src/libcamera/test/v4l2_videodevice/capture_async.cpp:82)\nTest::execute()+0x472 (../../src/libcamera/test/libtest/test.cpp:33)\nmain+0x2d2 (../../src/libcamera/test/v4l2_videodevice/capture_async.cpp:93)\n__libc_start_call_main+0x80 (../sysdeps/nptl/libc_start_call_main.h:58)\n__libc_start_main@@GLIBC_2.34+0x7d (../csu/libc-start.c:128)\n_start+0x25 (/home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/capture_async [0x000055a86d271fb5])\n――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n\n38/67 libcamera:v4l2_videodevice / buffer_sharing                OK              6.31s\n39/67 libcamera:v4l2_videodevice / v4l2_m2mdevice                FAIL            1.58s   killed by signal 6 SIGABRT\n>>> MALLOC_PERTURB_=171 /home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/v4l2_m2mdevice\n――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――\nstdout:\n\n\n\nReceived capture buffer\nReceived capture buffer\nReceived capture buffer\nReceived capture buffer\nstderr:\nOutput 31 frames\nCaptured 31 frames\n[339:44:02.406962689] [3693463] FATAL default v4l2_videodevice.cpp:1854 /dev/video9[9:cap]: assertion \"cache_->isEmpty()\" failed in streamOff()\nBacktrace:\nlibcamera::V4L2VideoDevice::streamOff()+0x14c2 (../../src/libcamera/src/libcamera/v4l2_videodevice.cpp:1854)\nV4L2M2MDeviceTest::run()+0x523d (../../src/libcamera/test/v4l2_videodevice/v4l2_m2mdevice.cpp:173)\nTest::execute()+0x472 (../../src/libcamera/test/libtest/test.cpp:33)\nmain+0x2bb (../../src/libcamera/test/v4l2_videodevice/v4l2_m2mdevice.cpp:205)\n__libc_start_call_main+0x80 (../sysdeps/nptl/libc_start_call_main.h:58)\n__libc_start_main@@GLIBC_2.34+0x7d (../csu/libc-start.c:128)\n_start+0x25 (/home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/v4l2_m2mdevice [0x000055b106567015])\n――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n\n--\nKieran\n\n\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 D16D1BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Mar 2022 13:34:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4DBE5604DC;\n\tMon, 21 Mar 2022 14:34:06 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 23306604C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Mar 2022 14:34:05 +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 BB0D9291;\n\tMon, 21 Mar 2022 14:34:04 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647869646;\n\tbh=+PslLBqOLgN9js4tcUMmtpcO3gxaOVQoR1E7NtsQczQ=;\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=1MotUEdem+CyONP8Df0JEmACU1FQm5lSqb3MugS76NGvLDpk0NUBqhEXdi8KFU5cU\n\tXzwQPEhd7C+YjoS8siTSzBYOImqzdeMhw33qstoKyjPYmGk18IyRtvsnZm6GXnWfbk\n\tNX49TdwcNP3UemkTbW4TOHr8kTOUi1HInlm7RHM+x7qWSXh5ZREM6DCdbAEEoEq3yj\n\tiB4VHPgq9wt4dgWiyaBRgw0J6Uk9HXpvVEogvenSpkK1WOzfmz2Q+Qo4dF5Cb7/aCJ\n\tEeCg/CRm5Vv3Zb8pUPknlNTia6ILuZfpHtEiwHGZVb7shX7PcVanVuKZb3gpagvH5L\n\tHa2qj078t/+aw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1647869644;\n\tbh=+PslLBqOLgN9js4tcUMmtpcO3gxaOVQoR1E7NtsQczQ=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=bIL0BbN90DOu/5l9u+vualQbl+gqo1bTNoVvUjniEr1d1Fl1A/FX6kYgnzusYzw5r\n\tSrHn7HdRQYBaPiWLq75/Bv2fTZt6XUbXmdAZ7mt/7c1Kjmo/jXTnt8YSJJGyhiB8Vh\n\t9tgV87T8j62lX9qQFBKP154ifk7Dqe2vxP1Ypoe8="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"bIL0BbN9\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220321102702.1753800-6-naush@raspberrypi.com>","References":"<20220321102702.1753800-1-naush@raspberrypi.com>\n\t<20220321102702.1753800-6-naush@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 21 Mar 2022 13:34:02 +0000","Message-ID":"<164786964227.2130830.10345500067316208132@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v3 5/5] 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>"}},{"id":22342,"web_url":"https://patchwork.libcamera.org/comment/22342/","msgid":"<CAEmqJPr4KJ_Pno4WQY_QeMWdTiPweuydDZG05fBb7_09n3mfBg@mail.gmail.com>","date":"2022-03-21T13:37:11","subject":"Re: [libcamera-devel] [PATCH v3 5/5] libcamera: v4l2_videodevice:\n\tEmpty the V4L2 buffer cache on streamOff()","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"On Mon, 21 Mar 2022 at 13:34, Kieran Bingham <\nkieran.bingham@ideasonboard.com> wrote:\n\n> Quoting Naushir Patuck (2022-03-21 10:27:02)\n> > When streamOff() is called, ensure the cache entires for the remaining\n> queued\n> > buffers are freed since this will not happen via the dequeueBuffer()\n> mechanism.\n> >\n> > Additionally, add a V4L2BufferCache::isEmpty() function and assert that\n> 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> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>\n> Ohh I love an assert addition. It catches things. I wonder if these are\n> good things or bad things to catch:\n>\n\nHmmm... How can this be possible?\nPresumably on streamOff(), all buffers must have been dequeued out of the\ndevice\ndriver, and the cache has to be empty.  Is that an invalid assumption?\n\nNaush\n\n\n>\n> Processed 31 frames\n> Buffer received\n> Buffer received\n> Buffer received\n> Buffer received\n> Buffer received\n> Buffer received\n> Buffer received\n> Buffer received\n> stderr:\n> [339:43:53.887319781] [3693294]  WARN CameraSensorProperties\n> camera_sensor_properties.cpp:148 No static properties available for 'Sensor\n> A'\n> [339:43:53.887388240] [3693294]  WARN CameraSensorProperties\n> camera_sensor_properties.cpp:150 Please consider updating the camera sensor\n> properties database\n> [339:43:53.887416152] [3693294]  WARN CameraSensor camera_sensor.cpp:411\n> 'Sensor A': Failed to retrieve the camera location\n> [339:43:54.491916393] [3693294] FATAL default v4l2_videodevice.cpp:1854\n> /dev/video6[7:cap]: assertion \"cache_->isEmpty()\" failed in streamOff()\n> Backtrace:\n> libcamera::V4L2VideoDevice::streamOff()+0x14c2\n> (../../src/libcamera/src/libcamera/v4l2_videodevice.cpp:1854)\n> CaptureAsyncTest::run()+0x2dbb\n> (../../src/libcamera/test/v4l2_videodevice/capture_async.cpp:82)\n> Test::execute()+0x472 (../../src/libcamera/test/libtest/test.cpp:33)\n> main+0x2d2 (../../src/libcamera/test/v4l2_videodevice/capture_async.cpp:93)\n> __libc_start_call_main+0x80 (../sysdeps/nptl/libc_start_call_main.h:58)\n> __libc_start_main@@GLIBC_2.34+0x7d (../csu/libc-start.c:128)\n> _start+0x25\n> (/home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/capture_async\n> [0x000055a86d271fb5])\n>\n> ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n>\n> 38/67 libcamera:v4l2_videodevice / buffer_sharing                OK\n>       6.31s\n> 39/67 libcamera:v4l2_videodevice / v4l2_m2mdevice                FAIL\n>       1.58s   killed by signal 6 SIGABRT\n> >>> MALLOC_PERTURB_=171\n> /home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/v4l2_m2mdevice\n> ――――――――――――――――――――――――――――――――――――― ✀\n> ―――――――――――――――――――――――――――――――――――――\n> stdout:\n>\n>\n>\n> Received capture buffer\n> Received capture buffer\n> Received capture buffer\n> Received capture buffer\n> stderr:\n> Output 31 frames\n> Captured 31 frames\n> [339:44:02.406962689] [3693463] FATAL default v4l2_videodevice.cpp:1854\n> /dev/video9[9:cap]: assertion \"cache_->isEmpty()\" failed in streamOff()\n> Backtrace:\n> libcamera::V4L2VideoDevice::streamOff()+0x14c2\n> (../../src/libcamera/src/libcamera/v4l2_videodevice.cpp:1854)\n> V4L2M2MDeviceTest::run()+0x523d\n> (../../src/libcamera/test/v4l2_videodevice/v4l2_m2mdevice.cpp:173)\n> Test::execute()+0x472 (../../src/libcamera/test/libtest/test.cpp:33)\n> main+0x2bb\n> (../../src/libcamera/test/v4l2_videodevice/v4l2_m2mdevice.cpp:205)\n> __libc_start_call_main+0x80 (../sysdeps/nptl/libc_start_call_main.h:58)\n> __libc_start_main@@GLIBC_2.34+0x7d (../csu/libc-start.c:128)\n> _start+0x25\n> (/home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/v4l2_m2mdevice\n> [0x000055b106567015])\n>\n> ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n>\n> --\n> Kieran\n>\n>\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\n> 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\n> 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>","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 CC6BDBDE17\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Mar 2022 13:37:30 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F2A20604E7;\n\tMon, 21 Mar 2022 14:37:29 +0100 (CET)","from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com\n\t[IPv6:2a00:1450:4864:20::22f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 480C4604C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Mar 2022 14:37:28 +0100 (CET)","by mail-lj1-x22f.google.com with SMTP id 17so4905436ljw.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Mar 2022 06:37:28 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647869850;\n\tbh=JADy/ap6Fp6vBWJwYPlYBhiFkUGQe4WD2UddZeVeCic=;\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=bECnwRCLJqprelYlQvzzxRuHSJLzLaH0AeAvmhe0N+wJKQVwLfxgky+h7zX83OypP\n\tD01xDUYG8otk5zMZXlmg0uZI31fi8IPuExhQrnQxO8ngf/XdbHA2C4sw0qUCzydq4G\n\tyQFNhgJXTIH8X9pvNURjKLU+KLkSAuCbWN4FU2fqvFLO5fCzgmfp1edtFbP5yybJ9K\n\t1OVxEEH4uJR1Kbp38608wLv2wgAzSMm4XRTI/0smuxJp1HuNlezeYsquJgRICEVmeW\n\t1LiJSnZOlcvZIl3IJhJTWtECJcwdURuBT5PtFF1tqumhBEgShSKJW1xnmx+pFQsEs1\n\tGyXvyDAFgHxTQ==","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=imxDahne6eC+zVL529gBrnutzaVLGLFucxab/RsRWQ0=;\n\tb=Sx2Jh8IonqiwyN8KzjmoAF1ItwWWJ0DrQvuguQ1Jrk4z5BKb1tzny0JJO715Q6kCzS\n\t3qUvH4oNkCINRrw8pJLROXcMPmAPSpxA5Hi0NXusJXVUJQsTpmLQn7uhDRbgpf9iCAV2\n\tHLwuot2WsnI7T0BA6zLlxo/ZQGZt+v8WnNgTh/J7jsJxTNPHfEBnWu7YXp6Uq0AIKxBF\n\tLJ++UWrdnn58kOF0gZLOePKCTc/5Phk2Xr2OZ/ahGccHLUAcnAxl0c+MtILEDhl2QP1I\n\tPwxa2GtG3TN1NqDZFMYyOJA6V4ZqZExLuBrwaXZW59p/ky0uSlz3CdBgi97HmCvSQOcC\n\tQorg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"Sx2Jh8Io\"; 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=imxDahne6eC+zVL529gBrnutzaVLGLFucxab/RsRWQ0=;\n\tb=OL1hEMDblJ9JDlUpL3/c4p/JZUBJJoahgcJu8pQ7IKCDFCyfIYfFoFKXGJl+tYhRdX\n\tmtvVWIY7A6qGqdMydtw/WWP8v2XVybVQ96CPJkty/72r9/RKeebzcwDNaiYKr5DbAN3g\n\tt1/ZfpCm4qy3k1o+X3GUSllEnvJksrChfkYtToVMU5F/dw0xC12AlyPXUGEQGhuejw4E\n\tyqrcY1QtLmTsjQi7ZZG9+C5ivAmEFL6fwhJRTgCujNakX+fLnrnLtYgAwZ3Jv6ExeiKm\n\t6sWj0Kr756EbPULYIPCEQYa+otMn4LLzeC4OzTOtxRs1TZUcWfLHPDAqt/OxL3CsU95G\n\tYDWg==","X-Gm-Message-State":"AOAM532KbAmUlEM9yCZmynIZhf437SHgKS++JUdSSh8lXwdF2ymVGgUH\n\t6I6i2xMXItw03xeYSTXBt62I/UHkhC64yt5dGFQZIA==","X-Google-Smtp-Source":"ABdhPJygzJwc/vbN9PhCxy2lmvcEEysuPawasPvFgp6R5DW+2fOoYezRBPR7MSVsBBrKnMznTdvYilKeUF5t5bIGOS0=","X-Received":"by 2002:a2e:9d83:0:b0:246:2c6:79df with SMTP id\n\tc3-20020a2e9d83000000b0024602c679dfmr14999922ljj.280.1647869847582;\n\tMon, 21 Mar 2022 06:37:27 -0700 (PDT)","MIME-Version":"1.0","References":"<20220321102702.1753800-1-naush@raspberrypi.com>\n\t<20220321102702.1753800-6-naush@raspberrypi.com>\n\t<164786964227.2130830.10345500067316208132@Monstersaurus>","In-Reply-To":"<164786964227.2130830.10345500067316208132@Monstersaurus>","Date":"Mon, 21 Mar 2022 13:37:11 +0000","Message-ID":"<CAEmqJPr4KJ_Pno4WQY_QeMWdTiPweuydDZG05fBb7_09n3mfBg@mail.gmail.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Content-Type":"multipart/alternative; boundary=\"000000000000e6d17205daba9813\"","Subject":"Re: [libcamera-devel] [PATCH v3 5/5] 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":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@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>"}},{"id":22344,"web_url":"https://patchwork.libcamera.org/comment/22344/","msgid":"<YjiDNu7LtakjxmeU@pendragon.ideasonboard.com>","date":"2022-03-21T13:52:54","subject":"Re: [libcamera-devel] [PATCH v3 5/5] libcamera: v4l2_videodevice:\n\tEmpty the V4L2 buffer cache on streamOff()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Mon, Mar 21, 2022 at 01:37:11PM +0000, Naushir Patuck via libcamera-devel wrote:\n> On Mon, 21 Mar 2022 at 13:34, Kieran Bingham wrote:\n> > Quoting Naushir Patuck (2022-03-21 10:27:02)\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> > > Tested-by: David Plowman <david.plowman@raspberrypi.com>\n> > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >\n> > Ohh I love an assert addition. It catches things. I wonder if these are\n> > good things or bad things to catch:\n> \n> Hmmm... How can this be possible?\n> Presumably on streamOff(), all buffers must have been dequeued out of the device\n> driver, and the cache has to be empty.  Is that an invalid assumption?\n\nIt doesn't sound invalid, but there's clearly a problem :-) You can\nreproduce this by running unit tests with \"ninja test\" (the assertion\nfails when running tests on an x86 machine with vimc, vim2m and vidid).\n\nAnd while at that, I forgot to note during review that the buffer cache\nunit test (test/v4l2_videodevice/buffer_cache.cpp) should be extended to\ntest the new isEmpty() function.\n\n> > Processed 31 frames\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > stderr:\n> > [339:43:53.887319781] [3693294]  WARN CameraSensorProperties camera_sensor_properties.cpp:148 No static properties available for 'Sensor A'\n> > [339:43:53.887388240] [3693294]  WARN CameraSensorProperties camera_sensor_properties.cpp:150 Please consider updating the camera sensor properties database\n> > [339:43:53.887416152] [3693294]  WARN CameraSensor camera_sensor.cpp:411 'Sensor A': Failed to retrieve the camera location\n> > [339:43:54.491916393] [3693294] FATAL default v4l2_videodevice.cpp:1854 /dev/video6[7:cap]: assertion \"cache_->isEmpty()\" failed in streamOff()\n> > Backtrace:\n> > libcamera::V4L2VideoDevice::streamOff()+0x14c2 (../../src/libcamera/src/libcamera/v4l2_videodevice.cpp:1854)\n> > CaptureAsyncTest::run()+0x2dbb (../../src/libcamera/test/v4l2_videodevice/capture_async.cpp:82)\n> > Test::execute()+0x472 (../../src/libcamera/test/libtest/test.cpp:33)\n> > main+0x2d2 (../../src/libcamera/test/v4l2_videodevice/capture_async.cpp:93)\n> > __libc_start_call_main+0x80 (../sysdeps/nptl/libc_start_call_main.h:58)\n> > __libc_start_main@@GLIBC_2.34+0x7d (../csu/libc-start.c:128)\n> > _start+0x25 (/home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/capture_async\n> > [0x000055a86d271fb5])\n> >\n> > ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n> >\n> > 38/67 libcamera:v4l2_videodevice / buffer_sharing                OK\n> >       6.31s\n> > 39/67 libcamera:v4l2_videodevice / v4l2_m2mdevice                FAIL\n> >       1.58s   killed by signal 6 SIGABRT\n> > >>> MALLOC_PERTURB_=171\n> > /home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/v4l2_m2mdevice\n> > ――――――――――――――――――――――――――――――――――――― ✀\n> > ―――――――――――――――――――――――――――――――――――――\n> > stdout:\n> >\n> >\n> >\n> > Received capture buffer\n> > Received capture buffer\n> > Received capture buffer\n> > Received capture buffer\n> > stderr:\n> > Output 31 frames\n> > Captured 31 frames\n> > [339:44:02.406962689] [3693463] FATAL default v4l2_videodevice.cpp:1854 /dev/video9[9:cap]: assertion \"cache_->isEmpty()\" failed in streamOff()\n> > Backtrace:\n> > libcamera::V4L2VideoDevice::streamOff()+0x14c2 (../../src/libcamera/src/libcamera/v4l2_videodevice.cpp:1854)\n> > V4L2M2MDeviceTest::run()+0x523d (../../src/libcamera/test/v4l2_videodevice/v4l2_m2mdevice.cpp:173)\n> > Test::execute()+0x472 (../../src/libcamera/test/libtest/test.cpp:33)\n> > main+0x2bb (../../src/libcamera/test/v4l2_videodevice/v4l2_m2mdevice.cpp:205)\n> > __libc_start_call_main+0x80 (../sysdeps/nptl/libc_start_call_main.h:58)\n> > __libc_start_main@@GLIBC_2.34+0x7d (../csu/libc-start.c:128)\n> > _start+0x25 (/home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/v4l2_m2mdevice\n> > [0x000055b106567015])\n> >\n> > ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\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\n> > 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;","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 6B5D5C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Mar 2022 13:53:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9F25A604DC;\n\tMon, 21 Mar 2022 14:53:13 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 53E03604C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Mar 2022 14:53:12 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B82C8291;\n\tMon, 21 Mar 2022 14:53:11 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647870793;\n\tbh=V6oDcR8LNEiu4Do42vt7PKkHdPYOBTlW9D8qGKM0zhc=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=LHUF/JwY4htTX5Whi2ScjujtAd0HnvMdJcPuk6QAFShGjKsuGpgQ9cNVcOVfayQLI\n\ttwcPoW//hTyKRgZVU+OxnloCSqkCY4tcwmuxSX6ybyNTGhx66Of/4VNqHzGDa25Fmf\n\tAPJ4LyRynpO+qPBPeMMXfGpecujakvlPeujYF6GSQPv9whJ+fUBNP9dWldpe2pUIu0\n\tvCuATsezVMaaNi85iMZ05VD7ybb3BAgTTtsbI+awa8E09/f0yNSTLqEHHulrzLOqcV\n\tJYmtTcHbFlPbH4zXsR4RFtkigSpQoVyz8fN4FZRXdIZci9wiU6QClEI0WxDLg6ic1D\n\tx+nGtEQnS9j4A==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1647870791;\n\tbh=V6oDcR8LNEiu4Do42vt7PKkHdPYOBTlW9D8qGKM0zhc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=jZsOEz0H9EIhdHQ7bP5l/0YDN/iO1Qt/xOHoAtWrcyOOKXgBu0h2bvtuKeRqI1xVY\n\tyjAU9H5lpAouMeWr8YDH72qsnI5eRVCrOOlIvo6rgppkGSIKWCHbEdkfhHrIaeuMcC\n\t5hsmjEblJCOsbf+sbNJ4NESLIc6ymZycn7+UeywE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"jZsOEz0H\"; dkim-atps=neutral","Date":"Mon, 21 Mar 2022 15:52:54 +0200","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<YjiDNu7LtakjxmeU@pendragon.ideasonboard.com>","References":"<20220321102702.1753800-1-naush@raspberrypi.com>\n\t<20220321102702.1753800-6-naush@raspberrypi.com>\n\t<164786964227.2130830.10345500067316208132@Monstersaurus>\n\t<CAEmqJPr4KJ_Pno4WQY_QeMWdTiPweuydDZG05fBb7_09n3mfBg@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<CAEmqJPr4KJ_Pno4WQY_QeMWdTiPweuydDZG05fBb7_09n3mfBg@mail.gmail.com>","Subject":"Re: [libcamera-devel] [PATCH v3 5/5] 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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.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>"}},{"id":22346,"web_url":"https://patchwork.libcamera.org/comment/22346/","msgid":"<164787128282.2130830.18440362405470538680@Monstersaurus>","date":"2022-03-21T14:01:22","subject":"Re: [libcamera-devel] [PATCH v3 5/5] libcamera: v4l2_videodevice:\n\tEmpty the V4L2 buffer cache on streamOff()","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck (2022-03-21 13:37:11)\n> On Mon, 21 Mar 2022 at 13:34, Kieran Bingham <\n> kieran.bingham@ideasonboard.com> wrote:\n> \n> > Quoting Naushir Patuck (2022-03-21 10:27:02)\n> > > When streamOff() is called, ensure the cache entires for the remaining\n> > queued\n> > > buffers are freed since this will not happen via the dequeueBuffer()\n> > mechanism.\n> > >\n> > > Additionally, add a V4L2BufferCache::isEmpty() function and assert that\n> > 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> > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >\n> > Ohh I love an assert addition. It catches things. I wonder if these are\n> > good things or bad things to catch:\n> >\n> \n> Hmmm... How can this be possible?\n\nI haven't looked close enough yet, but on the capture_async case, I\nthink the (application/test) code is requeing buffers unconditionally\nwhen they come back - without caring if they are cancelled - so it's\nnever considering that we are shutting down.\n\nWe might want to make sure that when we call streamOff we set some flag\nin V4L2VideoDevice that then prevents queueing buffers... as long as\nthat's expected...\n\nIt seems the V4L2 M2M test case is doing the same - unconditionally\nrequeueing buffers as long as it receives them.\n\nWhile an application shouldn't do this - it 'can' so I think it\nhighlights that we should be more defensive in the library and make sure\nthose calls to queueBuffer fail with an error.\n\nAs soon as we call streamOff we should enter a Stopping state and fail\nto accept any new calls to queueBuffer I believe.\n\n--\nKieran\n\n> Presumably on streamOff(), all buffers must have been dequeued out of the\n> device\n> driver, and the cache has to be empty.  Is that an invalid assumption?\n> \n> Naush\n> \n> \n> >\n> > Processed 31 frames\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > Buffer received\n> > stderr:\n> > [339:43:53.887319781] [3693294]  WARN CameraSensorProperties\n> > camera_sensor_properties.cpp:148 No static properties available for 'Sensor\n> > A'\n> > [339:43:53.887388240] [3693294]  WARN CameraSensorProperties\n> > camera_sensor_properties.cpp:150 Please consider updating the camera sensor\n> > properties database\n> > [339:43:53.887416152] [3693294]  WARN CameraSensor camera_sensor.cpp:411\n> > 'Sensor A': Failed to retrieve the camera location\n> > [339:43:54.491916393] [3693294] FATAL default v4l2_videodevice.cpp:1854\n> > /dev/video6[7:cap]: assertion \"cache_->isEmpty()\" failed in streamOff()\n> > Backtrace:\n> > libcamera::V4L2VideoDevice::streamOff()+0x14c2\n> > (../../src/libcamera/src/libcamera/v4l2_videodevice.cpp:1854)\n> > CaptureAsyncTest::run()+0x2dbb\n> > (../../src/libcamera/test/v4l2_videodevice/capture_async.cpp:82)\n> > Test::execute()+0x472 (../../src/libcamera/test/libtest/test.cpp:33)\n> > main+0x2d2 (../../src/libcamera/test/v4l2_videodevice/capture_async.cpp:93)\n> > __libc_start_call_main+0x80 (../sysdeps/nptl/libc_start_call_main.h:58)\n> > __libc_start_main@@GLIBC_2.34+0x7d (../csu/libc-start.c:128)\n> > _start+0x25\n> > (/home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/capture_async\n> > [0x000055a86d271fb5])\n> >\n> > ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n> >\n> > 38/67 libcamera:v4l2_videodevice / buffer_sharing                OK\n> >       6.31s\n> > 39/67 libcamera:v4l2_videodevice / v4l2_m2mdevice                FAIL\n> >       1.58s   killed by signal 6 SIGABRT\n> > >>> MALLOC_PERTURB_=171\n> > /home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/v4l2_m2mdevice\n> > ――――――――――――――――――――――――――――――――――――― ✀\n> > ―――――――――――――――――――――――――――――――――――――\n> > stdout:\n> >\n> >\n> >\n> > Received capture buffer\n> > Received capture buffer\n> > Received capture buffer\n> > Received capture buffer\n> > stderr:\n> > Output 31 frames\n> > Captured 31 frames\n> > [339:44:02.406962689] [3693463] FATAL default v4l2_videodevice.cpp:1854\n> > /dev/video9[9:cap]: assertion \"cache_->isEmpty()\" failed in streamOff()\n> > Backtrace:\n> > libcamera::V4L2VideoDevice::streamOff()+0x14c2\n> > (../../src/libcamera/src/libcamera/v4l2_videodevice.cpp:1854)\n> > V4L2M2MDeviceTest::run()+0x523d\n> > (../../src/libcamera/test/v4l2_videodevice/v4l2_m2mdevice.cpp:173)\n> > Test::execute()+0x472 (../../src/libcamera/test/libtest/test.cpp:33)\n> > main+0x2bb\n> > (../../src/libcamera/test/v4l2_videodevice/v4l2_m2mdevice.cpp:205)\n> > __libc_start_call_main+0x80 (../sysdeps/nptl/libc_start_call_main.h:58)\n> > __libc_start_main@@GLIBC_2.34+0x7d (../csu/libc-start.c:128)\n> > _start+0x25\n> > (/home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/v4l2_m2mdevice\n> > [0x000055b106567015])\n> >\n> > ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n> >\n> > --\n> > Kieran\n> >\n> >\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\n> > 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\n> > 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> >","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 5F318BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Mar 2022 14:01:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 003C5604DC;\n\tMon, 21 Mar 2022 15:01:26 +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 CE8EE604C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Mar 2022 15:01:25 +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 8CC26D6E;\n\tMon, 21 Mar 2022 15:01:25 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647871287;\n\tbh=BnbdDcPG8omFwcxQmnXIEPPY/Mzc/wM30MwDGN3t0so=;\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:Cc:\n\tFrom;\n\tb=c1Qr8+K4qbtTmNB0c43kh4SsGca8XQ0jNMaBDcKmMotwFMamkXdgP00NafioJWUn/\n\tBpnuWiHq2QrLTgBStpR4zMfPOQbeLV/PtbGsWJEopVzL2xzmthH1qeEHEX7wL7pq9+\n\tFG7APcMyX2XSGF9Zn10AWHCczTcOjKaKbJP0eLVM05XfIGAxBAQ9kJRAqB8Pq1O4Xz\n\tbu5K8+zFV+8FctqxvFVYUOpxzkXYtXlehYWqJI+Nz3dwslPcjob0yMUdtE+PkfZx0Q\n\tUeG3J+Gf3Jcb8yGLz/qUAzUjMgs/NQnajoWNdajC46S+R4S/TrTHzHjO870235CYbZ\n\tEkX3BMf3x7dEA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1647871285;\n\tbh=BnbdDcPG8omFwcxQmnXIEPPY/Mzc/wM30MwDGN3t0so=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=DQrn848q4sMg048JybOY/lAhlyv1wfEVodA4i48SxgZRhyjf8b3Hqb08Ww0BOu53+\n\tRqEz+cYhb4/SQ14LkXyVdw+D8rQxwbF75YMR4FplhMj02ZW/wA8hCmgTOLYw8lVtEz\n\tr6BX425zGsaqc0h4txDwHGGOiIgjyM3fbnbQIcSw="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"DQrn848q\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<CAEmqJPr4KJ_Pno4WQY_QeMWdTiPweuydDZG05fBb7_09n3mfBg@mail.gmail.com>","References":"<20220321102702.1753800-1-naush@raspberrypi.com>\n\t<20220321102702.1753800-6-naush@raspberrypi.com>\n\t<164786964227.2130830.10345500067316208132@Monstersaurus>\n\t<CAEmqJPr4KJ_Pno4WQY_QeMWdTiPweuydDZG05fBb7_09n3mfBg@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Date":"Mon, 21 Mar 2022 14:01:22 +0000","Message-ID":"<164787128282.2130830.18440362405470538680@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v3 5/5] 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>","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>"}},{"id":22350,"web_url":"https://patchwork.libcamera.org/comment/22350/","msgid":"<CAEmqJPrhcz1kCc34=2Ke0JJNaMef3Ez2+qdnY3Ja2M6xzxSfLA@mail.gmail.com>","date":"2022-03-21T16:05:46","subject":"Re: [libcamera-devel] [PATCH v3 5/5] libcamera: v4l2_videodevice:\n\tEmpty the V4L2 buffer cache on streamOff()","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"On Mon, 21 Mar 2022 at 14:01, Kieran Bingham <\nkieran.bingham@ideasonboard.com> wrote:\n\n> Quoting Naushir Patuck (2022-03-21 13:37:11)\n> > On Mon, 21 Mar 2022 at 13:34, Kieran Bingham <\n> > kieran.bingham@ideasonboard.com> wrote:\n> >\n> > > Quoting Naushir Patuck (2022-03-21 10:27:02)\n> > > > When streamOff() is called, ensure the cache entires for the\n> remaining\n> > > queued\n> > > > buffers are freed since this will not happen via the dequeueBuffer()\n> > > mechanism.\n> > > >\n> > > > Additionally, add a V4L2BufferCache::isEmpty() function and assert\n> that\n> > > 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> > > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > >\n> > > Ohh I love an assert addition. It catches things. I wonder if these are\n> > > good things or bad things to catch:\n> > >\n> >\n> > Hmmm... How can this be possible?\n>\n> I haven't looked close enough yet, but on the capture_async case, I\n> think the (application/test) code is requeing buffers unconditionally\n> when they come back - without caring if they are cancelled - so it's\n> never considering that we are shutting down.\n>\n> We might want to make sure that when we call streamOff we set some flag\n> in V4L2VideoDevice that then prevents queueing buffers... as long as\n> that's expected...\n>\n> It seems the V4L2 M2M test case is doing the same - unconditionally\n> requeueing buffers as long as it receives them.\n>\n\n> While an application shouldn't do this - it 'can' so I think it\n> highlights that we should be more defensive in the library and make sure\n> those calls to queueBuffer fail with an error.\n>\n> As soon as we call streamOff we should enter a Stopping state and fail\n> to accept any new calls to queueBuffer I believe.\n>\n\nPresumably in V4L2 you are allowed to queue buffers if the device is in a\n\"stream off\" state?  If so, I can't catch this in\nV4L2VideoDevice::queueBuffer()\nwith a simple test of if (!streaming_) ...\n\nHmmm, perhaps the ASSERT() test is not actually valid then?\n\n\n>\n> --\n> Kieran\n>\n> > Presumably on streamOff(), all buffers must have been dequeued out of the\n> > device\n> > driver, and the cache has to be empty.  Is that an invalid assumption?\n> >\n> > Naush\n> >\n> >\n> > >\n> > > Processed 31 frames\n> > > Buffer received\n> > > Buffer received\n> > > Buffer received\n> > > Buffer received\n> > > Buffer received\n> > > Buffer received\n> > > Buffer received\n> > > Buffer received\n> > > stderr:\n> > > [339:43:53.887319781] [3693294]  WARN CameraSensorProperties\n> > > camera_sensor_properties.cpp:148 No static properties available for\n> 'Sensor\n> > > A'\n> > > [339:43:53.887388240] [3693294]  WARN CameraSensorProperties\n> > > camera_sensor_properties.cpp:150 Please consider updating the camera\n> sensor\n> > > properties database\n> > > [339:43:53.887416152] [3693294]  WARN CameraSensor\n> camera_sensor.cpp:411\n> > > 'Sensor A': Failed to retrieve the camera location\n> > > [339:43:54.491916393] [3693294] FATAL default v4l2_videodevice.cpp:1854\n> > > /dev/video6[7:cap]: assertion \"cache_->isEmpty()\" failed in streamOff()\n> > > Backtrace:\n> > > libcamera::V4L2VideoDevice::streamOff()+0x14c2\n> > > (../../src/libcamera/src/libcamera/v4l2_videodevice.cpp:1854)\n> > > CaptureAsyncTest::run()+0x2dbb\n> > > (../../src/libcamera/test/v4l2_videodevice/capture_async.cpp:82)\n> > > Test::execute()+0x472 (../../src/libcamera/test/libtest/test.cpp:33)\n> > > main+0x2d2\n> (../../src/libcamera/test/v4l2_videodevice/capture_async.cpp:93)\n> > > __libc_start_call_main+0x80 (../sysdeps/nptl/libc_start_call_main.h:58)\n> > > __libc_start_main@@GLIBC_2.34+0x7d (../csu/libc-start.c:128)\n> > > _start+0x25\n> > >\n> (/home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/capture_async\n> > > [0x000055a86d271fb5])\n> > >\n> > >\n> ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n> > >\n> > > 38/67 libcamera:v4l2_videodevice / buffer_sharing                OK\n> > >       6.31s\n> > > 39/67 libcamera:v4l2_videodevice / v4l2_m2mdevice                FAIL\n> > >       1.58s   killed by signal 6 SIGABRT\n> > > >>> MALLOC_PERTURB_=171\n> > >\n> /home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/v4l2_m2mdevice\n> > > ――――――――――――――――――――――――――――――――――――― ✀\n> > > ―――――――――――――――――――――――――――――――――――――\n> > > stdout:\n> > >\n> > >\n> > >\n> > > Received capture buffer\n> > > Received capture buffer\n> > > Received capture buffer\n> > > Received capture buffer\n> > > stderr:\n> > > Output 31 frames\n> > > Captured 31 frames\n> > > [339:44:02.406962689] [3693463] FATAL default v4l2_videodevice.cpp:1854\n> > > /dev/video9[9:cap]: assertion \"cache_->isEmpty()\" failed in streamOff()\n> > > Backtrace:\n> > > libcamera::V4L2VideoDevice::streamOff()+0x14c2\n> > > (../../src/libcamera/src/libcamera/v4l2_videodevice.cpp:1854)\n> > > V4L2M2MDeviceTest::run()+0x523d\n> > > (../../src/libcamera/test/v4l2_videodevice/v4l2_m2mdevice.cpp:173)\n> > > Test::execute()+0x472 (../../src/libcamera/test/libtest/test.cpp:33)\n> > > main+0x2bb\n> > > (../../src/libcamera/test/v4l2_videodevice/v4l2_m2mdevice.cpp:205)\n> > > __libc_start_call_main+0x80 (../sysdeps/nptl/libc_start_call_main.h:58)\n> > > __libc_start_main@@GLIBC_2.34+0x7d (../csu/libc-start.c:128)\n> > > _start+0x25\n> > >\n> (/home/kbingham/iob/libcamera/ci/integrator/builds/unit-tests/test/v4l2_videodevice/v4l2_m2mdevice\n> > > [0x000055b106567015])\n> > >\n> > >\n> ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n> > >\n> > > --\n> > > Kieran\n> > >\n> > >\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\n> > > 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\n> > > 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 =\n> 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> > >\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 76DACC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Mar 2022 16:06:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC403604DB;\n\tMon, 21 Mar 2022 17:06:05 +0100 (CET)","from mail-lj1-x234.google.com (mail-lj1-x234.google.com\n\t[IPv6:2a00:1450:4864:20::234])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8B7A8604C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Mar 2022 17:06:03 +0100 (CET)","by mail-lj1-x234.google.com with SMTP id 25so20507805ljv.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Mar 2022 09:06:03 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647878765;\n\tbh=ajHUGy5roHklHGqOrfHlA9xPjlWsZ4zu2MK9jOI7oe4=;\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=yq8+sYin2DxCz8YooBgbA8OsNg7zj3tMurPAk66cglglPwIzXceiwLAbxI+/qUdA7\n\tr85JchCvX2XcgsPqiFiHJSdiDCkFOUg/5+IvzKvNk7EStULLuUuzFaK/Omk2sOrtbI\n\tB/19HPRiVkF/1IZQDZUoxWFhqeZ88ENAEHlDJ5QeHFoVWDeyxckD6AR0sDK/SOqwF6\n\thPnasNmktCsUzq1gPa0g+b42M92SkRwdozwBQBdMAnpf4PllhW1Qkip0mZGcE3SRXK\n\tVo0gVFCb1CqoDGi8XnAsjrjWtcbvJEyhOi60u9jvwYwk8Ud8LxNDCX1C3n2pgJfMI1\n\tdcZe7vjSpAS9A==","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=/R9Dj4yDuB6M2LM0+VP6pMg2v2bEWwK/n9aGvU3Jnlk=;\n\tb=d+C/kVVuQD58S6M4Y3YxptKafAmNN+9mFlFtj/rziPg0dgG6FJ/XvpK4MGhbrfzGjr\n\t5F4tEF27uDQhLphn6YxJOiBiL6TioeWiaed0AOS4xrwIgzYJ5GwWWlOzCFhSL3nvPDep\n\tTBEouJ02kJXMsFu4FRDdYHnYZQ6e2OXYZWZn3GEeCA0edfLTWbcHqUHyOlYi26Alj0c9\n\tzWYYvnARUTvJFfJEmVVtDGTt91lxZgtcdeyp3nLvWsdAwgz2YB+AhqthWPayGWx+vF9n\n\t0HxkpFm1XP2a1xIhLDtktN1Mi7u5z0XeijbF3N+o1YZoIzNqw3LjWI0t4PeTndx9U4TK\n\taLrQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"d+C/kVVu\"; 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=/R9Dj4yDuB6M2LM0+VP6pMg2v2bEWwK/n9aGvU3Jnlk=;\n\tb=G88V3vdhqFqDUkHILp22YKyxC/x94+0rzRiQm82YsR+kqtIP8JBNSVv4aNphVa4F63\n\tIBqIOukFNSGfTkT64L/SVlGuRpVOExNRucDjY5FDATBx7aKcx9uxcMLDLrCjvYlE20zl\n\th9PcojaWxRJ4Lnt8hX/oBQq6Y3LpIWhE7kACwV6u/XYEoXSwkDP5MFyaCcKySM9d6H6q\n\tH61fAExhv01YfmeM75ESOrKMMJ9RecczkG8STazzfOLDVN9E6SiwjH8Ci3k1s0N6kFjI\n\t27ai05dksqTngRZrHCdZPJSGt/eFNOYz3H1+gYAj00X44OHprpKbGPnNtdqZKIehlhwV\n\tZq8Q==","X-Gm-Message-State":"AOAM533DksDsd2tM1ZcCcVAzOMBX7pXCof2iimLFc6YDw2iK0MOPqw8b\n\temKxLtuvAdbt1njP3bXeF4qCDXXCnHAjtGC9USbMhw==","X-Google-Smtp-Source":"ABdhPJyS8A1FfINnAuubUERlB6l3hwsU4vkl7XJsCY5dzhaNP4PK/eAOsQhjr5Af+bBn2DPfGgIfZ3pE4OB/LVcYyLI=","X-Received":"by 2002:a05:651c:b10:b0:247:f37f:f595 with SMTP id\n\tb16-20020a05651c0b1000b00247f37ff595mr16117938ljr.444.1647878762552;\n\tMon, 21 Mar 2022 09:06:02 -0700 (PDT)","MIME-Version":"1.0","References":"<20220321102702.1753800-1-naush@raspberrypi.com>\n\t<20220321102702.1753800-6-naush@raspberrypi.com>\n\t<164786964227.2130830.10345500067316208132@Monstersaurus>\n\t<CAEmqJPr4KJ_Pno4WQY_QeMWdTiPweuydDZG05fBb7_09n3mfBg@mail.gmail.com>\n\t<164787128282.2130830.18440362405470538680@Monstersaurus>","In-Reply-To":"<164787128282.2130830.18440362405470538680@Monstersaurus>","Date":"Mon, 21 Mar 2022 16:05:46 +0000","Message-ID":"<CAEmqJPrhcz1kCc34=2Ke0JJNaMef3Ez2+qdnY3Ja2M6xzxSfLA@mail.gmail.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Content-Type":"multipart/alternative; boundary=\"00000000000046703505dabcace4\"","Subject":"Re: [libcamera-devel] [PATCH v3 5/5] 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":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@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>"}}]