From patchwork Thu Mar 17 14:08:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15476 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 18AD8C3264 for ; Thu, 17 Mar 2022 14:08:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C8A7F632EC; Thu, 17 Mar 2022 15:08:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647526120; bh=Y82iiUEJJo6jzF5KeFHe8+WlpcmdbOvrdS0L5r4/L2g=; 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=gcAI3qjDpD6hbkXDzSoUZLkCcpRPXVcPb9YWM7bJHiL5g0QEnRYxSitkWIDnwkDfv LVUNOW8PccHO/W3aQp0ztowMfd6CXhETN0BYM46CvBR0MT7dhc6JWuFWXn+ZRUoDgM uergrUqBtVZVFyPCctDDYmJcAXPru7YkU5K+U/NbYxshy1hxQzfb6MK1qLaHO0f5uz i5I2iwLgZu7I7bs0uy1JGZm+cspaqHOs0CL9zO2XRcSDlNe9f5d/hJ0bHI4KQJF5tV rRZEf+HbAx5pCqd11c20SOERy35Z/KH7mlIHf/Zqq7X6a8yuiQjjrl/hLNVbJvizoq Hv5LdWmdPwldA== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D4A48632E6 for ; Thu, 17 Mar 2022 15:08:37 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lqaOCxgd"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id u10so7524542wra.9 for ; Thu, 17 Mar 2022 07:08:37 -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=QA3Po4T5fYY/+GjRjk1tO1oLz80EHEdU9NtOOneB35c=; b=lqaOCxgdmHWzlpwF8s+fQi9xBt+4+pyvDScYb5BZ/4u9I2LZGrN1oYOKOXdinkVJE4 JvLuPS+Nk+7K2ehoM8sYRdxcS6cNGqM6nOcsjXYSlkueQ8eMcb2vA4J/Crd8jSt8Rr6y IDS/LhYT5CwLBDQgEZsV3jOCmWzuNmffOVNHHmWjGHmzfk3lK18tSReRuc1EbtvHHD5J yiIK18u7480Z0xOOhLbJpP290M+NuATNvXMVGYoINenuFdV2KpXDdzlvlkDJtbKDJe/k ySGeELsmX5pEbC70EGH9u8qMJ4oFy0ZkTu+UAG4Us0SeDh+WM92WJKrF7dgn5JJk1Sth kGsA== 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=QA3Po4T5fYY/+GjRjk1tO1oLz80EHEdU9NtOOneB35c=; b=5oYggDB6uYdkACuqqF/6Mr8CLqIl0FPepYuBiPmIf2XYrmNRzGDzGQiSAOlx1Si1eb lRwjTdeKajbGbFVNr+sXOf2hkW3oL1CKB0dgpgyOxd54HasAh9Cp14XAQKgbP4qLMgWu GI4eshT2YskRsmXwTVWH1HA+dmpVpdD4iZr52bMJkln9glNI4knNb7p9vNgCPYDI3obB vyfJ83TgWEN9vR6RnBVyIWEWI+MF3J55WU08BlzqLRkHGd7oWaFWtxZSkVjZJypPzVAk zL+1/EGabEG0umAgMvKbcgXQqtumgT68KZ2lZF4VAL3Ala/KcpfjuI/DiVlGjvUiBdO9 6gFw== X-Gm-Message-State: AOAM532On3EFS13qUkU6QVTod9E8M+IWWibh1RclLJMUXnnPywEvlfZX 5ozD8m5pBa/Jq6xUgF0Tu5J2YaxSgINlRg== X-Google-Smtp-Source: ABdhPJzudLNbX4j7rMGyPo6Nkzk+nNl8AUraXgS8Xl6wtVkwmYXiGUhGWYZYAlXYROnw8g5H+I3Euw== X-Received: by 2002:a05:6000:381:b0:203:84bf:3faa with SMTP id u1-20020a056000038100b0020384bf3faamr4242565wrf.324.1647526117363; Thu, 17 Mar 2022 07:08:37 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:371b:8e01:111f:5322]) by smtp.gmail.com with ESMTPSA id z5-20020a05600c0a0500b0037fa93193a8sm5287831wmp.44.2022.03.17.07.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 07:08:36 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Mar 2022 14:08:27 +0000 Message-Id: <20220317140827.1835029-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220317140827.1835029-1-naush@raspberrypi.com> References: <20220317140827.1835029-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 Reviewed-by: Kieran Bingham --- 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;