From patchwork Thu Mar 24 09:34:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15530 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 A464ABD80A for ; Thu, 24 Mar 2022 09:34:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BFB77604DA; Thu, 24 Mar 2022 10:34:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648114453; bh=zILa/s1ntW+kghEdxq25c2IT3/MqXufb22HdwyIDlaQ=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=P7zzfEmtnu+Hd8BQ7zeqqVw4k5UH91to50N4DYwCNCeLpHpq/tLzOhK5xM+iWMmVp WqrbmYTe2fVetyi0lv7+GjxONINxg5unKqsJ40jXTe0bAoyen/APlW7eZy/kgKUc93 YhC3aT2LSra2FtXHmxpNXRGsf05tppHgFoS+PrfFuxz4xptweTyxJcJLpC+VEuIIfd lv9RSzYTRQOhGLz0CsR72nPGdK+7FW1ncwtbwSXCWX6bQtBzmjPLKWhDIJ5PSv5Ptk Shou/3yGgPtOaYyS9+uFwwmkq273XymhEjgSEC6uAk6DjYgCLeK1IMM9a7wJqPVngm o+rI/s4I9r+Fw== Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D3DE601F5 for ; Thu, 24 Mar 2022 10:34:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="qwYDpSJM"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id t11so5732917wrm.5 for ; Thu, 24 Mar 2022 02:34:12 -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:mime-version :content-transfer-encoding; bh=ipNazOf+GDYpo5NVgHVuDTgMHP3J4Xmz8ZP+fnMDeXE=; b=qwYDpSJMyAXbuY1joW4PyF3BnGNsdTElGIsm6q18AEttLO/Ug8fy7wDBKpQCZsqBVy CS++ALMYed0kVfj5ZOyUWwZ3ys0Dylve/1eqGBnzrOThF+2Rga9+ha11bHu5OZAOu/wh J5OFgfKk0VNsRLIKd4h5db4fKPRu50vXOX1nlHcnfOyudGy36ow+qxddunV3y/1RNTff uahhOuG//O6oTxTyYumt+Iv3amfQi+CMYHISrLMv80wNtMuprYdhQcPAGGiSTfZbZc25 /807wbuan4FOw+2cZ5XqaYSl1WfEbcq9tHlawaqYWBgRNkLGkAhIdvoxX3SXhtwZIbMo WU4g== 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:mime-version :content-transfer-encoding; bh=ipNazOf+GDYpo5NVgHVuDTgMHP3J4Xmz8ZP+fnMDeXE=; b=kag4zuaWMD9xsDUIbYq7KeMGBzryNcjnSkf4i1jTPtiP7Fv+vFEDZa8Eo80ycpsD/K ZtONkdbN0FvqpWJ2+ooHcguVgHM1gE60gMORe7ZmzFVI5GM8kBBoIT0tjUjOwbjNPmxf Pvb7PTZCr0EqURFrFcWLy6hCCpqdTsTo0V1Cw28axCt37HmHVhxlFEaVXgfEM9fYVNMa WERdjhCNAwLEGVA34bPAaeKbDStS9GDArxdniFOMtWdxznymQzfhmwA4kG6XGcS/WCbv QxMuWsp4DWqUnVtFiq8Ure1nJI5Eqix4uOMi/WH3HDjIStsztApAhZ0yS20dXdbMi9if XEhQ== X-Gm-Message-State: AOAM531DmNtpOzEY5IeB+fwWta5etUDwhr25+s/518x9iimswnrxyyn6 m29Zlcee35SMTuxXltkyJWDSwOblt0SyjA== X-Google-Smtp-Source: ABdhPJy1VftVIwWyw3CjFXxCudIlqlkZH5ydjFQTvSViF+IM6XE3hO5ggI4iiyiXMb2ngjgSTtd9PA== X-Received: by 2002:adf:dfc2:0:b0:1f0:262a:d831 with SMTP id q2-20020adfdfc2000000b001f0262ad831mr3715271wrn.589.1648114451724; Thu, 24 Mar 2022 02:34:11 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:18f1:1b78:a3ab:7eda]) by smtp.gmail.com with ESMTPSA id v15-20020a056000144f00b002057eac999fsm2243889wrx.76.2022.03.24.02.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 02:34:11 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Mar 2022 09:34:08 +0000 Message-Id: <20220324093409.29247-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] 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 | 10 ++++ src/libcamera/v4l2_videodevice.cpp | 49 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 2d2ccc477c91..c34cc6585612 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include @@ -216,6 +218,9 @@ public: int streamOn(); int streamOff(); + void setDequeueTimeout(std::chrono::milliseconds msec); + Signal<> dequeueTimeout; + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); @@ -246,6 +251,8 @@ private: void bufferAvailable(); FrameBuffer *dequeueBuffer(); + void watchdogExpired(); + V4L2Capability caps_; V4L2DeviceFormat format_; const PixelFormatInfo *formatInfo_; @@ -259,6 +266,9 @@ private: EventNotifier *fdBufferNotifier_; bool streaming_; + + Timer watchdog_; + std::chrono::milliseconds watchdogDuration_; }; class V4L2M2MDevice diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 5f36ee20710d..29225f3058b0 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -526,6 +526,7 @@ V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode) V4L2VideoDevice::V4L2VideoDevice(const MediaEntity *entity) : V4L2VideoDevice(entity->deviceNode()) { + watchdog_.timeout.connect(this, &V4L2VideoDevice::watchdogExpired); } V4L2VideoDevice::~V4L2VideoDevice() @@ -1695,6 +1696,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() return nullptr; } + if (watchdogDuration_.count()) + watchdog_.start(watchdogDuration_); + cache_->put(buf.index); FrameBuffer *buffer = it->second; @@ -1797,6 +1801,8 @@ int V4L2VideoDevice::streamOn() } streaming_ = true; + if (watchdogDuration_.count()) + watchdog_.start(watchdogDuration_); return 0; } @@ -1821,6 +1827,9 @@ int V4L2VideoDevice::streamOff() if (!streaming_ && queuedBuffers_.empty()) return 0; + if (watchdogDuration_.count()) + watchdog_.stop(); + ret = ioctl(VIDIOC_STREAMOFF, &bufferType_); if (ret < 0) { LOG(V4L2, Error) @@ -1843,6 +1852,46 @@ int V4L2VideoDevice::streamOff() return 0; } +/** + * \brief Set the dequeue timeout value + * \param[in] msec The timeout value to be used + * + * Sets a timeout value, given by \a msec, 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 msec to 0 to disable the watchdog timer. + */ +void V4L2VideoDevice::setDequeueTimeout(std::chrono::milliseconds msec) +{ + watchdogDuration_ = msec; + + watchdog_.stop(); + if (watchdogDuration_.count() && streaming_) + watchdog_.start(msec); +} + +/** + * \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_.count() + << " ms has expired!"; + + dequeueTimeout.emit(); +} + /** * \brief Create a new video device instance from \a entity in media device * \a media