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