From patchwork Mon Mar 21 12:48:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15489 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 265C2BDE17 for ; Mon, 21 Mar 2022 12:48:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8F046604D4; Mon, 21 Mar 2022 13:48:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647866915; bh=l6FGZX125eO/R0eapnZwu2hSRp/wg9PDyas3WDx4bbE=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=1VGJzdOkTUOVl+M9Letjf3HWoEDJIDVLuwkUdWTOHZfQ0EKfwqLRa9ghR7E9SHsiY wCnueh4KpPb4cgGdGu/Ivcz8SG/tdsZ+x2iTqQ3pFqo3W9zO2Dy1C1BRyalz4BnRDE 2syv3utroyAIGcyuWGhkaxBvuUjqVT6dabByj+gym7LuxjsiW+QI/34Zmk0/FiFnVS ySBA0eIpV9OJ6CBAN5QLaJYldf9w4DEenCZIbt2RNPQUZuhJ99LWWySAp8dPjU4V3o VseLulw7MPSu0BFFLE6zrobvk4OyBuDTwRJEvkJRWMuqBMe+/jPhS7uuZYNA3pOdNh LAc63eimOYWjQ== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A03CD604C6 for ; Mon, 21 Mar 2022 13:48:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="MHD7rvvo"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id b19so20512421wrh.11 for ; Mon, 21 Mar 2022 05:48:33 -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=eom49egC79+V85At1spf0wwWgp6r3T8TKStanhXsZ+Y=; b=MHD7rvvolcaDBwffV5mlVqRngck5+uw2/zvjhejGWJFtQ6Y/8Lu84nbqTSWmJY96qr r3/4mLO82lFdmeWzm8n10PKob7kXefhuOrULk7sh3N4iOy02+0OZZXOISuLkGD04vYrX nEu1BpaUhys3Y8JYbQR5DEIrJg0WOWC7aMLbeuoXe3iUV9hAjdCSQw7X2slOGP/onvxh Y/B/EzvMagqqGH18JzFaV/BOo+Om1RO/nqKMZuhRVFkWg63GJP5kcYSHN2A1w4CoIk7w BCcdOlLAfYsdCeaA/iqnn5DRqSPJR4Nf8XdLEdL5BY4YlbTf3gYbgwi4dGzFuvLq6SPu t1ow== 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=eom49egC79+V85At1spf0wwWgp6r3T8TKStanhXsZ+Y=; b=QpMe7XfCmZN4hXO4AF29J6Qe5QghROCQBRk6bbG021XExhZgdsh4oMp8EytNhTuqPD hup5Q2S0RCO3As13Xpomk9fbaPBL/WSAUuUEZ1BLND0DaHuo3mE6SPggS1BKsZ5p2C9f +0Mq5x6gWWvSdl+xG6oCJf/SD5Qs6ijuREXlj/kZkiR4m6ct0vE8yan3pvCoyjfJNO3I 4//dh1cteNix/JYxJVHKqh2fsUSYCE+puti201xkEuxqoVMJAgeagbX+D6A7xTu300ha QE9ROvUsNQgVq1o7LegyNGmzMJWvcuq4Vp/bJXIuMEFGpjcbQkhMtougUvc593Zza59f t2nQ== X-Gm-Message-State: AOAM533Lm0Rf4By69xqRRE/njq8l3oL1VhoTxchCQkwgGWLFHFBWMequ CfCayrMsaLytj9SKxAs9+R5asNTmoVsSng== X-Google-Smtp-Source: ABdhPJw7arhMSovWUEEO8P/nxsF4cSka59qqclVEPRWavhAu324Djm8nl5Pw0rKrO7qQszMQYHLEIg== X-Received: by 2002:a5d:6707:0:b0:203:e60e:49fa with SMTP id o7-20020a5d6707000000b00203e60e49famr18522224wru.603.1647866912920; Mon, 21 Mar 2022 05:48:32 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:77bd:7c6c:a8b9:8855]) by smtp.gmail.com with ESMTPSA id l12-20020a05600c4f0c00b0038be825b774sm15120339wmq.45.2022.03.21.05.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 05:48:32 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Mar 2022 12:48:28 +0000 Message-Id: <20220321124828.1845058-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] pipeline: raspberrypi: Add a sensor 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" Add a timer to the pipeline handler that get set on start(), and subsequently reset on each frame dequeue from the sensor. If the timeout expires, log an error message indicating so. This is useful for debugging sensor failures were the device just stops streaming frames to Unicam, or the pipeline handler has failed to queue buffers to the Unicam device driver. The timeout is calculated as 2x the maximum frame length possible for a given mode. Signed-off-by: Naushir Patuck --- include/libcamera/ipa/raspberrypi.mojom | 1 + src/ipa/raspberrypi/raspberrypi.cpp | 7 ++++++ .../pipeline/raspberrypi/raspberrypi.cpp | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index acd3cafe6c91..33d2a97ca916 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 sensorTimeoutMs; }; interface IPARPiInterface { diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index fd8fecb07f81..983d6e998b4c 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -281,6 +281,13 @@ void IPARPi::start(const ControlList &controls, ipa::RPi::StartConfig *startConf startConfig->dropFrameCount = dropFrameCount_; + /* + * Set the pipeline handler's sensor timeout to 2x the maximum possible + * frame duration for this mode. + */ + const Duration maxSensorFrameDuration = mode_.max_frame_length * mode_.line_length; + startConfig->sensorTimeoutMs = 2 * maxSensorFrameDuration.get(); + firstStart_ = false; lastRunTimestamp_ = 0; } diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index c2230199fed7..86d952b52aed 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -202,6 +203,7 @@ public: void setIspControls(const ControlList &controls); void setDelayedControls(const ControlList &controls); void setSensorControls(ControlList &controls); + void sensorTimeout(); /* bufferComplete signal handlers. */ void unicamBufferDequeue(FrameBuffer *buffer); @@ -279,6 +281,10 @@ public: */ std::optional notifyGainsUnity_; + /* Timer to ensure the sensor is producing frames for the pipeline handler. */ + Timer sensorTimeout_; + std::chrono::milliseconds sensorTimeoutDuration_; + private: void checkRequestCompleted(); void fillRequestMetadata(const ControlList &bufferControls, @@ -1032,6 +1038,11 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) } } + LOG(RPI, Debug) << "Setting sensor timeout to " << startConfig.sensorTimeoutMs << " ms"; + data->sensorTimeoutDuration_ = std::chrono::milliseconds(startConfig.sensorTimeoutMs); + data->sensorTimeout_.start(data->sensorTimeoutDuration_); + data->sensorTimeout_.timeout.connect(data, &RPiCameraData::sensorTimeout); + return 0; } @@ -1040,6 +1051,8 @@ void PipelineHandlerRPi::stopDevice(Camera *camera) RPiCameraData *data = cameraData(camera); data->state_ = RPiCameraData::State::Stopped; + data->sensorTimeout_.timeout.disconnect(); + data->sensorTimeout_.stop(); /* Disable SOF event generation. */ data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(false); @@ -1757,6 +1770,12 @@ void RPiCameraData::setSensorControls(ControlList &controls) sensor_->setControls(&controls); } +void RPiCameraData::sensorTimeout() +{ + LOG(RPI, Error) << "Sensor has timed out after " + << sensorTimeoutDuration_.count() << " ms!"; +} + void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) { RPi::Stream *stream = nullptr; @@ -1792,6 +1811,9 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) */ ctrl.set(controls::SensorTimestamp, buffer->metadata().timestamp); bayerQueue_.push({ buffer, std::move(ctrl) }); + + /* Restart the sensor timer. */ + sensorTimeout_.start(sensorTimeoutDuration_); } else { embeddedQueue_.push(buffer); }