From patchwork Wed Apr 6 07:58: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: 15623 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 AE8F3C0F1B for ; Wed, 6 Apr 2022 07:59:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3DDCF65649; Wed, 6 Apr 2022 09:59:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1649231947; bh=rYcmruh35Pg+MdVWCwJV+IR5WnvTsKJr/Jx6h2VPJGk=; 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=3SyYtLkz7myab0hT8uElonBbE3l5BnEFpYePkjgaWSAclx89IP/rI84uVtN4wCFus j9OGQgwdgAzKw/ndynqOZqYZA3AvXJbEav1SszT89V7YbF2MG8P5A+r0xJYxyMVkrR A5W9VEGLMWF8Gouy7laIGHusHfwqYAW2SyZ01/xy2hTZGd9SqxJbZA3f1pWvto0RNT SmH5Lv8xnC+OkMvSPBSEWNylDFSlrHCd25upB11ZMVWVeF9RnLVUZxh0d8SJpJXAmh 1TjdXjx1xmmvw77X4bwxmR1CU4dTP6nYQRD2hox4tkWKtEywouEeI8ydHZm5nYtL7U sl8GHhxAOqldQ== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7ABBA6563F for ; Wed, 6 Apr 2022 09:59:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="orwOb8y1"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id l7-20020a05600c1d0700b0038c99618859so3084123wms.2 for ; Wed, 06 Apr 2022 00:59:05 -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=ZYCgnUfigpETSTFDrFlUETziIrYy1O0tzrpB8f0Bg/A=; b=orwOb8y1nU3pIRKc7SpZ5lpOuGnD3L6eLfBj5IcM7eBtL21XQtCmHQqyBP/znlDfMI z79aUg/3jVm8bySpvM+Hv4hzRfd9NOEfOuOansX5KOgDWrkDxbjtN+xFMmlCB6r6OdtL 46cH3Xd2XDYr1OydfX7g4UBRMGHPfDWmRJwsTsDMg75+jwJIrax/XlrdOb4VlZCPDVJg quUElZjvPoPxjX6jSnueMO2bOGg+YEURlVWMBunvO1R5cFw6GyhWkODs0V+0WnrL6Ef1 m7/qQ/n1CrPWkKMYVHjjyfg4ltw/Z5YTN9hG95hJvUlOIz/W8uw+2ZYtNVURKaLtxTRU peOA== 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=ZYCgnUfigpETSTFDrFlUETziIrYy1O0tzrpB8f0Bg/A=; b=tuwBB0Fn3dkY8spvUUE2F37kKLKNBX9mw1pbFe5eI9cbXIdlLESRgUEbKj9BSWXSL4 13UZUVmDsQOIqhQbDnqqHkOdcpn0U6I3mN5lFrxsxd8rAtsSB/P8vxCHjF11VHqhfBVC Q3h4OgM9NGFworl/3NCGN2nYIR6FirVnfI7XXlpiSj/X8rmwelVK0STBa6vyKfD8C022 tWYs8tiQnequB7fMDz9sxA8cHt7T95OjypjJYACcBVeYb6RAab90ntZd4w/nIUYEHPxG IgU8xEOaK+JCuYNJa5ZqoeZEmHKvJ5B5pxB9+gExehrFTjr/TTY9rnLa94UAZJmSdUBp FcxA== X-Gm-Message-State: AOAM531UOauKL7TvxT/bmV8rdwE4JCwIXqPhy8a76Vy6QEwkRIj3JPDD 1c335xY1UEJ9fq3FntfwcuNaNKnBnNQIrQ== X-Google-Smtp-Source: ABdhPJzBUHJviF339eL35Hh7FgEfRyWvNeagD1uTZ8ChtIEBYEBSfL7oWdHd7UdgF25OYtj4alvMLw== X-Received: by 2002:a05:600c:4fd4:b0:38c:cc3f:ac01 with SMTP id o20-20020a05600c4fd400b0038ccc3fac01mr6386109wmq.206.1649231944843; Wed, 06 Apr 2022 00:59:04 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:eedb:32e2:e3d4:3bfa]) by smtp.gmail.com with ESMTPSA id 14-20020a056000154e00b00203f8adde0csm17235503wry.32.2022.04.06.00.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 00:59:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Apr 2022 08:58:57 +0100 Message-Id: <20220406075859.3857121-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220406075859.3857121-1-naush@raspberrypi.com> References: <20220406075859.3857121-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/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" From: Naushir Patuck via 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 Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_videodevice.h | 10 ++++ src/libcamera/v4l2_videodevice.cpp | 55 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index cfeae7bd6c52..9c9493cc16ed 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include #include @@ -217,6 +219,9 @@ public: int streamOn(); int streamOff(); + void setDequeueTimeout(utils::Duration timeout); + Signal<> dequeueTimeout; + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); @@ -253,6 +258,8 @@ private: void bufferAvailable(); FrameBuffer *dequeueBuffer(); + void watchdogExpired(); + V4L2Capability caps_; V4L2DeviceFormat format_; const PixelFormatInfo *formatInfo_; @@ -266,6 +273,9 @@ private: EventNotifier *fdBufferNotifier_; State state_; + + Timer watchdog_; + utils::Duration watchdogDuration_; }; class V4L2M2MDevice diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 0830be80c553..dc5020df5c5c 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -539,6 +539,7 @@ V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode) V4L2VideoDevice::V4L2VideoDevice(const MediaEntity *entity) : V4L2VideoDevice(entity->deviceNode()) { + watchdog_.timeout.connect(this, &V4L2VideoDevice::watchdogExpired); } V4L2VideoDevice::~V4L2VideoDevice() @@ -1726,6 +1727,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() return nullptr; } + if (watchdogDuration_.count()) + watchdog_.start(std::chrono::duration_cast(watchdogDuration_)); + cache_->put(buf.index); FrameBuffer *buffer = it->second; @@ -1828,6 +1832,8 @@ int V4L2VideoDevice::streamOn() } state_ = State::Streaming; + if (watchdogDuration_.count()) + watchdog_.start(std::chrono::duration_cast(watchdogDuration_)); return 0; } @@ -1852,6 +1858,9 @@ int V4L2VideoDevice::streamOff() if (state_ != State::Streaming && queuedBuffers_.empty()) return 0; + if (watchdogDuration_.count()) + watchdog_.stop(); + ret = ioctl(VIDIOC_STREAMOFF, &bufferType_); if (ret < 0) { LOG(V4L2, Error) @@ -1879,6 +1888,52 @@ int V4L2VideoDevice::streamOff() return 0; } +/** + * \brief Set the dequeue timeout value + * \param[in] timeout The timeout value to be used + * + * Sets a timeout value, given by \a timeout, that will be used by a watchdog timer + * to ensure buffer dequeue events are periodically occurring when the device is + * streaming. The watchdog timer is only active when the device is streaming, so + * it is not necessary to disable it when the device stops streaming. The timeout + * value can be safely updated at any time. + * + * If the timer expires, the \ref V4L2VideoDevice::dequeueTimeout signal is + * emitted. This can typically be used by pipeline handlers to be notified of + * stalled devices. + * + * Set \a timeout to 0 to disable the watchdog timer. + */ +void V4L2VideoDevice::setDequeueTimeout(utils::Duration timeout) +{ + watchdogDuration_ = timeout; + + watchdog_.stop(); + if (watchdogDuration_.count() && state_ == State::Streaming) { + watchdog_.start(std::chrono::duration_cast(timeout)); + } +} + +/** + * \var V4L2VideoDevice::dequeueTimeout + * \brief A Signal emitted when the dequeue watchdog timer expires + */ + +/** + * \brief Slot to handle an expired dequeue timer + * + * When this slot is called, the time between successive dequeue events is over + * the required timeout. Emit the \ref V4L2VideoDevice::dequeueTimeout signal. + */ +void V4L2VideoDevice::watchdogExpired() +{ + LOG(V4L2, Warning) + << "Dequeue timer of " << watchdogDuration_ + << " has expired!"; + + dequeueTimeout.emit(); +} + /** * \brief Create a new video device instance from \a entity in media device * \a media