From patchwork Tue Mar 22 09:22:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15504 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 74255C3266 for ; Tue, 22 Mar 2022 09:23:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0A095604E9; Tue, 22 Mar 2022 10:23:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940990; bh=kfT4ZWkCPG3/gdZFNdt4nHwbshCKHdwdNoIP/9MpcQo=; 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=KdcIFFaJg/Ye3SeZBBuqFnmZtgei1ezxNcLix2igg5wLBit3QJaZNVouts3puL+f3 qJ9RU0HGaGlsFbPRWaE26sq14SIAX46399WKW17JvUp22SQzpzevkOxI0ow3dcD/dN Z90yZ+1axuDgCT9UWurRC+XHYvkLjuwtjvvz5ovTF3SBZiMUA/zSnqGC63R9k6QKMh iUaGJp0yylR+pDG69+cDY3PQMuK4QEIgdjwLjY/ycnwYUuzLbpP0jZDlKhg4entJ0K 8obfoRS4KO9qRR8gVm/Xytlv6HEV49+v8JQKWHPlHnmei2kalKGq9qy+Af2kbRoIWp oCENUQN7AYv4g== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 20DD4632E5 for ; Tue, 22 Mar 2022 10:23:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DbbwHCmY"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id m26-20020a05600c3b1a00b0038c8b999f58so1033279wms.1 for ; Tue, 22 Mar 2022 02:23:06 -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=TdgSbJYfrkGKhFpU5Csv2hwqt6vlahDqMHurCng86MM=; b=DbbwHCmYLyz/BFn+zYVIYC/ai9PJfZRRla5bZXCIII4iUCJRjExAZUdmtRzRv8GvzG OTQFktlF1mLJRYY0T5Vt5F7tL/cOnICdSrYtDHwFd+1SLBIRD8FUgakH/xMLdzSQiiNt lHGVAneleOk12bZRR3CA79sp7Z4EbHrjhAl7iaEOFSDN6AmnALZiBkmlld9oq7r5SkxY Q4Q+8xfv0M1ge4ramwAsZLSmsYRfHGiXMNpiS0H+2BO29EcIfX7Xkuid0+aFtMvdM26h qZoYxeOAIdtvHCZhmbcyDWhx3uTrRxTnAShHYO9ePj5eO2kzXDJojSU2tf0N1mk72RDv OWBA== 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=TdgSbJYfrkGKhFpU5Csv2hwqt6vlahDqMHurCng86MM=; b=UsWoWX4c3befrl7SVgOEhe4uocOOPjaUs3MAf125TuvIbVY4knQjz27L/aBJKfyLWH S4JrMn0SNn0kpporRaUkBsZ57qw3zptS5i2TFmreW74KT3iA6VUTFWDRWcpgKQ2xasdi IrfRrMMvchdOSrjUtesTMkFzs+1Y26644Kg+DwK2cXS5DXrrZPI88nTMfHUwsKcADAgv aR/VCjl64a8DOEkcoEo9s9LYPujR2BPdAgXk91b+w0A5qvFbAI/TbyddfkvWdrRy4GpI BoBM08MBFi4feoIugCalKfkmzPXY/7NTAo4OvQUXce+EuBo/CIAK4nnNfjy1uabECeck c7EQ== X-Gm-Message-State: AOAM5310UjhP9kwZBAgns94MExsd7l5Suan+0ayBlvO9CW+F4orX27TO lcmT9IXUK6+hAQCHtua9Z7NEoysjBS0Gqw== X-Google-Smtp-Source: ABdhPJzbDNnj7MqqKrq3iGw0zqRPh0kul1HrO7Ep96KVUpUOVnWNvFtpXQb1ucyHygh+hTPKjBX9NQ== X-Received: by 2002:a05:600c:2244:b0:38c:a3ff:ef67 with SMTP id a4-20020a05600c224400b0038ca3ffef67mr2694603wmm.122.1647940985582; Tue, 22 Mar 2022 02:23:05 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:05 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:56 +0000 Message-Id: <20220322092257.2713521-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 7/8] 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 entries 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 32e022543385..60d62212bfe1 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -124,6 +124,7 @@ public: V4L2BufferCache(const std::vector> &buffers); ~V4L2BufferCache(); + bool isEmpty() const; int get(const FrameBuffer &buffer); void put(unsigned int index); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 1516be129d73..a384de7507ba 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -201,6 +201,19 @@ V4L2BufferCache::~V4L2BufferCache() LOG(V4L2, Debug) << "Cache misses: " << missCounter_; } +/** + * \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; +} + /** * \brief Find the best V4L2 buffer for a FrameBuffer * \param[in] buffer The FrameBuffer @@ -1842,10 +1855,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); state_ = State::Stopped;