ipa: raspberrypi: Make sensor embedded data parser use Span class

Improve MdParser::Parse() by taking a Span, pointing to const data
that it should not change, as its input buffer.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
David Plowman 2021-05-07 12:37:27 +01:00 committed by Laurent Pinchart
parent 414babb60b
commit df36fb4abb
4 changed files with 28 additions and 31 deletions

View file

@ -8,6 +8,8 @@
#include <stdint.h>
#include <libcamera/span.h>
/* Camera metadata parser class. Usage as shown below.
Setup:
@ -21,17 +23,15 @@ parser->SetBitsPerPixel(bpp);
parser->SetLineLengthBytes(pitch);
parser->SetNumLines(2);
Note 1: if you don't know how many lines there are, you can use SetBufferSize
instead to limit the total buffer size.
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. In this
case SetBufferSize *must* be used so that the parser won't run off the end of
the buffer.
(or set to zero) and the parser will hunt for the line start instead.
Then on every frame:
if (parser->Parse(data) != MdParser::OK)
if (parser->Parse(buffer) != MdParser::OK)
much badness;
unsigned int exposure_lines, gain_code
if (parser->GetExposureLines(exposure_lines) != MdParser::OK)
@ -75,11 +75,7 @@ public:
{
line_length_bytes_ = num_bytes;
}
void SetBufferSize(unsigned int num_bytes)
{
buffer_size_bytes_ = num_bytes;
}
virtual Status Parse(void *data) = 0;
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;
@ -116,7 +112,7 @@ protected:
BAD_LINE_END = -4,
BAD_PADDING = -5
};
ParseStatus findRegs(unsigned char *data, uint32_t regs[],
ParseStatus findRegs(libcamera::Span<const uint8_t> buffer, uint32_t regs[],
int offsets[], unsigned int num_regs);
};