From patchwork Mon Mar 21 10:27:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15488 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B7BEFC3263 for ; Mon, 21 Mar 2022 10:27:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 49CDF604E6; Mon, 21 Mar 2022 11:27:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647858434; bh=ybhJApFq6t3QGdVlfyHFnQV5QqIRXyAUrlITt1hjF2U=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=RotIF6IZJF9W+WvGGG1yLm5ZV3B8T6u1C9Kq/WWAJb3lliQb6upxIOwOu9ncLelYb tAtm1as6WrU9vpGci7peImiUnUPw9vkIv6vrEa7F7yAmowlDvKj9SDBg4Oeti203ww bpxnQ/SGNlk7JYinlcohtG95iavFzM6naLrrv8VPFbk02wB9u0R/r2DnIQb3Y1vyWc mlndchPfzZyOT3y0DT5bx57hjNzOfJ1VqLNU+uIzHexqZkLH92a8tCSLi/RwhMq2+6 g/NTvnGsQ3zVDmyQ/iAOCiOGAxdDahXJt/JYE+nyN83GwyfAbFhBPcwn7n+SHWn4IH LGbSJ4Ld3EQ6Q== Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3963A604DC for ; Mon, 21 Mar 2022 11:27:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="J/ZxzWak"; dkim-atps=neutral Received: by mail-wr1-x42c.google.com with SMTP id d7so19994461wrb.7 for ; Mon, 21 Mar 2022 03:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dA347M0pNyRz++zk0ljRkwOtA4uH8Am/Ng8Xi1OF2Zk=; b=J/ZxzWakchSgxczPX10qbQc40aDgHl5HKgWh+cA8cvtdDOSYHYMCW18GTzwal7tAHj yeTuvSlnCLGwG5GfkaBlLqurScESGcE5MhOchKD1dvmkpbLpLx+C3Ztd0uN7OEfVgWuf tKlbWjQMh3GShbb5xw/FBfL22kSBJrHFMofbJpAFEWJkN/q3A41Tkrw+ovnLFb7SksiT eb62kOi3dXPUyp3E/mjKb+THKYv0HDCa8BEpaQgdEmrdYmGMvQNGhd2hckHhoUE5JnML S4EOwmVo54ffMxZ/QcwY/lHQIzDxZDVS01SCso9dLN6nZlOzq5Kwb1DKZ9rBKBlkl0+F BCwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dA347M0pNyRz++zk0ljRkwOtA4uH8Am/Ng8Xi1OF2Zk=; b=bLHAreIf5UxNAnuO4pFVGXm/nWGgexgG373m1OaGMLheFaxlzSI8PmN6yf67/+u84S /UKZtYWbyswsJYFsTnQhbviu8oKPabog/syoyTYu/n8RziGjzGwNnhWjHQAhfOHoYXtX qsB3JqaMvRNW/vF76zd5tIlXJw1a0ftnc3Q2i5DwoRLYNRmbXmMKaLVkCyk2768MCDYN eP/bmYWVlYvgjawLZlKe+KONf/+DyGswnSVHmoGCiasGxF0ruXezbs89DhtY9VgylXng ccHX4QZIrmpZwKItWfBIMx4SCYIZOLThhugxoz2+R6cXQDGInryKYKTKcJDTh+TROTpI Sdxg== X-Gm-Message-State: AOAM530NdJVNruLjtRroVBhrHutnLc2mxcSQvDLrHdRLCNVHb66xRdGU jFo8lGERc51TIKgC2WAURA3WodLQaY3EpA== X-Google-Smtp-Source: ABdhPJyPSWzxUDbDP5W3BvNPSJ2QCJjaIDE+8oriqpHvOc2J6QGrwCMNwfaGufmh0hXnQuLtn+FiSg== X-Received: by 2002:adf:fe81:0:b0:1f0:246e:ae5 with SMTP id l1-20020adffe81000000b001f0246e0ae5mr17598156wrr.652.1647858428688; Mon, 21 Mar 2022 03:27:08 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:77bd:7c6c:a8b9:8855]) by smtp.gmail.com with ESMTPSA id v10-20020a056000144a00b00203df06cf9bsm13530115wrx.106.2022.03.21.03.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 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 Subject: [libcamera-devel] [PATCH v3 5/5] libcamera: v4l2_videodevice: Empty the V4L2 buffer cache on streamOff() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When streamOff() is called, ensure the cache entires for the remaining queued buffers are freed since this will not happen via the dequeueBuffer() mechanism. Additionally, add a V4L2BufferCache::isEmpty() function and assert that the cache is empty at the end of the streamOff() call. Signed-off-by: Naushir Patuck Tested-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_videodevice.h | 1 + src/libcamera/v4l2_videodevice.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 2d2ccc477c91..37747c0b2f27 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -126,6 +126,7 @@ public: int get(const FrameBuffer &buffer); void put(unsigned int index); + bool isEmpty() const; private: class Entry diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 5f36ee20710d..9da82697e7f0 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -262,6 +262,19 @@ void V4L2BufferCache::put(unsigned int index) cache_[index].free_ = true; } +/** + * \brief Check if all the entries in the cache are unused + */ +bool V4L2BufferCache::isEmpty() const +{ + for (auto const &entry : cache_) { + if (!entry.free_) + return false; + } + + return true; +} + V4L2BufferCache::Entry::Entry() : free_(true), lastUsed_(0) { @@ -1832,10 +1845,13 @@ int V4L2VideoDevice::streamOff() for (auto it : queuedBuffers_) { FrameBuffer *buffer = it.second; + cache_->put(it.first); buffer->metadata_.status = FrameMetadata::FrameCancelled; bufferReady.emit(buffer); } + ASSERT(cache_->isEmpty()); + queuedBuffers_.clear(); fdBufferNotifier_->setEnabled(false); streaming_ = false;