From patchwork Mon Jun 14 09:53:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12581 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 B2658C3218 for ; Mon, 14 Jun 2021 09:53:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EAFF46893A; Mon, 14 Jun 2021 11:53:48 +0200 (CEST) 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="OAPPAdz5"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 04A3D6892E for ; Mon, 14 Jun 2021 11:53:47 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id g204so11746411wmf.5 for ; Mon, 14 Jun 2021 02:53:47 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=kPuFk49pii5/tLsd+X1YpO60JWW5UTyY5zkbwfO6vXY=; b=OAPPAdz5P3/NNhMuA9iK/tzwOZ7p/i5nY6U++e8AxFzRxZg57gUuWyd6x3SQyz58kg Bw+rdbo7Q9F9/0WJ/5F2GDCNX7bdgGoNRFg2R0Bd3gQ0IySl9WeKfFhkHH1Wn+MBjR7z +9/31gOwdQk930n087Mz+uUYeJxkSF9cxYFVZfYdVPddjQpfvQRRJiAFvnNlMkcOqYpP K3xWofuUILDkiWXi2HX8HitQ1gDPLIuFNJYdKUFxu0rLK/VZb6qXAPQ13a1Ss2s26GSc wlNIez3205H4O8KiMQgSrcfnO5c3Qw7lEe1sF0WZWGyHxkHXBALeOWHVL7H5q4Dvxtyj JYRA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=kPuFk49pii5/tLsd+X1YpO60JWW5UTyY5zkbwfO6vXY=; b=V/BNthgHBnoZnnsCoYKbDwg3KgKqLZa/gVyfVXyeRhTOvYeznqmNGiLqb4srSELzGM u0lELBrYKzhO1RjrglpDs+o8MNqErbwsU07BE1nN+/8Ufj8i0kkbYrqShDOF06CkXspo HooXoevV2fRvcchCbAqbP1tpwHjtPqK/czmDtYAsolJpgd15EEBbYFDbbDLUMdZWfAy8 zCFQ2nNiG3n3dYotj42HXtBOh7s5kpnyhSl2A9Bj97vrSEIAZ9JpfJRihL50BAgBtsg+ h+TocUCMQqKQGMnYYta73bdsdjeI6gBaUamakrruHoMU4tsgewVGHGCeyhBj2SRDsUiF OTrQ== X-Gm-Message-State: AOAM532nptT2X+ocRVHov1oeJiLle6gJqArdQVuOqOWx6yY0d03qu7XD VLKEOcMkrrusb7HOKuHF/KoJ+tmpd9sL5A== X-Google-Smtp-Source: ABdhPJzj0+4a2MQHE9wPcwVMuRyThPkLT4y5H1fZyb7tHQEQdiRySytjCFDl0CCtpdZgpTAazNQrCw== X-Received: by 2002:a7b:c7c5:: with SMTP id z5mr15247797wmk.77.1623664426310; Mon, 14 Jun 2021 02:53:46 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:fd93:d554:2dff:83ca]) by smtp.gmail.com with ESMTPSA id c2sm19834891wmf.24.2021.06.14.02.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 02:53:45 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 14 Jun 2021 10:53:35 +0100 Message-Id: <20210614095340.3051816-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614095340.3051816-1-naush@raspberrypi.com> References: <20210614095340.3051816-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/6] ipa: raspberrypi: Non-functional formatting fixes to md_parser.hpp 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" Adjust source formatting to closer match libcamera guidelines: - Remove unused header files. - Switch to C style comments. - Add whitespace for readability. There are no functional changes in this commit. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/md_parser.hpp | 144 ++++++++++++++++++------------ 1 file changed, 85 insertions(+), 59 deletions(-) diff --git a/src/ipa/raspberrypi/md_parser.hpp b/src/ipa/raspberrypi/md_parser.hpp index 8e22b1d7ca43..86e0577614e0 100644 --- a/src/ipa/raspberrypi/md_parser.hpp +++ b/src/ipa/raspberrypi/md_parser.hpp @@ -6,75 +6,94 @@ */ #pragma once -#include - #include /* Camera metadata parser class. Usage as shown below. - -Setup: - -Usually the metadata parser will be made as part of the CamHelper class so -application code doesn't have to worry which to kind to instantiate. But for -the sake of example let's suppose we're parsing imx219 metadata. - -MdParser *parser = new MdParserImx219(); // for example -parser->SetBitsPerPixel(bpp); -parser->SetLineLengthBytes(pitch); -parser->SetNumLines(2); - -Note 1: if you don't know how many lines there are, the size of the input -buffer is used as a limit instead. - -Note 2: if you don't know the line length, you can leave the line length unset -(or set to zero) and the parser will hunt for the line start instead. - -Then on every frame: - -if (parser->Parse(buffer) != MdParser::OK) - much badness; -unsigned int exposure_lines, gain_code -if (parser->GetExposureLines(exposure_lines) != MdParser::OK) - exposure was not found; -if (parser->GetGainCode(parser, gain_code) != MdParser::OK) - gain code was not found; - -(Note that the CamHelper class converts to/from exposure lines and time, -and gain_code / actual gain.) - -If you suspect your embedded data may have changed its layout, change any line -lengths, number of lines, bits per pixel etc. that are different, and -then: - -parser->Reset(); - -before calling Parse again. */ + * + * Setup: + * + * Usually the metadata parser will be made as part of the CamHelper class so + * application code doesn't have to worry which to kind to instantiate. But for + * the sake of example let's suppose we're parsing imx219 metadata. + * + * MdParser *parser = new MdParserImx219(); // for example + * parser->SetBitsPerPixel(bpp); + * parser->SetLineLengthBytes(pitch); + * parser->SetNumLines(2); + * + * Note 1: if you don't know how many lines there are, the size of the input + * buffer is used as a limit instead. + * + * Note 2: if you don't know the line length, you can leave the line length unset + * (or set to zero) and the parser will hunt for the line start instead. + * + * Then on every frame: + * + * if (parser->Parse(buffer) != MdParser::OK) + * much badness; + * unsigned int exposure_lines, gain_code + * if (parser->GetExposureLines(exposure_lines) != MdParser::OK) + * exposure was not found; + * if (parser->GetGainCode(parser, gain_code) != MdParser::OK) + * gain code was not found; + * + * (Note that the CamHelper class converts to/from exposure lines and time, + * and gain_code / actual gain.) + * + * If you suspect your embedded data may have changed its layout, change any line + * lengths, number of lines, bits per pixel etc. that are different, and + * then: + * + * parser->Reset(); + * + * before calling Parse again. + */ namespace RPiController { -// Abstract base class from which other metadata parsers are derived. +/* Abstract base class from which other metadata parsers are derived. */ class MdParser { public: - // Parser status codes: - // OK - success - // NOTFOUND - value such as exposure or gain was not found - // ERROR - all other errors + /* + * Parser status codes: + * OK - success + * NOTFOUND - value such as exposure or gain was not found + * ERROR - all other errors + */ enum Status { OK = 0, NOTFOUND = 1, ERROR = 2 }; - MdParser() : reset_(true) {} + + MdParser() : reset_(true) + { + } + virtual ~MdParser() = default; - void Reset() { reset_ = true; } - void SetBitsPerPixel(int bpp) { bits_per_pixel_ = bpp; } - void SetNumLines(unsigned int num_lines) { num_lines_ = num_lines; } + + void Reset() + { + reset_ = true; + } + + void SetBitsPerPixel(int bpp) + { + bits_per_pixel_ = bpp; + } + + void SetNumLines(unsigned int num_lines) + { + num_lines_ = num_lines; + } + void SetLineLengthBytes(unsigned int num_bytes) { line_length_bytes_ = num_bytes; } + virtual Status Parse(libcamera::Span buffer) = 0; virtual Status GetExposureLines(unsigned int &lines) = 0; virtual Status GetGainCode(unsigned int &gain_code) = 0; @@ -87,22 +106,28 @@ protected: unsigned int buffer_size_bytes_; }; -// This isn't a full implementation of a metadata parser for SMIA sensors, -// however, it does provide the findRegs method which will prove useful and make -// it easier to implement parsers for other SMIA-like sensors (see -// md_parser_imx219.cpp for an example). +/* + * This isn't a full implementation of a metadata parser for SMIA sensors, + * however, it does provide the findRegs method which will prove useful and make + * it easier to implement parsers for other SMIA-like sensors (see + * md_parser_imx219.cpp for an example). + */ class MdParserSmia : public MdParser { public: - MdParserSmia() : MdParser() {} + MdParserSmia() : MdParser() + { + } protected: - // Note that error codes > 0 are regarded as non-fatal; codes < 0 - // indicate a bad data buffer. Status codes are: - // PARSE_OK - found all registers, much happiness - // MISSING_REGS - some registers found; should this be a hard error? - // The remaining codes are all hard errors. + /* + * Note that error codes > 0 are regarded as non-fatal; codes < 0 + * indicate a bad data buffer. Status codes are: + * PARSE_OK - found all registers, much happiness + * MISSING_REGS - some registers found; should this be a hard error? + * The remaining codes are all hard errors. + */ enum ParseStatus { PARSE_OK = 0, MISSING_REGS = 1, @@ -112,6 +137,7 @@ protected: BAD_LINE_END = -4, BAD_PADDING = -5 }; + ParseStatus findRegs(libcamera::Span buffer, uint32_t regs[], int offsets[], unsigned int num_regs); }; From patchwork Mon Jun 14 09:53:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12582 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 A8FA8C3218 for ; Mon, 14 Jun 2021 09:53:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D13D56892F; Mon, 14 Jun 2021 11:53:51 +0200 (CEST) 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="ndbKxKRB"; dkim-atps=neutral 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 4C8A668933 for ; Mon, 14 Jun 2021 11:53:47 +0200 (CEST) Received: by mail-wr1-x433.google.com with SMTP id c5so13820524wrq.9 for ; Mon, 14 Jun 2021 02:53:47 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=ifVD5IiwHvkcKKMT1rdm93U31ooE4K5nZEZrQlYCzcg=; b=ndbKxKRBg/iInp20v+RYGpJS8SPSoCqD1IZlbhgSgsDJxy7RFiELbbmB5mXqzuaoz0 InpHKYfKjiGLG2v5qYX/E+VYpuOA8/z3x4MljcB4SN/RdTwBCkO8UijBku3iWwM47KvA J4gqDe983s6njBhZwhnVf8CDgESZaElyU6W1hR/88fKiSCzmF4vER4LLEW+LO6LUm2P7 N6hkuvrpspsa0AgLMXRJ9nJJrHyXEzr2sVUPNXcrBLqtPvMUph1sQTpb9raOnB3tcNl6 KOgEBBpFAR/r9bc0nkp7PSAP775zGaiU2RS4ej7R6XtS/hAyJTFamZZaggYEmyeLuUyX f5vg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=ifVD5IiwHvkcKKMT1rdm93U31ooE4K5nZEZrQlYCzcg=; b=ZN3gCPyUygdD6Uh8YaP8QiRUXOFBYpVsyfifaN+Kr7D90NsI9i6JrlP1kBL0jTcpvs aYN8wFjtR4o6EEh/YT220MShB4JzJzVKgl0uCEDrhokiAoaD2wWKR80LLGC7oQUSWs2N McF0eu3dPs3X1WOvzkY249LVa7z8c8mRhQhivzOjkfxkTCQUysYh5vMAH9sGV98goYR2 OyICP+cTQpv46UKL5WidEFEc3aHmIgEH23/NgftPvVIvYmEYL3NRXous/QgD7USvHbdA V9puJ6Tg+A0J1giPdRDgdRgWnlP0QuapaCKLaeot9aZU7WxXFgmkiZyU3h5VwjfQeVYQ ruGw== X-Gm-Message-State: AOAM530hejHjI+wxHphTXJUfw5xbgh2OrZ2VI2cgBoxee30hMYRhZUEv ZzNSlMVv49IWV9mpbsnsmbvnbmr00xTJbA== X-Google-Smtp-Source: ABdhPJxHrbEDsWHYr5x6LLoyz3t48/FJwrOQQI9L8rzo/7pEhvkdJCykCG2EMCsrUPdjH/ydFrjYkg== X-Received: by 2002:adf:e7d0:: with SMTP id e16mr17372066wrn.202.1623664426749; Mon, 14 Jun 2021 02:53:46 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:fd93:d554:2dff:83ca]) by smtp.gmail.com with ESMTPSA id c2sm19834891wmf.24.2021.06.14.02.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 02:53:46 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 14 Jun 2021 10:53:36 +0100 Message-Id: <20210614095340.3051816-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614095340.3051816-1-naush@raspberrypi.com> References: <20210614095340.3051816-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/6] ipa: raspberrypi: Set default values for member variables of MdParser 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" Set some sensible default values for member variables of the MdParser class. Remove buffer_size_bytes_ along with some related asserts as this class now uses libcamera::Span for buffer handling, and buffer_size_bytes_ is unused. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper_imx219.cpp | 1 - src/ipa/raspberrypi/cam_helper_imx477.cpp | 1 - src/ipa/raspberrypi/md_parser.hpp | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp index e550fba62cde..ec218dce5456 100644 --- a/src/ipa/raspberrypi/cam_helper_imx219.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp @@ -128,7 +128,6 @@ MdParser::Status MdParserImx219::Parse(libcamera::Span buffer) * registers. */ assert(bits_per_pixel_); - assert(num_lines_ || buffer_size_bytes_); /* Need to be ordered */ uint32_t regs[3] = { GAIN_REG, EXPHI_REG, EXPLO_REG }; reg_offsets_[0] = reg_offsets_[1] = reg_offsets_[2] = -1; diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp index a4a58c15467d..25b36bce0dac 100644 --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp @@ -117,7 +117,6 @@ MdParser::Status MdParserImx477::Parse(libcamera::Span buffer) * registers. */ assert(bits_per_pixel_); - assert(num_lines_ || buffer_size_bytes_); /* Need to be ordered */ uint32_t regs[4] = { EXPHI_REG, diff --git a/src/ipa/raspberrypi/md_parser.hpp b/src/ipa/raspberrypi/md_parser.hpp index 86e0577614e0..25ba0e7c9400 100644 --- a/src/ipa/raspberrypi/md_parser.hpp +++ b/src/ipa/raspberrypi/md_parser.hpp @@ -68,7 +68,8 @@ public: ERROR = 2 }; - MdParser() : reset_(true) + MdParser() + : reset_(true), bits_per_pixel_(0), num_lines_(0), line_length_bytes_(0) { } @@ -103,7 +104,6 @@ protected: int bits_per_pixel_; unsigned int num_lines_; unsigned int line_length_bytes_; - unsigned int buffer_size_bytes_; }; /* From patchwork Mon Jun 14 09:53:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12585 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 BAEA2C3218 for ; Mon, 14 Jun 2021 09:53:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 439936892E; Mon, 14 Jun 2021 11:53:57 +0200 (CEST) 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="Tiivs/dr"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C6F2B6892E for ; Mon, 14 Jun 2021 11:53:48 +0200 (CEST) Received: by mail-wm1-x335.google.com with SMTP id v206-20020a1cded70000b02901a586d3fa23so12410517wmg.4 for ; Mon, 14 Jun 2021 02:53:48 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=34le5w+WAQXu2pLv13o0Ik/41cbpR/8uQ+Df8ylFK58=; b=Tiivs/drImWpcYRokGpJMJh+ASHdnFPi1HxVAet8eZU3uJxeqKcFuvsfMZZZzG+NcZ FGugGmyDnYqo3F68QBuNULrqHNFwHI2fhRmwMLub5teqAAAcmTHD4iamXaQZcReagEqG SlMBFhhRNlTod4hnqF+0IoLwgrgU6wway5z/ZRN8NexAuWhK6BdoC5hL8by51eJfQ7KV QcOdZ+Por3VJq/dAdyS5CmR8q/V9hLMYbPrKzI7ip1uVG387KAAxRZh4kRq0AG+/8zPi 9vpkPYWnD+Gbonm0L/h5L480hhkfV341Vgz+omwVsUIx2yvNpSJT4FYrsUgKPl3YJkTY ec7A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=34le5w+WAQXu2pLv13o0Ik/41cbpR/8uQ+Df8ylFK58=; b=pU7huVarDAR6Jia8GPEEWx5YUKFTysBHTp6Pi1AB8A4iyE95jyyjSaVqHKsVcTXmol yfJHOH8RATl+sd5O+ga3arjYAKASEeib53J1UKfpOm2g4a5XlLhtrm2WJnHQ4fXbeUJO f4vCCIXQCyILGsMKcf4Agl0S83ARG1RvatT7qZa7YZ74bDR7+xcMwa7sVTJgJIN3IxOF NG294XQYEv6m5Z38ciG6jVyJ1YSRZf5Agk2csMn74el04Q634NETEqbZOC3jpHhEM4sK A3pua4kxUrK3MKTtll+2vswJChGsFydWokMCQPcQB3bRKDmxT1/4ICdcxmHsrAZyBL3p uMaA== X-Gm-Message-State: AOAM530pXX/xmqu31xbeajA+J/5/mTP2zDJnboRCH/8plo956Pcx/6zp c16nVjN4JP0hkpeO2MxRCnecW9UMdEj0vg== X-Google-Smtp-Source: ABdhPJxtnlmAVvKnLbl5hwZQkx5H7iA14U9ghDCQXjfbl30BBpKmX6u7SH7T0APCrisFPTko0I5RxA== X-Received: by 2002:a1c:7918:: with SMTP id l24mr12625115wme.126.1623664428036; Mon, 14 Jun 2021 02:53:48 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:fd93:d554:2dff:83ca]) by smtp.gmail.com with ESMTPSA id c2sm19834891wmf.24.2021.06.14.02.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 02:53:47 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 14 Jun 2021 10:53:38 +0100 Message-Id: <20210614095340.3051816-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614095340.3051816-1-naush@raspberrypi.com> References: <20210614095340.3051816-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/6] ipa: raspberrypi: Non-functional formatting fixes to md_parser_smia.cpp 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" Adjust source formatting to closer match libcamera guidelines: - Switch to C style comments. - Adjust whitespace for readability. - Remove retcode local variable usage. There are no functional changes in this commit. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/md_parser_smia.cpp | 70 ++++++++++++++------------ 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/src/ipa/raspberrypi/md_parser_smia.cpp b/src/ipa/raspberrypi/md_parser_smia.cpp index 852a1d347d11..65ffbe00c76e 100644 --- a/src/ipa/raspberrypi/md_parser_smia.cpp +++ b/src/ipa/raspberrypi/md_parser_smia.cpp @@ -1,31 +1,32 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * Copyright (C) 2019-2021, Raspberry Pi (Trading) Limited * - * md_parser.cpp - image sensor metadata parsers + * md_parser_smia.cpp - SMIA specification based embedded data parser */ - #include #include -#include +#include #include "md_parser.hpp" using namespace RPiController; -// This function goes through the embedded data to find the offsets (not -// values!), in the data block, where the values of the given registers can -// subsequently be found. - -// Embedded data tag bytes, from Sony IMX219 datasheet but general to all SMIA -// sensors, I think. +/* + * This function goes through the embedded data to find the offsets (not + * values!), in the data block, where the values of the given registers can + * subsequently be found. + * + * Embedded data tag bytes, from Sony IMX219 datasheet but general to all SMIA + * sensors, I think. + */ -#define LINE_START 0x0a -#define LINE_END_TAG 0x07 -#define REG_HI_BITS 0xaa -#define REG_LOW_BITS 0xa5 -#define REG_VALUE 0x5a -#define REG_SKIP 0x55 +constexpr unsigned int LINE_START = 0x0a; +constexpr unsigned int LINE_END_TAG = 0x07; +constexpr unsigned int REG_HI_BITS = 0xaa; +constexpr unsigned int REG_LOW_BITS = 0xa5; +constexpr unsigned int REG_VALUE = 0x5a; +constexpr unsigned int REG_SKIP = 0x55; MdParserSmia::ParseStatus MdParserSmia::findRegs(libcamera::Span buffer, uint32_t regs[], int offsets[], @@ -36,12 +37,13 @@ MdParserSmia::ParseStatus MdParserSmia::findRegs(libcamera::Span if (buffer[0] != LINE_START) return NO_LINE_START; - unsigned int current_offset = 1; // after the LINE_START + unsigned int current_offset = 1; /* after the LINE_START */ unsigned int current_line_start = 0, current_line = 0; unsigned int reg_num = 0, first_reg = 0; - ParseStatus retcode = PARSE_OK; + while (1) { int tag = buffer[current_offset++]; + if ((bits_per_pixel_ == 10 && (current_offset + 1 - current_line_start) % 5 == 0) || (bits_per_pixel_ == 12 && @@ -49,34 +51,38 @@ MdParserSmia::ParseStatus MdParserSmia::findRegs(libcamera::Span if (buffer[current_offset++] != REG_SKIP) return BAD_DUMMY; } + int data_byte = buffer[current_offset++]; - //printf("Offset %u, tag 0x%02x data_byte 0x%02x\n", current_offset-1, tag, data_byte); + if (tag == LINE_END_TAG) { if (data_byte != LINE_END_TAG) return BAD_LINE_END; + if (num_lines_ && ++current_line == num_lines_) return MISSING_REGS; + if (line_length_bytes_) { - current_offset = - current_line_start + line_length_bytes_; - // Require whole line to be in the buffer (if buffer size set). + current_offset = current_line_start + line_length_bytes_; + + /* Require whole line to be in the buffer (if buffer size set). */ if (buffer.size() && - current_offset + line_length_bytes_ > - buffer.size()) + current_offset + line_length_bytes_ > buffer.size()) return MISSING_REGS; + if (buffer[current_offset] != LINE_START) return NO_LINE_START; } else { - // allow a zero line length to mean "hunt for the next line" + /* allow a zero line length to mean "hunt for the next line" */ while (buffer[current_offset] != LINE_START && current_offset < buffer.size()) current_offset++; + if (current_offset == buffer.size()) return NO_LINE_START; } - // inc current_offset to after LINE_START - current_line_start = - current_offset++; + + /* inc current_offset to after LINE_START */ + current_line_start = current_offset++; } else { if (tag == REG_HI_BITS) reg_num = (reg_num & 0xff) | (data_byte << 8); @@ -86,13 +92,13 @@ MdParserSmia::ParseStatus MdParserSmia::findRegs(libcamera::Span reg_num++; else if (tag == REG_VALUE) { while (reg_num >= - // assumes registers are in order... + /* assumes registers are in order... */ regs[first_reg]) { if (reg_num == regs[first_reg]) - offsets[first_reg] = - current_offset - 1; + offsets[first_reg] = current_offset - 1; + if (++first_reg == num_regs) - return retcode; + return PARSE_OK; } reg_num++; } else From patchwork Mon Jun 14 09:53:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12583 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 7721BC3218 for ; Mon, 14 Jun 2021 09:53:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1220568936; Mon, 14 Jun 2021 11:53:56 +0200 (CEST) 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="S93QUUwQ"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 13E066893C for ; Mon, 14 Jun 2021 11:53:49 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id k5-20020a05600c1c85b02901affeec3ef8so12627537wms.0 for ; Mon, 14 Jun 2021 02:53:49 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=XejH4KqE96/4XmZzclPo+84OiNylXyKa77noPloxPaY=; b=S93QUUwQfGMkrC746tPlkKvY9rYx0wsdHM1jT1B2upnwvi09QY07a/YTpuiFxPelKB Fs90bmxDeOPwz/t+SiNaxQipXzD2RkF9rjQrXH7VnoA2K5b/swbwqX5NG0iE9jAxIPRI MjJi+8sRYAicVrJExtTDzIpVluMwiceIMKd+v1fePDV0baROhyu18TuQxaJ4CvUyCxEB pGyqPjMTEhVul5MdAp8kY+USbepjjl3MeP2ivZZMcyNs2hVxpDWH3ZaMbrcQIP2aNagV T0vmyq2fQrnLJqKlgxE7Vpm/kltRXOLMZiNqY6Wxm5Dv3CA5tIA8Zep0o2HDKY1/Y8QF tOqA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=XejH4KqE96/4XmZzclPo+84OiNylXyKa77noPloxPaY=; b=TpbMfFavX+1Mvqd1x3uGJLrGy9Qro6ARIlPgzjmINoEA2pln0rkoVll8UCB9ePrru8 vdezWG/U8b+ryRYKHUUoq5exoCGBcOuGEtj/KLCt47/yMqlZADSYZX6/OfoslsYsrR4M s2keqVwYFsUzs1qqOaO2BPWoSlsut9SxP85z1sH2CHwBdg3NUO0Zrs3aEhJTezjovlxN gnz2754iQWduXGNFzPNRhMh8uC+DNZCF+Q5861bxQz+8y1WI90eUa2janEutIpGzq1fU d4mYI1wvS5IGqENifedb4lA0PwWnb3OLDbvVfpeMJYNO7oBH5x3k0SfY66DosYs2DM/f T6VQ== X-Gm-Message-State: AOAM5325pTJ2p42tXaj26oIBHiW8LSyvj/fxr9ANT+yKPovQ+bxMPG1M 2Kd1o0iNCA8jspAh8UUFI9znzfuDWLQJtw== X-Google-Smtp-Source: ABdhPJyeNmkx8fcd16wzfe4vOYJe4n9BZqAlTqeGXOYqlOTsuAh14tbILgt86T2lSndU5SbSfLM3fw== X-Received: by 2002:a7b:c853:: with SMTP id c19mr32219493wml.30.1623664428547; Mon, 14 Jun 2021 02:53:48 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:fd93:d554:2dff:83ca]) by smtp.gmail.com with ESMTPSA id c2sm19834891wmf.24.2021.06.14.02.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 02:53:48 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 14 Jun 2021 10:53:39 +0100 Message-Id: <20210614095340.3051816-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614095340.3051816-1-naush@raspberrypi.com> References: <20210614095340.3051816-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/6] ipa: raspberrypi: Embed the metadata parser in the sensor CamHelper classes 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" This avoids the need for any dynamic allocations and lifetime management. The base CamHelper class still accesses the parser through a pointer that is setup by the derived class constructor. Signed-off-by: Naushir Patuck --- src/ipa/raspberrypi/cam_helper.cpp | 5 ++--- src/ipa/raspberrypi/cam_helper.hpp | 2 +- src/ipa/raspberrypi/cam_helper_imx219.cpp | 9 +++++---- src/ipa/raspberrypi/cam_helper_imx290.cpp | 2 +- src/ipa/raspberrypi/cam_helper_imx477.cpp | 5 ++++- src/ipa/raspberrypi/cam_helper_ov5647.cpp | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index 062e94c4fef3..ab66e2ddef3e 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -40,15 +40,14 @@ CamHelper *CamHelper::Create(std::string const &cam_name) return nullptr; } -CamHelper::CamHelper(MdParser *parser, unsigned int frameIntegrationDiff) - : parser_(parser), initialized_(false), +CamHelper::CamHelper(unsigned int frameIntegrationDiff) + : parser_(nullptr), initialized_(false), frameIntegrationDiff_(frameIntegrationDiff) { } CamHelper::~CamHelper() { - delete parser_; } void CamHelper::Prepare(Span buffer, diff --git a/src/ipa/raspberrypi/cam_helper.hpp b/src/ipa/raspberrypi/cam_helper.hpp index f53f5c39b01c..460839079741 100644 --- a/src/ipa/raspberrypi/cam_helper.hpp +++ b/src/ipa/raspberrypi/cam_helper.hpp @@ -67,7 +67,7 @@ class CamHelper { public: static CamHelper *Create(std::string const &cam_name); - CamHelper(MdParser *parser, unsigned int frameIntegrationDiff); + CamHelper(unsigned int frameIntegrationDiff); virtual ~CamHelper(); void SetCameraMode(const CameraMode &mode); virtual void Prepare(libcamera::Span buffer, diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp index ec218dce5456..36dbe8cd941a 100644 --- a/src/ipa/raspberrypi/cam_helper_imx219.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp @@ -54,15 +54,16 @@ private: * in units of lines. */ static constexpr int frameIntegrationDiff = 4; + + MdParserImx219 imx219_parser; }; CamHelperImx219::CamHelperImx219() + : CamHelper(frameIntegrationDiff) +{ #if ENABLE_EMBEDDED_DATA - : CamHelper(new MdParserImx219(), frameIntegrationDiff) -#else - : CamHelper(nullptr, frameIntegrationDiff) + parser_ = &imx219_parser; #endif -{ } uint32_t CamHelperImx219::GainCode(double gain) const diff --git a/src/ipa/raspberrypi/cam_helper_imx290.cpp b/src/ipa/raspberrypi/cam_helper_imx290.cpp index 6f412e403f16..dea57b84bf0b 100644 --- a/src/ipa/raspberrypi/cam_helper_imx290.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx290.cpp @@ -30,7 +30,7 @@ private: }; CamHelperImx290::CamHelperImx290() - : CamHelper(nullptr, frameIntegrationDiff) + : CamHelper(frameIntegrationDiff) { } diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp index 25b36bce0dac..038a8583d311 100644 --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp @@ -47,11 +47,14 @@ private: * in units of lines. */ static constexpr int frameIntegrationDiff = 22; + + MdParserImx477 imx477_parser; }; CamHelperImx477::CamHelperImx477() - : CamHelper(new MdParserImx477(), frameIntegrationDiff) + : CamHelper(frameIntegrationDiff) { + parser_ = &imx477_parser; } uint32_t CamHelperImx477::GainCode(double gain) const diff --git a/src/ipa/raspberrypi/cam_helper_ov5647.cpp b/src/ipa/raspberrypi/cam_helper_ov5647.cpp index 12be6bf931a8..fff648279d2a 100644 --- a/src/ipa/raspberrypi/cam_helper_ov5647.cpp +++ b/src/ipa/raspberrypi/cam_helper_ov5647.cpp @@ -38,7 +38,7 @@ private: */ CamHelperOv5647::CamHelperOv5647() - : CamHelper(nullptr, frameIntegrationDiff) + : CamHelper(frameIntegrationDiff) { } From patchwork Mon Jun 14 09:53:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12584 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 2ADFCC3218 for ; Mon, 14 Jun 2021 09:53:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C8A1A68933; Mon, 14 Jun 2021 11:53:56 +0200 (CEST) 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="Dhk43McI"; dkim-atps=neutral Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3144768937 for ; Mon, 14 Jun 2021 11:53:50 +0200 (CEST) Received: by mail-wm1-x32b.google.com with SMTP id b205so7061152wmb.3 for ; Mon, 14 Jun 2021 02:53:50 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=zdn6EoWhiSuHC85PVxRu8OiYwIw3pJWhCuzsm/sYzZ8=; b=Dhk43McIElE50QB17wAX7E0cU12M8wLYzHmyUwNetylOSCA7dBS/yVf59byYAOxysq m0Lr26fV+PELrhQtoOvpbyUfwccvCmNkVxNEpE8ZsTnk+TLLNDEuGXsXVlGh0M/Mqt+a qJkE+YgYsDit79O4TB/VSFtgXYdJDuKskRRSJ1BJ+oviECsuFU6FuEKAMAw5bF/+J8Nd N6PldwmjFpl35BIeBJhNQpksVwnZah9nqmFx+nOxM1mYzKJVxWfxZhbxWIRPUWKwu9LM wS6r7NPnZ4kBD4py+P7ru/bcp0FAsZ+bQqsqX6NT9byivS/yq20M8j/Z6rhquSOjdWiM aTGA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=zdn6EoWhiSuHC85PVxRu8OiYwIw3pJWhCuzsm/sYzZ8=; b=j8vt9jwoy5ZFBSAXayT/AJpw3Bq2yYimvVNpeQkFCBkOmu+azEYxudC/lOpu2Nu+30 NCESp4cF2b/hTffh+Q1vfVgmSKNL8dmXZmgO39gwZlAt8s+1hSBGBp8Wz+XWAH0iDYvO Pb7NOw5RDDBIKWOTbOcY820DQ7JQvFPE+8hGlyQ86FdzCNaSlk8YFgnU0deeO9qofx2b 6uniH05N8DpTTuiaIgcLTC8QgMFnat+qwZMB/NsVCP5o7sYt99VtwEhxlQzOQEjA+SkL 77YjcEzp5AdXdiYvlXtkKKk3sXS5ZoG3b75in+EUJN5WryC8cPTw60WPcAsWsWVi0/cA Ujuw== X-Gm-Message-State: AOAM5320PWMc8OUy5rxmZTeUKR3WOG2/jGQi6NB9iI/Pm64soZJ1Bebh I94PLcyuOXg56Zq8TFh1uu8PxTho7h4Wlw== X-Google-Smtp-Source: ABdhPJz8abpU5A0xGM0NyYNg0CYbXLsMPeehknLPv/+0iHFJWL03hC1njrzb8qfILu0nyElGVX2CAQ== X-Received: by 2002:a1c:7210:: with SMTP id n16mr30886583wmc.75.1623664429324; Mon, 14 Jun 2021 02:53:49 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:fd93:d554:2dff:83ca]) by smtp.gmail.com with ESMTPSA id c2sm19834891wmf.24.2021.06.14.02.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 02:53:48 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 14 Jun 2021 10:53:40 +0100 Message-Id: <20210614095340.3051816-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614095340.3051816-1-naush@raspberrypi.com> References: <20210614095340.3051816-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/6] ipa: raspberrypi: Generalise the SMIA metadata parser 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" Instead of having each CamHelper subclass the MdParserSmia, change the implementation of MdParserSmia to be more generic. The MdParserSmia now gets given a list of registers to search for and helper functions are used to compute exposure lines and gain codes from these registers. Update the imx219 and imx477 CamHelpers by using this new mechanism. As a drive-by change, fixup a possible buffer overrun in the parsing code. Signed-off-by: Naushir Patuck --- src/ipa/raspberrypi/cam_helper_imx219.cpp | 117 ++++---------------- src/ipa/raspberrypi/cam_helper_imx477.cpp | 125 ++++------------------ src/ipa/raspberrypi/md_parser.hpp | 42 ++++++-- src/ipa/raspberrypi/md_parser_smia.cpp | 89 ++++++++++++--- 4 files changed, 153 insertions(+), 220 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp index 36dbe8cd941a..72c1042ad6be 100644 --- a/src/ipa/raspberrypi/cam_helper_imx219.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp @@ -23,21 +23,13 @@ using namespace RPiController; -/* Metadata parser implementation specific to Sony IMX219 sensors. */ - -class MdParserImx219 : public MdParserSmia -{ -public: - MdParserImx219(); - Status Parse(libcamera::Span buffer) override; - Status GetExposureLines(unsigned int &lines) override; - Status GetGainCode(unsigned int &gain_code) override; -private: - /* Offset of the register's value in the metadata block. */ - int reg_offsets_[3]; - /* Value of the register, once read from the metadata block. */ - int reg_values_[3]; -}; +/* + * We care about one gain register and a pair of exposure registers. Their I2C + * addresses from the Sony IMX219 datasheet: + */ +constexpr uint32_t gainReg = 0x157; +constexpr uint32_t expHiReg = 0x15A; +constexpr uint32_t expLoReg = 0x15B; class CamHelperImx219 : public CamHelper { @@ -55,11 +47,23 @@ private: */ static constexpr int frameIntegrationDiff = 4; - MdParserImx219 imx219_parser; + MdParserSmia imx219_parser; + + static uint32_t ParseExposureLines(const MdParserSmia::RegMap &map) + { + return map.at(expHiReg).value * 256 + map.at(expLoReg).value; + } + + static uint32_t ParseGainCode(const MdParserSmia::RegMap &map) + { + return map.at(gainReg).value; + } }; CamHelperImx219::CamHelperImx219() - : CamHelper(frameIntegrationDiff) + : CamHelper(frameIntegrationDiff), + imx219_parser({ expHiReg, expLoReg, gainReg }, + ParseGainCode, ParseExposureLines) { #if ENABLE_EMBEDDED_DATA parser_ = &imx219_parser; @@ -97,82 +101,3 @@ static CamHelper *Create() } static RegisterCamHelper reg("imx219", &Create); - -/* - * We care about one gain register and a pair of exposure registers. Their I2C - * addresses from the Sony IMX219 datasheet: - */ -#define GAIN_REG 0x157 -#define EXPHI_REG 0x15A -#define EXPLO_REG 0x15B - -/* - * Index of each into the reg_offsets and reg_values arrays. Must be in - * register address order. - */ -#define GAIN_INDEX 0 -#define EXPHI_INDEX 1 -#define EXPLO_INDEX 2 - -MdParserImx219::MdParserImx219() -{ - reg_offsets_[0] = reg_offsets_[1] = reg_offsets_[2] = -1; -} - -MdParser::Status MdParserImx219::Parse(libcamera::Span buffer) -{ - bool try_again = false; - - if (reset_) { - /* - * Search again through the metadata for the gain and exposure - * registers. - */ - assert(bits_per_pixel_); - /* Need to be ordered */ - uint32_t regs[3] = { GAIN_REG, EXPHI_REG, EXPLO_REG }; - reg_offsets_[0] = reg_offsets_[1] = reg_offsets_[2] = -1; - int ret = static_cast(findRegs(buffer, - regs, reg_offsets_, 3)); - /* - * > 0 means "worked partially but parse again next time", - * < 0 means "hard error". - */ - if (ret > 0) - try_again = true; - else if (ret < 0) - return ERROR; - } - - for (int i = 0; i < 3; i++) { - if (reg_offsets_[i] == -1) - continue; - - reg_values_[i] = buffer[reg_offsets_[i]]; - } - - /* Re-parse next time if we were unhappy in some way. */ - reset_ = try_again; - - return OK; -} - -MdParser::Status MdParserImx219::GetExposureLines(unsigned int &lines) -{ - if (reg_offsets_[EXPHI_INDEX] == -1 || reg_offsets_[EXPLO_INDEX] == -1) - return NOTFOUND; - - lines = reg_values_[EXPHI_INDEX] * 256 + reg_values_[EXPLO_INDEX]; - - return OK; -} - -MdParser::Status MdParserImx219::GetGainCode(unsigned int &gain_code) -{ - if (reg_offsets_[GAIN_INDEX] == -1) - return NOTFOUND; - - gain_code = reg_values_[GAIN_INDEX]; - - return OK; -} diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp index 038a8583d311..7a1100c25afc 100644 --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp @@ -15,21 +15,14 @@ using namespace RPiController; -/* Metadata parser implementation specific to Sony IMX477 sensors. */ - -class MdParserImx477 : public MdParserSmia -{ -public: - MdParserImx477(); - Status Parse(libcamera::Span buffer) override; - Status GetExposureLines(unsigned int &lines) override; - Status GetGainCode(unsigned int &gain_code) override; -private: - /* Offset of the register's value in the metadata block. */ - int reg_offsets_[4]; - /* Value of the register, once read from the metadata block. */ - int reg_values_[4]; -}; +/* + * We care about two gain registers and a pair of exposure registers. Their + * I2C addresses from the Sony IMX477 datasheet: + */ +constexpr uint32_t expHiReg = 0x0202; +constexpr uint32_t expLoReg = 0x0203; +constexpr uint32_t gainHiReg = 0x0204; +constexpr uint32_t gainLoReg = 0x0205; class CamHelperImx477 : public CamHelper { @@ -48,11 +41,23 @@ private: */ static constexpr int frameIntegrationDiff = 22; - MdParserImx477 imx477_parser; + MdParserSmia imx477_parser; + + static uint32_t ParseExposureLines(const MdParserSmia::RegMap &map) + { + return map.at(expHiReg).value * 256 + map.at(expLoReg).value; + } + + static uint32_t ParseGainCode(const MdParserSmia::RegMap &map) + { + return map.at(gainHiReg).value * 256 + map.at(gainLoReg).value; + } }; CamHelperImx477::CamHelperImx477() - : CamHelper(frameIntegrationDiff) + : CamHelper(frameIntegrationDiff), + imx477_parser({ expHiReg, expLoReg, gainHiReg, gainLoReg }, + ParseGainCode, ParseExposureLines) { parser_ = &imx477_parser; } @@ -86,89 +91,3 @@ static CamHelper *Create() } static RegisterCamHelper reg("imx477", &Create); - -/* - * We care about two gain registers and a pair of exposure registers. Their - * I2C addresses from the Sony IMX477 datasheet: - */ -#define EXPHI_REG 0x0202 -#define EXPLO_REG 0x0203 -#define GAINHI_REG 0x0204 -#define GAINLO_REG 0x0205 - -/* - * Index of each into the reg_offsets and reg_values arrays. Must be in register - * address order. - */ -#define EXPHI_INDEX 0 -#define EXPLO_INDEX 1 -#define GAINHI_INDEX 2 -#define GAINLO_INDEX 3 - -MdParserImx477::MdParserImx477() -{ - reg_offsets_[0] = reg_offsets_[1] = reg_offsets_[2] = reg_offsets_[3] = -1; -} - -MdParser::Status MdParserImx477::Parse(libcamera::Span buffer) -{ - bool try_again = false; - - if (reset_) { - /* - * Search again through the metadata for the gain and exposure - * registers. - */ - assert(bits_per_pixel_); - /* Need to be ordered */ - uint32_t regs[4] = { - EXPHI_REG, - EXPLO_REG, - GAINHI_REG, - GAINLO_REG - }; - reg_offsets_[0] = reg_offsets_[1] = reg_offsets_[2] = reg_offsets_[3] = -1; - int ret = static_cast(findRegs(buffer, - regs, reg_offsets_, 4)); - /* - * > 0 means "worked partially but parse again next time", - * < 0 means "hard error". - */ - if (ret > 0) - try_again = true; - else if (ret < 0) - return ERROR; - } - - for (int i = 0; i < 4; i++) { - if (reg_offsets_[i] == -1) - continue; - - reg_values_[i] = buffer[reg_offsets_[i]]; - } - - /* Re-parse next time if we were unhappy in some way. */ - reset_ = try_again; - - return OK; -} - -MdParser::Status MdParserImx477::GetExposureLines(unsigned int &lines) -{ - if (reg_offsets_[EXPHI_INDEX] == -1 || reg_offsets_[EXPLO_INDEX] == -1) - return NOTFOUND; - - lines = reg_values_[EXPHI_INDEX] * 256 + reg_values_[EXPLO_INDEX]; - - return OK; -} - -MdParser::Status MdParserImx477::GetGainCode(unsigned int &gain_code) -{ - if (reg_offsets_[GAINHI_INDEX] == -1 || reg_offsets_[GAINLO_INDEX] == -1) - return NOTFOUND; - - gain_code = reg_values_[GAINHI_INDEX] * 256 + reg_values_[GAINLO_INDEX]; - - return OK; -} diff --git a/src/ipa/raspberrypi/md_parser.hpp b/src/ipa/raspberrypi/md_parser.hpp index 25ba0e7c9400..6bbcdec0830b 100644 --- a/src/ipa/raspberrypi/md_parser.hpp +++ b/src/ipa/raspberrypi/md_parser.hpp @@ -6,6 +6,10 @@ */ #pragma once +#include +#include +#include + #include /* Camera metadata parser class. Usage as shown below. @@ -16,7 +20,8 @@ * application code doesn't have to worry which to kind to instantiate. But for * the sake of example let's suppose we're parsing imx219 metadata. * - * MdParser *parser = new MdParserImx219(); // for example + * MdParser *parser = new MdParserSmia({ expHiReg, expLoReg, gainReg }, + ParseGainCode, ParseExposureLines)); * parser->SetBitsPerPixel(bpp); * parser->SetLineLengthBytes(pitch); * parser->SetNumLines(2); @@ -113,14 +118,32 @@ protected: * md_parser_imx219.cpp for an example). */ -class MdParserSmia : public MdParser +class MdParserSmia final : public MdParser { public: - MdParserSmia() : MdParser() - { - } + struct Register { + Register() + : offset(0), value(0), found(false) + { + } + + uint32_t offset; + uint32_t value; + bool found; + }; -protected: + /* Maps register address to offset in the buffer. */ + using RegMap = std::map; + using GetFn = std::function; + + MdParserSmia(const std::vector ®s, GetFn gain_fn, + GetFn exposureFn); + + MdParser::Status Parse(libcamera::Span buffer) override; + Status GetExposureLines(unsigned int &lines) override; + Status GetGainCode(unsigned int &gain_code) override; + +private: /* * Note that error codes > 0 are regarded as non-fatal; codes < 0 * indicate a bad data buffer. Status codes are: @@ -138,8 +161,11 @@ protected: BAD_PADDING = -5 }; - ParseStatus findRegs(libcamera::Span buffer, uint32_t regs[], - int offsets[], unsigned int num_regs); + ParseStatus findRegs(libcamera::Span buffer); + + RegMap map_; + GetFn gain_fn_; + GetFn exposure_fn_; }; } // namespace RPi diff --git a/src/ipa/raspberrypi/md_parser_smia.cpp b/src/ipa/raspberrypi/md_parser_smia.cpp index 65ffbe00c76e..f4748dd535d0 100644 --- a/src/ipa/raspberrypi/md_parser_smia.cpp +++ b/src/ipa/raspberrypi/md_parser_smia.cpp @@ -8,9 +8,11 @@ #include #include +#include "libcamera/internal/log.h" #include "md_parser.hpp" using namespace RPiController; +using namespace libcamera; /* * This function goes through the embedded data to find the offsets (not @@ -28,18 +30,79 @@ constexpr unsigned int REG_LOW_BITS = 0xa5; constexpr unsigned int REG_VALUE = 0x5a; constexpr unsigned int REG_SKIP = 0x55; -MdParserSmia::ParseStatus MdParserSmia::findRegs(libcamera::Span buffer, - uint32_t regs[], int offsets[], - unsigned int num_regs) +MdParserSmia::MdParserSmia(const std::vector ®isters, + GetFn gain_fn, GetFn exposure_fn) + : gain_fn_(gain_fn), exposure_fn_(exposure_fn) { - assert(num_regs > 0); + for (auto r : registers) + map_[r] = {}; +} + +MdParser::Status MdParserSmia::Parse(libcamera::Span buffer) +{ + if (reset_) { + /* + * Search again through the metadata for the gain and exposure + * registers. + */ + ASSERT(bits_per_pixel_); + + ParseStatus ret = findRegs(buffer); + /* + * > 0 means "worked partially but parse again next time", + * < 0 means "hard error". + * + * In either case, we retry parsing on the next frame. + */ + if (ret != PARSE_OK) + return ERROR; + + reset_ = false; + } + + /* Populate the register values requested. */ + for (auto &kv : map_) { + Register ® = kv.second; + + if (!reg.found) { + reset_ = true; + return NOTFOUND; + } + + reg.value = buffer[reg.offset]; + } + + return OK; +} + +MdParser::Status MdParserSmia::GetExposureLines(unsigned int &lines) +{ + if (reset_) + return NOTFOUND; + + lines = exposure_fn_(map_); + return OK; +} + +MdParser::Status MdParserSmia::GetGainCode(unsigned int &gain_code) +{ + if (reset_) + return NOTFOUND; + + gain_code = gain_fn_(map_); + return OK; +} + +MdParserSmia::ParseStatus MdParserSmia::findRegs(libcamera::Span buffer) +{ + ASSERT(map_.size()); if (buffer[0] != LINE_START) return NO_LINE_START; unsigned int current_offset = 1; /* after the LINE_START */ unsigned int current_line_start = 0, current_line = 0; - unsigned int reg_num = 0, first_reg = 0; + unsigned int reg_num = 0, regs_done = 0; while (1) { int tag = buffer[current_offset++]; @@ -73,8 +136,8 @@ MdParserSmia::ParseStatus MdParserSmia::findRegs(libcamera::Span return NO_LINE_START; } else { /* allow a zero line length to mean "hunt for the next line" */ - while (buffer[current_offset] != LINE_START && - current_offset < buffer.size()) + while (current_offset < buffer.size() && + buffer[current_offset] != LINE_START) current_offset++; if (current_offset == buffer.size()) @@ -91,13 +154,13 @@ MdParserSmia::ParseStatus MdParserSmia::findRegs(libcamera::Span else if (tag == REG_SKIP) reg_num++; else if (tag == REG_VALUE) { - while (reg_num >= - /* assumes registers are in order... */ - regs[first_reg]) { - if (reg_num == regs[first_reg]) - offsets[first_reg] = current_offset - 1; + auto reg = map_.find(reg_num); + + if (reg != map_.end()) { + map_[reg_num].offset = current_offset - 1; + map_[reg_num].found = true; - if (++first_reg == num_regs) + if (++regs_done == map_.size()) return PARSE_OK; } reg_num++;