From patchwork Tue Mar 22 09:22:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15501 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 39DC1BD80A for ; Tue, 22 Mar 2022 09:23:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 93E01610F8; Tue, 22 Mar 2022 10:23:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940987; bh=LAyJvKIGT2q0yec59HHtU1koPIGLOBZBSrRmPJWFo0Y=; 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=qmZAH7cu1K29ToSzzGqTRa3Tbmf23kM6QdqKl9vlT3TDWhx8TXsvWmxLVQx66t8F7 EMnvVIr0m89oKxZgW5hRmRxIQEO1ufun92t4TQuDZftFX3jhKa4S+hScPTPAVJVu8d NIIcJ4LzDnCOjAIU4MA05DfzBGDPD/Q9Cipt1mmGjbrwJ1TzhkHo/JTpKv0Q27UT/3 SCn5DA/N7nTxGprqWP4a0siOCODU22sM7Odqv3GOqCHHalHiswzSwpF1zWKnWCK8Rl kIw9xSmzNEHLn0PrVDBt8DOK5b+xe3Ldgp1Wn7lSPhzsWrVfh2G2YR5rcnqyMM4hBq bUHZrnZdnh3rg== Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 02085604E9 for ; Tue, 22 Mar 2022 10:23:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SH+6Sp3O"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id j13-20020a05600c1c0d00b0038c8f94aac2so1016316wms.3 for ; Tue, 22 Mar 2022 02:23:03 -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=y+AU3uHdQY363TBVi7RlIPz9CMOUvtyCfstDvCKShdo=; b=SH+6Sp3OZ+BxwKDy2RkHKHNyPCrUBuX2qcl/TZghRS5irAogZIok7KtlPA6Zwras5z 3TSZ4eiBLZUx0VBclt6K8GaqFDlFSwlhYtxyA9cf910h4Wv9DOwTsY9CxT4Eu97kvoAH VlRlSAA4HOOZhdQYneUOfzrQw9TaVf3SyLWv6oThfsrYTBW7tVzPIQszB8MP5JKeKq+D rxyAUyY/Kt4kLiuoIilW9PbfNHykS5ruNfHkj8Kxe3Nd90/7umCMOwnwcvRQS/zfJBSH fvOoqhi/vz/2DPku7/WFGtZDXAXzOR0mk/Eu6Zm6vLGluQL0sOzNQXh7MFoYpppb6I1J B0ew== 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=y+AU3uHdQY363TBVi7RlIPz9CMOUvtyCfstDvCKShdo=; b=vkCqPe2hQbMy1L5lD6Z02XMmH6BwThDq8FqfGUZnfJ3PgDcZ1BsSzvqqc9Uh3Ipz+E wJuYi78gF1MElVIeNey4zwti9Ywbsb/rR9w3Vag9ICKxpWD4F7siZGdRbnWRHMiRmOuE DgJFEGlWYWYuz9y2XhsKQpjhfncewZJo9ZYumL0wn5vVFjcrqrvMIhPbfxh7aSR/MM0x MXQTysjFtpv41WA/Dl3Y7aNaENaAqhbD0wEslPC3wO3yO0K7BP17IqTGQLQIdaFxcwU1 kIQ32DC/TvSUfAUgGmpJOnqgB+R9i8uPfu5beikcuLQSozLzbyuS8mDcxoraOQhIy5Wu AGUg== X-Gm-Message-State: AOAM531dePAmYyPSowKKoDneW4fArfiODhCCe4ehilkQA2qrfaQQJ/f8 A2KG3U8yAGFSDiqqkVfZxPdFPvjLsI8bUQ== X-Google-Smtp-Source: ABdhPJwXtFDPMmjLgtK0rd3ynoC42dsmVZu5vaM3URRafdnQg3WjgiWysuXe9/l6U6IGpkzxRxHjQg== X-Received: by 2002:a1c:f415:0:b0:37f:ab4d:1df2 with SMTP id z21-20020a1cf415000000b0037fab4d1df2mr2746893wma.75.1647940983474; Tue, 22 Mar 2022 02:23:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:53 +0000 Message-Id: <20220322092257.2713521-5-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 4/8] 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 | 5 ++++- src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 13 ++++++------- src/libcamera/pipeline/raspberrypi/rpi_stream.h | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 92043962494b..8fd79be67988 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); 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;