{"id":18760,"url":"https://patchwork.libcamera.org/api/patches/18760/?format=json","web_url":"https://patchwork.libcamera.org/patch/18760/","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":"<20230626143932.18888-1-naush@raspberrypi.com>","date":"2023-06-26T14:39:32","name":"[libcamera-devel,v2] ipa: rpi: imx296: Enable embedded data","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"2e3582551b68216de0dcf1d058c7e7b3de2d450d","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/18760/mbox/","series":[{"id":3937,"url":"https://patchwork.libcamera.org/api/series/3937/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3937","date":"2023-06-26T14:39:32","name":"[libcamera-devel,v2] ipa: rpi: imx296: Enable embedded data","version":2,"mbox":"https://patchwork.libcamera.org/series/3937/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18760/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18760/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 7AF87BE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 26 Jun 2023 14:39:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C76D7628BC;\n\tMon, 26 Jun 2023 16:39:42 +0200 (CEST)","from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com\n\t[IPv6:2a00:1450:4864:20::32c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 216D5628BB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 26 Jun 2023 16:39:41 +0200 (CEST)","by mail-wm1-x32c.google.com with SMTP id\n\t5b1f17b1804b1-3fa7512e599so42734965e9.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 26 Jun 2023 07:39:41 -0700 (PDT)","from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\ta10-20020a05600c224a00b003faef96ee78sm1740539wmm.33.2023.06.26.07.39.39\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 26 Jun 2023 07:39:39 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1687790382;\n\tbh=hXH/4526E4HB6etrfFtjgr1Bamw2gVBNCsVSBBiiI1Q=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=SkxW/iu8npPasp+OTFvcIUb8TF9kD1QaoBWzWqXFzG8fFj+y7MjiMYPenTdi8Fymp\n\t8M2ZVopOeg6QCz+IMbizdhaPPtS4cqUmK+dLcAVsMAxBo3fZJx8KI4cGMEwvLbM4Jf\n\t9BmO5CrXdnbrO49mGnanefN+YG0EAZW642UxpPcqapSkTMXgMP9sVQHQXwsfCZ+UGx\n\tAJzL/AeJNevWRbuWCep8xnVs1ppSgY6dnSneG0ScOqvr3nUaTNxvW4jLWx2XGBttY0\n\trDEeEmZU2OL+3lQJg6DpnqqmlJYDQq7+Cz4uTEcznDEaa3EXIWtG93683wpTLrCoZS\n\tjc7B2McNQfULQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1687790380; x=1690382380;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=srQSobLNFp4tpaFsvUikh1UEgwOsk04nj32HAQ8HttA=;\n\tb=nnQGh+nT7BmzeFl/fkC1z0y4VQcj4wJvCfLK3auDjXp5SDm7HhGsgAa+jxv+BdZLK9\n\t6MjH+aAVEOL8v9UMav62MC5VwgKm1M/ER8JAIFlNYlmGIhSLVUuN37GAY3zy4LohPV2h\n\tBNRzd/oIT3OC4ude5q1XrLZmNP5OJNXVj3655pgZ1Db/EarhU9znf5wBArFFaGDA4cqG\n\tVamdkbEqDFcqUngf88JhPnxeyyVaTiPMaXuOgTjwrXzQbLbUgKkK+x2jGTrN10R9WpE0\n\tVa7ekcJUaDau4jsBCB5FK7QndfUmU8HPzEnX2ElM+4Hl/tBS8iP5lZSxnVqztDDSuiUB\n\tkB5Q=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"nnQGh+nT\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1687790380; x=1690382380;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=srQSobLNFp4tpaFsvUikh1UEgwOsk04nj32HAQ8HttA=;\n\tb=jf+UBbEEA7H3AEUqMWEjwItwsuvRL52sq0OYz0hn0wCoaoOqV/KPwRaQmHfz38qeIt\n\tqzRQFLsZLbpldLeSB+mLjsmqUCkNRGlN7XfeEzkT4hRg3nerOmXEpDtlVsl4r+2me150\n\tipHITQ4HSYrpcIdv4pNC8dnEad7orjP63VS4RILi0z+80+ajCr8j71yHVW5/3vhUCyNV\n\tOK3BVf2BP9WMyD3YiKPckAPZ7wdAaiP2Y1tlOSMG/t81pqjqkwHGQaMLGmcKfjmnj27J\n\tGz6Of22N5E6HQB1eb0dCUZmexfx5PN7iya5o4MKc5At6y7s5kHeT85wDbjql5mKVG5eo\n\tG1fg==","X-Gm-Message-State":"AC+VfDzLjDsTKdvpYw2CdjZV+3e4VBnizq22iIIjQ3cFFLIKQDPARVyy\n\tQlXjXIkP17L0n3ASBV2JA+jfSntzZda+nOugj8zefA==","X-Google-Smtp-Source":"ACHHUZ5toog0PpIGSO0mK/6FVxpT14AKz6jPHesr2hYLDjviuvtid0yKjLMNBINYjlsAj7ifvz18xw==","X-Received":"by 2002:a7b:ca57:0:b0:3f9:b4a0:6062 with SMTP id\n\tm23-20020a7bca57000000b003f9b4a06062mr15467162wml.24.1687790380237; \n\tMon, 26 Jun 2023 07:39:40 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 26 Jun 2023 15:39:32 +0100","Message-Id":"<20230626143932.18888-1-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.34.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2] ipa: rpi: imx296: Enable embedded data","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 embedded data parsing for the imx296 sensor.\n\nHowever, the imx296 has a quirk where the embedded data is ahead by a\nsingle frame, i.e. embedded data in frame N corresponds to the image\ndata in frame N+1. So make a copy of the embedded data buffer stored in\nthe camera helper state, and use that copy in the next frame.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\nChanges since v1:\n- Replace the use of std::unique_ptr with std::vector<uint8_t>\n---\n src/ipa/rpi/cam_helper/cam_helper_imx296.cpp | 60 +++++++++++++++++++-\n 1 file changed, 59 insertions(+), 1 deletion(-)","diff":"diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\nindex ecb845e76e12..e84243704e5a 100644\n--- a/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n+++ b/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n@@ -7,7 +7,9 @@\n \n #include <algorithm>\n #include <cmath>\n+#include <string.h>\n #include <stddef.h>\n+#include <vector>\n \n #include \"cam_helper.h\"\n \n@@ -15,6 +17,17 @@ using namespace RPiController;\n using libcamera::utils::Duration;\n using namespace std::literals::chrono_literals;\n \n+constexpr uint32_t gainReg = 0x41ba;\n+constexpr uint32_t shsLoReg = 0x41b4;\n+constexpr uint32_t shsMidReg = 0x41b5;\n+constexpr uint32_t shsHiReg = 0x41b6;\n+constexpr uint32_t vmaxLoReg = 0x41cc;\n+constexpr uint32_t vmaxMidReg = 0x41cd;\n+constexpr uint32_t vmaxHiReg = 0x41ce;\n+constexpr uint32_t tempReg = 0x41da;\n+constexpr std::initializer_list<uint32_t> registerList =\n+\t{ gainReg, shsLoReg, shsMidReg, shsHiReg, vmaxLoReg, vmaxMidReg, vmaxHiReg, tempReg };\n+\n class CamHelperImx296 : public CamHelper\n {\n public:\n@@ -23,8 +36,12 @@ public:\n \tdouble gain(uint32_t gainCode) const override;\n \tuint32_t exposureLines(const Duration exposure, const Duration lineLength) const override;\n \tDuration exposure(uint32_t exposureLines, const Duration lineLength) const override;\n+\tvoid prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata) override;\n \tvoid getDelays(int &exposureDelay, int &gainDelay,\n \t\t       int &vblankDelay, int &hblankDelay) const override;\n+\tbool sensorEmbeddedDataPresent() const override;\n+\tvoid populateMetadata(const MdParser::RegisterMap &registers,\n+\t\t\t      Metadata &metadata) const override;\n \n private:\n \tstatic constexpr uint32_t minExposureLines = 1;\n@@ -36,10 +53,12 @@ private:\n \t * in units of lines.\n \t */\n \tstatic constexpr int frameIntegrationDiff = 4;\n+\n+\tstd::vector<uint8_t> lastEmbeddedBuffer_;\n };\n \n CamHelperImx296::CamHelperImx296()\n-\t: CamHelper(nullptr, frameIntegrationDiff)\n+\t: CamHelper(std::make_unique<MdParserSmia>(registerList), frameIntegrationDiff)\n {\n }\n \n@@ -66,6 +85,23 @@ Duration CamHelperImx296::exposure(uint32_t exposureLines,\n \treturn std::max<uint32_t>(minExposureLines, exposureLines) * timePerLine + 14.26us;\n }\n \n+void CamHelperImx296::prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata)\n+{\n+\t/*\n+\t * The imx296 embedded data is ahead by a single frame, i.e. embedded\n+\t * data in frame N corresponds to the image data in frame N+1. So make\n+\t * a copy of the embedded data buffer and use it as normal for the next\n+\t * frame.\n+\t */\n+\tCamHelper::prepare({ lastEmbeddedBuffer_.data(), lastEmbeddedBuffer_.size() },\n+\t\t\t   metadata);\n+\n+\tif (lastEmbeddedBuffer_.size() != buffer.size())\n+\t\tlastEmbeddedBuffer_.resize(buffer.size());\n+\n+\tmemcpy(lastEmbeddedBuffer_.data(), buffer.data(), buffer.size());\n+}\n+\n void CamHelperImx296::getDelays(int &exposureDelay, int &gainDelay,\n \t\t\t\tint &vblankDelay, int &hblankDelay) const\n {\n@@ -75,6 +111,28 @@ void CamHelperImx296::getDelays(int &exposureDelay, int &gainDelay,\n \thblankDelay = 2;\n }\n \n+bool CamHelperImx296::sensorEmbeddedDataPresent() const\n+{\n+\treturn true;\n+}\n+\n+void CamHelperImx296::populateMetadata(const MdParser::RegisterMap &registers,\n+\t\t\t\t       Metadata &metadata) const\n+{\n+\tuint32_t shs = registers.at(shsLoReg) + (registers.at(shsMidReg) << 8) +\n+\t\t       (registers.at(shsHiReg) << 16);\n+\tuint32_t vmax = registers.at(vmaxLoReg) + (registers.at(vmaxMidReg) << 8) +\n+\t\t\t(registers.at(vmaxHiReg) << 16);\n+\n+\tDeviceStatus deviceStatus;\n+\tdeviceStatus.lineLength = timePerLine;\n+\tdeviceStatus.frameLength = vmax;\n+\tdeviceStatus.shutterSpeed = exposure(vmax - shs, timePerLine);\n+\tdeviceStatus.analogueGain = gain(registers.at(gainReg));\n+\n+\tmetadata.set(\"device.status\", deviceStatus);\n+}\n+\n static CamHelper *create()\n {\n \treturn new CamHelperImx296();\n","prefixes":["libcamera-devel","v2"]}