From patchwork Mon Mar 7 12:46:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15431 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 29282C3261 for ; Mon, 7 Mar 2022 12:46:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D696761192; Mon, 7 Mar 2022 13:46:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1646657206; bh=j1yifcg2H5tqFnHv5TxW4VZaUjGkXmlKngikuNYDKKU=; 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=VFdU59WONTNb0hMSL+4X/6LbD3vujt65mXWqeKA+CFnrmZs1gM1O7wenqBZBNwmvi 8rpuw8+47RglGsCFMmH3orXxDFlLOEGWfs9P2cRgPKOZYlfbE5pc7awYDW19cethH9 NaKQ/Yf8sfKQPSZf4amFiyAU9r8i7iR/3Cuog/iW4W+mtVhqml3ArGkWSqZLXUfEL6 0f31PUfZAn16Svln0mIrwSQU8B7hI26eBBrlogOHdHHtEmQ0aBeS4vm+mZcQ2mVjAh ptx9TykYEEhJoTwd3VTNJ6zshw1MT61xJ9LP1qhRRpmW1vdHV+eeQ9yUW6MTHHc4h1 uNRc8D14DwugA== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BBDB761189 for ; Mon, 7 Mar 2022 13:46:43 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="f9lzWf3G"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id u1so23051409wrg.11 for ; Mon, 07 Mar 2022 04:46:43 -0800 (PST) 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=PRkhqrlp04FHuT3lgzDxfAUE/vo6bJn9nSQyQ3qDDVQ=; b=f9lzWf3G7OIDRAoSKWl1YLJqgzVINBtEdrq+w69QuV5t/v4AkHf4qAoXBz7deLa4ZP VRCwjURp6ufZ5teFeV3TllWt2EDL1nzNmYZ+RWYNUbNrkb/RIoHR+Vmsu4a/eSxitl5R cvZrAgakNNzIUjhlDkhgiR5mcDH84VpcHvN9Isjce0PNbd/mat9B0e2a71scRgsP7xkY HRv71Q09YF1xYEXALKgyVaDAHnryxyMm3nzkqw1u8N5wkBuityoe7qHyvm/2AU+1MGZi /QfcKsiyY4/QxBnXJJg1xTkORPJf6LCiaPwtalkip2J7axsa+6RuXhhDFdhbVeFE02PD 6LXA== 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=PRkhqrlp04FHuT3lgzDxfAUE/vo6bJn9nSQyQ3qDDVQ=; b=ayWcLpj5wJnz+Ww0AVS3bIIioA2rYouq7G91nyCzi6LF49KqQz2DVjQuhjNXIAw6e7 T6fLp6dx/xiNBUrbpY8TRA6vif3TZnatG4KQiMI0ORQ479D6m4BUVH7R/NYnzfQYnMz/ I4tOVGZQ6rPMJh2sU0wNkIv89925fa7f5wajQ0weWluGvaEKFEv+ucMTn4fKSPNWxrc5 KwT4Vlrna2U6wCShiqUaYHZeNVH/ASZDLj4dDVfnT3aKXLL9/wuEW09t7TSFmrUP5U7x QDK2CF4wdVaA/2CSY9MbaClfJD0PrzrqIUePc5WzvsKUF3zaxkv9l3C34BusEkVES/EM nTVQ== X-Gm-Message-State: AOAM531MWUQKmDvFEOy9lUVlMVwHQiT/is/nyQvYYROwhjW9apsaNl5C Jw03b1KMgoLYfq/qqb7g98f0AdK3XM+OZA== X-Google-Smtp-Source: ABdhPJxke08C4cGunZzAowhxRMzVxMnRtJWGXX3Kkrrxocln93zHO1Htesai7RgbKdttpuheFhpVQw== X-Received: by 2002:a5d:538b:0:b0:1f1:e60b:20c2 with SMTP id d11-20020a5d538b000000b001f1e60b20c2mr5982636wrv.294.1646657203211; Mon, 07 Mar 2022 04:46:43 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:c644:e9b3:de0b:54c5]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b0037c4e2d3baesm19759582wma.19.2022.03.07.04.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 04:46:42 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Mar 2022 12:46:33 +0000 Message-Id: <20220307124633.115452-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307124633.115452-1-naush@raspberrypi.com> References: <20220307124633.115452-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 6/6] 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 --- 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;