From patchwork Tue Apr 20 13:07:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 12011 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 B0BDBBDB16 for ; Tue, 20 Apr 2021 13:07:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6B0AC68843; Tue, 20 Apr 2021 15:07:49 +0200 (CEST) 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="C/ETQ+cy"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4B8876883E for ; Tue, 20 Apr 2021 15:07:46 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C1E5B470; Tue, 20 Apr 2021 15:07:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1618924065; bh=+2o1SbY9ZQUOfiOw1TMHvbg9ZFiOYLTvuH7NHSfrssU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C/ETQ+cyMMQmqcmIEZIaIpteVAijMdIY5D4w48wUiHAS5fQkBWtcZSRnCVGD37pzR icxwWw82deZs5JNic6QbmbvZ0tbHWiFsumyJSMC4vBdzjjQg0RORhcAj2J6JKF/9rT EkdH2f9mRVhcA7CuI9OM7L87UUEe1cYzaBMaRGBM= From: Kieran Bingham To: libcamera devel Date: Tue, 20 Apr 2021 14:07:36 +0100 Message-Id: <20210420130741.236848-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> References: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/6] libcamera: camera: Assert pipelines complete all 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" When the camera manager calls stop on a pipeline, it is expected that the pipeline handler guarantees all requests are returned back to the application before the camera has stopped. Ensure that this guarantee is met by providing an accessor on the pipeline handler to validate that all pending requests are removed. Signed-off-by: Kieran Bingham Reviewed-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart --- include/libcamera/internal/pipeline_handler.h | 1 + src/libcamera/camera.cpp | 2 ++ src/libcamera/pipeline_handler.cpp | 15 +++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index c6454db6b2c4..27d45d8ffc20 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -80,6 +80,7 @@ public: virtual int start(Camera *camera, const ControlList *controls) = 0; virtual void stop(Camera *camera) = 0; + bool active(const Camera *camera) const; void queueRequest(Request *request); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 763f3b9926fd..c3fc3dd91bd6 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -1084,6 +1084,8 @@ int Camera::stop() d->pipe_->invokeMethod(&PipelineHandler::stop, ConnectionTypeBlocking, this); + ASSERT(!d->pipe_->active(this)); + d->setState(Private::CameraConfigured); return 0; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 3b3150bdbbf7..8629e3578f02 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -368,6 +368,21 @@ const ControlList &PipelineHandler::properties(const Camera *camera) const * \context This function is called from the CameraManager thread. */ +/** + * \brief Determine if the camera has any requests pending + * \param[in] camera The camera to check + * + * This method determines if there are any requests queued to the pipeline + * awaiting processing. + * + * \return True if there are pending requests, or false otherwise + */ +bool PipelineHandler::active(const Camera *camera) const +{ + const CameraData *data = cameraData(camera); + return !data->queuedRequests_.empty(); +} + /** * \fn PipelineHandler::queueRequest() * \brief Queue a request From patchwork Tue Apr 20 13:07:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 12012 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 66F0DBDB16 for ; Tue, 20 Apr 2021 13:07:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D4EE468840; Tue, 20 Apr 2021 15:07:49 +0200 (CEST) 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="grORsmnd"; 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 9E0A06883E for ; Tue, 20 Apr 2021 15:07:46 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 211DC89B; Tue, 20 Apr 2021 15:07:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1618924066; bh=PJagYQs1QPFKkU8d8OPlYToJNuQFN8DkwVdmIBn5Qr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=grORsmndLMA2GVTP5GjMtsNVYujmqBuU00qm9whsDKFNiUrc0eiUG0lQ448oePZ0S RCssbJt3U+er6CnYSzIBggEbRxKI7bI2/1EKthK/VvCLUF8lCLwHxz+VD+fmF7U4yu NNcS1iHltNvZHmxIH4wflojJZ0pH49lHFHR++o3s= From: Kieran Bingham To: libcamera devel Date: Tue, 20 Apr 2021 14:07:37 +0100 Message-Id: <20210420130741.236848-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> References: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/6] libcamera: pipeline: ipu3: frames: Fail if the FrameInfo can't be found 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" The FrameInfo structure associates the data sent to the IPA and is essential for handling events. If it can not be found, this is a fatal error which must be fixed. Signed-off-by: Kieran Bingham Reviewed-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart Reviewed-by: Hirokazu Honda --- v3: - Make all occurrences of failing to find a frame info fatal. --- src/libcamera/pipeline/ipu3/frames.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp index 03e8131c4829..a1b014eed8d7 100644 --- a/src/libcamera/pipeline/ipu3/frames.cpp +++ b/src/libcamera/pipeline/ipu3/frames.cpp @@ -113,7 +113,8 @@ IPU3Frames::Info *IPU3Frames::find(unsigned int id) if (itInfo != frameInfo_.end()) return itInfo->second.get(); - LOG(IPU3, Error) << "Can't find tracking informaton for frame " << id; + LOG(IPU3, Fatal) << "Can't find tracking informaton for frame " << id; + return nullptr; } @@ -131,7 +132,8 @@ IPU3Frames::Info *IPU3Frames::find(FrameBuffer *buffer) return info; } - LOG(IPU3, Error) << "Can't find tracking informaton from buffer"; + LOG(IPU3, Fatal) << "Can't find tracking informaton from buffer"; + return nullptr; } From patchwork Tue Apr 20 13:07:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 12013 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 EE401BDB16 for ; Tue, 20 Apr 2021 13:07:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 368D068856; Tue, 20 Apr 2021 15:07:51 +0200 (CEST) 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="EZVAI5UA"; 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 0135E68840 for ; Tue, 20 Apr 2021 15:07:47 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C8238AD; Tue, 20 Apr 2021 15:07:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1618924066; bh=bh91nfL9I021cEfFTqVmCZcvRLjgxiXMG8vnDBDBZQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EZVAI5UAPWXxlaFik7TIJNNBaMjWZyUTyScUTksme2DoZCxl/VBpFBznNKXnwn+Yy 4ONyCufYz6DX7vIvRFPU3ljRV0Nqf9UQrpb27mtJUw8P1oXigNloZMNM2vt4VfKoll FVTDqKKw4gaAj8RQT4zET8E7MF7S1ZM30wqkhXF0= From: Kieran Bingham To: libcamera devel Date: Tue, 20 Apr 2021 14:07:38 +0100 Message-Id: <20210420130741.236848-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> References: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/6] libcamera: pipeline: rkisp1: Fail RkISP1FrameInfo can't be found 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" The RkISP1FrameInfo structure associated data sent to the IPA and is essential for handling events. If it can not be found, this is a fatal error which must be fixed. Signed-off-by: Kieran Bingham Reviewed-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart Reviewed-by: Hirokazu Honda --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 549f4a4e61a8..c75666391222 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -267,7 +267,8 @@ RkISP1FrameInfo *RkISP1Frames::find(unsigned int frame) if (itInfo != frameInfo_.end()) return itInfo->second; - LOG(RkISP1, Error) << "Can't locate info from frame"; + LOG(RkISP1, Fatal) << "Can't locate info from frame"; + return nullptr; } @@ -283,7 +284,8 @@ RkISP1FrameInfo *RkISP1Frames::find(FrameBuffer *buffer) return info; } - LOG(RkISP1, Error) << "Can't locate info from buffer"; + LOG(RkISP1, Fatal) << "Can't locate info from buffer"; + return nullptr; } @@ -296,7 +298,8 @@ RkISP1FrameInfo *RkISP1Frames::find(Request *request) return info; } - LOG(RkISP1, Error) << "Can't locate info from request"; + LOG(RkISP1, Fatal) << "Can't locate info from request"; + return nullptr; } From patchwork Tue Apr 20 13:07:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 12014 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 6D78EBDB16 for ; Tue, 20 Apr 2021 13:07:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A8C6268859; Tue, 20 Apr 2021 15:07:51 +0200 (CEST) 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="ML+ZUx9V"; 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 50FC768840 for ; Tue, 20 Apr 2021 15:07:47 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E298AE2E; Tue, 20 Apr 2021 15:07:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1618924067; bh=mtgPt6WVG6Nrocutt5ypSAYObhdFuRXAKfHyEiXOl4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ML+ZUx9V6o+g9BMA25bv2NRpMAyN1p9FJtCj3VxkS4+lPyIbgsZm47Tu9Bv4uM1/r s0Z0nA6po2GCw1bYuxiCbYgNBXXSUCMoQ2IQPyM+ToiBMUF1DZMMYwKcQ62ezRmb9d JW957FABKwKDM7khkvy+EXebqNuRDSQojNKq40vY= From: Kieran Bingham To: libcamera devel Date: Tue, 20 Apr 2021 14:07:39 +0100 Message-Id: <20210420130741.236848-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> References: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 4/6] libcamera: pipeline: ipu3: Cancel unused buffers 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" When the CIO2 returns a cancelled buffer, we will not queue buffers to the IMGU. These buffers should be explicitly marked as cancelled to ensure the application knows there is no valid metadata or frame data provided in the buffer. Provide a cancel() method on the FrameBuffer to allow explicitly cancelling a buffer. Signed-off-by: Kieran Bingham Reviewed-by: Jean-Michel Hautbois Reviewed-by: Hirokazu Honda --- include/libcamera/buffer.h | 2 ++ src/libcamera/buffer.cpp | 8 ++++++++ src/libcamera/pipeline/ipu3/ipu3.cpp | 7 +++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h index 620f8a66f6a2..e0af00900409 100644 --- a/include/libcamera/buffer.h +++ b/include/libcamera/buffer.h @@ -53,6 +53,8 @@ public: unsigned int cookie() const { return cookie_; } void setCookie(unsigned int cookie) { cookie_ = cookie; } + void cancel() { metadata_.status = FrameMetadata::FrameCancelled; } + private: LIBCAMERA_DISABLE_COPY_AND_MOVE(FrameBuffer) diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp index 75b2693281a7..7635226b9045 100644 --- a/src/libcamera/buffer.cpp +++ b/src/libcamera/buffer.cpp @@ -226,6 +226,14 @@ FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) * core never modifies the buffer cookie. */ +/** + * \fn FrameBuffer::cancel() + * \brief Marks the buffer as cancelled + * + * If a buffer is not used by a request, it shall be marked as cancelled to + * indicate that the metadata is invalid. + */ + /** * \class MappedBuffer * \brief Provide an interface to support managing memory mapped buffers diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 51446fcf5bc1..73306cea6b37 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -1257,8 +1257,11 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer) /* If the buffer is cancelled force a complete of the whole request. */ if (buffer->metadata().status == FrameMetadata::FrameCancelled) { - for (auto it : request->buffers()) - pipe_->completeBuffer(request, it.second); + for (auto it : request->buffers()) { + FrameBuffer *b = it.second; + b->cancel(); + pipe_->completeBuffer(request, b); + } frameInfos_.remove(info); pipe_->completeRequest(request); From patchwork Tue Apr 20 13:07:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 12015 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 1B29EBDB16 for ; Tue, 20 Apr 2021 13:07:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 93DB260516; Tue, 20 Apr 2021 15:07:52 +0200 (CEST) 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="rTEeviZv"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BB3C068840 for ; Tue, 20 Apr 2021 15:07:47 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3A05C1051; Tue, 20 Apr 2021 15:07:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1618924067; bh=ey58rlmbpyMlhmZ+G5GXv23lVH3y3Lqx3oMP1V/IdaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rTEeviZv7YdXSm1/tBRe6SiQFuZ21hDGY/z30TQ5RQS90q0zum3KD/8pPwOYu+sw5 Y6DLDfPbTh6EvVuYubbDX65T6q62KZ77QifwcLNIb0fDL+VWIlXjtz2pSS1uyuSLAA loX3Gynxp3rlPhbqxSAKaoEC/EAi2k/RrzT8elJY= From: Kieran Bingham To: libcamera devel Date: Tue, 20 Apr 2021 14:07:40 +0100 Message-Id: <20210420130741.236848-6-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> References: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/6] libcamera: internal: log: Report function on asserts 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" Report the function which fails an assertion as well as the actual assertion. This now reports as: [30:08:53.218816270] [226567] FATAL default request.cpp:150 assertion "d" failed in reuse() rather than: [30:11:05.271888926] [228531] FATAL default request.cpp:150 assertion "d" failed Signed-off-by: Kieran Bingham Reviewed-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart --- We could use __PRETTY_FUNCTION__ instead to get: [30:17:16.736265045] [232054] FATAL default request.cpp:150 assertion "d" failed in void libcamera::Request::reuse(libcamera::Request::ReuseFlag) include/libcamera/internal/log.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h index be0bab3c1272..b66bf55bc57d 100644 --- a/include/libcamera/internal/log.h +++ b/include/libcamera/internal/log.h @@ -117,9 +117,10 @@ LogMessage _log(const LogCategory *category, LogSeverity severity, #endif /* __DOXYGEN__ */ #ifndef NDEBUG -#define ASSERT(condition) static_cast(({ \ - if (!(condition)) \ - LOG(Fatal) << "assertion \"" #condition "\" failed"; \ +#define ASSERT(condition) static_cast(({ \ + if (!(condition)) \ + LOG(Fatal) << "assertion \"" #condition "\" failed in " \ + << __func__ << "()"; \ })) #else #define ASSERT(condition) static_cast(false && (condition)) From patchwork Tue Apr 20 13:07:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 12016 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 A740DBDB16 for ; Tue, 20 Apr 2021 13:07:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5A4056885B; Tue, 20 Apr 2021 15:07:53 +0200 (CEST) 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="GB/kSRZB"; 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 27C8868848 for ; Tue, 20 Apr 2021 15:07:48 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AB8C21172; Tue, 20 Apr 2021 15:07:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1618924067; bh=wMRpuy1H/rF5bzYMG+ti3c5ayvGN5Ca88P/T1NxiRI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GB/kSRZBS9/qfhQPYau4mPI0//U5QZoxOGz1x4jaAErEMdZTktVYqB+1KRZHI6yH0 lgPLWNDaHVzOK8PJ4I7nHSpd5eJc0MXGw/FlVOjBqOCvc0Uoe+qTvdkYiZ2/tzFYdH +3j3t+SJC0CYqLFDDxFcw2W9sw7fTWCFEoxsfFOc= From: Kieran Bingham To: libcamera devel Date: Tue, 20 Apr 2021 14:07:41 +0100 Message-Id: <20210420130741.236848-7-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> References: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 6/6] libcamera: request: Make it extensible 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 an extensible private object for the Request class. This allows us to make modifications to the private API and storage of requests without affecting the public API or ABI. The D pointer is obtained in all Request functions implemented in the request.cpp file along with an assertion that the D pointer was valid to provide extra validation checking that the Request has not been deleted, while in use as it is 'owned' by the application. Signed-off-by: Kieran Bingham Reviewed-by: Jean-Michel Hautbois --- The assertions added in findBuffer, complete() and completeBuffer() allow us to ensure that the Request is still valid while asynchronous actions occur on the Request internally in libcamera, and provide (almost) equivalent functionality as the Request Canary previously proposed. The additions in reuse() and addBuffer() are called from applications, so the assertions may be less helpful there, but I've added them for consistency. include/libcamera/request.h | 4 +++- src/libcamera/request.cpp | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/libcamera/request.h b/include/libcamera/request.h index 4cf5ff3f7d3b..909a1aebc2d2 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -24,8 +24,10 @@ class CameraControlValidator; class FrameBuffer; class Stream; -class Request +class Request : public Extensible { + LIBCAMERA_DECLARE_PRIVATE(Request) + public: enum Status { RequestPending, diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index ce2dd7b17f10..977bfac4fce6 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -28,6 +28,19 @@ namespace libcamera { LOG_DEFINE_CATEGORY(Request) +class Request::Private : public Extensible::Private +{ + LIBCAMERA_DECLARE_PUBLIC(Request) + +public: + Private(Request *request); +}; + +Request::Private::Private(Request *request) + : Extensible::Private(request) +{ +} + /** * \enum Request::Status * Request completion status @@ -73,8 +86,8 @@ LOG_DEFINE_CATEGORY(Request) * */ Request::Request(Camera *camera, uint64_t cookie) - : camera_(camera), sequence_(0), cookie_(cookie), - status_(RequestPending), cancelled_(false) + : Extensible(new Private(this)), camera_(camera), sequence_(0), + cookie_(cookie), status_(RequestPending), cancelled_(false) { /** * \todo Should the Camera expose a validator instance, to avoid @@ -114,6 +127,9 @@ Request::~Request() */ void Request::reuse(ReuseFlag flags) { + Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); + LIBCAMERA_TRACEPOINT(request_reuse, this); pending_.clear(); @@ -179,6 +195,9 @@ void Request::reuse(ReuseFlag flags) */ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) { + Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); + if (!stream) { LOG(Request, Error) << "Invalid stream reference"; return -EINVAL; @@ -214,6 +233,9 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) */ FrameBuffer *Request::findBuffer(const Stream *stream) const { + const Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); + const auto it = bufferMap_.find(stream); if (it == bufferMap_.end()) return nullptr; @@ -282,6 +304,8 @@ FrameBuffer *Request::findBuffer(const Stream *stream) const */ void Request::complete() { + Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); ASSERT(status_ == RequestPending); ASSERT(!hasPendingBuffers()); @@ -307,6 +331,9 @@ void Request::complete() */ bool Request::completeBuffer(FrameBuffer *buffer) { + Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); + LIBCAMERA_TRACEPOINT(request_complete_buffer, this, buffer); int ret = pending_.erase(buffer); @@ -330,6 +357,9 @@ bool Request::completeBuffer(FrameBuffer *buffer) */ std::string Request::toString() const { + const Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); + std::stringstream ss; /* Pending, Completed, Cancelled(X). */