From patchwork Wed Sep 21 08:02:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17385 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 8AC05C327D for ; Wed, 21 Sep 2022 08:03:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3646A621E1; Wed, 21 Sep 2022 10:03:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1663747386; bh=p76Ra6oGRS2oGIAl/DgzwgcUTg1Gtz3X4lYsY/MwjxI=; 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=RO7GmfKjPgMxb4ZGrEhyMkmbKw3a5wqSy0g57gh7lHtg7RaYgLJgmcVWVsrg7zbEv T8D4hvxt5eR2XJKoCwIqmKXPuoBXIcv9hD8KIf6TNI0+1h0YIQC9iUWA3DMkJYx2KT 7I1IxL0kX1eC42RKNKDTMAj+AkKoLOw+rMaDZnNIzeSB6FPdnEsoSUuhDEArU43OPI L8SCT0Ohn+R3kkzfMtnRQCNa7PpYhtx6SZ/P9faCndcVeOYHFUCYg4lp+kcxryN67P 6ThUyKfReL6stQ+90pptQh7rHSeXKjOS6g9eIET+CxeTOOCMJnYRBs9EWs6e7o+YVo 0hP3HbfKW9NLQ== Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1933C621DA for ; Wed, 21 Sep 2022 10:03:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="nqp0nAJr"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id fn7-20020a05600c688700b003b4fb113b86so368408wmb.0 for ; Wed, 21 Sep 2022 01:03:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Z7GOK/fFFzV59ouyerKPz+mBpJ1VsiYEYq2C9B2xYMM=; b=nqp0nAJrCbadCRxkmp1J58bibJdr8AgVciivCjZBTgfDjY1lo1mEF+SknyGIFo8+RO hcIebsEKzK+Qsquima5kNp9f4iUuo2vR29su9B9Th0uTFzkDtk1tkasNwCT0V2yxcZBU SkEpFZeFqFGNDPhntdmkgy2EQ/yr/WRIdTw4X+BzXWrci9aVl/MyGuikzZUdAdHnzNyv V+XO94OlHNP6KUl9fjUUogiWSe3KlcnQ+YVU4WT8ionVKHeoMBUETYvKKsNs9i0G8wmO 3QIZrKSBHGZGj4XYtr28/OnXhNhULIUjGqmAdcJu9gUUf0tBL0n0nFDGDQIiDEp/mwBY /QOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Z7GOK/fFFzV59ouyerKPz+mBpJ1VsiYEYq2C9B2xYMM=; b=AKAGEDcKzvDb8v0E9i/65hUN0J4g7exRBLFO+Ck7wL3l0WmHKq8FGeYtZRCjS2fRKz nPCOatg0Ddwdzh5B/86jJs7HgKgTZ3Xkz3PKJzgmbnJX1cL8cVWBNq5YhTjKyMSVOQFo lYkLnob3ExqtuFP+f7Enf468hlxvqINDO1iDFjiFrECy3jxFptQQ663HGyw8JIRbL7X+ ZsIXoSfe3kae3Y1GKMXM2pq/HNv9NXdSb6sGd0nIXEMfNAG6P/5fb5hUbYdeRZBENWRW Vx3SXTzOKH92mlGUzamhWgNACiGYptMiVUlRVmlWGSuLkZVNo7D7eugLRTHf0qjcydUb nhLQ== X-Gm-Message-State: ACrzQf2dyC6udGLklLT1GeBDLMlu5YTtEfCg4KDW4HMq2mOUh8kGvpCL 0dRDBkV7RLgQFmnvrZ6SfE0AlbGqtbobrE0m X-Google-Smtp-Source: AMsMyM6z2OULktCCJ19wI90YcoipPi84X6Lwzdm23QRdQicjv10GXgmQ+lBjC38AxgmJmOEsECzS8g== X-Received: by 2002:a05:600c:22d3:b0:3a8:424d:f386 with SMTP id 19-20020a05600c22d300b003a8424df386mr4991159wmg.57.1663747382463; Wed, 21 Sep 2022 01:03:02 -0700 (PDT) Received: from naush-laptop.localdomain (global-5-56.n-1.net.cam.ac.uk. [131.111.5.56]) by smtp.gmail.com with ESMTPSA id l36-20020a05600c08a400b003b4727d199asm1905782wmp.15.2022.09.21.01.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 01:03:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 21 Sep 2022 09:02:57 +0100 Message-Id: <20220921080258.5268-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220921080258.5268-1-naush@raspberrypi.com> References: <20220921080258.5268-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] pipeline: raspberrypi: Add an error state 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" Add an error state used internally in the Raspberry Pi pipeline handler. Currently this state is never set, but will be in a subsequent commit when a device timeout has been signalled. Add a isRunning() helper to identify if the state machine is in a stopped/error state. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham Reviewed-by: David Plowman --- .../pipeline/raspberrypi/raspberrypi.cpp | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index b4094898ca6c..5c8c89585200 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -253,9 +253,14 @@ public: * thread. So, we do not need to have any mutex to protect access to any * of the variables below. */ - enum class State { Stopped, Idle, Busy, IpaComplete }; + enum class State { Stopped, Idle, Busy, IpaComplete, Error }; State state_; + bool isRunning() + { + return state_ != State::Stopped && state_ != State::Error; + } + struct BayerFrame { FrameBuffer *buffer; ControlList controls; @@ -1109,7 +1114,7 @@ int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) { RPiCameraData *data = cameraData(camera); - if (data->state_ == RPiCameraData::State::Stopped) + if (!data->isRunning()) return -EINVAL; LOG(RPI, Debug) << "queueRequestDevice: New request."; @@ -1708,7 +1713,7 @@ void RPiCameraData::enumerateVideoDevices(MediaLink *link) void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &controls) { - if (state_ == State::Stopped) + if (!isRunning()) return; FrameBuffer *buffer = isp_[Isp::Stats].getBuffers().at(bufferId); @@ -1744,7 +1749,7 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList & void RPiCameraData::runIsp(uint32_t bufferId) { - if (state_ == State::Stopped) + if (!isRunning()) return; FrameBuffer *buffer = unicam_[Unicam::Image].getBuffers().at(bufferId); @@ -1759,7 +1764,7 @@ void RPiCameraData::runIsp(uint32_t bufferId) void RPiCameraData::embeddedComplete(uint32_t bufferId) { - if (state_ == State::Stopped) + if (!isRunning()) return; FrameBuffer *buffer = unicam_[Unicam::Embedded].getBuffers().at(bufferId); @@ -1825,7 +1830,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) RPi::Stream *stream = nullptr; int index; - if (state_ == State::Stopped) + if (!isRunning()) return; for (RPi::Stream &s : unicam_) { @@ -1864,7 +1869,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) void RPiCameraData::ispInputDequeue(FrameBuffer *buffer) { - if (state_ == State::Stopped) + if (!isRunning()) return; LOG(RPI, Debug) << "Stream ISP Input buffer complete" @@ -1881,7 +1886,7 @@ void RPiCameraData::ispOutputDequeue(FrameBuffer *buffer) RPi::Stream *stream = nullptr; int index; - if (state_ == State::Stopped) + if (!isRunning()) return; for (RPi::Stream &s : isp_) { @@ -1991,6 +1996,7 @@ void RPiCameraData::handleState() switch (state_) { case State::Stopped: case State::Busy: + case State::Error: break; case State::IpaComplete: From patchwork Wed Sep 21 08:02: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: 17386 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 2AA75C3272 for ; Wed, 21 Sep 2022 08:03:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9BB5B621DE; Wed, 21 Sep 2022 10:03:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1663747386; bh=JFuytqubwHW4jMyriYXD/uXre9j0FdOSmOh60kEISoU=; 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=mqpzfLZJUEbE0XfcBJ7rYjSsLXo3MP7sRxxz8YUuVO0srErEykd5H1lajJYGLxCrz 06j9kEoXmpEDDaKvwiXw+tEWExRRyXK/SI49i/YywC6fWHB9pzSKor+NDUkNjYBc1U G1z0TGzJTu7cO91V1IBiKrD2P6ykJbR0erNhpEQXYdI5EB7eQhG9Gqbk5iMK5fizby 0CANZQLD4j9YSBLrtWFlr7Y8tjrsBpmu6cmf+DQblLhsPz/HAp+98CnkPoamqW0405 43K10P6i2/PkUpT2q0oamyHg/xUihfnuHiiISynAeQTdg8iUVqb67vYcD9AkNXRCQ2 caxvpGEnIDGsQ== 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 E4F2461F80 for ; Wed, 21 Sep 2022 10:03:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SmO5tnnG"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id bq9so8510013wrb.4 for ; Wed, 21 Sep 2022 01:03:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=ayQ2oRjuGzA/5I7cNI63lEToSCgSiCoOFJLWeh35i4c=; b=SmO5tnnGu+rRNZVl/UmvxVyont0dVvHDo0WN1eVrHfKc52xiJaDiYmQ9WpXZb5K4ho OPdsjxT8NO/m6JZ7fJtX2p+zcFsgpnzpqdN8CHJkWiPAWKeUAGtzxCYh/wlL3rKql8j7 ehklRyDGLi4QvaSp2dSRCJQGHg8fqkvxm+OgaB612ra8Ik5r26ZtZ8ELA4jmXQDCSYOS 7HP0eDLxKZ+9NBoRN0edFHXrbPmUchxNW6Pjo3dYHoaJBa0GIITuxv/ada7HgyEXq9wc M0OHlO4k411B5BqDeifdcDLiFe2qCuBAqitjh8ipd6xPX5QiBQOIPRMPyIXxKkfBPbgW wifg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=ayQ2oRjuGzA/5I7cNI63lEToSCgSiCoOFJLWeh35i4c=; b=dk+6na5XyqWsB9+kbrtd3QgUQ+uIXxxxH8aCc8p/dBPwyQ9jBexcqj8QU+sbqu5q77 gho8wDkDhOHymE1l6sstS3b70q2MTyQmISer4sx65Ss95l3quBRJ51oz363sRjS6KkWn 5XLZRsY62kd7C87989ja5VmA2GtBY0s3+cYq7T+/rPkdbMNyjlg/xg864O0iXeFmgJF8 T27KEev8ORon3LGDk5OgvgLXedkzwvDrP5Had49Kezb+TS0KeTjmESrLALpjScWKK4gB CXwFw57KJkpmij6upqsfghu02k97qLCLwvULcSqoB81N8Mjz14is2Heyk1jTfD6dnCL1 GNvg== X-Gm-Message-State: ACrzQf2X4awEnUG/+SmfmR/8KFMxy8klkM5GW7Kqa9TT7mPEygiutkrs paeKjYI5qLOp8xHFKF0o9iaACV4C6YM8NKTC X-Google-Smtp-Source: AMsMyM5d81YlqM8oxsi2cUkRY1NaOxKyg51LVs4qRuh78wkpjLT4vkK4H2T8OMntqShyl+JJUvGzaw== X-Received: by 2002:a5d:64e5:0:b0:22a:3cae:93bf with SMTP id g5-20020a5d64e5000000b0022a3cae93bfmr16526808wri.323.1663747383214; Wed, 21 Sep 2022 01:03:03 -0700 (PDT) Received: from naush-laptop.localdomain (global-5-56.n-1.net.cam.ac.uk. [131.111.5.56]) by smtp.gmail.com with ESMTPSA id l36-20020a05600c08a400b003b4727d199asm1905782wmp.15.2022.09.21.01.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 01:03:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 21 Sep 2022 09:02:58 +0100 Message-Id: <20220921080258.5268-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220921080258.5268-1-naush@raspberrypi.com> References: <20220921080258.5268-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] pipeline: raspberrypi: Improve Unicam timeout handling 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, if a Unicam timeout is signalled, the pipeline handler only raises an error message. Update the error handling to put the pipeline handler in an internal error state, disable all device streams, and return all outstanding requests as cancelled. Any subsequent requests that come into the pipeline handler will also be returned as cancelled. Any further error handling (e.g. a reset with camera stop()/start()) is up to the application to perform as it requires. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham Reviewed-by: David Plowman --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 5c8c89585200..dcd81650c32d 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1823,6 +1823,17 @@ void RPiCameraData::unicamTimeout() LOG(RPI, Error) << "Unicam has timed out!"; LOG(RPI, Error) << "Please check that your camera sensor connector is attached securely."; LOG(RPI, Error) << "Alternatively, try another cable and/or sensor."; + + state_ = RPiCameraData::State::Error; + /* + * To allow the application to attempt a recovery from this timeout, + * stop all devices streaming, and return any outstanding requests as + * incomplete and cancelled. + */ + for (auto const stream : streams_) + stream->dev()->streamOff(); + + clearIncompleteRequests(); } void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)