From patchwork Tue Feb 2 17:05:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 11106 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 AB4B3BD161 for ; Tue, 2 Feb 2021 17:05:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 340AA6842D; Tue, 2 Feb 2021 18:05:48 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="k/BVeZ/S"; dkim-atps=neutral Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C0DB60307 for ; Tue, 2 Feb 2021 18:05:46 +0100 (CET) Received: by mail-ed1-x52c.google.com with SMTP id d2so23768919edz.3 for ; Tue, 02 Feb 2021 09:05:46 -0800 (PST) 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=MRkQGwixRVDHJM7wFkYJttDisg7LFhYxpKvPiXZz7Mo=; b=k/BVeZ/S/R2P2740XILmx2tcQP4p9lB/Gmm7FzvHQA4qm9Cy87uzt5S7Q8x+Al39tw U7vI2JYyDUBKeVuYMmBMOdbY+r6gCK97SonRlxIOijO2V+XiaiG8gjeWigsfa7WWYedo BOkbyWUX8am/Tfe0QnqTGTaBZoiyHSkpIQtZlYk3RtcrrFChjRqpfPu0ApkVSKIPA8mm jw6GmD/bgjrcSbX/7ItY1xRe/eNxbSxvWsWeUPhMU9aLzjpZdRz8iPntEeEt/+ASQEsC ER5ny0b6GSVafFiKaZ2mUmdefQDyffW59kxAecd+olxtfUv2paCrC9YLJJvXQQjE2ncL nOfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MRkQGwixRVDHJM7wFkYJttDisg7LFhYxpKvPiXZz7Mo=; b=aSPB+vtyAh12GWnkh8R4IhRtQu3ppdLrQRkukPO6/NIxMkXOHT2HwYOzv1ctK24yOC bCBBg5LiLQUnY7wnKcVs1CxQF8yIr1V5uq4TyUbVd0kIw43E2zeQgwnbnBbO1CA+zd+U 7lDT7CEzZkUOHZSIzilg7R/HaZ3seMA2dauhkaDTwfxCELVAduTLvpw6iM+/XmOpqgYZ EVc6G+zKSBdC8yvdzd/zSYGn0BQSALc8vZi6hyrZVPkrZUCHW4aetRrS29/PpG9GRB5j s80KX+XXAV9NS0zyc7OlTh4GFcWReVW7x852sC6AjFQJxGEIFKQ0W/ldJUpujLlbT+VB i7Aw== X-Gm-Message-State: AOAM530NZMl3pjuvrvpena0WmQCOaQ3xbYmj1zkdeeLG6JogjskZ+Z3r ON72Ob/r68y5rWEw3siTsa2nIg9SWT+skF+B X-Google-Smtp-Source: ABdhPJyYPbeqFS/dDQ5wzzp5DzqPCi9CG2a75nQek2RFoRHY88pK5cdg8KdAvNxLXCWsNsvLLq6Alw== X-Received: by 2002:a50:c403:: with SMTP id v3mr6349363edf.217.1612285545455; Tue, 02 Feb 2021 09:05:45 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id u16sm9673314ejn.117.2021.02.02.09.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 09:05:44 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Feb 2021 17:05:37 +0000 Message-Id: <20210202170537.11699-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] ipa: raspberrypi: Warn when control algorithms are missing; do not fail 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Users are free to avoid loading certain control algorithms from the json tuning file if they wish, and this could mean that some libcamera controls will therefore not be available. Currently we don't have a good means of indicating which these are, therefore failing completely when an application tries to use one is unhelpful - it is better just to issue a warning. Note that once we can indicate this properly, applications should check for supported controls as this change may be reverted. Signed-off-by: David Plowman Reviewed-by: Kieran Bingham --- include/libcamera/ipa/raspberrypi.h | 10 +++- src/ipa/raspberrypi/raspberrypi.cpp | 86 ++++++++++++++++++++++++----- 2 files changed, 81 insertions(+), 15 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h index 5a943382..3500f7df 100644 --- a/include/libcamera/ipa/raspberrypi.h +++ b/include/libcamera/ipa/raspberrypi.h @@ -49,7 +49,15 @@ enum BufferMask { /* Size of the LS grid allocation. */ static constexpr unsigned int MaxLsGridSize = 32 << 10; -/* List of controls handled by the Raspberry Pi IPA */ +/* + * List of controls handled by the Raspberry Pi IPA + * + * \todo This list will need to be built dynamically from the control + * algorithms loaded by the json file, once this is supported. At that + * point applications should check first whether a control is supported, + * and the pipeline handler may be reverted so that it aborts when an + * unsupported control is encountered. + */ static const ControlInfoMap Controls = { { &controls::AeEnable, ControlInfo(false, true) }, { &controls::ExposureTime, ControlInfo(0, 999999) }, diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 681ab921..8048bb26 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -627,7 +627,12 @@ void IPARPi::queueRequest(const ControlList &controls) switch (ctrl.first) { case controls::AE_ENABLE: { RPiController::Algorithm *agc = controller_.GetAlgorithm("agc"); - ASSERT(agc); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set AE_ENABLE - no AGC algorithm"; + break; + } + if (ctrl.second.get() == false) agc->Pause(); else @@ -640,7 +645,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::EXPOSURE_TIME: { RPiController::AgcAlgorithm *agc = dynamic_cast( controller_.GetAlgorithm("agc")); - ASSERT(agc); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set EXPOSURE_TIME - no AGC algorithm"; + break; + } /* This expects units of micro-seconds. */ agc->SetFixedShutter(ctrl.second.get()); @@ -652,7 +661,12 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::ANALOGUE_GAIN: { RPiController::AgcAlgorithm *agc = dynamic_cast( controller_.GetAlgorithm("agc")); - ASSERT(agc); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set ANALOGUE_GAIN - no AGC algorithm"; + break; + } + agc->SetFixedAnalogueGain(ctrl.second.get()); libcameraMetadata_.set(controls::AnalogueGain, @@ -663,7 +677,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::AE_METERING_MODE: { RPiController::AgcAlgorithm *agc = dynamic_cast( controller_.GetAlgorithm("agc")); - ASSERT(agc); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set AE_METERING_MODE - no AGC algorithm"; + break; + } int32_t idx = ctrl.second.get(); if (MeteringModeTable.count(idx)) { @@ -679,7 +697,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::AE_CONSTRAINT_MODE: { RPiController::AgcAlgorithm *agc = dynamic_cast( controller_.GetAlgorithm("agc")); - ASSERT(agc); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set AE_CONSTRAINT_MODE - no AGC algorithm"; + break; + } int32_t idx = ctrl.second.get(); if (ConstraintModeTable.count(idx)) { @@ -695,7 +717,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::AE_EXPOSURE_MODE: { RPiController::AgcAlgorithm *agc = dynamic_cast( controller_.GetAlgorithm("agc")); - ASSERT(agc); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set AE_EXPOSURE_MODE - no AGC algorithm"; + break; + } int32_t idx = ctrl.second.get(); if (ExposureModeTable.count(idx)) { @@ -711,7 +737,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::EXPOSURE_VALUE: { RPiController::AgcAlgorithm *agc = dynamic_cast( controller_.GetAlgorithm("agc")); - ASSERT(agc); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set EXPOSURE_VALUE - no AGC algorithm"; + break; + } /* * The SetEv() method takes in a direct exposure multiplier. @@ -726,7 +756,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::AWB_ENABLE: { RPiController::Algorithm *awb = controller_.GetAlgorithm("awb"); - ASSERT(awb); + if (!awb) { + LOG(IPARPI, Warning) + << "Could not set AWB_ENABLE - no AWB algorithm"; + break; + } if (ctrl.second.get() == false) awb->Pause(); @@ -741,7 +775,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::AWB_MODE: { RPiController::AwbAlgorithm *awb = dynamic_cast( controller_.GetAlgorithm("awb")); - ASSERT(awb); + if (!awb) { + LOG(IPARPI, Warning) + << "Could not set AWB_MODE - no AWB algorithm"; + break; + } int32_t idx = ctrl.second.get(); if (AwbModeTable.count(idx)) { @@ -758,7 +796,11 @@ void IPARPi::queueRequest(const ControlList &controls) auto gains = ctrl.second.get>(); RPiController::AwbAlgorithm *awb = dynamic_cast( controller_.GetAlgorithm("awb")); - ASSERT(awb); + if (!awb) { + LOG(IPARPI, Warning) + << "Could not set COLOUR_GAINS - no AWB algorithm"; + break; + } awb->SetManualGains(gains[0], gains[1]); if (gains[0] != 0.0f && gains[1] != 0.0f) @@ -771,7 +813,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::BRIGHTNESS: { RPiController::ContrastAlgorithm *contrast = dynamic_cast( controller_.GetAlgorithm("contrast")); - ASSERT(contrast); + if (!contrast) { + LOG(IPARPI, Warning) + << "Could not set BRIGHTNESS - no contrast algorithm"; + break; + } contrast->SetBrightness(ctrl.second.get() * 65536); libcameraMetadata_.set(controls::Brightness, @@ -782,7 +828,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::CONTRAST: { RPiController::ContrastAlgorithm *contrast = dynamic_cast( controller_.GetAlgorithm("contrast")); - ASSERT(contrast); + if (!contrast) { + LOG(IPARPI, Warning) + << "Could not set CONTRAST - no contrast algorithm"; + break; + } contrast->SetContrast(ctrl.second.get()); libcameraMetadata_.set(controls::Contrast, @@ -793,7 +843,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::SATURATION: { RPiController::CcmAlgorithm *ccm = dynamic_cast( controller_.GetAlgorithm("ccm")); - ASSERT(ccm); + if (!ccm) { + LOG(IPARPI, Warning) + << "Could not set SATURATION - no ccm algorithm"; + break; + } ccm->SetSaturation(ctrl.second.get()); libcameraMetadata_.set(controls::Saturation, @@ -804,7 +858,11 @@ void IPARPi::queueRequest(const ControlList &controls) case controls::SHARPNESS: { RPiController::SharpenAlgorithm *sharpen = dynamic_cast( controller_.GetAlgorithm("sharpen")); - ASSERT(sharpen); + if (!sharpen) { + LOG(IPARPI, Warning) + << "Could not set SHARPNESS - no sharpen algorithm"; + break; + } sharpen->SetStrength(ctrl.second.get()); libcameraMetadata_.set(controls::Sharpness,