From patchwork Tue Mar 22 13:16:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15507 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 E1CAFC0F1B for ; Tue, 22 Mar 2022 13:16:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D1F0604E8; Tue, 22 Mar 2022 14:16:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647955003; bh=g9npiaJ1NLUxGnHgqKHo+sbhVxhONahh4QBM2jPes6U=; 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=p1qhJ+1rQO2o4Qh64ge0PmpmumelGAWq1RUkceK0yF+sKw+ha2NQdztbLFPnUOOLu 6vyJsZnaQJ6swtsYj3x9LCYZObqu7FkUuUR66x9aX4RDGGQ8/Zi3QhcjvF4uynxS7/ yXK/4T/Ql0AadFRXxlJ261/p8+3iJhlNn6BoVQKjtVLFsYoOr3GM05BFpMS5BLUb4c tJbXqeFJV8aI6ITR4ljNrfnM4zsXqrVsN3xHBrW5vOzzQXeVIw5u1eU+6Fc0dGq1b4 bo9y5haCeiuUEnlkP5q2/ozReB8hg3W0jlvTBe/6lUyyITJGfa4cZO8EXmSfqWvIDC jK2UGbPQsdeSQ== Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A9010604C5 for ; Tue, 22 Mar 2022 14:16:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="a8o564gn"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id r64so10923943wmr.4 for ; Tue, 22 Mar 2022 06:16:39 -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=fnC/L+iITI19MxC5UkoX7mdIvfoQD2Z62GPX+M0fcUs=; b=a8o564gnXyng9PE1jo1M1mw5LW14UxFp306hpSMFKjHwc8zQSF+JtmmPy8bJ1Z2wf0 /DnuO9+FEEnYIKisr2rYrtTYmEdE5wsloD9MJm808q6ACJCz4rjrS3tOHh3HyAH4Mnig l/P5TcHASe5tiD2e7MhdTtUp/KOEgLgUEukf0B6A9ydme6YK6Hoj8AnfaPnEck+XCdRk a8NMncRnRj4s1jjwuzMQVHTURybalEx5a0E1b/dRO41cMMDLfOEEPLqiYfv90gwnjez3 qNuJIhLNiyklQZgX6Dk3SDQxaTQevrYehpGBdG6ETY+kE2lGJN7VN76VErW01ilxegH1 kIOQ== 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=fnC/L+iITI19MxC5UkoX7mdIvfoQD2Z62GPX+M0fcUs=; b=BkaeTGvnkltT++HFmG/tHhJuQh+fKJuTUOphvE8u16dJL0HOHJn3ngndpcO5QYkJkk QMGHPwURq+gxZfHy6TOmrRn+o+o9txSsErnM6JzaqnvIsKUllVqDGXHcpp8HN1Vx3tvb J+QxPWvsa47ZNoJ2NRZakAz9+TvWnwv2vwciPMfql9OY5m3yqmxVnYMZxxL2+38JMcGH /SZQADRdnO4bKTdVU14QeWG+7gJpazdgAtiyGpx0QH4eb5moMr4tlELkwtGD01Vv0WD+ pAyOFild3psBxK6tcK9T/iSd3yKpzSUW2eOO5Li1rqTdLQ6B0jk7RyvG9M5mZeez0OoT Iynw== X-Gm-Message-State: AOAM532tRnVRXqIlD7pIMB/iMwi0UGHZdMH/+kROZ2mv9Qb+MEmw0axq tE/FUnL/6ONs9hkEz4qiDIWtQAC8cctMAQ== X-Google-Smtp-Source: ABdhPJwWZJUlmA43+vd2p02VDwKH18gABY+ar9DSxRQw2eBU0eE11X2i0uj4DZ+9vNocyjJPIczD9A== X-Received: by 2002:adf:fe10:0:b0:203:d794:93e6 with SMTP id n16-20020adffe10000000b00203d79493e6mr22337218wrr.588.1647954999195; Tue, 22 Mar 2022 06:16:39 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id n14-20020a7bcbce000000b0038c7776a300sm2293478wmi.0.2022.03.22.06.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 06:16:38 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 13:16:33 +0000 Message-Id: <20220322131635.2869526-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322131635.2869526-1-naush@raspberrypi.com> References: <20220322131635.2869526-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/3] utils: timer: Allow Timer::start to use utils::Duration 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 overload of the Timer::start member function to accept a utils::Duration type for the timer duration. Signed-off-by: Naushir Patuck --- include/libcamera/base/timer.h | 2 ++ src/libcamera/base/timer.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libcamera/base/timer.h b/include/libcamera/base/timer.h index 09f1d3229bd5..f42a8cfd4d6d 100644 --- a/include/libcamera/base/timer.h +++ b/include/libcamera/base/timer.h @@ -14,6 +14,7 @@ #include #include +#include namespace libcamera { @@ -27,6 +28,7 @@ public: void start(unsigned int msec) { start(std::chrono::milliseconds(msec)); } void start(std::chrono::milliseconds duration); + void start(utils::Duration duration); void start(std::chrono::steady_clock::time_point deadline); void stop(); bool isRunning() const; diff --git a/src/libcamera/base/timer.cpp b/src/libcamera/base/timer.cpp index 187336e3a1a4..3ff526aea8ae 100644 --- a/src/libcamera/base/timer.cpp +++ b/src/libcamera/base/timer.cpp @@ -85,6 +85,20 @@ void Timer::start(std::chrono::milliseconds duration) start(utils::clock::now() + duration); } +/** + * \brief Start or restart the timer with a timeout of \a duration + * \param[in] duration The timer duration given by \a utils::Duration + * + * If the timer is already running it will be stopped and restarted. + * + * \context This function is \threadbound. + */ +void Timer::start(utils::Duration duration) +{ + auto msec = std::chrono::duration_cast(duration); + start(utils::clock::now() + msec); +} + /** * \brief Start or restart the timer with a \a deadline * \param[in] deadline The timer deadline From patchwork Tue Mar 22 13:16:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15508 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 D1AADC3264 for ; Tue, 22 Mar 2022 13:16:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 136E9604DC; Tue, 22 Mar 2022 14:16:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647955004; bh=qTM4qmAxdbtRT4BQtkJcg/pXc5jc8EJQPvPqtB864us=; 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=Tl7Be3oVhD2JHT451X5yImb7h+aeZum9xnTwIqe7WcWSYar576yyzf5dPsQ0n7Ksf yb5pXwuwzMR6H0d6briLdKFyH+7W1KeI4kFL2D+dSizbOISm5qN4nnhbajWyNkn56Z Q+Dl0d9raGzr2yr/+Z+hqxvC37TQxGHGOd60uYfLIR3djwGNE2BCCWNvygQ3Ug4H+A csuKnPEzZvqXVjf2jFwkhy3ciXRyByvxMUF5pumjLSRCVAPsbxsquMk5AgYLBd2NOX BYcUeSKPlMoxpXb1oG4fb4RFWTOfCWMjpZtpCVBoBvabwYcQZLl+bMsN7ZSNOPbHBA xKMxySiBQf65g== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9A62D604C5 for ; Tue, 22 Mar 2022 14:16:40 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="nyi2HF3F"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id p184-20020a1c29c1000000b0037f76d8b484so1680191wmp.5 for ; Tue, 22 Mar 2022 06:16:40 -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=TT/6DZd4OaL1YskByu42Q+/sSbt1hoBuWG14c19MMoY=; b=nyi2HF3FLpebjyGmHH3C/xmapimFHvzToHawPoENaDcI7vk8eoIHSeB6iyPGBjJ3Tn vIul1762snKCtwaSHUtpMbvh5zusSTG/OJZise7ZVYF1YsS6vDxGqAAg1ZZohH6WU2ZV tlRZvxbGd0JBrRTjX573zXghFJPeu3e3GHtX0a7MS3fCldMlEwz+7yeonCHZHeusSSZn vxqAOTCNE76bq8ZFLDg4Qzr0uLCDWuX4WsK2l4DtnI83CZA9UhanuJVzbUi5IVa2PdZ0 GXMq4KiYN15cBtOtAQ2WYmlYfflZJ5/BzEWqSo+nuGICfTj0TtWvrXpGfNoluQX46pyY Sk4A== 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=TT/6DZd4OaL1YskByu42Q+/sSbt1hoBuWG14c19MMoY=; b=NONWXONyQ4jAj5fDRd1Kwbbxm/kq2vYSkclo26CGRCuC1G61MGdB89vZzS6FuWhHQX qlzQPcTx2o9+vxQLRFruS5yfTBETNv+5wBItMpInrWV7hkW2KGD9KLILo+rjeSXuQZtk 2dBS8V0oK9npEMXg+t/vXz4KXFpHh/Ugw1bqRI0/g7ZC5xYTxIvQx1oQWY1YPglHNGF3 5eZ2oZJGkMDkCbTKspAr/PgnB0w/7N8zmHnAA4KseLja1Y/RX5GAGXkh4Y05TebX6IZI LnwvlRoxEZibcVOIybYk59dVYyBMPLaqQQhomZVwjVzRYL91vBNPrr6phDboU0KmRUqB iPbA== X-Gm-Message-State: AOAM533knc+HIR2NGPYM8Q1HzYb57H+LGU2I6poJ64JHc6fLXQvlaTiq M/aNoknTV1NngaqlRYCZE7s+Lem3hEv6Jg== X-Google-Smtp-Source: ABdhPJwTT+AqQH5Qs5N3l/Av9AF7xuNc2/RlRNz61QrmCPgoO7v6Pq50+kdGMpEjdGE2AEBDJZv/eQ== X-Received: by 2002:a05:6000:154c:b0:203:d46b:ede4 with SMTP id 12-20020a056000154c00b00203d46bede4mr22458424wry.501.1647955000105; Tue, 22 Mar 2022 06:16:40 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id n14-20020a7bcbce000000b0038c7776a300sm2293478wmi.0.2022.03.22.06.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 06:16:39 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 13:16:34 +0000 Message-Id: <20220322131635.2869526-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322131635.2869526-1-naush@raspberrypi.com> References: <20220322131635.2869526-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 2/3] libcamera: v4l2_videodevice: Add a dequeue timer 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 a timer that gets reset on every buffer dequeue event. If the timeout expires, optionally call a slot in the pipeline handler to handle this condition. This may be useful in detecting and handling stalls in either the hardware or device driver. Signed-off-by: Naushir Patuck --- include/libcamera/internal/v4l2_videodevice.h | 9 ++++ src/libcamera/v4l2_videodevice.cpp | 47 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 2d2ccc477c91..dd6e96438637 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -216,6 +217,9 @@ public: int streamOn(); int streamOff(); + void setDequeueTimeout(utils::Duration duration); + Signal dequeueTimeout; + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); @@ -246,6 +250,8 @@ private: void bufferAvailable(); FrameBuffer *dequeueBuffer(); + void timerExpired(); + V4L2Capability caps_; V4L2DeviceFormat format_; const PixelFormatInfo *formatInfo_; @@ -259,6 +265,9 @@ private: EventNotifier *fdBufferNotifier_; bool streaming_; + + Timer timer_; + utils::Duration timerDuration_; }; class V4L2M2MDevice diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 5f36ee20710d..25bce5475e07 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -600,6 +600,8 @@ int V4L2VideoDevice::open() fdBufferNotifier_->activated.connect(this, &V4L2VideoDevice::bufferAvailable); fdBufferNotifier_->setEnabled(false); + timer_.timeout.connect(this, &V4L2VideoDevice::timerExpired); + LOG(V4L2, Debug) << "Opened device " << caps_.bus_info() << ": " << caps_.driver() << ": " << caps_.card(); @@ -1695,6 +1697,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() return nullptr; } + if (timerDuration_.count()) + timer_.start(timerDuration_); + cache_->put(buf.index); FrameBuffer *buffer = it->second; @@ -1797,6 +1802,8 @@ int V4L2VideoDevice::streamOn() } streaming_ = true; + if (timerDuration_.count()) + timer_.start(timerDuration_); return 0; } @@ -1821,6 +1828,9 @@ int V4L2VideoDevice::streamOff() if (!streaming_ && queuedBuffers_.empty()) return 0; + if (timerDuration_.count()) + timer_.stop(); + ret = ioctl(VIDIOC_STREAMOFF, &bufferType_); if (ret < 0) { LOG(V4L2, Error) @@ -1843,6 +1853,43 @@ int V4L2VideoDevice::streamOff() return 0; } +/** + * \brief Set the dequeue timeout value + * \param[in] duration The timeout value to be used + * + * Sets a timeout value, given by \a duration, that will be used by a timer to + * ensure buffer dequeue events are periodically occurring. If the timer + * expires, a slot in the pipeline handler may be optionally called to handle + * this condition through the \a dequeueTimeout signal. + * + * Set \a duration to 0 to disable the timeout. + * + */ +void V4L2VideoDevice::setDequeueTimeout(utils::Duration duration) +{ + timerDuration_ = duration; + + timer_.stop(); + if (duration.count() && streaming_) + timer_.start(duration); +} + +/** + * \brief Slot to handle an expired dequeue timer. + * + * When this slot is called, the the time between successive dequeue events + * is over the required timeout. Optionally call a slot in the pipeline handler + * given by the \a dequeueTimeout signal. + */ +void V4L2VideoDevice::timerExpired() +{ + LOG(V4L2, Info) + << "Dequeue timer of " << timerDuration_ + << " has expired!"; + + dequeueTimeout.emit(this); +} + /** * \brief Create a new video device instance from \a entity in media device * \a media From patchwork Tue Mar 22 13:16:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15509 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 C88A8C0F1B for ; Tue, 22 Mar 2022 13:16:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 85FBB604DB; Tue, 22 Mar 2022 14:16:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647955006; bh=SRHd8zX2rGP5uypPrEvgme6+IFfRAI8ytSzNdhWjXDU=; 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=D5qzvjP6uOl583JNYA/E3nICiCPFvW01Ew0nW34BrlaLI7xUrBNB4FXP5B1OLyTOt TpsJsL7dUiXMdCwi4UnpMNOTGzBrYXP56PACqc9ekX1qLQVomdu1h3J5QwbU55Qnfg tOxlUNV0Wk7g7AH2gDg0zijTS/wJHjGYTlQ+NQb5h4fvsL/MmaQG8mjzWr27RQ0uCn MQOp4bsyc6HrlUgFRMyL6cHt+6Hv0cj2GZDE+mDEydiqSSb6vkdMqj6kITFFyHEN40 uMywRtJvUOx1HGrv5Zir2O/2TsWkdxL1Tckr2hYxnHCGPnvhHO/Dxd3OcH/04O9xyx Q14OmBadrkUxw== Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 77414604E8 for ; Tue, 22 Mar 2022 14:16:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Bvu3mWU9"; dkim-atps=neutral Received: by mail-wm1-x333.google.com with SMTP id bi13-20020a05600c3d8d00b0038c2c33d8f3so2431665wmb.4 for ; Tue, 22 Mar 2022 06:16:41 -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=tgA21Uc9i7A/Vd4j8bEgnI9K63bVJqGeeiMn4t/Uurs=; b=Bvu3mWU9RKcLvF9hkwFGQi3koH+ZoCIfbYAblzfJ2VHgDX7ekNcxYuSKLVIJwfWqyb pog/NsbBWwoDv0KOah+7yQbIziKfypTIA0PqRxLWuLM/4jVuNiE54y8hR0suOrpfa8zf QpA0TpywAY9H0Ik49RbNy39NMDYKSxnnU54ZsSLd1oyI9JgjPAjEYxZK3UGh8T0HBAix ijiYq76rm62YIbJ29P5vO/RYcNDOdDNIfXNWT3z8hZlImdYwkRdMoVoQZiAqoKmcsX0i Qo3+ry5i/7Q0pHhnIcAPKss9SggMahbo0S7w0H84Ly9P3N8fUuNpUIBo5GM/cEGDbSu3 DdxQ== 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=tgA21Uc9i7A/Vd4j8bEgnI9K63bVJqGeeiMn4t/Uurs=; b=r7+cVDqJbWaUif04VNSXnZtZSxzqV/Cwq2fA/khPQIY9YOBJXcSU0/FTFOh2l8e7Zf NPOMvD7CyvHGr7H5q8mkAz0JAxF1i9iWms9rZUq+ymtTYKmYzYLnKDY4B/hp+LvATGop JpfXx0gWPy/xSE018h3bEtjksZYylgfiyJ1PPoPOAp/TweMGSP3PhjXWjZTXPryI8k6h K+NZnrEUIab6A2d7DfaKNQb9dTKoVHGDIlIhjmkxrFYodVI0BSgBQNegWlKFGvq+E9Li pxfjTDglqTCzMxMkjL9dh9GSFtVCupeLPnEYoD0lpvV6FkAPTctdKWMnmzI1LibRrgfc un1A== X-Gm-Message-State: AOAM533yBcnOfMbeew9MlVMX4lxHhZa2vSHlnXPBWZP/COJ9dvtOWlaA D4UGCiMy104R8nHyXxFUgdjGFfUvmZ2Kpw== X-Google-Smtp-Source: ABdhPJxKY8R0YQ6OafX9uarK9lQ5wWJVLxv+YBh6Y18/S0oFmklCel0XNLDZcMJ409In0f8GKnqcZg== X-Received: by 2002:adf:e6ce:0:b0:203:d9cb:a1b4 with SMTP id y14-20020adfe6ce000000b00203d9cba1b4mr22731083wrm.140.1647955000933; Tue, 22 Mar 2022 06:16:40 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id n14-20020a7bcbce000000b0038c7776a300sm2293478wmi.0.2022.03.22.06.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 06:16:40 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 13:16:35 +0000 Message-Id: <20220322131635.2869526-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322131635.2869526-1-naush@raspberrypi.com> References: <20220322131635.2869526-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 3/3] pipeline: raspberrypi: Add a Unicam dequeue timeout 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" Enable the V4L2VideoDevice dequeue timeout for the Unicam Image node, and connect the timeout signal to a slot in the pipeline handler. This slot will log a fatal error message informing the user of a possible hardware stall. The timeout is calculated as 2x the maximum frame length possible for a given mode, returned by the IPA. Signed-off-by: Naushir Patuck --- include/libcamera/ipa/raspberrypi.mojom | 1 + src/ipa/raspberrypi/raspberrypi.cpp | 2 ++ .../pipeline/raspberrypi/raspberrypi.cpp | 15 +++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index acd3cafe6c91..5a228b75cd2f 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -41,6 +41,7 @@ struct IPAConfig { struct StartConfig { libcamera.ControlList controls; int32 dropFrameCount; + uint32 maxSensorFrameLengthMs; }; interface IPARPiInterface { diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index fd8fecb07f81..675f9ba1b350 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -280,6 +280,8 @@ void IPARPi::start(const ControlList &controls, ipa::RPi::StartConfig *startConf } startConfig->dropFrameCount = dropFrameCount_; + const Duration maxSensorFrameDuration = mode_.max_frame_length * mode_.line_length; + startConfig->maxSensorFrameLengthMs = maxSensorFrameDuration.get(); firstStart_ = false; lastRunTimestamp_ = 0; diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index c2230199fed7..50b39f1adf93 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -45,6 +45,8 @@ #include "dma_heaps.h" #include "rpi_stream.h" +using namespace std::literals::chrono_literals; + namespace libcamera { LOG_DEFINE_CATEGORY(RPI) @@ -202,6 +204,7 @@ public: void setIspControls(const ControlList &controls); void setDelayedControls(const ControlList &controls); void setSensorControls(ControlList &controls); + void unicamTimeout(V4L2VideoDevice *dev); /* bufferComplete signal handlers. */ void unicamBufferDequeue(FrameBuffer *buffer); @@ -1032,6 +1035,12 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) } } + /* Set the dequeue timeout to 2x the maximum possible frame duration. */ + utils::Duration duration = startConfig.maxSensorFrameLengthMs * 2 * 1ms; + data->unicam_[Unicam::Image].dev()->setDequeueTimeout(duration); + data->unicam_[Unicam::Image].dev()->dequeueTimeout.connect(data, &RPiCameraData::unicamTimeout); + LOG(RPI, Debug) << "Setting sensor timeout to " << duration; + return 0; } @@ -1040,6 +1049,7 @@ void PipelineHandlerRPi::stopDevice(Camera *camera) RPiCameraData *data = cameraData(camera); data->state_ = RPiCameraData::State::Stopped; + data->unicam_[Unicam::Image].dev()->dequeueTimeout.disconnect(); /* Disable SOF event generation. */ data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(false); @@ -1757,6 +1767,11 @@ void RPiCameraData::setSensorControls(ControlList &controls) sensor_->setControls(&controls); } +void RPiCameraData::unicamTimeout([[maybe_unused]] V4L2VideoDevice *dev) +{ + LOG(RPI, Fatal) << "Unicam has timed out!"; +} + void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) { RPi::Stream *stream = nullptr;