From patchwork Fri Jan 21 14:24:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15291 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 D0FE1BF415 for ; Fri, 21 Jan 2022 14:24:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4410760213; Fri, 21 Jan 2022 15:24:26 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="drJN9Fnw"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CBF4060213 for ; Fri, 21 Jan 2022 15:24:24 +0100 (CET) Received: from Monstersaurus.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5C196883; Fri, 21 Jan 2022 15:24:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1642775064; bh=nIC6eEgXKLqAKaO16kN8Lxpo2etssNMRbCBBnqn9j50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=drJN9FnwYXWDlASSoZKbA8iTSGo5nm/xmrBzOim4vZeqeGaFjI4JLe2uOZaJY5ipE QaEhGUU9oeILq5VrMZ6ulAaRFYetvfCcaEusOTozoy+pdfZaEfIOQJEDGQX5JDN271 mTpSMNgGkYaSvit7tH39PvUQ5Y6InjZgCLomsDVY= From: Kieran Bingham To: libcamera devel Date: Fri, 21 Jan 2022 14:24:19 +0000 Message-Id: <20220121142420.3531497-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220121142420.3531497-1-kieran.bingham@ideasonboard.com> References: <20220121142420.3531497-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/2] libcamera: pipeline_handler: Register requests 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Provide a call allowing requests to be registered and associated with the pipeline handler after being constructed by the camera. This provides an opportunity for the Pipeline Handler to connect any signals it may be interested in receiving for the request such as getting notifications when the request is ready for processing when using a fence. While here, update the existing usage of the d pointer in Camera::createRequest() to match the style of other functions. Signed-off-by: Kieran Bingham Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- v3: - Remove unneeded conditional on construction of the request. v2: - Rename function to 'registerRequest' rather than 'prepareRequest'. include/libcamera/internal/pipeline_handler.h | 1 + src/libcamera/camera.cpp | 13 ++++++++++--- src/libcamera/pipeline_handler.cpp | 19 ++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index e5b8ffb4db3d..c3e4c2587ecd 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -59,6 +59,7 @@ public: void stop(Camera *camera); bool hasPendingRequests(const Camera *camera) const; + void registerRequest(Request *request); void queueRequest(Request *request); bool completeBuffer(Request *request, FrameBuffer *buffer); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 86d84ac0a77d..bb856d606f4a 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -1074,12 +1074,19 @@ int Camera::configure(CameraConfiguration *config) */ std::unique_ptr Camera::createRequest(uint64_t cookie) { - int ret = _d()->isAccessAllowed(Private::CameraConfigured, - Private::CameraRunning); + Private *const d = _d(); + + int ret = d->isAccessAllowed(Private::CameraConfigured, + Private::CameraRunning); if (ret < 0) return nullptr; - return std::make_unique(this, cookie); + std::unique_ptr request = std::make_unique(this, cookie); + + /* Associate the request with the pipeline handler. */ + d->pipe_->registerRequest(request.get()); + + return request; } /** diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 03e4b9e66aa6..e27dc182c128 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -337,6 +337,22 @@ bool PipelineHandler::hasPendingRequests(const Camera *camera) const return !camera->_d()->queuedRequests_.empty(); } +/** + * \fn PipelineHandler::registerRequest() + * \brief Register a request for use by the Pipeline Handler + * \param[in] request The request to register + */ +void PipelineHandler::registerRequest(Request *request) +{ + /* + * Connect the request prepared signal to notify the pipeline handler + * when a request is ready to be processed. + */ + request->_d()->prepared.connect(this, [this]() { + doQueueRequests(); + }); +} + /** * \fn PipelineHandler::queueRequest() * \brief Queue a request @@ -366,9 +382,6 @@ void PipelineHandler::queueRequest(Request *request) waitingRequests_.push(request); - request->_d()->prepared.connect(this, [this]() { - doQueueRequests(); - }); request->_d()->prepare(300ms); } From patchwork Fri Jan 21 14:24:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15292 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 6CB92BF415 for ; Fri, 21 Jan 2022 14:24:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 532C96017A; Fri, 21 Jan 2022 15:24:27 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="LK5hsp/W"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0DF3F60983 for ; Fri, 21 Jan 2022 15:24:25 +0100 (CET) Received: from Monstersaurus.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A0C239FF; Fri, 21 Jan 2022 15:24:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1642775064; bh=yMovVWJ6RG3IzvC/325nRMz/Xk0zPA1FzPTOYDnUjlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LK5hsp/WYdPlHMHPXATvy0frnNUuNXbhFkOJ3Qg7gkHJ1SBctOTmwdrV56jW6m4eR XYMCE44Hpg4vI/r5oXuvw4TEoWz19O3Z0IrU+NBgXQ1e8RD84+mMnjA7kuaddS80/A DN+zuacYPfGLF6Fbegk+6BW2/04qPxr+RzMd0vEI= From: Kieran Bingham To: libcamera devel Date: Fri, 21 Jan 2022 14:24:20 +0000 Message-Id: <20220121142420.3531497-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220121142420.3531497-1-kieran.bingham@ideasonboard.com> References: <20220121142420.3531497-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/2] libcamera: base: object: Prevent the same signal being connected more than once 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Objects shouldn't be connected to the same signal more than once. Doing so indicates a bug in the code, and can be highlighted in debug builds with an assert that performs a lookup on the signals_ list. Remove the support in the test framework which uses multiple Signal connections on the same object. Signed-off-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- v2: - Move assertion / validation to object instead of signal. - This equivalent list assertion in signal does not trap the reported issue, while this does validate and trap on the reported bug. src/libcamera/base/object.cpp | 6 ++++++ test/signal.cpp | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libcamera/base/object.cpp b/src/libcamera/base/object.cpp index 3f28768e48f8..7311b1d5a3a1 100644 --- a/src/libcamera/base/object.cpp +++ b/src/libcamera/base/object.cpp @@ -284,6 +284,12 @@ void Object::notifyThreadMove() void Object::connect(SignalBase *signal) { + /* + * Connecting the same signal to an object multiple times is not + * supported. + */ + ASSERT(signals_.end() == std::find(signals_.begin(), signals_.end(), signal)); + signals_.push_back(signal); } diff --git a/test/signal.cpp b/test/signal.cpp index fcf2def18df4..a1effaab0346 100644 --- a/test/signal.cpp +++ b/test/signal.cpp @@ -212,14 +212,12 @@ protected: /* ----------------- Signal -> Object tests ----------------- */ /* - * Test automatic disconnection on object deletion. Connect the - * slot twice to ensure all instances are disconnected. + * Test automatic disconnection on object deletion. */ signalVoid_.disconnect(); SlotObject *slotObject = new SlotObject(); signalVoid_.connect(slotObject, &SlotObject::slot); - signalVoid_.connect(slotObject, &SlotObject::slot); delete slotObject; valueStatic_ = 0; signalVoid_.emit(); @@ -298,14 +296,12 @@ protected: /* --------- Signal -> Object (multiple inheritance) -------- */ /* - * Test automatic disconnection on object deletion. Connect the - * slot twice to ensure all instances are disconnected. + * Test automatic disconnection on object deletion. */ signalVoid_.disconnect(); SlotMulti *slotMulti = new SlotMulti(); signalVoid_.connect(slotMulti, &SlotMulti::slot); - signalVoid_.connect(slotMulti, &SlotMulti::slot); delete slotMulti; valueStatic_ = 0; signalVoid_.emit();