{"id":18158,"url":"https://patchwork.libcamera.org/api/1.1/patches/18158/?format=json","web_url":"https://patchwork.libcamera.org/patch/18158/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20230119104544.9456-10-naush@raspberrypi.com>","date":"2023-01-19T10:45:39","name":"[libcamera-devel,v1,09/14] ipa: raspberrypi: Handle autofocus controls","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"75f17b9f30d386e1a66cc0280b055e01dff2e82d","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18158/mbox/","series":[{"id":3715,"url":"https://patchwork.libcamera.org/api/1.1/series/3715/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3715","date":"2023-01-19T10:45:30","name":"Raspberry Pi: Camera Module 3 support","version":1,"mbox":"https://patchwork.libcamera.org/series/3715/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18158/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18158/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 F1CF7BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Jan 2023 10:46:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 933E46260C;\n\tThu, 19 Jan 2023 11:46:06 +0100 (CET)","from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com\n\t[IPv6:2a00:1450:4864:20::32b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D6F5A625E7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Jan 2023 11:45:58 +0100 (CET)","by mail-wm1-x32b.google.com with SMTP id g10so1170170wmo.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Jan 2023 02:45:58 -0800 (PST)","from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tbe12-20020a05600c1e8c00b003db06224953sm5332029wmb.41.2023.01.19.02.45.57\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 19 Jan 2023 02:45:57 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1674125166;\n\tbh=FwWs23/yLeIYaKR2QHxyiUmReWahysMWlCP0J/P5NkU=;\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:Cc:\n\tFrom;\n\tb=JRiZzGwXWv2qAbyc0tdeU5AFfQJLl1jTvJJzoDUz4y33mUu5SdxfQMQHxk1MIvnvu\n\tGQrSQifwM/JwJ30GsyuQiSOLAil0XAxQGce3MhKtQuLbj8KB6Rh/GX5P5B6gWpHVha\n\ttB3PbI4IsdbSKvdY99p57Cz6mxkhdN9sveMZHhll8lHihrDCoFUE8mDwIhsV0C1rs0\n\tgHiyISunKLoxeuYUhiRBruZPrROkHFEnQIOZ/862SWLcZLbvTtGCzujwyca88C9hI+\n\tqO2fNZmvr/NuH4883rKK+4fsEevWOH94V1ds1EOxTIDVJIH3Yq0VF8g5BYm6WhxKMk\n\t/McvCMzYAZzbw==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=4UYvcAZ8aQ9iDqO1x3vQcdFJHQPnJdXnBpdMdVUYWW4=;\n\tb=EEk9IlBzSrAUuynjqdmXZStL/VN1S9bS7jo05JFuvIPSJ28xZAH/ebq97EZZ7z1vtD\n\t4lPy5EAhk5hj5bHFwjO4cybu4RcNG34hEQi7024Or3PqajRKaXAkGY80lu78Yuq4FVdk\n\tH5Aad89YRxj4Kg6Ga5JIQchsZnRNt4vfgfI+ckyUkIpLDqeBMZI7aauU+56M02ZLR6Ad\n\tWm7ZSk12Gh2hcfMzy0ZHE/LMDEqrgNXxunZbBohMdCxORhD80q/7sdFBP9AdJdvfo9aa\n\t6gZtcgKT1mPhUEfQh8Ibf66h3mVRsRj2cEqJTQPaTcpBFa5CNOv72J1cX/rnYPMyXQ2s\n\t25Sw=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"EEk9IlBz\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=4UYvcAZ8aQ9iDqO1x3vQcdFJHQPnJdXnBpdMdVUYWW4=;\n\tb=Lu4sJB0U0+9Dlxrn9f8YL2L94Gr9lnNCGyr5vFQ93kNFqHpCjjDgCu6j22fZCI8aLb\n\tu+KVp/sCj/0fzEI8x+YJGvdBReYbwwNjcLPTfYPx2RZ/xCC4r/nsYEMjGlLRqXP8SD49\n\tClDa8TvK6cUPL4PPHJdgUZTwmNvHeIDeVfxnVm71DsPPR8OQVIzkRO6D5d6AMd+XjbpE\n\tfYCre32Cov8Wj8bhzScUXDnEflzWPw2SRlwRyBt0bfeZK8+BfE0A424wmqfuIH8uBKN8\n\tuf5nxlEvUu/3dJousL1KI5bmADd1wU1FV3NfmbIs+tYTDQP0mf2gVINY+wGda0MRFv2D\n\t4vzA==","X-Gm-Message-State":"AFqh2koKKVihyP9DA0iTlbkUX+MaVu6p4eRqYoOUlJoni0ghSzs+pgdr\n\tIjRDRKC67dhAo4LOb74VCtam0mAospbM7rt6kyI=","X-Google-Smtp-Source":"AMrXdXs0IKF4BOO+aT3L9MXS0PXVEHNlFc2wI3oca5vX6vARKdwWnCrP7W+xJS/9THA9ou6yn9RVXA==","X-Received":"by 2002:a05:600c:539a:b0:3d9:ef72:190d with SMTP id\n\thg26-20020a05600c539a00b003d9ef72190dmr9705986wmb.19.1674125158292; \n\tThu, 19 Jan 2023 02:45:58 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 19 Jan 2023 10:45:39 +0000","Message-Id":"<20230119104544.9456-10-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20230119104544.9456-1-naush@raspberrypi.com>","References":"<20230119104544.9456-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1 09/14] ipa: raspberrypi: Handle\n\tautofocus controls","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>","Cc":"Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>\n\nAdd handlers for all autofocus related libcamera controls. Translate these\ncontrols to the RPiController autofocus algorithm API.\n\nSigned-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/raspberrypi.cpp | 144 ++++++++++++++++++++++++++++\n 1 file changed, 144 insertions(+)","diff":"diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 745c16f354ce..0eb55ed605b6 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -31,6 +31,7 @@\n \n #include \"libcamera/internal/mapped_framebuffer.h\"\n \n+#include \"af_algorithm.h\"\n #include \"agc_algorithm.h\"\n #include \"agc_status.h\"\n #include \"alsc_status.h\"\n@@ -732,11 +733,49 @@ static const std::map<int32_t, RPiController::DenoiseMode> DenoiseModeTable = {\n \t{ controls::draft::NoiseReductionModeZSL, RPiController::DenoiseMode::ColourHighQuality },\n };\n \n+static const std::map<int32_t, RPiController::AfAlgorithm::AfMode> AfModeTable = {\n+\t{ controls::AfModeManual, RPiController::AfAlgorithm::AfModeManual },\n+\t{ controls::AfModeAuto, RPiController::AfAlgorithm::AfModeAuto },\n+\t{ controls::AfModeContinuous, RPiController::AfAlgorithm::AfModeContinuous },\n+};\n+\n+static const std::map<int32_t, RPiController::AfAlgorithm::AfRange> AfRangeTable = {\n+\t{ controls::AfRangeNormal, RPiController::AfAlgorithm::AfRangeNormal },\n+\t{ controls::AfRangeMacro, RPiController::AfAlgorithm::AfRangeMacro },\n+\t{ controls::AfRangeFull, RPiController::AfAlgorithm::AfRangeFull },\n+};\n+\n+static const std::map<int32_t, RPiController::AfAlgorithm::AfPause> AfPauseTable = {\n+\t{ controls::AfPauseImmediate, RPiController::AfAlgorithm::AfPauseImmediate },\n+\t{ controls::AfPauseDeferred, RPiController::AfAlgorithm::AfPauseDeferred },\n+\t{ controls::AfPauseResume, RPiController::AfAlgorithm::AfPauseResume },\n+};\n+\n void IPARPi::queueRequest(const ControlList &controls)\n {\n+\tusing RPiController::AfAlgorithm;\n+\n \t/* Clear the return metadata buffer. */\n \tlibcameraMetadata_.clear();\n \n+\t/* Because some AF controls are mode-specific, handle AF mode change first. */\n+\tif (controls.contains(controls::AF_MODE)) {\n+\t\tAfAlgorithm *af = dynamic_cast<AfAlgorithm *>(controller_.getAlgorithm(\"af\"));\n+\t\tif (!af) {\n+\t\t\tLOG(IPARPI, Warning)\n+\t\t\t\t<< \"Could not set AF_MODE - no AF algorithm\";\n+\t\t}\n+\n+\t\tint32_t idx = controls.get(controls::AF_MODE).get<int32_t>();\n+\t\tauto mode = AfModeTable.find(idx);\n+\t\tif (mode == AfModeTable.end()) {\n+\t\t\tLOG(IPARPI, Error) << \"AF mode \" << idx\n+\t\t\t\t\t   << \" not recognised\";\n+\t\t} else\n+\t\t\taf->setMode(mode->second);\n+\t}\n+\n+\t/* Iterate over controls */\n \tfor (auto const &ctrl : controls) {\n \t\tLOG(IPARPI, Debug) << \"Request ctrl: \"\n \t\t\t\t   << controls::controls.at(ctrl.first)->name()\n@@ -1028,6 +1067,111 @@ void IPARPi::queueRequest(const ControlList &controls)\n \t\t\tbreak;\n \t\t}\n \n+\t\tcase controls::AF_MODE:\n+\t\t\tbreak; /* We already handled this one above */\n+\n+\t\tcase controls::AF_RANGE: {\n+\t\t\tAfAlgorithm *af = dynamic_cast<AfAlgorithm *>(controller_.getAlgorithm(\"af\"));\n+\t\t\tif (!af) {\n+\t\t\t\tLOG(IPARPI, Warning)\n+\t\t\t\t\t<< \"Could not set AF_RANGE - no focus algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tauto range = AfRangeTable.find(ctrl.second.get<int32_t>());\n+\t\t\tif (range == AfRangeTable.end()) {\n+\t\t\t\tLOG(IPARPI, Error) << \"AF range \" << ctrl.second.get<int32_t>()\n+\t\t\t\t\t\t   << \" not recognised\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\taf->setRange(range->second);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase controls::AF_SPEED: {\n+\t\t\tAfAlgorithm *af = dynamic_cast<AfAlgorithm *>(controller_.getAlgorithm(\"af\"));\n+\t\t\tif (!af) {\n+\t\t\t\tLOG(IPARPI, Warning)\n+\t\t\t\t\t<< \"Could not set AF_SPEED - no focus algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tAfAlgorithm::AfSpeed speed = ctrl.second.get<int32_t>() == controls::AfSpeedFast ?\n+\t\t\t\t\t\t      AfAlgorithm::AfSpeedFast : AfAlgorithm::AfSpeedNormal;\n+\t\t\taf->setSpeed(speed);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase controls::AF_METERING: {\n+\t\t\tAfAlgorithm *af = dynamic_cast<AfAlgorithm *>(controller_.getAlgorithm(\"af\"));\n+\t\t\tif (!af) {\n+\t\t\t\tLOG(IPARPI, Warning)\n+\t\t\t\t\t<< \"Could not set AF_METERING - no AF algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\taf->setMetering(ctrl.second.get<int32_t>() == controls::AfMeteringWindows);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase controls::AF_WINDOWS: {\n+\t\t\tAfAlgorithm *af = dynamic_cast<AfAlgorithm *>(controller_.getAlgorithm(\"af\"));\n+\t\t\tif (!af) {\n+\t\t\t\tLOG(IPARPI, Warning)\n+\t\t\t\t\t<< \"Could not set AF_WINDOWS - no AF algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\taf->setWindows(ctrl.second.get<Span<const Rectangle>>());\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase controls::AF_PAUSE: {\n+\t\t\tAfAlgorithm *af = dynamic_cast<AfAlgorithm *>(controller_.getAlgorithm(\"af\"));\n+\t\t\tif (!af || af->getMode() != AfAlgorithm::AfModeContinuous) {\n+\t\t\t\tLOG(IPARPI, Warning)\n+\t\t\t\t\t<< \"Could not set AF_PAUSE - no AF algorithm or not Continuous\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tauto pause = AfPauseTable.find(ctrl.second.get<int32_t>());\n+\t\t\tif (pause == AfPauseTable.end()) {\n+\t\t\t\tLOG(IPARPI, Error) << \"AF pause \" << ctrl.second.get<int32_t>()\n+\t\t\t\t\t\t   << \" not recognised\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\taf->pause(pause->second);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase controls::AF_TRIGGER: {\n+\t\t\tAfAlgorithm *af = dynamic_cast<AfAlgorithm *>(controller_.getAlgorithm(\"af\"));\n+\t\t\tif (!af || af->getMode() != AfAlgorithm::AfModeAuto) {\n+\t\t\t\tLOG(IPARPI, Warning)\n+\t\t\t\t\t<< \"Could not set AF_TRIGGER - no AF algorithm or not Auto\";\n+\t\t\t\tbreak;\n+\t\t\t} else {\n+\t\t\t\tif (ctrl.second.get<int32_t>() == controls::AfTriggerStart)\n+\t\t\t\t\taf->triggerScan();\n+\t\t\t\telse\n+\t\t\t\t\taf->cancelScan();\n+\t\t\t}\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase controls::LENS_POSITION: {\n+\t\t\tAfAlgorithm *af = dynamic_cast<AfAlgorithm *>(controller_.getAlgorithm(\"af\"));\n+\t\t\tif (af) {\n+\t\t\t\tint32_t hwpos;\n+\t\t\t\tif (af->setLensPosition(ctrl.second.get<float>(), &hwpos)) {\n+\t\t\t\t\tControlList lensCtrls(lensCtrls_);\n+\t\t\t\t\tlensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, hwpos);\n+\t\t\t\t\tsetLensControls.emit(lensCtrls);\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tLOG(IPARPI, Warning)\n+\t\t\t\t\t<< \"Could not set LENS_POSITION - no AF algorithm\";\n+\t\t\t}\n+\t\t\tbreak;\n+\t\t}\n+\n \t\tdefault:\n \t\t\tLOG(IPARPI, Warning)\n \t\t\t\t<< \"Ctrl \" << controls::controls.at(ctrl.first)->name()\n","prefixes":["libcamera-devel","v1","09/14"]}