From patchwork Mon Mar 21 10:26:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15484 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 D3783BD80A for ; Mon, 21 Mar 2022 10:27:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 794A9604EA; Mon, 21 Mar 2022 11:27:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647858428; bh=i63d6hUH3isSXt4iyQ9OeO4uzCK+/jYWFH31E+5m1HE=; 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=ILkxIULU0q1llinUYi0zFAJtw1LznHogSKQuvNcnOOAnmAHEkx8PYo08FJKUYns8c jkZNTaOaz6hA7S39W4cyeuWDeG1ePzhDJ03671h86iLe6POmYu/vQn28ofGGZGebgu SOJbCV40Qms7kfYzd5ArmACx028c2thxlql3vBSo8yQ1p3dAojuY1QGjFEBRICzbDx pxSeBYn0UelSXzfGZl8uD5c1PJAff6oQkFx85ejQoPmAR3If6wz37VQOmOEttUHD/W o0z7rI6/Q30u8FPqGV3oyeEwybXMWkHGwtoJZ5qi8pR1KYn7KNZa0UGYT74vRg03CY ttrOt1qNnfkLw== Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 60A0E604C4 for ; Mon, 21 Mar 2022 11:27:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="do6lP/L6"; dkim-atps=neutral Received: by mail-wm1-x329.google.com with SMTP id r64so8208631wmr.4 for ; Mon, 21 Mar 2022 03:27: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=jcfkXUDyQsMHFwrfe/cenXQcfke3b/k+swts4GnZTjQ=; b=do6lP/L6+wRR6gJMX4dfdCcVlPupIQYowN7ZGpGXd7EJV55aAuNdbqd3FyWaG2cium Sfj5T+vvO+OtBSY1lAbqru6qOqjsO2+eVFfRduUKsxiXM2Wl3VaFwBalzfiVTqEJ3lFT 1/C33S7L/y2ndZ1XcGt9QkIAWzfApzMe/MdExIvJX2K1SFK6kIcTXSDpBctGtaLiBB5G Gwp4qDNsLz37JNPKZs0ESov7tXj4zkd27ExypD5kjbdT7gAy9FjpPsgEW3I7gMApFLNa yyIr5O7FxKVEguAHWAsbpEDs0T4/dMyHLnIeeaee1g6JzLaCi9jdDRJoqUJU/jcbnheA Erww== 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=jcfkXUDyQsMHFwrfe/cenXQcfke3b/k+swts4GnZTjQ=; b=lmeShbnJvk+1wWYYtoK0ICI3e2HE9VMc/TGIZy96iRoU+p53t+aJb4Ot9mos4WNRj/ nMl52eXYrx/bMw3nkWwTow56xoFjhQ3JL2d1EJZ43DnvzpUhms5kMYAlVkhIJepmmwXb jB17dmGlVqid9S73/eCr7uA3YmMICpj6auZ6gB0yGBN5rC/k6xbmc6ZOJISu5mVYDVOx g3M+GAnCw28nJtPIQ7Vhv2JHBzB+piW9Y+GBwt+r6n/yYTNHXoGEBP6G+DShLWkQKLTn quPlPxWbZ5YARBrR180yETzfbVX14ERhM+wfE4y5EOFwvXiEGmTGDu59nZ4NTP5n2koo 2EEQ== X-Gm-Message-State: AOAM533MrsVaq4M9Vf1FnhyhOQ6WaoyMOwlcwGxQiNlqUPZNalArQfSN 4IqU+WxiBGLmRDzs6qY8s9em9AaPVTMTCg== X-Google-Smtp-Source: ABdhPJwDbOo1A8fldnrC1myj31l7VO02PiBOvZRkIWGrrEoq6CBH8VACShy0XNp1CQsfL3X8KAXQ7Q== X-Received: by 2002:a05:600c:49a9:b0:38c:987d:d692 with SMTP id h41-20020a05600c49a900b0038c987dd692mr8798819wmp.166.1647858425878; Mon, 21 Mar 2022 03:27:05 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 03:27:05 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Mar 2022 10:26:58 +0000 Message-Id: <20220321102702.1753800-2-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 1/5] pipeline: raspberrypi: Avoid over-allocation for ISP Output 1 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" The V4L2DeviceFormat structure for the ISP Output 1 node was a copy of what is used ISP Output 0 node, but with the size changed. However, the plane size and stride values were not updated. So there is a possibility that the buffer might be over-sized for the requested resolution. Fix this by only copying the relevant fields from the ISP Output 0 V4L2DeviceFormat structure, and let the device driver size the planes as needed. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index c2230199fed7..43e87a406036 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -845,11 +845,13 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) * colour denoise will not run. */ if (!output1Set) { - V4L2DeviceFormat output1Format = format; + V4L2DeviceFormat output1Format; constexpr Size maxDimensions(1200, 1200); const Size limit = maxDimensions.boundedToAspectRatio(format.size); output1Format.size = (format.size / 2).boundedTo(limit).alignedDownTo(2, 2); + output1Format.colorSpace = format.colorSpace; + output1Format.fourcc = V4L2PixelFormat::fromPixelFormat(formats::YUV420); LOG(RPI, Debug) << "Setting ISP Output1 (internal) to " << output1Format.toString(); From patchwork Mon Mar 21 10:26:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15485 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 44063BD80A for ; Mon, 21 Mar 2022 10:27:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F3ACA610F8; Mon, 21 Mar 2022 11:27:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647858430; bh=kXB2y+u+v0J4lOfnEEEK0fEHQi8UCDN+opF1eo2OslI=; 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=kJsblsTAxBB4+Dpvioxq+ZF0WT63iF1RM4T+Kiroj57zfmPzYjju4zQTZXcjU/mHV vu03g579cVgz+/+jMCCQKjYwZk/wjvEC1IhnO675y4z6rSyBHfLDs6B74qV3s2goed PvXN5jqmb4vKSPVuywBBczdxxnDRLAJ4K/5rkHbBwp9lwr+T6qL3eXvw7Z0HmaIwsP KcsLPcixBRzCecouyoRF8t0rjHha2VPjkclSaSkhOhqGHzIG5xkmGSzgBhTSOkqim2 r/rB7/jVrWAUU/vYi045NbnG/W3ZVo11EoN6FxLl52D9W2lzI3p5Kwc7WS4fABQCEr 3YJTgXSdKVqog== 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 37CAB604DA for ; Mon, 21 Mar 2022 11:27:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="nHwK4o1v"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id u16so18995344wru.4 for ; Mon, 21 Mar 2022 03:27:07 -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=gxKs37xBf6jAcWLRbf5L/O2SlW/iZaDg6COx8v6by6c=; b=nHwK4o1vdq2MCd3EBqqdMyh0j+agzust9QwR/K/3MDg4EzFw8XV9rEDY4a8lKxf0D8 tSIJVYJr4MbOVr2VDe1odf94V7jLJsV94QL0GIiXlXbizv7MawG78TIPehyHXqTJKDto 60y+Ay5HykE1cIdgZNcWaJFjVE0tPRwTkH4Px8GAZWBmPnhRRu9cftwe3pQn08fMIw17 MzhVVpJhyaWfnCtZneUn/hoo+gHazrx8yUcuVEsw3IHzYiMaIuvqwTHVZu7AqqOLeMrr r72cXw9OzOcmKvKk2+t21KyyZ3q0X6a+q9GreGYEIQOEUoN5tiE3j3UNbvVF6lASPpDv 5dLw== 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=gxKs37xBf6jAcWLRbf5L/O2SlW/iZaDg6COx8v6by6c=; b=iZr1SeIjMn4vImFr+8eXP1h1xKHPmRnhmF3ec7mnJ5fIXMPu49naS0CUX/YFpbzHhM jG8thPLRb/uJshbkAxQzbMl3IIAAIkXr3BqhcCVIh+PWZt1jK0OxH3OB4TwFfnGVJCxg 6O7xlp9Ma29XJAKA9WS9GtjwWHXGgWqTyiZzvBrFjti/817CRr7C5Gbm17WiJ6Eqq6nc QA4zht7Q7lLmT3BTmPFMNZJqmK1eI7G7ECa3MCSQeMPVzJUnwsG31QDW9UqAfrOSksPX 5vjXkHnW7RVb4SWLyWyh+Wi0vS01NN7jRwkOhJqPqwVWkpXpEv0Ewl+9h/oDji20ILmV ojoQ== X-Gm-Message-State: AOAM531Y1lu5bpGhNIlgSPQk8vRYVRAv+a4mZejiuFvLUjxQXOLbiOv8 4jc1DPcMFICsTVZ5gYnA6uwH97Bk+iZAOw== X-Google-Smtp-Source: ABdhPJw1VEUs7CTcaV4qKo1Q0PwmjDQS8BVN0czaQhn0qQuk4As06fWlW4dIooQkr4BWoh3qYwbLxg== X-Received: by 2002:a5d:6208:0:b0:203:dde4:c76e with SMTP id y8-20020a5d6208000000b00203dde4c76emr17785921wru.273.1647858426567; Mon, 21 Mar 2022 03:27:06 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 03:27:06 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Mar 2022 10:26:59 +0000 Message-Id: <20220321102702.1753800-3-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 2/5] pipeline: raspberrypi: Move freeBuffers() to the RPiCameraData class 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" This function used to clear the camera buffers does not belong in the PipelineHandlerRPi class as it only access members of the RPiCameraData, so move it. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 43e87a406036..2281b43fc3ac 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -189,6 +189,7 @@ public: { } + void freeBuffers(); void frameStarted(uint32_t sequence); int loadIPA(ipa::RPi::SensorConfig *sensorConfig); @@ -330,7 +331,6 @@ private: int registerCamera(MediaDevice *unicam, MediaDevice *isp, MediaEntity *sensorEntity); int queueAllBuffers(Camera *camera); int prepareBuffers(Camera *camera); - void freeBuffers(Camera *camera); void mapBuffers(Camera *camera, const RPi::BufferMap &buffers, unsigned int mask); }; @@ -1056,7 +1056,7 @@ void PipelineHandlerRPi::stopDevice(Camera *camera) /* Stop the IPA. */ data->ipa_->stop(); - freeBuffers(camera); + data->freeBuffers(); } int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) @@ -1452,16 +1452,14 @@ void PipelineHandlerRPi::mapBuffers(Camera *camera, const RPi::BufferMap &buffer data->ipa_->mapBuffers(ipaBuffers); } -void PipelineHandlerRPi::freeBuffers(Camera *camera) +void RPiCameraData::freeBuffers() { - RPiCameraData *data = cameraData(camera); - /* Copy the buffer ids from the unordered_set to a vector to pass to the IPA. */ - std::vector ipaBuffers(data->ipaBuffers_.begin(), data->ipaBuffers_.end()); - data->ipa_->unmapBuffers(ipaBuffers); - data->ipaBuffers_.clear(); + std::vector ipaBuffers(ipaBuffers_.begin(), ipaBuffers_.end()); + ipa_->unmapBuffers(ipaBuffers); + ipaBuffers_.clear(); - for (auto const stream : data->streams_) + for (auto const stream : streams_) stream->releaseBuffers(); } From patchwork Mon Mar 21 10:27:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15486 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 F38F5C3263 for ; Mon, 21 Mar 2022 10:27:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 56E04604E9; Mon, 21 Mar 2022 11:27:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647858430; bh=OxqN9wPG8w9e6CpTtvUEfPWMYZqPcncE8Vf26vFzLOs=; 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=BRKwTbJeeJdl72qVCqfmy6OCyNSFhatVPIDx44JOcQG7uAEE5hGpmChF1C85yKHH2 d6zq0TXLg/6JvoXY7EVhVcUHMcN2PsxqU4Y53dEgjmcfztLVp1g9dUnxyfLQgLo1gI WJQwWCBnokNqAl5g/LZ6Iyc4dyd0G71poUgSiwxvaPYDpeALso7id2g7SyS5568Ac1 AF8E2Xbp2GXI+m8E2h/Zi632gSFzYGvDTMLnDZKtnFwas6xIz4LpEUOTKI70XWF9b0 dx2+OG/fR3xUf9+n9tqDd4haaBkBD5ECXPGDiGzV5ALthn97zirXVNtqMTjczAWkC6 H9lifCj4xlrhw== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CD9FC604E6 for ; Mon, 21 Mar 2022 11:27:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="PIlQ5vyN"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id j18so10374210wrd.6 for ; Mon, 21 Mar 2022 03:27:07 -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=n8rXhvCEYFa+f6swEAKkBsiiVnN1PTWYev6x2wU9AhU=; b=PIlQ5vyNtzhcqtIQhcThmKLwfx/90FkpZp511hatj8DwTVIgFtWvwocKJXKaTdss6P EuWc36RpzY6Ji03h8HrRu9iCkeB1Y6GWDzVb/lI33BYUatV/m3l8n3EwBUp6Dvy6t6tx jCfW85y9/GcwAwMlZRNPcHnQ4kLdCxEbqRACPfmw3HaoEgMJ7JN/bz6EismQ8fKZG3iB dbgMGRwp3dy73LaxTEuEu5KiQbfR5wWfbvwdyx2kraeNT5tPPnjxmce+XbYMchPXirXO t0CCgHgGaJsBG9deruHZ6I2cQFS2XzgkNVx1UparYeXLnna9zcWvThMlNAGrsobeliad kNKQ== 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=n8rXhvCEYFa+f6swEAKkBsiiVnN1PTWYev6x2wU9AhU=; b=mnBv4gQx4cW+MMg2ATRR12gBUP0VhVSEwGS6b2NS8IcX+u2sC+KH+cN5+Jzc49YGdm za03FhvNL0PLr+CBpvgFL5qMrO5l+SoFV2D3S0PmlyDasUctmZ20jDMgY/KT8tSby33f mtFr5QJWR3qQOoOKQZPMCUswzdJckgV+KRZZErBVzqKNAi6Z7KNiqXsja6Ss+cBPmRwt nsNGiuehv/5H/zIVcW/acQLJqGrqkCnCrTWOgnJ6ZrBm9ahqZXRnIGyDA1DiLlz67hS7 hOzsPDZGWJ2Fvhd4rEym4OUPf/bicOME6EitBLvZMQiBPDiG7HTmst2mWwSxj8UMptAL 8O8w== X-Gm-Message-State: AOAM5325BkSPft3Gk8KkGTdhRNrVDSBk7NTpL26jBTl9sNzt7WRro+52 JK1JUVFM/dp8vl3GrV8IqmhB1dpWsYMTSg== X-Google-Smtp-Source: ABdhPJxAmQYgfkqRbaF5FHclJre4fig5/DR2/jZYWyqlnNmdrL5DW+bVuUmLP7bivMZ29Y9tMPy2Cg== X-Received: by 2002:a5d:4ecd:0:b0:203:fd7b:bdd1 with SMTP id s13-20020a5d4ecd000000b00203fd7bbdd1mr9833282wrv.265.1647858427288; Mon, 21 Mar 2022 03:27:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 03:27:06 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Mar 2022 10:27:00 +0000 Message-Id: <20220321102702.1753800-4-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 3/5] pipeline: raspberrypi: Free buffers in the RPiCamera destructor and re-configure 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" Currently, all framebuffer allocations get freed and cleared on a stop in PipelineHandlerRPi::stopDevice(). If PipelineHandlerRPi::start() is then called without an intermediate PipelineHandlerRPi::configure(), it will re-allocate and prepare all the buffers again, which is unnecessary. Fix this by not freeing the buffer in PipelineHandlerRPi::stopDevice(), but insted doing it in PipelineHandlerRPi::configure(), as the buffers might have to be resized. Add a flag to indicate that buffer allocations need to be done on the next call to PipelineHandlerRPi::start(). Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 2281b43fc3ac..92043962494b 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -185,10 +185,15 @@ public: RPiCameraData(PipelineHandler *pipe) : Camera::Private(pipe), state_(State::Stopped), supportsFlips_(false), flipsAlterBayerOrder_(false), - dropFrameCount_(0), ispOutputCount_(0) + dropFrameCount_(0), buffersAllocated_(false), ispOutputCount_(0) { } + ~RPiCameraData() + { + freeBuffers(); + } + void freeBuffers(); void frameStarted(uint32_t sequence); @@ -280,6 +285,9 @@ public: */ std::optional notifyGainsUnity_; + /* Have internal buffers been allocated? */ + bool buffersAllocated_; + private: void checkRequestCompleted(); void fillRequestMetadata(const ControlList &bufferControls, @@ -682,7 +690,8 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) RPiCameraData *data = cameraData(camera); int ret; - /* Start by resetting the Unicam and ISP stream states. */ + /* Start by freeing all buffers and reset the Unicam and ISP stream states. */ + data->freeBuffers(); for (auto const stream : data->streams_) stream->reset(); @@ -982,12 +991,16 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) RPiCameraData *data = cameraData(camera); int ret; - /* Allocate buffers for internal pipeline usage. */ - ret = prepareBuffers(camera); - if (ret) { - LOG(RPI, Error) << "Failed to allocate buffers"; - stop(camera); - return ret; + if (!data->buffersAllocated_) { + /* Allocate buffers for internal pipeline usage. */ + ret = prepareBuffers(camera); + if (ret) { + LOG(RPI, Error) << "Failed to allocate buffers"; + data->freeBuffers(); + stop(camera); + return ret; + } + data->buffersAllocated_ = true; } /* Check if a ScalerCrop control was specified. */ @@ -1055,8 +1068,6 @@ void PipelineHandlerRPi::stopDevice(Camera *camera) /* Stop the IPA. */ data->ipa_->stop(); - - data->freeBuffers(); } int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) @@ -1461,6 +1472,8 @@ void RPiCameraData::freeBuffers() for (auto const stream : streams_) stream->releaseBuffers(); + + buffersAllocated_ = false; } void RPiCameraData::frameStarted(uint32_t sequence) From patchwork Mon Mar 21 10:27:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15487 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 1954CBD80A 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 C81DD632E2; Mon, 21 Mar 2022 11:27:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647858433; bh=7NJoJpsjqQ7kNIZM1leTOmokHIm6yQ5mTBCrreBgu0I=; 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=vTiE+AgIAAv+/F1TrtjCgS7yQuj86S00ADF6WlyXrIJzmHT5ajNksxnTLtBNcVwJi EiFgH9A7oJYEsVRH88Otw6TYOZgeTqAjMHtDDg/5KEVvwzThU4Bso0TnmlALo82BVW Vc1Mtg8hHeZPxL6bCg45je1j8ZHg4kWO4Mt0MwTl3XfSAUI5072aRjg5BNX27Cyh4j kbaLWMpePIqkvzl41r92VtItMS8d/O2nJzqoBfpTKuPtPNHbOZh2+8k5cxy4VGQZ6h /TCClJgK9doOZuZMeaYDiszX/rbQxr9VSdsXETaHBC/4Oozf2brqcJa3HkuAK3CE5s Mx1S8ZVLy7oPA== Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 84A04610F8 for ; Mon, 21 Mar 2022 11:27:08 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="mR9MZ1sM"; dkim-atps=neutral Received: by mail-wm1-x32f.google.com with SMTP id bi13-20020a05600c3d8d00b0038c2c33d8f3so7382325wmb.4 for ; Mon, 21 Mar 2022 03:27:08 -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=RughUZPLJCp5nFwjdB+7SjIyn+ztq4xtc1EQkx+ClCE=; b=mR9MZ1sMpIKynJzQFSmVpqwS8XPhHFxuKLA1KqLZkchCVrKrkibeDVbeRQVunt4mpB ElWEZcW5XmbeOku9zUXq1DIkKYq1R+tVrOIroBBVHZ0W/nsC7eEgjVzhJuz7+uqONGnG gFcYEr7Y93LybqBNt51dgg1Y4s4mPZUhFkpLynSjEoM+9KQubnD4KZOy4MnEM8L9cu4l T2w/7n10yO3PdbycjWbW7oK5zpLWBXoUOinX1sb8fHG55urhuCsFDmtIsJta9MToN6WK G+jRuHnCp+EmyEU9tpRSo7Q4tH0NWySenSWp21DpDrY8oNPfqkwj7j3doo3BZe4ix/W4 GzHg== 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=RughUZPLJCp5nFwjdB+7SjIyn+ztq4xtc1EQkx+ClCE=; b=MdFbgn4PPFvVWPh2C7Ay8kHq3DoDuVoBb63DE4s5Zot8IA86XuEkt7HM3hrCmr0EeQ d0qPbnFhAjsn0yGpleLfgBwTj0v/tBJ07eVFxImFk4fcd4V8/qDKWq2Kyfksg7MjBzIk /AYsA7SmRXrYZ2Mj6tDvARJLW05RPdkscVR3fNhhrmG285SWdntKtfCH3i7f+IiFb/vw Zajb81sm59B35rt2gs9vYMPkxGIw6sjDUST+8XUQkwAB8QYxYDmdEVGUG2g+x5E/mxkn 2TjMh9L/Jv3C+qJ/3F+y2Rr1fcWJ0XFdG2Ly2lh6hlWcNVqwf+Jige96UgvXOPLvxv10 DqNw== X-Gm-Message-State: AOAM530BAf4VV15g5tSaWsZTSnqqqDbqphm20mUrDlGA3+8OUE0YtGFP nsj+UlJJTd2Gl/eNSOTjswEM08SveQd96Q== X-Google-Smtp-Source: ABdhPJw9pM4CRdwJjOQJxGRB17JLdB6dd7Tk48GuKGq9lk+gCmN4U3aF1wJdQ23W62xbPHGVo6KUPg== X-Received: by 2002:a7b:cb46:0:b0:37b:dd79:e1c4 with SMTP id v6-20020a7bcb46000000b0037bdd79e1c4mr18940305wmj.39.1647858427964; Mon, 21 Mar 2022 03:27:07 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 03:27:07 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Mar 2022 10:27:01 +0000 Message-Id: <20220321102702.1753800-5-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 4/5] pipeline: raspberrypi: Repurpose RPi::Stream::reset() 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" The original use of RPi::Stream::reset() was to clear the external flag state and free/clear out the framebuffers for the stream. However, the latter is now done through PipelineHandlerRPi::configure(). Rework PipelineHandlerRPi::configure() to call RPi::Stream::setExternal() instead of RPi::Stream::reset() to achieve the same thing. Repurpose RPi::Stream::reset() to instead reset the state of the buffer handling logic, where all internally allocated buffers are put back into the queue of available buffers. As such, rename the function to RPi::Stream::resetbuffers() This resetbuffers() is now called from PipelineHandlerRPi::start(), allowing the pipeline handler to correctly deal with start()/stop()/start() sequences and reusing the buffers allocated on the first start(). Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 7 +++++-- src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 13 ++++++------- src/libcamera/pipeline/raspberrypi/rpi_stream.h | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 92043962494b..0ff6acdceb66 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -693,7 +693,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) /* Start by freeing all buffers and reset the Unicam and ISP stream states. */ data->freeBuffers(); for (auto const stream : data->streams_) - stream->reset(); + stream->setExternal(false); BayerFormat::Packing packing = BayerFormat::Packing::CSI2; Size maxSize, sensorSize; @@ -991,6 +991,9 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) RPiCameraData *data = cameraData(camera); int ret; + for (auto const stream : data->streams_) + stream->resetBuffers(); + if (!data->buffersAllocated_) { /* Allocate buffers for internal pipeline usage. */ ret = prepareBuffers(camera); @@ -1031,7 +1034,7 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true); /* - * Reset the delayed controls with the gain and exposure values set by + * resetBuffers the delayed controls with the gain and exposure values set by * the IPA. */ data->delayedCtrls_->reset(); diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp index f446e1ce66c7..7a93efaa29da 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp @@ -26,10 +26,12 @@ std::string Stream::name() const return name_; } -void Stream::reset() +void Stream::resetBuffers() { - external_ = false; - clearBuffers(); + /* Add all internal buffers to the queue of usable buffers. */ + availableBuffers_ = {}; + for (auto const &buffer : internalBuffers_) + availableBuffers_.push(buffer.get()); } void Stream::setExternal(bool external) @@ -97,10 +99,7 @@ int Stream::prepareBuffers(unsigned int count) /* Add these exported buffers to the internal/external buffer list. */ setExportedBuffers(&internalBuffers_); - - /* Add these buffers to the queue of internal usable buffers. */ - for (auto const &buffer : internalBuffers_) - availableBuffers_.push(buffer.get()); + resetBuffers(); } /* We must import all internal/external exported buffers. */ diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h index d6f49d34f8c8..c37f7e82eef6 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.h +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h @@ -45,7 +45,7 @@ public: V4L2VideoDevice *dev() const; std::string name() const; bool isImporter() const; - void reset(); + void resetBuffers(); void setExternal(bool external); bool isExternal() const; 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;