summaryrefslogtreecommitdiff
path: root/src/ipa/raspberrypi/md_parser.hpp
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2021-06-29 11:45:00 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-06-30 23:16:18 +0300
commit579f55b1086db0d7df1608ad24513a673818f408 (patch)
treecda9f085220bd961ed8c36fd70e891860566d192 /src/ipa/raspberrypi/md_parser.hpp
parentd3ea8e78852ba91245fdb9069363c1149e99c3b0 (diff)
ipa: raspberrypi: Generalise the SMIA metadata parser
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. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/ipa/raspberrypi/md_parser.hpp')
-rw-r--r--src/ipa/raspberrypi/md_parser.hpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/ipa/raspberrypi/md_parser.hpp b/src/ipa/raspberrypi/md_parser.hpp
index 8497216f..e3e27385 100644
--- a/src/ipa/raspberrypi/md_parser.hpp
+++ b/src/ipa/raspberrypi/md_parser.hpp
@@ -6,6 +6,9 @@
*/
#pragma once
+#include <initializer_list>
+#include <map>
+#include <optional>
#include <stdint.h>
#include <libcamera/base/span.h>
@@ -19,7 +22,7 @@
* application code doesn't have to worry which 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 });
* parser->SetBitsPerPixel(bpp);
* parser->SetLineLengthBytes(pitch);
* parser->SetNumLines(2);
@@ -32,13 +35,11 @@
*
* Then on every frame:
*
- * if (parser->Parse(buffer) != MdParser::OK)
+ * RegisterMap registers;
+ * if (parser->Parse(buffer, registers) != 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;
+ * Metadata metadata;
+ * CamHelper::PopulateMetadata(registers, metadata);
*
* (Note that the CamHelper class converts to/from exposure lines and time,
* and gain_code / actual gain.)
@@ -59,6 +60,8 @@ namespace RPiController {
class MdParser
{
public:
+ using RegisterMap = std::map<uint32_t, uint32_t>;
+
/*
* Parser status codes:
* OK - success
@@ -98,9 +101,8 @@ public:
line_length_bytes_ = num_bytes;
}
- virtual Status Parse(libcamera::Span<const uint8_t> buffer) = 0;
- virtual Status GetExposureLines(unsigned int &lines) = 0;
- virtual Status GetGainCode(unsigned int &gain_code) = 0;
+ virtual Status Parse(libcamera::Span<const uint8_t> buffer,
+ RegisterMap &registers) = 0;
protected:
bool reset_;
@@ -116,14 +118,18 @@ protected:
* md_parser_imx219.cpp for an example).
*/
-class MdParserSmia : public MdParser
+class MdParserSmia final : public MdParser
{
public:
- MdParserSmia() : MdParser()
- {
- }
+ MdParserSmia(std::initializer_list<uint32_t> registerList);
+
+ MdParser::Status Parse(libcamera::Span<const uint8_t> buffer,
+ RegisterMap &registers) override;
+
+private:
+ /* Maps register address to offset in the buffer. */
+ using OffsetMap = std::map<uint32_t, std::optional<uint32_t>>;
-protected:
/*
* Note that error codes > 0 are regarded as non-fatal; codes < 0
* indicate a bad data buffer. Status codes are:
@@ -141,8 +147,9 @@ protected:
BAD_PADDING = -5
};
- ParseStatus findRegs(libcamera::Span<const uint8_t> buffer, uint32_t regs[],
- int offsets[], unsigned int num_regs);
+ ParseStatus findRegs(libcamera::Span<const uint8_t> buffer);
+
+ OffsetMap offsets_;
};
} // namespace RPi