{"id":15632,"url":"https://patchwork.libcamera.org/api/patches/15632/?format=json","web_url":"https://patchwork.libcamera.org/patch/15632/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220406123554.4042163-3-naush@raspberrypi.com>","date":"2022-04-06T12:35:53","name":"[libcamera-devel,v5,2/3] pipeline: raspberrypi: Add a Unicam dequeue timeout","commit_ref":"04faa8477abdaf1dafad3fdbe9dc58326e9126d2","pull_url":null,"state":"accepted","archived":false,"hash":"8ff573b754c659a9f4513f65d786453263c6326a","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15632/mbox/","series":[{"id":3035,"url":"https://patchwork.libcamera.org/api/series/3035/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3035","date":"2022-04-06T12:35:51","name":"Dequeue timeout","version":5,"mbox":"https://patchwork.libcamera.org/series/3035/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15632/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15632/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 26A38C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  6 Apr 2022 12:36:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 632576564C;\n\tWed,  6 Apr 2022 14:36:04 +0200 (CEST)","from mail-wr1-x433.google.com (mail-wr1-x433.google.com\n\t[IPv6:2a00:1450:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D7126563F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  6 Apr 2022 14:36:03 +0200 (CEST)","by mail-wr1-x433.google.com with SMTP id m30so3036114wrb.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 06 Apr 2022 05:36:03 -0700 (PDT)","from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:8464:e7f5:f44c:ee9f])\n\tby smtp.gmail.com with ESMTPSA id\n\tp8-20020a5d59a8000000b00204178688d3sm16712490wrr.100.2022.04.06.05.36.01\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 06 Apr 2022 05:36:01 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1649248564;\n\tbh=Z37E5czrIxS96iACdLcn9YE3Yf7nsd/gVZv1kceH06E=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=zG5PbzLIcSog+kbsclKnq4naIq2eiayWLmnuUhLEMrRl+prNUnLN8+9YWjkhaFNAf\n\t5sqkQBnB0Io+88pF1JzVYnjMLu5+OpqAXLNxw6xCm8YZWqkRNiHnJ+0vc1/KuaKiVh\n\tHfdppLT3Mo+x2b6ZYnyMdGdnRjEQmW8Lw3l4FHk1H+GZZ85cyG5jjSkgxuFSngRRLe\n\tmP8d7dYfH7t6wbQLjaJy4h/cuLNgIl2nhAdfIaP7zMogyt+56hrTDiCWWokSxxjP/w\n\t3Po52ryCgsXbghocMbjc4C1hUe6xlM1LVW0CJOCd0w2ZJacjmdOQgpgaSxlqDEW0sz\n\tp52jnOHF23iQw==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=SfEznbmp787RA8aq2UHbqCWXXr1yMkSr3uFtkGUjOHE=;\n\tb=d/w9tiHwgP2fJ0pxkZkA31T/RT2X5NciOfmc/uhek1pr9MAB47qPyFCss2lQl5wJD4\n\txPYXdHaA63edTwbC2nhiwv2xEGjXeaALi9VPA0PxWMwAG5SG3/jvX2uTzxQEixm0QWiZ\n\tgKvhY3/RYfgNPDDJ+OBOk/DfSTOoRSCLsB5CoB/3EGT8z50oAOgIuAym9+IwrT5dvq6B\n\tGBU6+wBfRG1YvbfDppjnuS1si0kAzDQgv0i+jD8YqfB3kyO8CQh1tG5KF3ccz8cV4cFt\n\tn1wEgaLHxvsZijOe2bJiUF/vX6Y/DDdnVcVMkvqPgq94vMPVcNV9OXh6mxTXRdKTyUps\n\teL1g=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"d/w9tiHw\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=SfEznbmp787RA8aq2UHbqCWXXr1yMkSr3uFtkGUjOHE=;\n\tb=7AchjltM/y8QrdTN73hxK3GjBUQQcVmoz5jPTXcEgUp41WC6o4+yFkRPmVOLc6rxpb\n\tUm03xBB/k/w23jIvtE3b8qr04rzNOd+4P7aLrefnksS5M3/i8gZKIoltFrpqqeAuIZhq\n\tlYvWmA/JxUYswSGAT4PhB4CH73PLchwbH8oQmXUVsbAsGl7KDV1DTaSehxWEqkmUvs2f\n\tACtMkV4ffUg0IR68smC5tiF1a+D89I0ZMYKroYJpVch5i5oSsk5X/4vAyrKWB2K5wnP1\n\tTfLKo8AI3+XqI9qqw0nExYnMzd4KviMH3h0POELU8cbHuDr0vMSMkmWvdqGMhGsbpNY9\n\tugxA==","X-Gm-Message-State":"AOAM533rk7i9U9E4QfQ2Kl1WxP8WfrcxpzRax8O61uQ0kxh0WltXeQ1W\n\t6YIeaTjhyQ0faYCU1JXw26UeeoNJTrXscw==","X-Google-Smtp-Source":"ABdhPJwf/Qn01fMIcwmZCLZbzf/umDyeb6QidGgFctauHT0x37lFblji5SYXrpdTyLwLzj1JbNbWjA==","X-Received":"by 2002:adf:f74a:0:b0:206:1767:129 with SMTP id\n\tz10-20020adff74a000000b0020617670129mr3852440wrp.87.1649248562545; \n\tWed, 06 Apr 2022 05:36:02 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  6 Apr 2022 13:35:53 +0100","Message-Id":"<20220406123554.4042163-3-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20220406123554.4042163-1-naush@raspberrypi.com>","References":"<20220406123554.4042163-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 2/3] pipeline: raspberrypi: Add a\n\tUnicam dequeue timeout","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Enable the V4L2VideoDevice dequeue timeout for the Unicam Image node, and\nconnect the timeout signal to a slot in the pipeline handler. This slot will\nlog an error message informing the user of a possible hardware stall.\n\nThe timeout is calculated as 2x the maximum frame length possible for a given\nmode, returned by the IPA.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/ipa/raspberrypi.mojom       |  1 +\n src/ipa/raspberrypi/raspberrypi.cpp           |  2 ++\n .../pipeline/raspberrypi/raspberrypi.cpp      | 19 +++++++++++++++++++\n 3 files changed, 22 insertions(+)","diff":"diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom\nindex acd3cafe6c91..5a228b75cd2f 100644\n--- a/include/libcamera/ipa/raspberrypi.mojom\n+++ b/include/libcamera/ipa/raspberrypi.mojom\n@@ -41,6 +41,7 @@ struct IPAConfig {\n struct StartConfig {\n \tlibcamera.ControlList controls;\n \tint32 dropFrameCount;\n+\tuint32 maxSensorFrameLengthMs;\n };\n \n interface IPARPiInterface {\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 1bf4e270b062..89767a9db471 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -280,6 +280,8 @@ void IPARPi::start(const ControlList &controls, ipa::RPi::StartConfig *startConf\n \t}\n \n \tstartConfig->dropFrameCount = dropFrameCount_;\n+\tconst Duration maxSensorFrameDuration = mode_.max_frame_length * mode_.line_length;\n+\tstartConfig->maxSensorFrameLengthMs = maxSensorFrameDuration.get<std::milli>();\n \n \tfirstStart_ = false;\n \tlastRunTimestamp_ = 0;\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 8fd79be67988..d6148724bdd5 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -45,6 +45,8 @@\n #include \"dma_heaps.h\"\n #include \"rpi_stream.h\"\n \n+using namespace std::chrono_literals;\n+\n namespace libcamera {\n \n LOG_DEFINE_CATEGORY(RPI)\n@@ -208,6 +210,7 @@ public:\n \tvoid setIspControls(const ControlList &controls);\n \tvoid setDelayedControls(const ControlList &controls);\n \tvoid setSensorControls(ControlList &controls);\n+\tvoid unicamTimeout();\n \n \t/* bufferComplete signal handlers. */\n \tvoid unicamBufferDequeue(FrameBuffer *buffer);\n@@ -1050,6 +1053,14 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls)\n \t\t}\n \t}\n \n+\t/*\n+\t * Set the dequeue timeout to the larger of 2x the maximum possible\n+\t * frame duration or 1 second.\n+\t */\n+\tutils::Duration timeout =\n+\t\tstd::max<utils::Duration>(1s, 2 * startConfig.maxSensorFrameLengthMs * 1ms);\n+\tdata->unicam_[Unicam::Image].dev()->setDequeueTimeout(timeout);\n+\n \treturn 0;\n }\n \n@@ -1192,6 +1203,7 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me\n \tdata->isp_[Isp::Stats] = RPi::Stream(\"ISP Stats\", ispCapture3);\n \n \t/* Wire up all the buffer connections. */\n+\tdata->unicam_[Unicam::Image].dev()->dequeueTimeout.connect(data.get(), &RPiCameraData::unicamTimeout);\n \tdata->unicam_[Unicam::Image].dev()->frameStart.connect(data.get(), &RPiCameraData::frameStarted);\n \tdata->unicam_[Unicam::Image].dev()->bufferReady.connect(data.get(), &RPiCameraData::unicamBufferDequeue);\n \tdata->isp_[Isp::Input].dev()->bufferReady.connect(data.get(), &RPiCameraData::ispInputDequeue);\n@@ -1773,6 +1785,13 @@ void RPiCameraData::setSensorControls(ControlList &controls)\n \tsensor_->setControls(&controls);\n }\n \n+void RPiCameraData::unicamTimeout()\n+{\n+\tLOG(RPI, Error) << \"Unicam has timed out!\";\n+\tLOG(RPI, Error) << \"Please check that your camera sensor connector is attached securely.\";\n+\tLOG(RPI, Error) << \"Alternatively, try another cable and/or sensor.\";\n+}\n+\n void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n {\n \tRPi::Stream *stream = nullptr;\n","prefixes":["libcamera-devel","v5","2/3"]}