{"id":15488,"url":"https://patchwork.libcamera.org/api/patches/15488/?format=json","web_url":"https://patchwork.libcamera.org/patch/15488/","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":"<20220321102702.1753800-6-naush@raspberrypi.com>","date":"2022-03-21T10:27:02","name":"[libcamera-devel,v3,5/5] 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/15488/mbox/","series":[{"id":2977,"url":"https://patchwork.libcamera.org/api/series/2977/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2977","date":"2022-03-21T10:26:57","name":"Raspberry Pi: Efficient start/stop/start sequences","version":3,"mbox":"https://patchwork.libcamera.org/series/2977/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15488/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15488/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 B7BEFC3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Mar 2022 10:27:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 49CDF604E6;\n\tMon, 21 Mar 2022 11:27:14 +0100 (CET)","from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com\n\t[IPv6:2a00:1450:4864:20::42c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3963A604DC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Mar 2022 11:27:09 +0100 (CET)","by mail-wr1-x42c.google.com with SMTP id d7so19994461wrb.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Mar 2022 03:27:09 -0700 (PDT)","from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:77bd:7c6c:a8b9:8855])\n\tby smtp.gmail.com with ESMTPSA id\n\tv10-20020a056000144a00b00203df06cf9bsm13530115wrx.106.2022.03.21.03.27.08\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 21 Mar 2022 03:27:08 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647858434;\n\tbh=ybhJApFq6t3QGdVlfyHFnQV5QqIRXyAUrlITt1hjF2U=;\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=RotIF6IZJF9W+WvGGG1yLm5ZV3B8T6u1C9Kq/WWAJb3lliQb6upxIOwOu9ncLelYb\n\ttAtm1as6WrU9vpGci7peImiUnUPw9vkIv6vrEa7F7yAmowlDvKj9SDBg4Oeti203ww\n\tbpxnQ/SGNlk7JYinlcohtG95iavFzM6naLrrv8VPFbk02wB9u0R/r2DnIQb3Y1vyWc\n\tmlndchPfzZyOT3y0DT5bx57hjNzOfJ1VqLNU+uIzHexqZkLH92a8tCSLi/RwhMq2+6\n\tg/NTvnGsQ3zVDmyQ/iAOCiOGAxdDahXJt/JYE+nyN83GwyfAbFhBPcwn7n+SHWn4IH\n\tLGbSJ4Ld3EQ6Q==","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=dA347M0pNyRz++zk0ljRkwOtA4uH8Am/Ng8Xi1OF2Zk=;\n\tb=J/ZxzWakchSgxczPX10qbQc40aDgHl5HKgWh+cA8cvtdDOSYHYMCW18GTzwal7tAHj\n\tyeTuvSlnCLGwG5GfkaBlLqurScESGcE5MhOchKD1dvmkpbLpLx+C3Ztd0uN7OEfVgWuf\n\ttKlbWjQMh3GShbb5xw/FBfL22kSBJrHFMofbJpAFEWJkN/q3A41Tkrw+ovnLFb7SksiT\n\teb62kOi3dXPUyp3E/mjKb+THKYv0HDCa8BEpaQgdEmrdYmGMvQNGhd2hckHhoUE5JnML\n\tS4EOwmVo54ffMxZ/QcwY/lHQIzDxZDVS01SCso9dLN6nZlOzq5Kwb1DKZ9rBKBlkl0+F\n\tBCwQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"J/ZxzWak\"; 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=dA347M0pNyRz++zk0ljRkwOtA4uH8Am/Ng8Xi1OF2Zk=;\n\tb=bLHAreIf5UxNAnuO4pFVGXm/nWGgexgG373m1OaGMLheFaxlzSI8PmN6yf67/+u84S\n\t/UKZtYWbyswsJYFsTnQhbviu8oKPabog/syoyTYu/n8RziGjzGwNnhWjHQAhfOHoYXtX\n\tqsB3JqaMvRNW/vF76zd5tIlXJw1a0ftnc3Q2i5DwoRLYNRmbXmMKaLVkCyk2768MCDYN\n\teP/bmYWVlYvgjawLZlKe+KONf/+DyGswnSVHmoGCiasGxF0ruXezbs89DhtY9VgylXng\n\tccHX4QZIrmpZwKItWfBIMx4SCYIZOLThhugxoz2+R6cXQDGInryKYKTKcJDTh+TROTpI\n\tSdxg==","X-Gm-Message-State":"AOAM530NdJVNruLjtRroVBhrHutnLc2mxcSQvDLrHdRLCNVHb66xRdGU\n\tjFo8lGERc51TIKgC2WAURA3WodLQaY3EpA==","X-Google-Smtp-Source":"ABdhPJyPSWzxUDbDP5W3BvNPSJ2QCJjaIDE+8oriqpHvOc2J6QGrwCMNwfaGufmh0hXnQuLtn+FiSg==","X-Received":"by 2002:adf:fe81:0:b0:1f0:246e:ae5 with SMTP id\n\tl1-20020adffe81000000b001f0246e0ae5mr17598156wrr.652.1647858428688; \n\tMon, 21 Mar 2022 03:27:08 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 21 Mar 2022 10:27:02 +0000","Message-Id":"<20220321102702.1753800-6-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20220321102702.1753800-1-naush@raspberrypi.com>","References":"<20220321102702.1753800-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 5/5] 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 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>\nTested-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-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(+)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 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 \n private:\n \tclass Entry\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 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;\n","prefixes":["libcamera-devel","v3","5/5"]}